// File: /workspace/github_cpp_makefile_star2_O3/AndrewAlbert[P]Compiler-Theory/SourceCode/parser.cpp
// Function: Parser::ProcedureBody()
bool Parser::ProcedureBody(){
	bool resyncEnabled = true;
	bool procDec = false;
	//get symbol declarations for next procedure
	while(true){
		while( Declaration(procDec) ){
			if(procDec){
				if( !CheckToken(T_SEMICOLON) ) ReportWarning("expected ';' after procedure declaration in procedure");
			}
			else if( !CheckToken(T_SEMICOLON) ) ReportLineError("expected ';' after variable declaration in procedure", true);
		}
		
		// GEN: set the procedure's FP and SP in the program body after all declarations have been made
		// Each procedure declaration added its bytes to the frame size so this is the max size
		int frameSize = Scopes->getFrameSize();
		generator->setProcedurePointers(frameSize);
		
		//get statements for procedure body
		if( CheckToken(T_BEGIN) ){
			resyncEnabled = true;
			while(true){
				while( Statement() ){
					if( !CheckToken(T_SEMICOLON) ) ReportLineError("expected ';' after statement in procedure",true);
				}
				if( CheckToken(T_END) ){

					// Add label for procedure end and return
					string labelEnd;
					labelEnd = generator->newLabel("Procedure_End");
					generator->placeLabel( labelEnd );
					generator->ProcedureReturn();

					if( CheckToken(T_PROCEDURE) ) return true;
					else{
						ReportError("expected 'end procedure' at end of procedure declaration");
						return true;
					}
				}
				else if(resyncEnabled){
					resyncEnabled = false;
					ReportLineError("Bad line. Expected Statement or 'end' reserved keyword in procedure body.");
				}
				else{
					ReportFatalError("expected 'end procedure' at end of procedure declaration");
					return false;
				}
			}
		}
		else if(resyncEnabled){
			resyncEnabled = false;
			ReportLineError("Bad line. Expected Declaration or 'begin' reserved keyword in procedure body.");
		}
		else{
			ReportFatalError("Parser resync failed. Couldn't find a valid declaration or the 'begin reserved keyword in procedure body.");
			return false;
		}
		
	}

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x188, %rsp            # imm = 0x188
movq %rdi, %rbx
leaq 0x3(%rsp), %r14
movb $0x0, (%r14)
leaq 0xf8(%rsp), %rbp
leaq 0x118(%rsp), %r15
movb $0x1, %al
leaq 0x58(%rsp), %r13
movl %eax, 0x4(%rsp)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x6b10
testb %al, %al
je 0x77e9
movq %r13, %r12
movb 0x3(%rsp), %r13b
movq %rbx, %rdi
movl $0x12c, %esi            # imm = 0x12C
callq 0x5c08
cmpb $0x1, %r13b
jne 0x7788
testb %al, %al
movq %r12, %r13
jne 0x7710
movq %r15, 0x108(%rsp)
leaq 0x108(%rsp), %r12
movq %r12, %rdi
leaq 0x11cdc(%rip), %rsi     # 0x1943b
leaq 0x11d0a(%rip), %rdx     # 0x19470
callq 0x3c42
movq %rbx, %rdi
movq %r12, %rsi
callq 0x4388
movq 0x108(%rsp), %rdi
movq %r15, %rax
cmpq %r15, %rdi
jne 0x77d9
jmp 0x7710
testb %al, %al
movq %r12, %r13
jne 0x7710
movq %rbp, 0xe8(%rsp)
leaq 0xe8(%rsp), %r12
movq %r12, %rdi
leaq 0x11cc8(%rip), %rsi     # 0x19471
leaq 0x11cf5(%rip), %rdx     # 0x194a5
callq 0x3c42
movq %rbx, %rdi
movq %r12, %rsi
movl $0x1, %edx
callq 0x4e96
movq 0xe8(%rsp), %rdi
movq %rbp, %rax
cmpq %rbp, %rdi
je 0x7710
movq (%rax), %rsi
incq %rsi
callq 0x2200
jmp 0x7710
movq 0x90(%rbx), %rdi
callq 0x101ba
movq 0x98(%rbx), %rdi
movl %eax, %esi
callq 0x15fe8
movq %rbx, %rdi
movl $0x103, %esi            # imm = 0x103
callq 0x5c08
testb %al, %al
jne 0x7873
testb $0x1, 0x4(%rsp)
je 0x7b12
movq %r13, 0x48(%rsp)
leaq 0x48(%rsp), %r12
movq %r12, %rdi
leaq 0x12082(%rip), %rsi     # 0x198b5
leaq 0x120c8(%rip), %rdx     # 0x19902
callq 0x3c42
movq %rbx, %rdi
movq %r12, %rsi
movl $0x1, %edx
callq 0x4e96
movq 0x48(%rsp), %rdi
xorl %eax, %eax
cmpq %r13, %rdi
je 0x770c
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x2200
xorl %eax, %eax
jmp 0x770c
leaq 0x38(%rsp), %r13
movb $0x1, %al
leaq 0x11f79(%rip), %r14     # 0x197fa
leaq 0x11f9b(%rip), %rbp     # 0x19823
leaq 0x28(%rsp), %r12
movl %eax, 0x4(%rsp)
movq %rbx, %rdi
callq 0x6efe
movq %rbx, %rdi
testb %al, %al
je 0x78ea
movl $0x12c, %esi            # imm = 0x12C
callq 0x5c08
testb %al, %al
jne 0x7891
movq %r13, 0x28(%rsp)
movq %r12, %rdi
movq %r14, %rsi
movq %rbp, %rdx
callq 0x3c42
movq %rbx, %rdi
movq %r12, %rsi
movl $0x1, %edx
callq 0x4e96
movq 0x28(%rsp), %rdi
cmpq %r13, %rdi
je 0x7891
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x2200
jmp 0x7891
movl $0x104, %esi            # imm = 0x104
callq 0x5c08
testb %al, %al
jne 0x796d
testb $0x1, 0x4(%rsp)
je 0x7b47
movq %r13, %r12
movq %r14, %r15
leaq 0x78(%rsp), %r13
movq %r13, 0x68(%rsp)
leaq 0x68(%rsp), %r14
movq %r14, %rdi
leaq 0x11f49(%rip), %rsi     # 0x1986b
leaq 0x11f8b(%rip), %rdx     # 0x198b4
callq 0x3c42
movq %rbx, %rdi
movq %r14, %rsi
movl $0x1, %edx
callq 0x4e96
movq 0x68(%rsp), %rdi
xorl %eax, %eax
cmpq %r13, %rdi
movq %r15, %r14
movq %r12, %r13
leaq 0x28(%rsp), %r12
je 0x788d
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x2200
xorl %eax, %eax
jmp 0x788d
leaq 0x18(%rsp), %r15
movq %r15, -0x10(%r15)
movq $0x0, -0x8(%r15)
movb $0x0, (%r15)
movq 0x98(%rbx), %r14
leaq 0xd8(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x11e87(%rip), %rsi     # 0x19824
leaq 0x11e8d(%rip), %rdx     # 0x19831
leaq 0xc8(%rsp), %rdi
callq 0x3c42
leaq 0x168(%rsp), %rdi
leaq 0xc8(%rsp), %rdx
movq %r14, %rsi
callq 0x15d26
leaq 0x8(%rsp), %rdi
leaq 0x168(%rsp), %r14
movq %r14, %rsi
callq 0x2270
movq (%r14), %rdi
leaq 0x178(%rsp), %rax
cmpq %rax, %rdi
je 0x79fe
movq 0x178(%rsp), %rsi
incq %rsi
callq 0x2200
movq 0xc8(%rsp), %rdi
cmpq %r12, %rdi
je 0x7a1b
movq 0xd8(%rsp), %rsi
incq %rsi
callq 0x2200
movq 0x98(%rbx), %r14
leaq 0xb8(%rsp), %r12
movq %r12, -0x10(%r12)
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
addq %rsi, %rdx
leaq 0xa8(%rsp), %rdi
callq 0x3bac
leaq 0xa8(%rsp), %rsi
movq %r14, %rdi
callq 0x15fc6
movq 0xa8(%rsp), %rdi
cmpq %r12, %rdi
je 0x7a76
movq 0xb8(%rsp), %rsi
incq %rsi
callq 0x2200
movq 0x98(%rbx), %rdi
callq 0x1650c
movq %rbx, %rdi
movl $0x106, %esi            # imm = 0x106
callq 0x5c08
testb %al, %al
jne 0x7ae7
leaq 0x98(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x11d8c(%rip), %rsi     # 0x19832
leaq 0x11dbd(%rip), %rdx     # 0x1986a
leaq 0x88(%rsp), %rdi
callq 0x3c42
leaq 0x88(%rsp), %rsi
movq %rbx, %rdi
callq 0x5694
movq 0x88(%rsp), %rdi
cmpq %r14, %rdi
je 0x7ae7
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x2200
movq 0x8(%rsp), %rdi
cmpq %r15, %rdi
je 0x7afe
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x2200
movb $0x1, %al
addq $0x188, %rsp            # imm = 0x188
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x138(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x11dde(%rip), %rsi     # 0x19903
leaq 0x11e40(%rip), %rdx     # 0x1996c
leaq 0x128(%rsp), %r14
movq %r14, %rdi
callq 0x3c42
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4a02
leaq 0x158(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x11cd8(%rip), %rsi     # 0x19832
leaq 0x11d09(%rip), %rdx     # 0x1986a
leaq 0x148(%rsp), %r14
movq %r14, %rdi
callq 0x3c42
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4a02
movq %rax, %rbx
movq 0x88(%rsp), %rdi
cmpq %r14, %rdi
je 0x7bd9
movq 0x98(%rsp), %rsi
jmp 0x7bca
jmp 0x7bd6
movq %rax, %rbx
movq 0xa8(%rsp), %rdi
cmpq %r12, %rdi
je 0x7bd9
movq 0xb8(%rsp), %rsi
jmp 0x7bca
movq %rax, %rbx
movq 0xc8(%rsp), %rdi
cmpq %r12, %rdi
je 0x7bd9
movq 0xd8(%rsp), %rsi
incq %rsi
callq 0x2200
jmp 0x7bd9
jmp 0x7bd6
movq %rax, %rbx
movq 0x8(%rsp), %rdi
cmpq %r15, %rdi
je 0x7ca6
movq 0x18(%rsp), %rsi
jmp 0x7c9e
movq %rax, %rbx
movq 0x148(%rsp), %rdi
cmpq %r15, %rdi
je 0x7ca6
movq 0x158(%rsp), %rsi
jmp 0x7c9e
movq %rax, %rbx
movq 0x68(%rsp), %rdi
cmpq %r13, %rdi
je 0x7ca6
movq 0x78(%rsp), %rsi
jmp 0x7c9e
movq %rax, %rbx
movq 0x128(%rsp), %rdi
cmpq %r15, %rdi
je 0x7ca6
movq 0x138(%rsp), %rsi
jmp 0x7c9e
movq %rax, %rbx
movq 0x48(%rsp), %rdi
cmpq %r13, %rdi
je 0x7ca6
movq 0x58(%rsp), %rsi
jmp 0x7c9e
movq %rax, %rbx
movq 0xe8(%rsp), %rdi
cmpq %rbp, %rdi
je 0x7ca6
movq 0xf8(%rsp), %rsi
jmp 0x7c9e
movq %rax, %rbx
movq 0x108(%rsp), %rdi
cmpq %r15, %rdi
je 0x7ca6
movq 0x118(%rsp), %rsi
jmp 0x7c9e
movq %rax, %rbx
movq 0x28(%rsp), %rdi
cmpq %r13, %rdi
je 0x7ca6
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x2200
movq %rbx, %rdi
callq 0x2330