// File: /workspace/github_cpp_makefile_star2_O1/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 0xe77c
leaq 0x38(%rsp), %rdi
xorps %xmm0, %xmm0
movups %xmm0, (%rdi)
xorl %eax, %eax
movq %rax, 0x10(%rdi)
leaq 0x60(%rsp), %rbx
movq %rbx, -0x10(%rbx)
movq %rax, -0x8(%rbx)
movb $0x0, (%rbx)
movq -0x28(%rbx), %rsi
callq 0xe77c
movl $0x122, 0x10(%rbx)      # imm = 0x122
movq 0x8(%r15), %rbx
cmpq 0x10(%r15), %rbx
je 0x84b1
cmpl $0x120, 0x40(%rbx)      # imm = 0x120
jne 0x84b1
movb $0x1, 0x7c(%r12)
leaq 0x34(%rsp), %rdx
leaq 0x30(%rsp), %rsi
movq %r12, %rdi
callq 0x8632
testb %al, %al
je 0x85bd
movq 0x8(%rsp), %rsi
movl $0x2, (%rsi)
movq 0x98(%r12), %rdi
movl 0x40(%rbx), %edx
callq 0x168f6
leaq 0x30(%rsp), %rsi
movq (%rsp), %rdi
callq 0xde50
leaq 0x20(%rsp), %r13
leaq 0x10(%rsp), %rbp
leaq 0x48(%rbx), %r14
movq %r12, %rdi
movl $0x134, %esi            # imm = 0x134
callq 0x5c0a
testb %al, %al
je 0x85bd
cmpq 0x10(%r15), %r14
je 0x8537
cmpl $0x120, 0x88(%rbx)      # imm = 0x120
jne 0x8531
movb $0x1, 0x7c(%r12)
jmp 0x8537
movb $0x0, 0x7c(%r12)
movq %r12, %rdi
leaq 0x30(%rsp), %rsi
leaq 0x34(%rsp), %rdx
callq 0x8632
testb %al, %al
jne 0x858f
movq %r13, 0x10(%rsp)
movq %rbp, %rdi
leaq 0x114c6(%rip), %rsi     # 0x19a22
leaq 0x11505(%rip), %rdx     # 0x19a68
callq 0x3c34
movq %r12, %rdi
movq %rbp, %rsi
callq 0x5696
movq 0x10(%rsp), %rdi
cmpq %r13, %rdi
je 0x8502
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x2200
jmp 0x8502
movq (%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0xde50
movq 0x98(%r12), %rdi
movl 0x88(%rbx), %edx
movq 0x8(%rsp), %rsi
callq 0x168f6
movq %r14, %rbx
jmp 0x84fe
movb $0x0, 0x7c(%r12)
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x85df
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x2200
leaq 0x38(%rsp), %rdi
callq 0xdea4
movb $0x1, %al
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x861c
jmp 0x861c
jmp 0x861c
movq %rax, %rbx
movq 0x10(%rsp), %rdi
cmpq %r13, %rdi
je 0x861f
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x2200
jmp 0x861f
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0xde7a
movq %rbx, %rdi
callq 0x2330
nop