// File: /workspace/github_cpp_makefile_star2_O2/AndrewAlbert[P]Compiler-Theory/SourceCode/parser.cpp
// Function: Parser::ArgumentList(std::vector<scopeValue, std::allocator<scopeValue>>&, scopeValue, int&)
bool Parser::ArgumentList(vector<scopeValue> &list, scopeValue procValue, int &offset){
	//create vector<scopeValue> where all argument list information will be stored and later returned by the function
	list.clear();

	/* argEntry variable will contain argument information about expression type and size. 
	 * All arguments will have an empty arguments vector and have their paramType = TYPE_PARAM_NULL
	 * The procedure call, when checking these arguments, will not compare the paramType value against the declared values */
	scopeValue argEntry;
	argEntry.arguments.clear();
	argEntry.paramType = TYPE_PARAM_NULL;

	//For each comma-separated expression, store the type and size values, in the order encountered, in the 'list' vector
	vector<scopeValue>::iterator it = procValue.arguments.begin();
	if( it != procValue.arguments.end() ){
		if( it->paramType == TYPE_PARAM_OUT) outArg = true;
	}
	
	if( Expression(argEntry.type, argEntry.size) ){
		// GEN: add arguments from register to correct frame
		
		offset = 2;
		generator->pushArgument(offset, it->paramType);
		++it;
		
		list.push_back(argEntry);
		while( CheckToken(T_COMMA) ){
			if( it != procValue.arguments.end() ){
				if( it->paramType == TYPE_PARAM_OUT ){
					outArg = true;
				}
				else outArg = false;
			}
			if( Expression(argEntry.type, argEntry.size) ){
				list.push_back(argEntry);
				// Add arguments from register to correct frame
				generator->pushArgument(offset, it->paramType);
				++it;
			}
			else ReportError("expected another argument after ',' in argument list of procedure call");
		}
	}
	outArg = false;
	return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rcx, 0x18(%rsp)
movq %rdx, %r14
movq %rdi, %r15
movq %rsi, 0x10(%rsp)
movq %rsi, %rdi
callq 0x97b2
leaq 0x28(%rsp), %rdi
andq $0x0, 0x10(%rdi)
xorps %xmm0, %xmm0
movups %xmm0, (%rdi)
leaq 0x50(%rsp), %rbx
movq %rbx, -0x10(%rbx)
andq $0x0, -0x8(%rbx)
movb $0x0, (%rbx)
callq 0x97b2
movl $0x122, 0x10(%rbx)      # imm = 0x122
movq 0x8(%r14), %r13
cmpq 0x10(%r14), %r13
je 0x6397
cmpl $0x120, 0x40(%r13)      # imm = 0x120
jne 0x6397
movb $0x1, 0x7c(%r15)
leaq 0x24(%rsp), %rdx
leaq 0x20(%rsp), %rsi
movq %r15, %rdi
callq 0x64cc
testb %al, %al
je 0x647e
movq 0x18(%rsp), %rsi
movl $0x2, (%rsi)
movq 0x98(%r15), %rdi
movl 0x40(%r13), %edx
callq 0xf096
leaq 0x20(%rsp), %rsi
movq 0x10(%rsp), %rdi
callq 0x97ba
leaq 0x20(%rsp), %rbp
leaq 0x68(%rsp), %r12
leaq 0x48(%r13), %rbx
movq %r15, %rdi
movl $0x134, %esi            # imm = 0x134
callq 0x49b0
testb %al, %al
je 0x647e
cmpq 0x10(%r14), %rbx
je 0x6414
cmpl $0x120, 0x88(%r13) # imm = 0x120
sete 0x7c(%r15)
movq %r15, %rdi
movq %rbp, %rsi
leaq 0x24(%rsp), %rdx
callq 0x64cc
testb %al, %al
jne 0x6451
movq %r12, %rdi
leaq 0xb5f0(%rip), %rsi      # 0x11a22
leaq 0xf(%rsp), %rdx
callq 0x36b8
movq %r15, %rdi
movq %r12, %rsi
callq 0x47e0
movq %r12, %rdi
callq 0x20f0
jmp 0x63e9
movq 0x10(%rsp), %rdi
movq %rbp, %rsi
callq 0x97ba
movq 0x98(%r15), %rdi
movl 0x88(%r13), %edx
movq 0x18(%rsp), %rsi
callq 0xf096
movq %rbx, %r13
jmp 0x63e5
movb $0x0, 0x7c(%r15)
leaq 0x20(%rsp), %rdi
callq 0x9836
movb $0x1, %al
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x64b6
jmp 0x64b6
jmp 0x64b6
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
callq 0x20f0
jmp 0x64b9
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x9836
movq %rbx, %rdi
callq 0x2310
nop