// File: 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
subq $0x4d0, %rsp            # imm = 0x4D0
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x478(%rbp)
leaq -0x208(%rbp), %rdi
movq %rdi, -0x470(%rbp)
callq 0x34b0
movq -0x470(%rbp), %rdi
leaq 0x12316(%rip), %rsi     # 0x19911
movl $0x10, %edx
callq 0x3040
jmp 0x7607
leaq -0x420(%rbp), %rdi
callq 0x3370
jmp 0x7615
leaq 0x12300(%rip), %rsi     # 0x1991c
leaq -0x420(%rbp), %rdi
movl $0x8, %edx
callq 0x31c0
jmp 0x762f
leaq -0x440(%rbp), %rdi
callq 0x3410
movq -0x420(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x420(%rbp,%rax), %rdi
callq 0x34a0
movb %al, -0x479(%rbp)
jmp 0x765b
movb -0x479(%rbp), %al
testb $0x1, %al
jne 0x766a
jmp 0x7a02
leaq -0x440(%rbp), %rdi
movq %rdi, -0x488(%rbp)
callq 0x33e0
movq -0x488(%rbp), %rsi
leaq -0x420(%rbp), %rdi
callq 0x3080
jmp 0x7692
leaq -0x440(%rbp), %rdi
callq 0x3200
cmpq $0x0, %rax
jne 0x7700
movq 0x1c91d(%rip), %rsi     # 0x23fc8
leaq -0x208(%rbp), %rdi
callq 0x3320
jmp 0x76b9
jmp 0x763b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x210(%rbp)
movl %eax, -0x214(%rbp)
jmp 0x7a63
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x210(%rbp)
movl %eax, -0x214(%rbp)
jmp 0x7a57
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x210(%rbp)
movl %eax, -0x214(%rbp)
jmp 0x7a4b
xorl %eax, %eax
movl %eax, %esi
leaq -0x440(%rbp), %rdi
callq 0x3550
movq %rax, -0x490(%rbp)
jmp 0x7719
movq -0x490(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x25, %eax
jne 0x79cc
leaq -0x440(%rbp), %rdi
movl $0x1, %esi
callq 0x3550
movq %rax, -0x498(%rbp)
jmp 0x7746
movq -0x498(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x25, %eax
jne 0x79cc
leaq -0x460(%rbp), %rdi
callq 0x3410
movl $0x2, -0x464(%rbp)
movslq -0x464(%rbp), %rax
movq %rax, -0x4a0(%rbp)
leaq -0x440(%rbp), %rdi
callq 0x3200
movq %rax, %rcx
movq -0x4a0(%rbp), %rax
cmpq %rcx, %rax
jae 0x7836
movslq -0x464(%rbp), %rsi
leaq -0x440(%rbp), %rdi
callq 0x3550
movq %rax, -0x4a8(%rbp)
jmp 0x77b8
movq -0x4a8(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x25, %eax
jne 0x77ec
jmp 0x7836
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x210(%rbp)
movl %eax, -0x214(%rbp)
leaq -0x460(%rbp), %rdi
callq 0x31b0
jmp 0x7a4b
movslq -0x464(%rbp), %rsi
leaq -0x440(%rbp), %rdi
callq 0x3550
movq %rax, -0x4b0(%rbp)
jmp 0x7808
movq -0x4b0(%rbp), %rax
movsbl (%rax), %esi
leaq -0x460(%rbp), %rdi
callq 0x3270
jmp 0x7820
jmp 0x7822
movl -0x464(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x464(%rbp)
jmp 0x776f
leaq 0x120ec(%rip), %rsi     # 0x19929
leaq -0x460(%rbp), %rdi
callq 0xc700
movb %al, -0x4b1(%rbp)
jmp 0x7851
movb -0x4b1(%rbp), %al
testb $0x1, %al
jne 0x785d
jmp 0x7877
movq -0x478(%rbp), %rdi
leaq -0x208(%rbp), %rsi
callq 0xb4d0
jmp 0x7872
jmp 0x79bb
leaq 0x120c0(%rip), %rsi     # 0x1993e
leaq -0x460(%rbp), %rdi
callq 0xc700
movb %al, -0x4b2(%rbp)
jmp 0x7892
movb -0x4b2(%rbp), %al
testb $0x1, %al
jne 0x789e
jmp 0x78b8
movq -0x478(%rbp), %rdi
leaq -0x208(%rbp), %rsi
callq 0xb5d0
jmp 0x78b3
jmp 0x79b9
leaq 0x12092(%rip), %rsi     # 0x19951
leaq -0x460(%rbp), %rdi
callq 0xc700
movb %al, -0x4b3(%rbp)
jmp 0x78d3
movb -0x4b3(%rbp), %al
testb $0x1, %al
jne 0x78df
jmp 0x78f9
movq -0x478(%rbp), %rdi
leaq -0x208(%rbp), %rsi
callq 0xb8c0
jmp 0x78f4
jmp 0x79b7
leaq 0x12066(%rip), %rsi     # 0x19966
leaq -0x460(%rbp), %rdi
callq 0xc700
movb %al, -0x4b4(%rbp)
jmp 0x7914
movb -0x4b4(%rbp), %al
testb $0x1, %al
jne 0x7920
jmp 0x7937
movq -0x478(%rbp), %rdi
leaq -0x208(%rbp), %rsi
callq 0xbb70
jmp 0x7935
jmp 0x79b5
leaq 0x1203c(%rip), %rsi     # 0x1997a
leaq -0x460(%rbp), %rdi
callq 0xc700
movb %al, -0x4b5(%rbp)
jmp 0x7952
movb -0x4b5(%rbp), %al
testb $0x1, %al
jne 0x795e
jmp 0x79b3
movq -0x478(%rbp), %rdi
addq $0x90, %rdi
callq 0x3200
cmpq $0x0, %rax
jbe 0x79b1
movq -0x478(%rbp), %rsi
addq $0x90, %rsi
leaq -0x208(%rbp), %rdi
callq 0x3290
movq %rax, -0x4c0(%rbp)
jmp 0x799a
movq -0x4c0(%rbp), %rdi
movq 0x1c620(%rip), %rsi     # 0x23fc8
callq 0x3320
jmp 0x79af
jmp 0x79b1
jmp 0x79b3
jmp 0x79b5
jmp 0x79b7
jmp 0x79b9
jmp 0x79bb
leaq -0x460(%rbp), %rdi
callq 0x31b0
jmp 0x763b
leaq -0x208(%rbp), %rdi
leaq -0x440(%rbp), %rsi
callq 0x3290
movq %rax, -0x4c8(%rbp)
jmp 0x79e8
movq -0x4c8(%rbp), %rdi
movq 0x1c5d2(%rip), %rsi     # 0x23fc8
callq 0x3320
jmp 0x79fd
jmp 0x763b
leaq -0x420(%rbp), %rdi
callq 0x3090
jmp 0x7a10
leaq -0x208(%rbp), %rdi
callq 0x3420
jmp 0x7a1e
leaq -0x440(%rbp), %rdi
callq 0x31b0
leaq -0x420(%rbp), %rdi
callq 0x30b0
leaq -0x208(%rbp), %rdi
callq 0x3440
addq $0x4d0, %rsp            # imm = 0x4D0
popq %rbp
retq
leaq -0x440(%rbp), %rdi
callq 0x31b0
leaq -0x420(%rbp), %rdi
callq 0x30b0
leaq -0x208(%rbp), %rdi
callq 0x3440
movq -0x210(%rbp), %rdi
callq 0x34e0
nopl (%rax,%rax)