// File: 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
movq %rsp, %rbp
subq $0x1f0, %rsp            # imm = 0x1F0
movb %r8b, %al
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
andb $0x1, %cl
movb %cl, -0x21(%rbp)
andb $0x1, %al
movb %al, -0x22(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x1c0(%rbp)
movq 0x80(%rax), %rsi
leaq -0x50(%rbp), %rdi
callq 0x3130
movq -0x1c0(%rbp), %rdi
movl $0x139, %esi            # imm = 0x139
callq 0x9300
movb %al, -0x1b5(%rbp)
jmp 0x10599
movb -0x1b5(%rbp), %al
testb $0x1, %al
jne 0x105a8
jmp 0x109f5
movq -0x1c0(%rbp), %rdi
leaq -0x28(%rbp), %rsi
leaq -0x2c(%rbp), %rdx
callq 0x104e0
movb %al, -0x1c1(%rbp)
jmp 0x105c4
movb -0x1c1(%rbp), %al
testb $0x1, %al
jne 0x105d3
jmp 0x10894
testb $0x1, -0x21(%rbp)
je 0x106af
movq -0x18(%rbp), %rax
cmpl $0x10c, (%rax)          # imm = 0x10C
je 0x105f5
movq -0x18(%rbp), %rax
cmpl $0x10a, (%rax)          # imm = 0x10A
jne 0x1060f
cmpl $0x10c, -0x28(%rbp)     # imm = 0x10C
je 0x106ad
cmpl $0x10a, -0x28(%rbp)     # imm = 0x10A
je 0x106ad
leaq -0x81(%rbp), %rdi
movq %rdi, -0x1d0(%rbp)
callq 0x3430
movq -0x1d0(%rbp), %rdx
leaq 0x160f0(%rip), %rsi     # 0x26720
leaq -0x80(%rbp), %rdi
callq 0x62d0
jmp 0x1063b
movq -0x1c0(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x9060
jmp 0x1064d
leaq -0x80(%rbp), %rdi
callq 0x31a0
leaq -0x81(%rbp), %rdi
callq 0x32e0
movb $0x0, -0x21(%rbp)
jmp 0x106ad
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x10a1a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x1069c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x31a0
leaq -0x81(%rbp), %rdi
callq 0x32e0
jmp 0x10a1a
jmp 0x106af
testb $0x1, -0x22(%rbp)
je 0x1088f
movq -0x20(%rbp), %rax
movl (%rax), %eax
cmpl -0x2c(%rbp), %eax
je 0x1087c
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
je 0x1087c
cmpl $0x0, -0x2c(%rbp)
je 0x1087c
movq -0x20(%rbp), %rax
movl (%rax), %esi
leaq -0x128(%rbp), %rdi
callq 0x123d0
jmp 0x106f3
leaq 0x1607a(%rip), %rsi     # 0x26774
leaq -0x108(%rbp), %rdi
leaq -0x128(%rbp), %rdx
callq 0x12380
jmp 0x1070f
leaq 0x15f38(%rip), %rdx     # 0x2664e
leaq -0xe8(%rbp), %rdi
leaq -0x108(%rbp), %rsi
callq 0x12330
jmp 0x1072b
movl -0x2c(%rbp), %esi
leaq -0x148(%rbp), %rdi
callq 0x123d0
jmp 0x1073c
leaq -0xc8(%rbp), %rdi
leaq -0xe8(%rbp), %rsi
leaq -0x148(%rbp), %rdx
callq 0x12990
jmp 0x10758
leaq 0x16013(%rip), %rdx     # 0x26772
leaq -0xa8(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x12330
jmp 0x10774
movq -0x1c0(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x9060
jmp 0x10789
leaq -0xa8(%rbp), %rdi
callq 0x31a0
leaq -0xc8(%rbp), %rdi
callq 0x31a0
leaq -0x148(%rbp), %rdi
callq 0x31a0
leaq -0xe8(%rbp), %rdi
callq 0x31a0
leaq -0x108(%rbp), %rdi
callq 0x31a0
leaq -0x128(%rbp), %rdi
callq 0x31a0
movb $0x0, -0x22(%rbp)
jmp 0x1088d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x1086b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x1085f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x10853
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x10847
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x1083b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x31a0
leaq -0xc8(%rbp), %rdi
callq 0x31a0
leaq -0x148(%rbp), %rdi
callq 0x31a0
leaq -0xe8(%rbp), %rdi
callq 0x31a0
leaq -0x108(%rbp), %rdi
callq 0x31a0
leaq -0x128(%rbp), %rdi
callq 0x31a0
jmp 0x10a1a
cmpl $0x0, -0x2c(%rbp)
je 0x1088b
movl -0x2c(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
jmp 0x1088d
jmp 0x1088f
jmp 0x10931
leaq -0x169(%rbp), %rdi
movq %rdi, -0x1d8(%rbp)
callq 0x3430
movq -0x1d8(%rbp), %rdx
leaq 0x15ed6(%rip), %rsi     # 0x2678b
leaq -0x168(%rbp), %rdi
callq 0x62d0
jmp 0x108c3
movq -0x1c0(%rbp), %rdi
leaq -0x168(%rbp), %rsi
callq 0x9060
jmp 0x108d8
leaq -0x168(%rbp), %rdi
callq 0x31a0
leaq -0x169(%rbp), %rdi
callq 0x32e0
movb $0x0, -0x21(%rbp)
movb $0x0, -0x22(%rbp)
jmp 0x10931
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x10920
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x168(%rbp), %rdi
callq 0x31a0
leaq -0x169(%rbp), %rdi
callq 0x32e0
jmp 0x10a1a
movq -0x1c0(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movzbl -0x22(%rbp), %r8d
movzbl -0x21(%rbp), %ecx
andl $0x1, %ecx
andl $0x1, %r8d
callq 0x10540
jmp 0x10957
movq -0x1c0(%rbp), %rax
movq 0x98(%rax), %rax
movq %rax, -0x1e0(%rbp)
leaq -0x1b0(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x3130
jmp 0x1097e
movq -0x1e0(%rbp), %rsi
movq -0x20(%rbp), %rax
movl (%rax), %ecx
movl -0x2c(%rbp), %r8d
movq -0x18(%rbp), %rax
movl (%rax), %r9d
movl -0x28(%rbp), %edx
movq %rsp, %rax
movl %edx, (%rax)
leaq -0x190(%rbp), %rdi
leaq -0x1b0(%rbp), %rdx
callq 0x1abf0
jmp 0x109b3
leaq -0x190(%rbp), %rdi
callq 0x31a0
leaq -0x1b0(%rbp), %rdi
callq 0x31a0
movb $0x1, -0x1(%rbp)
movl $0x1, -0x1b4(%rbp)
jmp 0x10a03
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x1b0(%rbp), %rdi
callq 0x31a0
jmp 0x10a1a
movb $0x0, -0x1(%rbp)
movl $0x1, -0x1b4(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x31a0
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x1f0, %rsp            # imm = 0x1F0
popq %rbp
retq
leaq -0x50(%rbp), %rdi
callq 0x31a0
movq -0x58(%rbp), %rdi
callq 0x3420
nopl (%rax)