// File: /workspace/github_cpp_makefile_star2_O2/AndrewAlbert[P]Compiler-Theory/SourceCode/parser.cpp
// Function: Parser::RelationPrime(int&, int&, bool, bool)
bool Parser::RelationPrime(int &inputType, int &inputSize, bool catchTypeError, bool catchSizeError){
	//Type and size of relation being compared to.
	int termType, termSize;

	//get relationsal op to pass to the codegenerator evaluation stack
	string op = token->ascii;
	
	if (CheckToken(T_COMPARE)){
		//Get next term, otherwise report missing term error.
		if( Term(termType, termSize) ){
			if(catchTypeError){
				//Ensure both terms are of type integer or bool. The two types can be compared against each other.
				if( ((inputType != TYPE_BOOL) && (inputType != TYPE_INTEGER)) || ((termType != TYPE_BOOL) && (termType != TYPE_INTEGER)) ){
					ReportError("Relational operators are only valid for terms of type bool or integers '0' and '1'.");
					catchTypeError = false;
				}
			}
			if(catchSizeError){
				//Ensure compatible sizes are used.
				if( (inputSize != termSize) && ( (inputSize != 0) && (termSize != 0) ) ){
					ReportError("Expected term of size " + to_string(inputSize) + ", but found one of size " + to_string(termSize) + ".");
					catchSizeError = false;
				}
				//Assign termSize to inputSize if termSize is non-zero.
				else if(termSize != 0) inputSize = termSize;
			}
		}
		else{
			ReportError("Expected term after relational operator.");
			catchTypeError = false;
			catchSizeError = false;
		}
		//Check for another relational operator and term.
		RelationPrime(inputType, inputSize, catchTypeError, catchSizeError);
		
		//evaluate relation expression and push to the codegenerator evaluation stack
		generator->evalExpr( op, inputSize, termSize, inputType, termType );
		
		return true;
	}
	else return false;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x178, %rsp            # imm = 0x178
movl %r8d, %ebp
movl %ecx, %r13d
movq %rdx, %r15
movq %rsi, %r14
movq %rdi, %r12
movq 0x80(%rdi), %rsi
leaq 0x138(%rsp), %rdi
callq 0x2270
movq %r12, %rdi
movl $0x139, %esi            # imm = 0x139
callq 0x49b0
movl %eax, %ebx
testb %al, %al
je 0x87b0
leaq 0x14(%rsp), %rsi
leaq 0x10(%rsp), %rdx
movq %r12, %rdi
callq 0x8504
testb %al, %al
je 0x8710
testb %r13b, %r13b
je 0x8606
movl (%r14), %eax
cmpl $0x10c, %eax            # imm = 0x10C
je 0x85bb
cmpl $0x10a, %eax            # imm = 0x10A
jne 0x85d0
movb $0x1, %r13b
movl 0x14(%rsp), %eax
cmpl $0x10a, %eax            # imm = 0x10A
je 0x8609
cmpl $0x10c, %eax            # imm = 0x10C
je 0x8609
leaq 0x9e83(%rip), %rsi      # 0x1245a
leaq 0x118(%rsp), %rdi
leaq 0x18(%rsp), %rdx
callq 0x36b8
leaq 0x118(%rsp), %rsi
movq %r12, %rdi
callq 0x47e0
leaq 0x118(%rsp), %rdi
callq 0x20f0
xorl %r13d, %r13d
testb %bpl, %bpl
je 0x8740
movl (%r15), %esi
movl 0x10(%rsp), %ecx
cmpl %ecx, %esi
je 0x87d1
testl %esi, %esi
sete %al
testl %ecx, %ecx
sete %dl
orb %al, %dl
jne 0x87d1
leaq 0x98(%rsp), %rdi
callq 0x96b3
leaq 0x9e67(%rip), %rsi      # 0x124ae
leaq 0xb8(%rsp), %rdi
leaq 0x98(%rsp), %rdx
callq 0x968f
leaq 0x9d25(%rip), %rdx      # 0x12388
leaq 0xd8(%rsp), %rdi
leaq 0xb8(%rsp), %rsi
callq 0x9670
movl 0x10(%rsp), %esi
leaq 0x78(%rsp), %rdi
callq 0x96b3
leaq 0x18(%rsp), %rdi
leaq 0xd8(%rsp), %rsi
leaq 0x78(%rsp), %rdx
callq 0x9871
leaq 0x9e08(%rip), %rdx      # 0x124ac
leaq 0xf8(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x9670
leaq 0xf8(%rsp), %rsi
movq %r12, %rdi
callq 0x47e0
leaq 0xf8(%rsp), %rdi
callq 0x20f0
leaq 0x18(%rsp), %rdi
callq 0x20f0
leaq 0x78(%rsp), %rdi
callq 0x20f0
leaq 0xd8(%rsp), %rdi
callq 0x20f0
leaq 0xb8(%rsp), %rdi
callq 0x20f0
leaq 0x98(%rsp), %rdi
callq 0x20f0
jmp 0x8740
leaq 0x9dae(%rip), %rsi      # 0x124c5
leaq 0x58(%rsp), %rdi
leaq 0x18(%rsp), %rdx
callq 0x36b8
leaq 0x58(%rsp), %rsi
movq %r12, %rdi
callq 0x47e0
leaq 0x58(%rsp), %rdi
callq 0x20f0
xorl %r13d, %r13d
xorl %eax, %eax
movzbl %r13b, %ecx
movzbl %al, %r8d
movq %r12, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x8540
movq 0x98(%r12), %r12
leaq 0x38(%rsp), %rdi
leaq 0x138(%rsp), %rsi
callq 0x2270
movl (%r15), %ecx
movl 0x10(%rsp), %r8d
movl (%r14), %r9d
movl 0x14(%rsp), %eax
movl %eax, (%rsp)
leaq 0x158(%rsp), %rdi
leaq 0x38(%rsp), %rdx
movq %r12, %rsi
callq 0xcbbe
leaq 0x158(%rsp), %rdi
callq 0x20f0
leaq 0x38(%rsp), %rdi
callq 0x20f0
leaq 0x138(%rsp), %rdi
callq 0x20f0
movl %ebx, %eax
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movb $0x1, %al
testl %ecx, %ecx
je 0x8742
movl %ecx, (%r15)
jmp 0x8742
movq %rax, %rbx
leaq 0xf8(%rsp), %rdi
callq 0x20f0
jmp 0x87f8
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x20f0
jmp 0x8807
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
callq 0x20f0
jmp 0x8816
movq %rax, %rbx
leaq 0xd8(%rsp), %rdi
callq 0x20f0
jmp 0x8828
movq %rax, %rbx
leaq 0xb8(%rsp), %rdi
callq 0x20f0
leaq 0x98(%rsp), %rdi
jmp 0x8869
movq %rax, %rbx
jmp 0x8835
jmp 0x8870
movq %rax, %rbx
leaq 0x118(%rsp), %rdi
jmp 0x8869
jmp 0x8870
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
jmp 0x8869
jmp 0x8870
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x20f0
jmp 0x8873
movq %rax, %rbx
leaq 0x138(%rsp), %rdi
callq 0x20f0
movq %rbx, %rdi
callq 0x2310