// File: /workspace/github_cpp_makefile_star2_O2/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 %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdi, %rbx
movq 0x308(%rdi), %rcx
leaq 0x6e0b(%rip), %rdi      # 0x12a06
pushq $0x13
popq %rsi
pushq $0x1
popq %r14
movq %r14, %rdx
callq 0x2380
movq 0x308(%rbx), %rcx
leaq 0x6e02(%rip), %rdi      # 0x12a1a
pushq $0x14
popq %rbp
movq %rbp, %rsi
movq %r14, %rdx
callq 0x2380
movq 0x308(%rbx), %rcx
leaq 0x6dfb(%rip), %rdi      # 0x12a2f
pushq $0x15
popq %rsi
movq %r14, %rdx
callq 0x2380
movq 0x308(%rbx), %rdi
movl (%rbx), %edx
leaq 0x6df6(%rip), %rsi      # 0x12a45
xorl %eax, %eax
callq 0x2280
movq 0x308(%rbx), %rdi
movl 0x4(%rbx), %edx
leaq 0x6df2(%rip), %rsi      # 0x12a59
xorl %eax, %eax
callq 0x2280
leaq 0x6df9(%rip), %rsi      # 0x12a6e
leaq 0x48(%rsp), %r15
leaq 0x7(%rsp), %rdx
movq %r15, %rdi
callq 0x36b8
movq %rbx, %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0xbf98
movq %r15, %rdi
callq 0x20f0
movq 0x308(%rbx), %rcx
leaq 0x6ddf(%rip), %rdi      # 0x12a89
pushq $0x30
popq %rsi
movq %r14, %rdx
callq 0x2380
movq 0x308(%rbx), %rcx
leaq 0x6df7(%rip), %rdi      # 0x12aba
pushq $0x16
popq %r15
movq %r15, %rsi
movq %r14, %rdx
callq 0x2380
movq 0x308(%rbx), %rcx
leaq 0x6df1(%rip), %rdi      # 0x12ad1
pushq $0x19
popq %r13
movq %r13, %rsi
movq %r14, %rdx
callq 0x2380
movq 0x308(%rbx), %rcx
leaq 0x6dee(%rip), %rdi      # 0x12aeb
movq %r13, %rsi
movq %r14, %rdx
callq 0x2380
movq 0x308(%rbx), %rcx
leaq 0x6def(%rip), %rdi      # 0x12b05
pushq $0x18
popq %r12
movq %r12, %rsi
movq %r14, %rdx
callq 0x2380
movq 0x308(%rbx), %rcx
leaq 0x6deb(%rip), %rdi      # 0x12b1e
movq %r12, %rsi
movq %r14, %rdx
callq 0x2380
movq 0x308(%rbx), %rcx
leaq 0x6deb(%rip), %rdi      # 0x12b37
pushq $0x20
popq %rsi
movq %r14, %rdx
callq 0x2380
movq 0x308(%rbx), %rcx
leaq 0x6df3(%rip), %rdi      # 0x12b58
pushq $0x23
popq %r12
movq %r12, %rsi
movq %r14, %rdx
callq 0x2380
movq 0x308(%rbx), %rcx
leaq 0x6dfa(%rip), %rdi      # 0x12b7c
movq %r12, %rsi
movq %r14, %rdx
callq 0x2380
movq 0x308(%rbx), %rcx
leaq 0x6e05(%rip), %rdi      # 0x12ba0
pushq $0x28
popq %rsi
movq %r14, %rdx
callq 0x2380
movq 0x308(%rbx), %rcx
leaq 0x6e15(%rip), %rdi      # 0x12bc9
pushq $0x22
popq %rsi
movq %r14, %rdx
callq 0x2380
movq 0x308(%rbx), %rcx
leaq 0x6e1f(%rip), %rdi      # 0x12bec
pushq $0x11
popq %rsi
movq %r14, %rdx
callq 0x2380
movq 0x308(%rbx), %rcx
leaq 0x6e18(%rip), %rdi      # 0x12bfe
movq %rbp, %rsi
movq %r14, %rdx
callq 0x2380
movq 0x308(%rbx), %rcx
leaq 0x6e14(%rip), %rdi      # 0x12c13
movq %r15, %rsi
movq %r14, %rdx
callq 0x2380
movq 0x308(%rbx), %rcx
leaq 0x6e12(%rip), %rdi      # 0x12c2a
pushq $0xc
popq %r15
movq %r15, %rsi
movq %r14, %rdx
callq 0x2380
movq 0x308(%rbx), %rcx
leaq 0x6e02(%rip), %rdi      # 0x12c37
movq %r15, %rsi
movq %r14, %rdx
callq 0x2380
movq 0x308(%rbx), %rcx
leaq 0x6df6(%rip), %rdi      # 0x12c44
movq %r15, %rsi
movq %r14, %rdx
callq 0x2380
movq 0x308(%rbx), %rcx
leaq 0x6dea(%rip), %rdi      # 0x12c51
movq %r15, %rsi
movq %r14, %rdx
callq 0x2380
movq 0x308(%rbx), %rcx
leaq 0x6dde(%rip), %rdi      # 0x12c5e
pushq $0x13
popq %rsi
movq %r14, %rdx
callq 0x2380
leaq 0x6de0(%rip), %rsi      # 0x12c72
leaq 0x28(%rsp), %r15
leaq 0x7(%rsp), %rdx
movq %r15, %rdi
callq 0x36b8
movq %rbx, %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0xbf98
movq %r15, %rdi
callq 0x20f0
movq 0x308(%rbx), %rcx
leaq 0x6dc3(%rip), %rdi      # 0x12c8a
pushq $0x12
popq %rsi
movq %r14, %rdx
callq 0x2380
leaq 0x6dc4(%rip), %rsi      # 0x12c9d
leaq 0x8(%rsp), %r15
leaq 0x7(%rsp), %rdx
movq %r15, %rdi
callq 0x36b8
movq %rbx, %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0xbf98
movq %r15, %rdi
callq 0x20f0
movq 0x308(%rbx), %rcx
leaq 0x6db8(%rip), %rdi      # 0x12cc6
pushq $0xf
popq %r15
movq %r15, %rsi
movq %r14, %rdx
callq 0x2380
movq 0x308(%rbx), %rcx
leaq 0x6dab(%rip), %rdi      # 0x12cd6
movq %r15, %rsi
movq %r14, %rdx
callq 0x2380
movq 0x308(%rbx), %rcx
leaq 0x6da2(%rip), %rdi      # 0x12ce6
movq %r15, %rsi
movq %r14, %rdx
callq 0x2380
movq 0x308(%rbx), %rcx
leaq 0x6d99(%rip), %rdi      # 0x12cf6
movq %r13, %rsi
movq %r14, %rdx
callq 0x2380
movq 0x308(%rbx), %rcx
leaq 0x6d9a(%rip), %rdi      # 0x12d10
pushq $0x15
popq %rsi
movq %r14, %rdx
callq 0x2380
movq %rbx, %rdi
callq 0xbffc
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq