// File: /workspace/github_cpp_makefile_star2_O3/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 0x9e56(%rip), %rdi      # 0x1aa26
movl $0x13, %esi
movl $0x1, %edx
callq 0x2390
movq 0x308(%rbx), %rcx
leaq 0x9e4d(%rip), %rdi      # 0x1aa3a
movl $0x14, %esi
movl $0x1, %edx
callq 0x2390
movq 0x308(%rbx), %rcx
leaq 0x9e45(%rip), %rdi      # 0x1aa4f
movl $0x15, %esi
movl $0x1, %edx
callq 0x2390
movq 0x308(%rbx), %rdi
movl (%rbx), %edx
leaq 0x9e3c(%rip), %rsi      # 0x1aa65
xorl %eax, %eax
callq 0x22a0
movq 0x308(%rbx), %rdi
movl 0x4(%rbx), %edx
leaq 0x9e38(%rip), %rsi      # 0x1aa79
xorl %eax, %eax
callq 0x22a0
leaq 0x50(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x9e36(%rip), %rsi      # 0x1aa8e
leaq 0x9e49(%rip), %rdx      # 0x1aaa8
leaq 0x40(%rsp), %r14
movq %r14, %rdi
callq 0x3c42
movq 0x308(%rbx), %rdi
movq (%r14), %rdx
leaq 0x9da2(%rip), %rsi      # 0x1aa1f
xorl %eax, %eax
callq 0x22a0
movq (%r14), %rdi
cmpq %r15, %rdi
je 0x10c99
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x2200
movq 0x308(%rbx), %rcx
leaq 0x9e02(%rip), %rdi      # 0x1aaa9
movl $0x30, %esi
movl $0x1, %edx
callq 0x2390
movq 0x308(%rbx), %rcx
leaq 0x9e16(%rip), %rdi      # 0x1aada
movl $0x16, %esi
movl $0x1, %edx
callq 0x2390
movq 0x308(%rbx), %rcx
leaq 0x9e10(%rip), %rdi      # 0x1aaf1
movl $0x19, %esi
movl $0x1, %edx
callq 0x2390
movq 0x308(%rbx), %rcx
leaq 0x9e0d(%rip), %rdi      # 0x1ab0b
movl $0x19, %esi
movl $0x1, %edx
callq 0x2390
movq 0x308(%rbx), %rcx
leaq 0x9e0a(%rip), %rdi      # 0x1ab25
movl $0x18, %esi
movl $0x1, %edx
callq 0x2390
movq 0x308(%rbx), %rcx
leaq 0x9e06(%rip), %rdi      # 0x1ab3e
movl $0x18, %esi
movl $0x1, %edx
callq 0x2390
movq 0x308(%rbx), %rcx
leaq 0x9e02(%rip), %rdi      # 0x1ab57
movl $0x20, %esi
movl $0x1, %edx
callq 0x2390
movq 0x308(%rbx), %rcx
leaq 0x9e06(%rip), %rdi      # 0x1ab78
movl $0x23, %esi
movl $0x1, %edx
callq 0x2390
movq 0x308(%rbx), %rcx
leaq 0x9e0d(%rip), %rdi      # 0x1ab9c
movl $0x23, %esi
movl $0x1, %edx
callq 0x2390
movq 0x308(%rbx), %rcx
leaq 0x9e14(%rip), %rdi      # 0x1abc0
movl $0x28, %esi
movl $0x1, %edx
callq 0x2390
movq 0x308(%rbx), %rcx
leaq 0x9e20(%rip), %rdi      # 0x1abe9
movl $0x22, %esi
movl $0x1, %edx
callq 0x2390
movq 0x308(%rbx), %rcx
leaq 0x9e26(%rip), %rdi      # 0x1ac0c
movl $0x11, %esi
movl $0x1, %edx
callq 0x2390
movq 0x308(%rbx), %rcx
leaq 0x9e1b(%rip), %rdi      # 0x1ac1e
movl $0x14, %esi
movl $0x1, %edx
callq 0x2390
movq 0x308(%rbx), %rcx
leaq 0x9e13(%rip), %rdi      # 0x1ac33
movl $0x16, %esi
movl $0x1, %edx
callq 0x2390
movq 0x308(%rbx), %rcx
leaq 0x9e0d(%rip), %rdi      # 0x1ac4a
movl $0xc, %esi
movl $0x1, %edx
callq 0x2390
movq 0x308(%rbx), %rcx
leaq 0x9dfd(%rip), %rdi      # 0x1ac57
movl $0xc, %esi
movl $0x1, %edx
callq 0x2390
movq 0x308(%rbx), %rcx
leaq 0x9ded(%rip), %rdi      # 0x1ac64
movl $0xc, %esi
movl $0x1, %edx
callq 0x2390
movq 0x308(%rbx), %rcx
leaq 0x9ddd(%rip), %rdi      # 0x1ac71
movl $0xc, %esi
movl $0x1, %edx
callq 0x2390
movq 0x308(%rbx), %rcx
leaq 0x9dcd(%rip), %rdi      # 0x1ac7e
movl $0x13, %esi
movl $0x1, %edx
callq 0x2390
leaq 0x30(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x9dc2(%rip), %rsi      # 0x1ac92
leaq 0x9dd2(%rip), %rdx      # 0x1aca9
leaq 0x20(%rsp), %r14
movq %r14, %rdi
callq 0x3c42
movq 0x308(%rbx), %rdi
movq (%r14), %rdx
leaq 0x9b2a(%rip), %rsi      # 0x1aa1f
xorl %eax, %eax
callq 0x22a0
movq (%r14), %rdi
cmpq %r15, %rdi
je 0x10f11
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x2200
movq 0x308(%rbx), %rcx
leaq 0x9d8b(%rip), %rdi      # 0x1acaa
movl $0x12, %esi
movl $0x1, %edx
callq 0x2390
leaq 0x10(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x9d7f(%rip), %rsi      # 0x1acbd
leaq 0x9da0(%rip), %rdx      # 0x1ace5
movq %rsp, %r14
movq %r14, %rdi
callq 0x3c42
movq 0x308(%rbx), %rdi
movq (%r14), %rdx
leaq 0x9abe(%rip), %rsi      # 0x1aa1f
xorl %eax, %eax
callq 0x22a0
movq (%r14), %rdi
cmpq %r15, %rdi
je 0x10f7d
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x2200
movq 0x308(%rbx), %rcx
leaq 0x9d5b(%rip), %rdi      # 0x1ace6
movl $0xf, %esi
movl $0x1, %edx
callq 0x2390
movq 0x308(%rbx), %rcx
leaq 0x9d4e(%rip), %rdi      # 0x1acf6
movl $0xf, %esi
movl $0x1, %edx
callq 0x2390
movq 0x308(%rbx), %rcx
leaq 0x9d41(%rip), %rdi      # 0x1ad06
movl $0xf, %esi
movl $0x1, %edx
callq 0x2390
movq 0x308(%rbx), %rcx
leaq 0x9d34(%rip), %rdi      # 0x1ad16
movl $0x19, %esi
movl $0x1, %edx
callq 0x2390
movq 0x308(%rbx), %rcx
leaq 0x9d31(%rip), %rdi      # 0x1ad30
movl $0x15, %esi
movl $0x1, %edx
callq 0x2390
movq %rbx, %rdi
callq 0x1108e
addq $0x60, %rsp
popq %rbx
popq %r14
popq %r15
retq