// File: 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
movq %rsp, %rbp
subq $0x270, %rsp            # imm = 0x270
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x200(%rbp)
movb $0x1, -0x11(%rbp)
movb $0x0, -0x12(%rbp)
jmp 0xb754
movq -0x200(%rbp), %rdi
leaq -0x12(%rbp), %rsi
callq 0xa8b0
testb $0x1, %al
jne 0xb76d
jmp 0xb8ba
testb $0x1, -0x12(%rbp)
je 0xb815
movq -0x200(%rbp), %rdi
movl $0x12c, %esi            # imm = 0x12C
callq 0x9300
testb $0x1, %al
jne 0xb810
leaq -0x39(%rbp), %rdi
movq %rdi, -0x208(%rbp)
callq 0x3430
movq -0x208(%rbp), %rdx
leaq 0x19f0b(%rip), %rsi     # 0x256b9
leaq -0x38(%rbp), %rdi
callq 0x62d0
jmp 0xb7b9
movq -0x200(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x8510
jmp 0xb7cb
leaq -0x38(%rbp), %rdi
callq 0x31a0
leaq -0x39(%rbp), %rdi
callq 0x32e0
jmp 0xb810
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0xb802
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x31a0
leaq -0x39(%rbp), %rdi
callq 0x32e0
jmp 0xbf03
jmp 0xb8b5
movq -0x200(%rbp), %rdi
movl $0x12c, %esi            # imm = 0x12C
callq 0x9300
testb $0x1, %al
jne 0xb8b3
leaq -0x71(%rbp), %rdi
movq %rdi, -0x210(%rbp)
callq 0x3430
movq -0x210(%rbp), %rdx
leaq 0x19ea3(%rip), %rsi     # 0x256ef
leaq -0x70(%rbp), %rdi
callq 0x62d0
jmp 0xb857
movq -0x200(%rbp), %rdi
leaq -0x70(%rbp), %rsi
movl $0x1, %edx
callq 0x8b50
jmp 0xb86e
leaq -0x70(%rbp), %rdi
callq 0x31a0
leaq -0x71(%rbp), %rdi
callq 0x32e0
jmp 0xb8b3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0xb8a5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x31a0
leaq -0x71(%rbp), %rdi
callq 0x32e0
jmp 0xbf03
jmp 0xb8b5
jmp 0xb754
movq -0x200(%rbp), %rax
movq 0x90(%rax), %rdi
callq 0x189b0
movl %eax, %ecx
movq -0x200(%rbp), %rax
movl %ecx, -0x78(%rbp)
movq 0x98(%rax), %rdi
movl -0x78(%rbp), %esi
callq 0x1e0c0
movq -0x200(%rbp), %rdi
movl $0x103, %esi            # imm = 0x103
callq 0x9300
testb $0x1, %al
jne 0xb902
jmp 0xbdad
movb $0x1, -0x11(%rbp)
jmp 0xb908
movq -0x200(%rbp), %rdi
callq 0xac60
testb $0x1, %al
jne 0xb91d
jmp 0xb9d5
movq -0x200(%rbp), %rdi
movl $0x12c, %esi            # imm = 0x12C
callq 0x9300
testb $0x1, %al
jne 0xb9d0
leaq -0x99(%rbp), %rdi
movq %rdi, -0x218(%rbp)
callq 0x3430
movq -0x218(%rbp), %rdx
leaq 0x1a169(%rip), %rsi     # 0x25ac0
leaq -0x98(%rbp), %rdi
callq 0x62d0
jmp 0xb965
movq -0x200(%rbp), %rdi
leaq -0x98(%rbp), %rsi
movl $0x1, %edx
callq 0x8b50
jmp 0xb97f
leaq -0x98(%rbp), %rdi
callq 0x31a0
leaq -0x99(%rbp), %rdi
callq 0x32e0
jmp 0xb9d0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0xb9bf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x31a0
leaq -0x99(%rbp), %rdi
callq 0x32e0
jmp 0xbf03
jmp 0xb908
movq -0x200(%rbp), %rdi
movl $0x104, %esi            # imm = 0x104
callq 0x9300
testb $0x1, %al
jne 0xb9ef
jmp 0xbc5f
leaq -0xc0(%rbp), %rdi
callq 0x3370
movq -0x200(%rbp), %rax
movq 0x98(%rax), %rax
movq %rax, -0x228(%rbp)
leaq -0x101(%rbp), %rdi
movq %rdi, -0x220(%rbp)
callq 0x3430
movq -0x220(%rbp), %rdx
leaq 0x1a0b9(%rip), %rsi     # 0x25aea
leaq -0x100(%rbp), %rdi
callq 0x62d0
jmp 0xba3f
movq -0x228(%rbp), %rsi
leaq -0xe0(%rbp), %rdi
leaq -0x100(%rbp), %rdx
callq 0x1ded0
jmp 0xba5b
leaq -0xc0(%rbp), %rdi
movq %rdi, -0x238(%rbp)
leaq -0xe0(%rbp), %rsi
movq %rsi, -0x240(%rbp)
callq 0x3340
movq -0x240(%rbp), %rdi
callq 0x31a0
leaq -0x100(%rbp), %rdi
callq 0x31a0
leaq -0x101(%rbp), %rdi
callq 0x32e0
movq -0x200(%rbp), %rax
movq -0x238(%rbp), %rsi
movq 0x98(%rax), %rax
movq %rax, -0x230(%rbp)
leaq -0x128(%rbp), %rdi
callq 0x3130
jmp 0xbaca
movq -0x230(%rbp), %rdi
leaq -0x128(%rbp), %rsi
callq 0x1e060
jmp 0xbadf
leaq -0x128(%rbp), %rdi
callq 0x31a0
movq -0x200(%rbp), %rax
movq 0x98(%rax), %rdi
callq 0x1e550
jmp 0xbb00
movq -0x200(%rbp), %rdi
movl $0x106, %esi            # imm = 0x106
callq 0x9300
movb %al, -0x241(%rbp)
jmp 0xbb19
movb -0x241(%rbp), %al
testb $0x1, %al
jne 0xbb25
jmp 0xbb9d
movb $0x1, -0x1(%rbp)
movl $0x1, -0x12c(%rbp)
jmp 0xbc3d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0xbb5e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x100(%rbp), %rdi
callq 0x31a0
leaq -0x101(%rbp), %rdi
callq 0x32e0
jmp 0xbc4e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0xbc4e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x128(%rbp), %rdi
callq 0x31a0
jmp 0xbc4e
leaq -0x151(%rbp), %rdi
movq %rdi, -0x250(%rbp)
callq 0x3430
movq -0x250(%rbp), %rdx
leaq 0x19f3a(%rip), %rsi     # 0x25af8
leaq -0x150(%rbp), %rdi
callq 0x62d0
jmp 0xbbcc
movq -0x200(%rbp), %rdi
leaq -0x150(%rbp), %rsi
callq 0x9060
jmp 0xbbe1
leaq -0x150(%rbp), %rdi
callq 0x31a0
leaq -0x151(%rbp), %rdi
callq 0x32e0
movb $0x1, -0x1(%rbp)
movl $0x1, -0x12c(%rbp)
jmp 0xbc3d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0xbc2f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x150(%rbp), %rdi
callq 0x31a0
leaq -0x151(%rbp), %rdi
callq 0x32e0
jmp 0xbc4e
leaq -0xc0(%rbp), %rdi
callq 0x31a0
jmp 0xbef5
leaq -0xc0(%rbp), %rdi
callq 0x31a0
jmp 0xbf03
testb $0x1, -0x11(%rbp)
je 0xbd0a
movb $0x0, -0x11(%rbp)
leaq -0x179(%rbp), %rdi
movq %rdi, -0x258(%rbp)
callq 0x3430
movq -0x258(%rbp), %rdx
leaq 0x19ea3(%rip), %rsi     # 0x25b31
leaq -0x178(%rbp), %rdi
callq 0x62d0
jmp 0xbc9c
movq -0x200(%rbp), %rdi
leaq -0x178(%rbp), %rsi
movl $0x1, %edx
callq 0x8b50
jmp 0xbcb6
leaq -0x178(%rbp), %rdi
callq 0x31a0
leaq -0x179(%rbp), %rdi
callq 0x32e0
jmp 0xbda6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0xbcf9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x178(%rbp), %rdi
callq 0x31a0
leaq -0x179(%rbp), %rdi
callq 0x32e0
jmp 0xbf03
leaq -0x1a1(%rbp), %rdi
movq %rdi, -0x260(%rbp)
callq 0x3430
movq -0x260(%rbp), %rdx
leaq 0x19dcd(%rip), %rsi     # 0x25af8
leaq -0x1a0(%rbp), %rdi
callq 0x62d0
jmp 0xbd39
movq -0x200(%rbp), %rdi
leaq -0x1a0(%rbp), %rsi
callq 0x88a0
jmp 0xbd4e
leaq -0x1a0(%rbp), %rdi
callq 0x31a0
leaq -0x1a1(%rbp), %rdi
callq 0x32e0
movb $0x0, -0x1(%rbp)
jmp 0xbef5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0xbd95
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x1a0(%rbp), %rdi
callq 0x31a0
leaq -0x1a1(%rbp), %rdi
callq 0x32e0
jmp 0xbf03
jmp 0xbda8
jmp 0xb906
testb $0x1, -0x11(%rbp)
je 0xbe58
movb $0x0, -0x11(%rbp)
leaq -0x1c9(%rbp), %rdi
movq %rdi, -0x268(%rbp)
callq 0x3430
movq -0x268(%rbp), %rdx
leaq 0x19d9f(%rip), %rsi     # 0x25b7b
leaq -0x1c8(%rbp), %rdi
callq 0x62d0
jmp 0xbdea
movq -0x200(%rbp), %rdi
leaq -0x1c8(%rbp), %rsi
movl $0x1, %edx
callq 0x8b50
jmp 0xbe04
leaq -0x1c8(%rbp), %rdi
callq 0x31a0
leaq -0x1c9(%rbp), %rdi
callq 0x32e0
jmp 0xbeee
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0xbe47
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x1c8(%rbp), %rdi
callq 0x31a0
leaq -0x1c9(%rbp), %rdi
callq 0x32e0
jmp 0xbf03
leaq -0x1f1(%rbp), %rdi
movq %rdi, -0x270(%rbp)
callq 0x3430
movq -0x270(%rbp), %rdx
leaq 0x19d50(%rip), %rsi     # 0x25bc9
leaq -0x1f0(%rbp), %rdi
callq 0x62d0
jmp 0xbe87
movq -0x200(%rbp), %rdi
leaq -0x1f0(%rbp), %rsi
callq 0x88a0
jmp 0xbe9c
leaq -0x1f0(%rbp), %rdi
callq 0x31a0
leaq -0x1f1(%rbp), %rdi
callq 0x32e0
movb $0x0, -0x1(%rbp)
jmp 0xbef5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0xbee0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x1f0(%rbp), %rdi
callq 0x31a0
leaq -0x1f1(%rbp), %rdi
callq 0x32e0
jmp 0xbf03
jmp 0xbef0
jmp 0xb752
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x270, %rsp            # imm = 0x270
popq %rbp
retq
movq -0x48(%rbp), %rdi
callq 0x3420
nopl (%rax)