// File: kiven-li[P]xbytes/xbytes.cpp
// Function: xbytes::xbytes::emit_hxx_file()
void xbytes::emit_hxx_file()
{
	//open output file
	std::ofstream ofs;
	ofs.open("PARSER.hxx", std::ofstream::out);

	//open template file
	std::ifstream ifs;
	ifs.open("TEMPLATE.hxx", 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")
			{
				output_declare_symbol(ofs);
			}
			else if(keyword == "DECLARE_INCLUDE_CODE")
			{
				if(include_code.size() > 0)
				{
					ofs << "//include file from .x file";
					ofs << include_code << std::endl;
				}					
			}
			else if(keyword == "DECLARE_TOKEN_CODE")
			{
				if(token_code.size() > 0)
				{
					ofs << "//declare token from .x file\n";
					ofs << "typedef " << token_code  << "TOKEN_TYPE;" << std::endl;					
				}
			}
		}
		else
		{
			ofs << line << std::endl;
		}
	}

	ifs.close();
	ofs.close();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x4f0, %rsp            # imm = 0x4F0
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 0x12758(%rip), %rsi     # 0x19873
movl $0x10, %edx
callq 0x3040
jmp 0x7127
leaq -0x420(%rbp), %rdi
callq 0x3370
jmp 0x7135
leaq 0x12742(%rip), %rsi     # 0x1987e
leaq -0x420(%rbp), %rdi
movl $0x8, %edx
callq 0x31c0
jmp 0x714f
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 0x717b
movb -0x479(%rbp), %al
testb $0x1, %al
jne 0x718a
jmp 0x7539
leaq -0x440(%rbp), %rdi
movq %rdi, -0x488(%rbp)
callq 0x33e0
movq -0x488(%rbp), %rsi
leaq -0x420(%rbp), %rdi
callq 0x3080
jmp 0x71b2
leaq -0x440(%rbp), %rdi
callq 0x3200
cmpq $0x0, %rax
jne 0x7220
movq 0x1cdfd(%rip), %rsi     # 0x23fc8
leaq -0x208(%rbp), %rdi
callq 0x3320
jmp 0x71d9
jmp 0x715b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x210(%rbp)
movl %eax, -0x214(%rbp)
jmp 0x759a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x210(%rbp)
movl %eax, -0x214(%rbp)
jmp 0x758e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x210(%rbp)
movl %eax, -0x214(%rbp)
jmp 0x7582
xorl %eax, %eax
movl %eax, %esi
leaq -0x440(%rbp), %rdi
callq 0x3550
movq %rax, -0x490(%rbp)
jmp 0x7239
movq -0x490(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x25, %eax
jne 0x7501
leaq -0x440(%rbp), %rdi
movl $0x1, %esi
callq 0x3550
movq %rax, -0x498(%rbp)
jmp 0x7266
movq -0x498(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x25, %eax
jne 0x7501
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 0x7356
movslq -0x464(%rbp), %rsi
leaq -0x440(%rbp), %rdi
callq 0x3550
movq %rax, -0x4a8(%rbp)
jmp 0x72d8
movq -0x4a8(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x25, %eax
jne 0x730c
jmp 0x7356
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x210(%rbp)
movl %eax, -0x214(%rbp)
leaq -0x460(%rbp), %rdi
callq 0x31b0
jmp 0x7582
movslq -0x464(%rbp), %rsi
leaq -0x440(%rbp), %rdi
callq 0x3550
movq %rax, -0x4b0(%rbp)
jmp 0x7328
movq -0x4b0(%rbp), %rax
movsbl (%rax), %esi
leaq -0x460(%rbp), %rdi
callq 0x3270
jmp 0x7340
jmp 0x7342
movl -0x464(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x464(%rbp)
jmp 0x728f
leaq 0x1252e(%rip), %rsi     # 0x1988b
leaq -0x460(%rbp), %rdi
callq 0xc700
movb %al, -0x4b1(%rbp)
jmp 0x7371
movb -0x4b1(%rbp), %al
testb $0x1, %al
jne 0x737d
jmp 0x7397
movq -0x478(%rbp), %rdi
leaq -0x208(%rbp), %rsi
callq 0xb330
jmp 0x7392
jmp 0x74f3
leaq 0x124fc(%rip), %rsi     # 0x1989a
leaq -0x460(%rbp), %rdi
callq 0xc700
movb %al, -0x4b2(%rbp)
jmp 0x73b2
movb -0x4b2(%rbp), %al
testb $0x1, %al
jne 0x73be
jmp 0x7425
movq -0x478(%rbp), %rdi
addq $0x50, %rdi
callq 0x3200
cmpq $0x0, %rax
jbe 0x7420
leaq 0x124d4(%rip), %rsi     # 0x198af
leaq -0x208(%rbp), %rdi
callq 0x32e0
jmp 0x73e9
movq -0x478(%rbp), %rsi
addq $0x50, %rsi
leaq -0x208(%rbp), %rdi
callq 0x3290
movq %rax, -0x4c0(%rbp)
jmp 0x7409
movq -0x4c0(%rbp), %rdi
movq 0x1cbb1(%rip), %rsi     # 0x23fc8
callq 0x3320
jmp 0x741e
jmp 0x7420
jmp 0x74f1
leaq 0x1249f(%rip), %rsi     # 0x198cb
leaq -0x460(%rbp), %rdi
callq 0xc700
movb %al, -0x4c1(%rbp)
jmp 0x7440
movb -0x4c1(%rbp), %al
testb $0x1, %al
jne 0x744f
jmp 0x74ef
movq -0x478(%rbp), %rdi
addq $0x70, %rdi
callq 0x3200
cmpq $0x0, %rax
jbe 0x74ed
leaq 0x1246e(%rip), %rsi     # 0x198de
leaq -0x208(%rbp), %rdi
callq 0x32e0
jmp 0x747e
leaq 0x12477(%rip), %rsi     # 0x198fc
leaq -0x208(%rbp), %rdi
callq 0x32e0
movq %rax, -0x4d0(%rbp)
jmp 0x749a
movq -0x4d0(%rbp), %rdi
movq -0x478(%rbp), %rsi
addq $0x70, %rsi
callq 0x3290
movq %rax, -0x4d8(%rbp)
jmp 0x74ba
movq -0x4d8(%rbp), %rdi
leaq 0x1243d(%rip), %rsi     # 0x19905
callq 0x32e0
movq %rax, -0x4e0(%rbp)
jmp 0x74d6
movq -0x4e0(%rbp), %rdi
movq 0x1cae4(%rip), %rsi     # 0x23fc8
callq 0x3320
jmp 0x74eb
jmp 0x74ed
jmp 0x74ef
jmp 0x74f1
jmp 0x74f3
leaq -0x460(%rbp), %rdi
callq 0x31b0
jmp 0x7534
leaq -0x208(%rbp), %rdi
leaq -0x440(%rbp), %rsi
callq 0x3290
movq %rax, -0x4e8(%rbp)
jmp 0x751d
movq -0x4e8(%rbp), %rdi
movq 0x1ca9d(%rip), %rsi     # 0x23fc8
callq 0x3320
jmp 0x7532
jmp 0x7534
jmp 0x715b
leaq -0x420(%rbp), %rdi
callq 0x3090
jmp 0x7547
leaq -0x208(%rbp), %rdi
callq 0x3420
jmp 0x7555
leaq -0x440(%rbp), %rdi
callq 0x31b0
leaq -0x420(%rbp), %rdi
callq 0x30b0
leaq -0x208(%rbp), %rdi
callq 0x3440
addq $0x4f0, %rsp            # imm = 0x4F0
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
nopw %cs:(%rax,%rax)