// File: /workspace/github_cpp_makefile_star2_O3/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 $0x78, %rsp
movq %rcx, 0x8(%rsp)
movq %rdx, %r15
movq %rsi, %rax
movq %rdi, %r12
movq (%rsi), %rsi
movq %rax, (%rsp)
movq %rax, %rdi
callq 0xe698
leaq 0x38(%rsp), %rdi
xorl %eax, %eax
movq %rax, 0x10(%rdi)
xorps %xmm0, %xmm0
movups %xmm0, (%rdi)
leaq 0x60(%rsp), %rbx
movq %rbx, -0x10(%rbx)
movq %rax, -0x8(%rbx)
movb $0x0, (%rbx)
xorl %esi, %esi
callq 0xe698
movl $0x122, 0x10(%rbx)      # imm = 0x122
movq 0x8(%r15), %rbx
cmpq 0x10(%r15), %rbx
je 0x8417
cmpl $0x120, 0x40(%rbx)      # imm = 0x120
jne 0x8417
movb $0x1, 0x7c(%r12)
leaq 0x34(%rsp), %rdx
leaq 0x30(%rsp), %rsi
movq %r12, %rdi
callq 0x858a
testb %al, %al
je 0x8516
movq 0x8(%rsp), %rsi
movl $0x2, (%rsi)
movq 0x98(%r12), %rdi
movl 0x40(%rbx), %edx
callq 0x16810
leaq 0x30(%rsp), %rsi
movq (%rsp), %rdi
callq 0xdd50
leaq 0x20(%rsp), %r13
leaq 0x10(%rsp), %rbp
leaq 0x48(%rbx), %r14
movq %r12, %rdi
movl $0x134, %esi            # imm = 0x134
callq 0x5c08
testb %al, %al
je 0x8516
cmpq 0x10(%r15), %r14
je 0x8493
cmpl $0x120, 0x88(%rbx)      # imm = 0x120
sete 0x7c(%r12)
movq %r12, %rdi
leaq 0x30(%rsp), %rsi
leaq 0x34(%rsp), %rdx
callq 0x858a
testb %al, %al
jne 0x84e8
movq %r13, 0x10(%rsp)
movq %rbp, %rdi
leaq 0x1156a(%rip), %rsi     # 0x19a22
leaq 0x115a9(%rip), %rdx     # 0x19a68
callq 0x3c42
movq %r12, %rdi
movq %rbp, %rsi
callq 0x5694
movq 0x10(%rsp), %rdi
cmpq %r13, %rdi
je 0x8468
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x2200
jmp 0x8468
movq (%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0xdd50
movq 0x98(%r12), %rdi
movl 0x88(%rbx), %edx
movq 0x8(%rsp), %rsi
callq 0x16810
movq %r14, %rbx
jmp 0x8464
movb $0x0, 0x7c(%r12)
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x8538
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x2200
leaq 0x38(%rsp), %rdi
callq 0xdda4
movb $0x1, %al
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x8575
jmp 0x8575
jmp 0x8575
movq %rax, %rbx
movq 0x10(%rsp), %rdi
cmpq %r13, %rdi
je 0x8578
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x2200
jmp 0x8578
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0xdd7a
movq %rbx, %rdi
callq 0x2330