// File: /workspace/github_cpp_makefile_star2_O2/lhydave[P]SysYCompilerLab/main.cpp
// Function: main
int main(int argc, char **argv)
{
	bool S = false, e = false, t = false, v = false;
	string output_s;
	// parse args
	for (auto i = 0; i < argc; i++)
	{
		if (argv[i][0] == '-')
		{
			switch (argv[i][1])
			{
			case 'S': S = true; break;
			case 'e': e = true; break;
			case 't': t = true; break;
			case 'v': v = true; break;
			case 'o':
				if (argv[i + 1] == nullptr)
				{
					printf("no output file dedicated");
					return 0;
				}
				output_s = argv[++i];
				break;
			default: printf("unrecognized parameter\n"); return 0;
			}
		}
		else
			yyin = fopen(argv[i], "r");
	}
	if (!S)
	{
		printf("not support yet!\n");
		return 0;
	}
	if (e && t)
	{
		printf("at most one parameter can be dedicated.\n");
		return 0;
	}
	if (!yyin)
	{
		printf("no valid input file!\n");
		return 0;
	}
	sysY_AST::init_tables();
	do
	{
		yyparse();
	} while (!feof(yyin));
	sysY_AST::check_main();
	if (has_err)
		return 1;
	if (e) // generate eeyore
	{
		auto out_f = fopen(output_s.c_str(), "w");
		fprintf(out_f, "%s", sysY_AST::root->code.c_str());
		return 0;
	}
	else if (v) // debug
	{
		auto out_f = fopen("eeyore.out", "w");
		fprintf(out_f, "%s", sysY_AST::root->code.c_str());
		fflush(out_f);
	}
	// generate tigger
	eeyore_AST::build_AST(sysY_AST::root->code);
	no_alloc::gen_code();
	if (t)
	{
		auto out_f = fopen(output_s.c_str(), "w");
		fprintf(out_f, "%s", tigger_dst.str().c_str());
		return 0;
	}
	else if (v)
	{
		auto out_f = fopen("tigger.out", "w");
		fprintf(out_f, "%s", tigger_dst.str().c_str());
		fflush(out_f);
	}
	// generate risc-v code
	riscv::gen_code();
	if (!(e || t))
	{
		auto out_f = fopen(output_s.c_str(), "w");
		fprintf(out_f, "%s", riscv_dst.str().c_str());
		return 0;
	}
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rsi, %rbx
movl %edi, %ebp
leaq 0x28(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
xorl %r13d, %r13d
leaq 0xe6f4(%rip), %r15      # 0x1e48e
leaq 0x1e547(%rip), %r12     # 0x2e2e8
movl $0x0, 0xc(%rsp)
movl $0x0, 0x10(%rsp)
movl $0x0, 0x14(%rsp)
xorl %r14d, %r14d
cmpl %ebp, %r13d
jge 0xfe39
movslq %r13d, %rax
movq (%rbx,%rax,8), %rdi
cmpb $0x2d, (%rdi)
jne 0xfdf6
movzbl 0x1(%rdi), %ecx
cmpl $0x53, %ecx
je 0xfe34
cmpl $0x76, %ecx
je 0xfe07
cmpl $0x6f, %ecx
je 0xfe17
cmpl $0x74, %ecx
je 0xfe0f
cmpl $0x65, %ecx
jne 0xfec6
movb $0x1, %al
movl %eax, 0x14(%rsp)
jmp 0xfe02
movq %r15, %rsi
callq 0x52c0
movq %rax, (%r12)
incl %r13d
jmp 0xfdbc
movb $0x1, %al
movl %eax, 0xc(%rsp)
jmp 0xfe02
movb $0x1, %al
movl %eax, 0x10(%rsp)
jmp 0xfe02
movq 0x8(%rbx,%rax,8), %rsi
testq %rsi, %rsi
je 0xfeef
leaq 0x18(%rsp), %rdi
callq 0x5510
incl %r13d
jmp 0xfe02
movb $0x1, %r14b
jmp 0xfe02
testb $0x1, %r14b
je 0xfe58
movl 0x14(%rsp), %ebx
testb $0x1, %bl
je 0xfe61
testb $0x1, 0x10(%rsp)
je 0xfe61
leaq 0xf199(%rip), %rdi      # 0x1efef
jmp 0xfecd
leaq 0xf16a(%rip), %rdi      # 0x1efc9
jmp 0xfecd
cmpq $0x0, (%r12)
je 0xfe92
callq 0xdc34
callq 0x5b30
movq (%r12), %rdi
callq 0x53f0
testl %eax, %eax
je 0xfe6d
callq 0xe922
cmpb $0x0, 0x1e56d(%rip)     # 0x2e3f8
je 0xfe9b
pushq $0x1
popq %rbx
jmp 0xfed4
leaq 0xf141(%rip), %rdi      # 0x1efda
jmp 0xfecd
testb $0x1, %bl
je 0xff01
movq 0x18(%rsp), %rdi
leaq 0xe73d(%rip), %rsi      # 0x1e5e9
callq 0x52c0
movq 0x1e538(%rip), %rcx     # 0x2e3f0
movq 0x18(%rcx), %rdi
movq %rax, %rsi
callq 0x5290
jmp 0xfed2
leaq 0xf0e5(%rip), %rdi      # 0x1efb2
callq 0x53e0
xorl %ebx, %ebx
leaq 0x18(%rsp), %rdi
callq 0x5548
movl %ebx, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xf08d(%rip), %rdi      # 0x1ef83
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x5050
jmp 0xfed4
testb $0x1, 0xc(%rsp)
je 0xff39
leaq 0xf08d(%rip), %rdi      # 0x1ef9c
leaq 0xe6d3(%rip), %rsi      # 0x1e5e9
callq 0x52c0
movq %rax, %rbx
movq 0x1e4cb(%rip), %rax     # 0x2e3f0
movq 0x18(%rax), %rdi
movq %rbx, %rsi
callq 0x5290
movq %rbx, %rdi
callq 0x52b0
movq 0x1e4b0(%rip), %rdi     # 0x2e3f0
addq $0x18, %rdi
callq 0x100aa
callq 0x1736c
testb $0x1, 0x10(%rsp)
je 0xff7c
movq 0x18(%rsp), %rdi
leaq 0xe688(%rip), %rsi      # 0x1e5e9
callq 0x52c0
movq %rax, %rbx
leaq 0x1e498(%rip), %rsi     # 0x2e408
leaq 0x38(%rsp), %rdi
callq 0x5420
jmp 0xfff4
testb $0x1, 0xc(%rsp)
je 0xffca
leaq 0xf01d(%rip), %rdi      # 0x1efa7
leaq 0xe658(%rip), %rsi      # 0x1e5e9
callq 0x52c0
movq %rax, %rbx
leaq 0x1e468(%rip), %rsi     # 0x2e408
leaq 0x38(%rsp), %rdi
callq 0x5420
leaq 0x38(%rsp), %r14
movq (%r14), %rdi
movq %rbx, %rsi
callq 0x5290
movq %r14, %rdi
callq 0x5548
movq %rbx, %rdi
callq 0x52b0
callq 0x19b5c
movq 0x18(%rsp), %rdi
leaq 0xe60e(%rip), %rsi      # 0x1e5e9
callq 0x52c0
movq %rax, %rbx
leaq 0x1e596(%rip), %rsi     # 0x2e580
leaq 0x38(%rsp), %rdi
callq 0x5420
leaq 0x38(%rsp), %r14
movq (%r14), %rdi
movq %rbx, %rsi
callq 0x5290
movq %r14, %rdi
callq 0x5548
jmp 0xfed2
jmp 0x1001b
jmp 0x1001b
jmp 0x1001b
jmp 0x1001b
jmp 0x1001b
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x5548
movq %rbx, %rdi
callq 0x54c0