// File: /workspace/github_cpp_makefile_star2_O2/kiven-li[P]xbytes/xbytes.cpp
// Function: xbytes::xbytes::emit_cxx_file()
void xbytes::emit_cxx_file()
{
	//open output file
	std::ofstream ofs;
	ofs.open("PARSER.cxx", std::ofstream::out);

	//open template file
	std::ifstream ifs;
	ifs.open("TEMPLATE.cxx", std::ifstream::in);

	//copy data
	string line;
	while(ifs.good())
	{
		line.clear();
		getline(ifs, line);

		if(line.size() == 0)
		{
			ofs << std::endl;
			continue;
		}
		
		if(line[0] == '%' && line[1] == '%')
		{
			string keyword;
			for(int i = 2; i < line.size(); ++i)
			{
				if(line[i] == '%') break;
				keyword.push_back(line[i]);
			}

			if(keyword == "DECLARE_SYMBOL_TABLE")
			{
				output_symbol_table(ofs);
			}
			else if(keyword == "DECLARE_RULE_TABLE")
			{
				output_rule_table(ofs);
			}
			else if(keyword == "DECLARE_ACTION_TABLE")
			{
				output_action_table(ofs);
			}
			else if(keyword == "DECLARE_REDUCE_CODE")
			{
				output_reduce_code(ofs);
			}
			else if(keyword == "DECLARE_SYNTAX_ERROR_CODE")
			{
				if(syntax_error_code.size() > 0)
					ofs << syntax_error_code << std::endl;
			}

			continue;
		}

		ofs << line << std::endl;	
	}

	ifs.close();
	ofs.close();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x458, %rsp            # imm = 0x458
movq %rdi, -0x30(%rbp)
leaq -0x480(%rbp), %r14
movq %r14, %rdi
callq 0x2360
leaq 0x6547(%rip), %rsi      # 0xa921
pushq $0x10
popq %rdx
movq %r14, %rdi
callq 0x2030
leaq -0x280(%rbp), %rdi
callq 0x2260
leaq 0x6534(%rip), %rsi      # 0xa92c
leaq -0x280(%rbp), %rdi
pushq $0x8
popq %rdx
callq 0x2150
leaq -0x40(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq -0x30(%rbp), %rax
addq $0x90, %rax
movq %rax, -0x58(%rbp)
leaq -0x280(%rbp), %r12
leaq -0x50(%rbp), %r13
leaq -0x78(%rbp), %r15
movq -0x280(%rbp), %rax
movq -0x18(%rax), %rax
cmpl $0x0, -0x260(%rbp,%rax)
jne 0x4598
andq $0x0, -0x48(%rbp)
movq -0x50(%rbp), %rax
movb $0x0, (%rax)
movq %r12, %rdi
movq %r13, %rsi
callq 0x2060
movq -0x48(%rbp), %rcx
movq %r14, %rax
testq %rcx, %rcx
je 0x44c2
movq -0x50(%rbp), %rax
cmpb $0x25, (%rax)
jne 0x44b7
cmpb $0x25, 0x1(%rax)
jne 0x44b7
leaq -0x68(%rbp), %rax
movq %rax, -0x78(%rbp)
andq $0x0, -0x70(%rbp)
movb $0x0, -0x68(%rbp)
pushq $0x2
popq %rbx
cmpq %rbx, %rcx
jbe 0x44cf
movq -0x50(%rbp), %rax
movb (%rax,%rbx), %al
cmpb $0x25, %al
je 0x44cf
movsbl %al, %esi
movq %r15, %rdi
callq 0x21e0
incq %rbx
movq -0x48(%rbp), %rcx
jmp 0x4493
movq %r14, %rdi
movq %r13, %rsi
callq 0x2200
movq %rax, %rdi
callq 0x2110
jmp 0x4434
movq %r15, %rdi
leaq 0x6460(%rip), %rsi      # 0xa939
callq 0x7074
testb %al, %al
je 0x44f3
movq -0x30(%rbp), %rdi
movq %r14, %rsi
callq 0x66f4
jmp 0x458b
movq %r15, %rdi
leaq 0x6451(%rip), %rsi      # 0xa94e
callq 0x7074
testb %al, %al
je 0x4514
movq -0x30(%rbp), %rdi
movq %r14, %rsi
callq 0x67ac
jmp 0x458b
movq %r15, %rdi
leaq 0x6443(%rip), %rsi      # 0xa961
callq 0x7074
testb %al, %al
je 0x4535
movq -0x30(%rbp), %rdi
movq %r14, %rsi
callq 0x6994
jmp 0x458b
movq %r15, %rdi
leaq 0x6437(%rip), %rsi      # 0xa976
callq 0x7074
testb %al, %al
je 0x4556
movq -0x30(%rbp), %rdi
movq %r14, %rsi
callq 0x6b88
jmp 0x458b
movq %r15, %rdi
leaq 0x642a(%rip), %rsi      # 0xa98a
callq 0x7074
testb %al, %al
je 0x458b
movq -0x30(%rbp), %rax
cmpq $0x0, 0x98(%rax)
je 0x458b
movq %r14, %rdi
movq -0x58(%rbp), %rsi
callq 0x2200
movq %rax, %rdi
callq 0x2110
movq %r15, %rdi
callq 0x2100
jmp 0x4434
leaq -0x280(%rbp), %rdi
callq 0x2070
leaq -0x480(%rbp), %rdi
callq 0x22c0
leaq -0x50(%rbp), %rdi
callq 0x2100
leaq -0x280(%rbp), %rdi
callq 0x2080
leaq -0x480(%rbp), %rdi
callq 0x22e0
addq $0x458, %rsp            # imm = 0x458
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x460d
jmp 0x45ea
movq %rax, %rbx
jmp 0x4619
jmp 0x45f3
jmp 0x45f8
movq %rax, %rbx
jmp 0x4604
movq %rax, %rbx
leaq -0x78(%rbp), %rdi
callq 0x2100
leaq -0x50(%rbp), %rdi
callq 0x2100
leaq -0x280(%rbp), %rdi
callq 0x2080
leaq -0x480(%rbp), %rdi
callq 0x22e0
movq %rbx, %rdi
callq 0x2380
nop