// File: /workspace/github_cpp_makefile_star2_O1/AndrewAlbert[P]Compiler-Theory/SourceCode/codeGenerator.cpp
// Function: codeGenerator::header()
void codeGenerator::header(){
	//Attach necessary header files for c program
	fprintf( oFile, "#include <stdio.h>\n" );
	fprintf( oFile, "#include <stdlib.h>\n" );
	fprintf( oFile, "#include <string.h>\n\n" );

	//Define the memory space attributes
	fprintf( oFile, "#define MM_SIZE %d\n", MM_SIZE );
	fprintf( oFile, "#define REG_SIZE %d\n", REG_SIZE );
	
	comment("Include runtime functions\n");
	
	fprintf( oFile, "extern void handleBoolOp( int val1, int val2 );\n" );
	fprintf( oFile, "extern int getBool();\n" );
	fprintf( oFile, "extern int getInteger();\n" );
	fprintf( oFile, "extern float getFloat();\n" );
	fprintf( oFile, "extern int getString();\n" );
	fprintf( oFile, "extern char getChar();\n\n" );
	fprintf( oFile, "extern void putBool( int val );\n" );
	fprintf( oFile, "extern void putInteger( int val );\n" );
	fprintf( oFile, "extern void putFloat( float val );\n" );
	fprintf( oFile, "extern void putString( char* str_ptr );\n" );
	fprintf( oFile, "extern void putChar( char val );\n\n" );

	//Create registers and stack
	fprintf( oFile, "int MM[MM_SIZE];\n" );
	fprintf( oFile, "int iReg[REG_SIZE];\n" );
	fprintf( oFile, "float fReg[REG_SIZE];\n" );
	fprintf( oFile, "int FP_reg;\n" );
	fprintf( oFile, "int SP_reg;\n" );
	fprintf( oFile, "int TP_reg;\n" );
	fprintf( oFile, "int HP_reg;\n" );
	fprintf( oFile, "char buffer[256];\n\n" );

	comment( "Begin program execution" );
	//Call to main for function
	fprintf( oFile, "int main( void ){\n" );
	
	//Declare registers
	comment("Allocated registers for stack operations");
	fprintf( oFile, "   FP_reg = 0;\n" );
	fprintf( oFile, "   SP_reg = 0;\n" );
	fprintf( oFile, "   TP_reg = 0;\n" );
	fprintf( oFile, "   HP_reg = MM_SIZE - 1;\n" );
	fprintf( oFile, "   goto BUILD_HEAP;\n\n" );
	
	// Add the runtime function inline code
	WriteRuntime();
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x60, %rsp
movq %rdi, %rbx
movq 0x308(%rdi), %rcx
leaq 0x9d74(%rip), %rdi      # 0x1aa26
movl $0x13, %esi
movl $0x1, %edx
callq 0x2390
movq 0x308(%rbx), %rcx
leaq 0x9d6b(%rip), %rdi      # 0x1aa3a
movl $0x14, %esi
movl $0x1, %edx
callq 0x2390
movq 0x308(%rbx), %rcx
leaq 0x9d63(%rip), %rdi      # 0x1aa4f
movl $0x15, %esi
movl $0x1, %edx
callq 0x2390
movq 0x308(%rbx), %rdi
movl (%rbx), %edx
leaq 0x9d5a(%rip), %rsi      # 0x1aa65
xorl %eax, %eax
callq 0x22a0
movq 0x308(%rbx), %rdi
movl 0x4(%rbx), %edx
leaq 0x9d56(%rip), %rsi      # 0x1aa79
xorl %eax, %eax
callq 0x22a0
leaq 0x50(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x9d54(%rip), %rsi      # 0x1aa8e
leaq 0x9d67(%rip), %rdx      # 0x1aaa8
leaq 0x40(%rsp), %r14
movq %r14, %rdi
callq 0x3c34
movq 0x308(%rbx), %rdi
movq (%r14), %rdx
leaq 0x9cc0(%rip), %rsi      # 0x1aa1f
xorl %eax, %eax
callq 0x22a0
movq (%r14), %rdi
cmpq %r15, %rdi
je 0x10d7b
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x2200
movq 0x308(%rbx), %rcx
leaq 0x9d20(%rip), %rdi      # 0x1aaa9
movl $0x30, %esi
movl $0x1, %edx
callq 0x2390
movq 0x308(%rbx), %rcx
leaq 0x9d34(%rip), %rdi      # 0x1aada
movl $0x16, %esi
movl $0x1, %edx
callq 0x2390
movq 0x308(%rbx), %rcx
leaq 0x9d2e(%rip), %rdi      # 0x1aaf1
movl $0x19, %esi
movl $0x1, %edx
callq 0x2390
movq 0x308(%rbx), %rcx
leaq 0x9d2b(%rip), %rdi      # 0x1ab0b
movl $0x19, %esi
movl $0x1, %edx
callq 0x2390
movq 0x308(%rbx), %rcx
leaq 0x9d28(%rip), %rdi      # 0x1ab25
movl $0x18, %esi
movl $0x1, %edx
callq 0x2390
movq 0x308(%rbx), %rcx
leaq 0x9d24(%rip), %rdi      # 0x1ab3e
movl $0x18, %esi
movl $0x1, %edx
callq 0x2390
movq 0x308(%rbx), %rcx
leaq 0x9d20(%rip), %rdi      # 0x1ab57
movl $0x20, %esi
movl $0x1, %edx
callq 0x2390
movq 0x308(%rbx), %rcx
leaq 0x9d24(%rip), %rdi      # 0x1ab78
movl $0x23, %esi
movl $0x1, %edx
callq 0x2390
movq 0x308(%rbx), %rcx
leaq 0x9d2b(%rip), %rdi      # 0x1ab9c
movl $0x23, %esi
movl $0x1, %edx
callq 0x2390
movq 0x308(%rbx), %rcx
leaq 0x9d32(%rip), %rdi      # 0x1abc0
movl $0x28, %esi
movl $0x1, %edx
callq 0x2390
movq 0x308(%rbx), %rcx
leaq 0x9d3e(%rip), %rdi      # 0x1abe9
movl $0x22, %esi
movl $0x1, %edx
callq 0x2390
movq 0x308(%rbx), %rcx
leaq 0x9d44(%rip), %rdi      # 0x1ac0c
movl $0x11, %esi
movl $0x1, %edx
callq 0x2390
movq 0x308(%rbx), %rcx
leaq 0x9d39(%rip), %rdi      # 0x1ac1e
movl $0x14, %esi
movl $0x1, %edx
callq 0x2390
movq 0x308(%rbx), %rcx
leaq 0x9d31(%rip), %rdi      # 0x1ac33
movl $0x16, %esi
movl $0x1, %edx
callq 0x2390
movq 0x308(%rbx), %rcx
leaq 0x9d2b(%rip), %rdi      # 0x1ac4a
movl $0xc, %esi
movl $0x1, %edx
callq 0x2390
movq 0x308(%rbx), %rcx
leaq 0x9d1b(%rip), %rdi      # 0x1ac57
movl $0xc, %esi
movl $0x1, %edx
callq 0x2390
movq 0x308(%rbx), %rcx
leaq 0x9d0b(%rip), %rdi      # 0x1ac64
movl $0xc, %esi
movl $0x1, %edx
callq 0x2390
movq 0x308(%rbx), %rcx
leaq 0x9cfb(%rip), %rdi      # 0x1ac71
movl $0xc, %esi
movl $0x1, %edx
callq 0x2390
movq 0x308(%rbx), %rcx
leaq 0x9ceb(%rip), %rdi      # 0x1ac7e
movl $0x13, %esi
movl $0x1, %edx
callq 0x2390
leaq 0x30(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x9ce0(%rip), %rsi      # 0x1ac92
leaq 0x9cf0(%rip), %rdx      # 0x1aca9
leaq 0x20(%rsp), %r14
movq %r14, %rdi
callq 0x3c34
movq 0x308(%rbx), %rdi
movq (%r14), %rdx
leaq 0x9a48(%rip), %rsi      # 0x1aa1f
xorl %eax, %eax
callq 0x22a0
movq (%r14), %rdi
cmpq %r15, %rdi
je 0x10ff3
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x2200
movq 0x308(%rbx), %rcx
leaq 0x9ca9(%rip), %rdi      # 0x1acaa
movl $0x12, %esi
movl $0x1, %edx
callq 0x2390
leaq 0x10(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x9c9d(%rip), %rsi      # 0x1acbd
leaq 0x9cbe(%rip), %rdx      # 0x1ace5
movq %rsp, %r14
movq %r14, %rdi
callq 0x3c34
movq 0x308(%rbx), %rdi
movq (%r14), %rdx
leaq 0x99dc(%rip), %rsi      # 0x1aa1f
xorl %eax, %eax
callq 0x22a0
movq (%r14), %rdi
cmpq %r15, %rdi
je 0x1105f
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x2200
movq 0x308(%rbx), %rcx
leaq 0x9c79(%rip), %rdi      # 0x1ace6
movl $0xf, %esi
movl $0x1, %edx
callq 0x2390
movq 0x308(%rbx), %rcx
leaq 0x9c6c(%rip), %rdi      # 0x1acf6
movl $0xf, %esi
movl $0x1, %edx
callq 0x2390
movq 0x308(%rbx), %rcx
leaq 0x9c5f(%rip), %rdi      # 0x1ad06
movl $0xf, %esi
movl $0x1, %edx
callq 0x2390
movq 0x308(%rbx), %rcx
leaq 0x9c52(%rip), %rdi      # 0x1ad16
movl $0x19, %esi
movl $0x1, %edx
callq 0x2390
movq 0x308(%rbx), %rcx
leaq 0x9c4f(%rip), %rdi      # 0x1ad30
movl $0x15, %esi
movl $0x1, %edx
callq 0x2390
movq %rbx, %rdi
callq 0x11170
addq $0x60, %rsp
popq %rbx
popq %r14
popq %r15
retq