// File: /workspace/github_cpp_makefile_star2_O2/AndrewAlbert[P]Compiler-Theory/SourceCode/compiler.cpp
// Function: main
int main(int argc, char **argv){
	bool debug;
	string filename;
	if( (argc == 2) || (argc == 3) ){
		if( (string(argv[1]) == "--help") || (string(argv[1]) == "--h") ){
			cout << "\nThis is a compiler written for the University of Cincinnati class: EECE6083 Compiler Theory" << endl;
			cout << "\nThe compiler is an LL(1) recursive descent compiler and utilizes the C++ programming language to scan, parse, and type check the program and LLVM to generate the compiler backend." << endl;
			cout << "\nTo use this compiler, compile and then run from the command line using the arguments: [ --help | --h | --debug | --d ] filename." << endl;
			cout << "\nThe compiler will scan and parse your file and generate code if parsing is successful. Otherwise relevant errors and warnings will be shown." << endl;
			cout << "\n--debug or --d argument will print out each token as it is scanned and print out each scope's symbol table after the scope is exited." << endl;
			return 0;
		}
		else if( (string(argv[1]) == "--debug") || (string(argv[1]) == "--d") ){
			debug = true;
			filename = string(argv[2]);
		}
		else if(argc == 2){
			debug = false;
			filename = string(argv[1]);
		}	
	}
	else{
		commandError();
		return 0;
	}

	//Initialize scanner and symbol tables.
	Scanner *scanner = new Scanner;
	scopeTracker *scopes = new scopeTracker(debug);
	codeGenerator *gen = new codeGenerator;

	//Contains token currently being scanned/parsed
	token_type *token = new token_type;

	scanner->token = token;
	//Initialize scanner, then begin parsing if there are no errors
	if(scanner->InitScanner(filename, debug)){
		*token = scanner->getToken();
		gen->attachOutputFile( (filename) + ".c" );
		Parser parser(token, scanner, scopes, gen);
	}
	delete scanner;
	delete scopes;
	delete gen;

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1b8, %rsp            # imm = 0x1B8
leaq 0x20(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movl %edi, %eax
andl $-0x2, %eax
cmpl $0x2, %eax
jne 0x105af
movq %rsi, %rbx
movl %edi, %ebp
movq 0x8(%rsi), %rsi
leaq 0x90(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0x36b8
leaq 0x2f48(%rip), %rsi      # 0x134d7
leaq 0x90(%rsp), %rdi
callq 0x3757
testb %al, %al
je 0x105b9
leaq 0x90(%rsp), %rdi
callq 0x20f0
jmp 0x10601
callq 0x10524
jmp 0x108a0
movq 0x8(%rbx), %rsi
leaq 0x30(%rsp), %rdi
leaq 0xe(%rsp), %rdx
callq 0x36b8
leaq 0x2f0b(%rip), %rsi      # 0x134de
leaq 0x30(%rsp), %r14
movq %r14, %rdi
callq 0x3757
movl %eax, %r15d
movq %r14, %rdi
callq 0x20f0
leaq 0x90(%rsp), %rdi
callq 0x20f0
testb %r15b, %r15b
je 0x1068d
movq 0xa9c8(%rip), %rdi      # 0x1afd0
leaq 0x2ed3(%rip), %rsi      # 0x134e2
callq 0x21c0
movq %rax, %rdi
callq 0x2100
movq 0xa9ad(%rip), %rdi      # 0x1afd0
leaq 0x2f15(%rip), %rsi      # 0x1353f
callq 0x21c0
movq %rax, %rdi
callq 0x2100
movq 0xa992(%rip), %rdi      # 0x1afd0
leaq 0x2faf(%rip), %rsi      # 0x135f4
callq 0x21c0
movq %rax, %rdi
callq 0x2100
movq 0xa977(%rip), %rdi      # 0x1afd0
leaq 0x3016(%rip), %rsi      # 0x13676
callq 0x21c0
movq %rax, %rdi
callq 0x2100
movq 0xa95c(%rip), %rdi      # 0x1afd0
leaq 0x3089(%rip), %rsi      # 0x13704
callq 0x21c0
movq %rax, %rdi
callq 0x2100
jmp 0x108a0
movq 0x8(%rbx), %rsi
leaq 0x90(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0x36b8
leaq 0x30e1(%rip), %rsi      # 0x1378b
leaq 0x90(%rsp), %rdi
callq 0x3757
testb %al, %al
je 0x106ca
leaq 0x90(%rsp), %rdi
callq 0x20f0
jmp 0x10712
movq 0x8(%rbx), %rsi
leaq 0x30(%rsp), %rdi
leaq 0xe(%rsp), %rdx
callq 0x36b8
leaq 0x30af(%rip), %rsi      # 0x13793
leaq 0x30(%rsp), %r14
movq %r14, %rdi
callq 0x3757
movl %eax, %r15d
movq %r14, %rdi
callq 0x20f0
leaq 0x90(%rsp), %rdi
callq 0x20f0
testb %r15b, %r15b
je 0x108be
movq 0x10(%rbx), %rsi
leaq 0x90(%rsp), %rdi
leaq 0x30(%rsp), %rdx
callq 0x36b8
leaq 0x10(%rsp), %rdi
leaq 0x90(%rsp), %rbx
movq %rbx, %rsi
callq 0x2240
movq %rbx, %rdi
callq 0x20f0
movb $0x1, %r15b
movl $0x178, %edi            # imm = 0x178
callq 0x21e0
movq %rax, %rbx
movq %rax, %rdi
callq 0x258c
pushq $0x20
popq %rdi
callq 0x21e0
movq %rax, %r14
movzbl %r15b, %ebp
andl $0x1, %ebp
movq %rax, %rdi
movl %ebp, %esi
callq 0xb0b0
movl $0x338, %edi            # imm = 0x338
callq 0x21e0
movq %rax, %r15
movq %rax, %rdi
callq 0xb5bc
movl $0x128, %edi            # imm = 0x128
callq 0x21e0
movq %rax, %r12
addq $0x10, %rax
movq %rax, (%r12)
andq $0x0, 0x8(%r12)
movb $0x0, 0x10(%r12)
movq %r12, 0x170(%rbx)
leaq 0x70(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x2270
leaq 0x70(%rsp), %rsi
movq %rbx, %rdi
movl %ebp, %edx
callq 0x25f8
movl %eax, %ebp
leaq 0x70(%rsp), %rdi
callq 0x20f0
testb %bpl, %bpl
je 0x10863
leaq 0x90(%rsp), %rdi
movq %rbx, %rsi
callq 0x2f1e
leaq 0x90(%rsp), %r13
movq %r12, %rdi
movq %r13, %rsi
callq 0x9782
movq %r13, %rdi
callq 0x20f0
leaq 0x2f80(%rip), %rdx      # 0x13797
leaq 0x50(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x98d8
leaq 0x50(%rsp), %rsi
movq %r15, %rdi
callq 0xbb72
leaq 0x50(%rsp), %rdi
callq 0x20f0
leaq 0x90(%rsp), %rdi
movq %r12, %rsi
movq %rbx, %rdx
movq %r14, %rcx
movq %r15, %r8
callq 0x3dcc
leaq 0x90(%rsp), %rdi
callq 0x4250
movq %rbx, %rdi
callq 0x25ca
movl $0x178, %esi            # imm = 0x178
movq %rbx, %rdi
callq 0x21f0
movq %r14, %rdi
callq 0xb0c0
pushq $0x20
popq %rsi
movq %r14, %rdi
callq 0x21f0
movq %r15, %rdi
callq 0xb8a0
movl $0x338, %esi            # imm = 0x338
movq %r15, %rdi
callq 0x21f0
leaq 0x10(%rsp), %rdi
callq 0x20f0
xorl %eax, %eax
addq $0x1b8, %rsp            # imm = 0x1B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x2, %ebp
jne 0x10748
movq 0x8(%rbx), %rsi
leaq 0x90(%rsp), %rdi
leaq 0x30(%rsp), %rdx
callq 0x36b8
leaq 0x10(%rsp), %rdi
leaq 0x90(%rsp), %rbx
movq %rbx, %rsi
callq 0x2240
movq %rbx, %rdi
callq 0x20f0
xorl %r15d, %r15d
jmp 0x10748
jmp 0x10968
jmp 0x10968
movq %rax, %r12
leaq 0x50(%rsp), %rdi
jmp 0x1095d
jmp 0x10968
jmp 0x10952
jmp 0x10968
movq %rax, %r12
leaq 0x70(%rsp), %rdi
jmp 0x1095d
movq %rax, %r12
movl $0x338, %esi            # imm = 0x338
movq %r15, %rdi
jmp 0x10947
jmp 0x10968
movq %rax, %r12
pushq $0x20
popq %rsi
movq %r14, %rdi
jmp 0x10947
jmp 0x10968
movq %rax, %r12
movl $0x178, %esi            # imm = 0x178
movq %rbx, %rdi
callq 0x21f0
jmp 0x1096b
jmp 0x10968
jmp 0x10968
movq %rax, %r12
leaq 0x90(%rsp), %rdi
callq 0x20f0
jmp 0x1096b
jmp 0x10968
jmp 0x10968
movq %rax, %r12
leaq 0x10(%rsp), %rdi
callq 0x20f0
movq %r12, %rdi
callq 0x2310