// File: kiven-li[P]xbytes/xbytes.cpp
// Function: xbytes::xbytes::emit_action_table()
void xbytes::emit_action_table()
{
	std::ofstream ofs;
	ofs.open("ACTION.txt", std::ofstream::out);

	for(int i = 0; i < states.size(); ++i)
	{
		lr_state* ls = states[i];
		ofs << "STATE " << i << ":" << std::endl;

		//output all terms
		for(int j = 0; j < ls->terms.size(); ++j)
		{
			rule* r = ls->terms[j]->r;
			int dot = ls->terms[j]->dot;

			ofs << "	" << r->left->name << " -> ";
			int m = 0;
			for(m = 0; m < r->rights.size(); ++m)
			{
				if(m == dot) ofs << "*";
				ofs << " " << r->rights[m]->name; 
			}
			if(m == dot) ofs << "*";
			ofs << std::endl;
		}
		ofs << std::endl;

		//output all action
		for(int j = 0; j < states[i]->actions.size(); ++j)
		{
			action_array& aa = states[i]->actions[j];
			for(int m = 0; m < aa.size(); ++m)
			{
				action& act = aa[m];
				switch(act.type)
				{
				case LR_ACTION_REDUCE:
					ofs << "	" << symbols[j]->name << " REDUCE " << act.r->index << std::endl;
					break;
				case LR_ACTION_SHIFT:
					ofs << "	" << symbols[j]->name << " SHIFT " << act.next_state << std::endl;
					break;
				case LR_ACTION_GOTO:
					ofs << "	" << symbols[j]->name << " GOTO " << act.next_state << std::endl;
					break;
				case LR_ACTION_ACCEPT:
					ofs << "	" << symbols[j]->name << " ACCEPT" << std::endl;
					break;
				case LR_ACTION_SSCONFLICT:
					ofs << "	" << symbols[j]->name << " SSCONFLICT" << std::endl;
					break;
				case LR_ACTION_SRCONFLICT:
					ofs << "	" << symbols[j]->name << " SRCONFLICT" << std::endl;
					break;
				case LR_ACTION_RRCONFLICT:
					ofs << "	" << symbols[j]->name << " RRCONFLICT" << std::endl;
					break;
				case LR_ACTION_RDRESOLVED:
					ofs << "	" << symbols[j]->name << " RDRESOLVED" << std::endl;
					break;
				case LR_ACTION_SHRESOLVED:
					ofs << "	" << symbols[j]->name << " SHRESOLVED" << std::endl;
					break;
				}
			}
		}
		ofs << std::endl;	
	}

	ofs.close();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x3c0, %rsp            # imm = 0x3C0
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x268(%rbp)
leaq -0x208(%rbp), %rdi
movq %rdi, -0x260(%rbp)
callq 0x34b0
movq -0x260(%rbp), %rdi
leaq 0x11ed9(%rip), %rsi     # 0x19994
movl $0x10, %edx
callq 0x3040
jmp 0x7ac7
movl $0x0, -0x218(%rbp)
movq -0x268(%rbp), %rdi
movslq -0x218(%rbp), %rax
movq %rax, -0x270(%rbp)
addq $0x38, %rdi
callq 0xc550
movq %rax, %rcx
movq -0x270(%rbp), %rax
cmpq %rcx, %rax
jae 0x8417
movq -0x268(%rbp), %rdi
addq $0x38, %rdi
movslq -0x218(%rbp), %rsi
callq 0xc570
movq (%rax), %rax
movq %rax, -0x220(%rbp)
leaq 0x11ba8(%rip), %rsi     # 0x196d2
leaq -0x208(%rbp), %rdi
callq 0x32e0
movq %rax, -0x278(%rbp)
jmp 0x7b3f
movq -0x278(%rbp), %rdi
movl -0x218(%rbp), %esi
callq 0x34d0
movq %rax, -0x280(%rbp)
jmp 0x7b5a
movq -0x280(%rbp), %rdi
leaq 0x1161f(%rip), %rsi     # 0x19187
callq 0x32e0
movq %rax, -0x288(%rbp)
jmp 0x7b76
movq -0x288(%rbp), %rdi
movq 0x1c444(%rip), %rsi     # 0x23fc8
callq 0x3320
jmp 0x7b8b
movl $0x0, -0x224(%rbp)
movslq -0x224(%rbp), %rax
movq %rax, -0x290(%rbp)
movq -0x220(%rbp), %rdi
addq $0x8, %rdi
callq 0xc590
movq %rax, %rcx
movq -0x290(%rbp), %rax
cmpq %rcx, %rax
jae 0x7d9d
movq -0x220(%rbp), %rdi
addq $0x8, %rdi
movslq -0x224(%rbp), %rsi
callq 0xc5b0
movq (%rax), %rax
movq (%rax), %rax
movq %rax, -0x230(%rbp)
movq -0x220(%rbp), %rdi
addq $0x8, %rdi
movslq -0x224(%rbp), %rsi
callq 0xc5b0
movq (%rax), %rax
movl 0x8(%rax), %eax
movl %eax, -0x234(%rbp)
leaq 0x11a2b(%rip), %rsi     # 0x1963f
leaq -0x208(%rbp), %rdi
callq 0x32e0
movq %rax, -0x298(%rbp)
jmp 0x7c29
movq -0x298(%rbp), %rdi
movq -0x230(%rbp), %rax
movq 0x8(%rax), %rsi
addq $0x8, %rsi
callq 0x3290
movq %rax, -0x2a0(%rbp)
jmp 0x7c4d
movq -0x2a0(%rbp), %rdi
leaq 0x11a7e(%rip), %rsi     # 0x196d9
callq 0x32e0
jmp 0x7c62
movl $0x0, -0x238(%rbp)
movl $0x0, -0x238(%rbp)
movslq -0x238(%rbp), %rax
movq %rax, -0x2a8(%rbp)
movq -0x230(%rbp), %rdi
addq $0x30, %rdi
callq 0xc4d0
movq %rax, %rcx
movq -0x2a8(%rbp), %rax
cmpq %rcx, %rax
jae 0x7d4d
movl -0x238(%rbp), %eax
cmpl -0x234(%rbp), %eax
jne 0x7cef
leaq 0x11b48(%rip), %rsi     # 0x19804
leaq -0x208(%rbp), %rdi
callq 0x32e0
jmp 0x7cca
jmp 0x7cef
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x210(%rbp)
movl %eax, -0x214(%rbp)
leaq -0x208(%rbp), %rdi
callq 0x3440
jmp 0x843a
leaq 0x118cf(%rip), %rsi     # 0x195c5
leaq -0x208(%rbp), %rdi
callq 0x32e0
movq %rax, -0x2b0(%rbp)
jmp 0x7d0b
movq -0x230(%rbp), %rdi
addq $0x30, %rdi
movslq -0x238(%rbp), %rsi
callq 0xc4f0
movq -0x2b0(%rbp), %rdi
movq (%rax), %rsi
addq $0x8, %rsi
callq 0x3290
jmp 0x7d37
jmp 0x7d39
movl -0x238(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x238(%rbp)
jmp 0x7c76
movl -0x238(%rbp), %eax
cmpl -0x234(%rbp), %eax
jne 0x7d72
leaq 0x11aa2(%rip), %rsi     # 0x19804
leaq -0x208(%rbp), %rdi
callq 0x32e0
jmp 0x7d70
jmp 0x7d72
movq 0x1c24f(%rip), %rsi     # 0x23fc8
leaq -0x208(%rbp), %rdi
callq 0x3320
jmp 0x7d87
jmp 0x7d89
movl -0x224(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x224(%rbp)
jmp 0x7b95
movq 0x1c224(%rip), %rsi     # 0x23fc8
leaq -0x208(%rbp), %rdi
callq 0x3320
jmp 0x7db2
movl $0x0, -0x23c(%rbp)
movq -0x268(%rbp), %rdi
movslq -0x23c(%rbp), %rax
movq %rax, -0x2b8(%rbp)
addq $0x38, %rdi
movslq -0x218(%rbp), %rsi
callq 0xc570
movq (%rax), %rdi
addq $0x50, %rdi
callq 0xcef0
movq %rax, %rcx
movq -0x2b8(%rbp), %rax
cmpq %rcx, %rax
jae 0x83ec
movq -0x268(%rbp), %rdi
addq $0x38, %rdi
movslq -0x218(%rbp), %rsi
callq 0xc570
movq (%rax), %rdi
addq $0x50, %rdi
movslq -0x23c(%rbp), %rsi
callq 0xce30
movq %rax, -0x248(%rbp)
movl $0x0, -0x24c(%rbp)
movslq -0x24c(%rbp), %rax
movq %rax, -0x2c0(%rbp)
movq -0x248(%rbp), %rdi
callq 0xcf20
movq %rax, %rcx
movq -0x2c0(%rbp), %rax
cmpq %rcx, %rax
jae 0x83d6
movq -0x248(%rbp), %rdi
movslq -0x24c(%rbp), %rsi
callq 0xcf50
movq %rax, -0x258(%rbp)
movq -0x258(%rbp), %rax
movl (%rax), %eax
decl %eax
movl %eax, %ecx
movq %rcx, -0x2c8(%rbp)
subl $0x9, %eax
ja 0x83c0
movq -0x2c8(%rbp), %rax
leaq 0x111d7(%rip), %rcx     # 0x19084
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x11782(%rip), %rsi     # 0x1963f
leaq -0x208(%rbp), %rdi
callq 0x32e0
movq %rax, -0x2d0(%rbp)
jmp 0x7ed2
movq -0x268(%rbp), %rdi
addq $0x8, %rdi
movslq -0x23c(%rbp), %rsi
callq 0xc4f0
movq -0x2d0(%rbp), %rdi
movq (%rax), %rsi
addq $0x8, %rsi
callq 0x3290
movq %rax, -0x2d8(%rbp)
jmp 0x7f05
movq -0x2d8(%rbp), %rdi
leaq 0x11a8c(%rip), %rsi     # 0x1999f
callq 0x32e0
movq %rax, -0x2e0(%rbp)
jmp 0x7f21
movq -0x2e0(%rbp), %rdi
movq -0x258(%rbp), %rax
movq 0x8(%rax), %rax
movl (%rax), %esi
callq 0x34d0
movq %rax, -0x2e8(%rbp)
jmp 0x7f43
movq -0x2e8(%rbp), %rdi
movq 0x1c077(%rip), %rsi     # 0x23fc8
callq 0x3320
jmp 0x7f58
jmp 0x83c0
leaq 0x116db(%rip), %rsi     # 0x1963f
leaq -0x208(%rbp), %rdi
callq 0x32e0
movq %rax, -0x2f0(%rbp)
jmp 0x7f79
movq -0x268(%rbp), %rdi
addq $0x8, %rdi
movslq -0x23c(%rbp), %rsi
callq 0xc4f0
movq -0x2f0(%rbp), %rdi
movq (%rax), %rsi
addq $0x8, %rsi
callq 0x3290
movq %rax, -0x2f8(%rbp)
jmp 0x7fac
movq -0x2f8(%rbp), %rdi
leaq 0x119ee(%rip), %rsi     # 0x199a8
callq 0x32e0
movq %rax, -0x300(%rbp)
jmp 0x7fc8
movq -0x300(%rbp), %rdi
movq -0x258(%rbp), %rax
movl 0x4(%rax), %esi
callq 0x34d0
movq %rax, -0x308(%rbp)
jmp 0x7fe7
movq -0x308(%rbp), %rdi
movq 0x1bfd3(%rip), %rsi     # 0x23fc8
callq 0x3320
jmp 0x7ffc
jmp 0x83c0
leaq 0x11637(%rip), %rsi     # 0x1963f
leaq -0x208(%rbp), %rdi
callq 0x32e0
movq %rax, -0x310(%rbp)
jmp 0x801d
movq -0x268(%rbp), %rdi
addq $0x8, %rdi
movslq -0x23c(%rbp), %rsi
callq 0xc4f0
movq -0x310(%rbp), %rdi
movq (%rax), %rsi
addq $0x8, %rsi
callq 0x3290
movq %rax, -0x318(%rbp)
jmp 0x8050
movq -0x318(%rbp), %rdi
leaq 0x11680(%rip), %rsi     # 0x196de
callq 0x32e0
movq %rax, -0x320(%rbp)
jmp 0x806c
movq -0x320(%rbp), %rdi
movq -0x258(%rbp), %rax
movl 0x4(%rax), %esi
callq 0x34d0
movq %rax, -0x328(%rbp)
jmp 0x808b
movq -0x328(%rbp), %rdi
movq 0x1bf2f(%rip), %rsi     # 0x23fc8
callq 0x3320
jmp 0x80a0
jmp 0x83c0
leaq 0x11593(%rip), %rsi     # 0x1963f
leaq -0x208(%rbp), %rdi
callq 0x32e0
movq %rax, -0x330(%rbp)
jmp 0x80c1
movq -0x268(%rbp), %rdi
addq $0x8, %rdi
movslq -0x23c(%rbp), %rsi
callq 0xc4f0
movq -0x330(%rbp), %rdi
movq (%rax), %rsi
addq $0x8, %rsi
callq 0x3290
movq %rax, -0x338(%rbp)
jmp 0x80f4
movq -0x338(%rbp), %rdi
leaq 0x118ae(%rip), %rsi     # 0x199b0
callq 0x32e0
movq %rax, -0x340(%rbp)
jmp 0x8110
movq -0x340(%rbp), %rdi
movq 0x1beaa(%rip), %rsi     # 0x23fc8
callq 0x3320
jmp 0x8125
jmp 0x83c0
leaq 0x1150e(%rip), %rsi     # 0x1963f
leaq -0x208(%rbp), %rdi
callq 0x32e0
movq %rax, -0x348(%rbp)
jmp 0x8146
movq -0x268(%rbp), %rdi
addq $0x8, %rdi
movslq -0x23c(%rbp), %rsi
callq 0xc4f0
movq -0x348(%rbp), %rdi
movq (%rax), %rsi
addq $0x8, %rsi
callq 0x3290
movq %rax, -0x350(%rbp)
jmp 0x8179
movq -0x350(%rbp), %rdi
leaq 0x11831(%rip), %rsi     # 0x199b8
callq 0x32e0
movq %rax, -0x358(%rbp)
jmp 0x8195
movq -0x358(%rbp), %rdi
movq 0x1be25(%rip), %rsi     # 0x23fc8
callq 0x3320
jmp 0x81aa
jmp 0x83c0
leaq 0x11489(%rip), %rsi     # 0x1963f
leaq -0x208(%rbp), %rdi
callq 0x32e0
movq %rax, -0x360(%rbp)
jmp 0x81cb
movq -0x268(%rbp), %rdi
addq $0x8, %rdi
movslq -0x23c(%rbp), %rsi
callq 0xc4f0
movq -0x360(%rbp), %rdi
movq (%rax), %rsi
addq $0x8, %rsi
callq 0x3290
movq %rax, -0x368(%rbp)
jmp 0x81fe
movq -0x368(%rbp), %rdi
leaq 0x117b8(%rip), %rsi     # 0x199c4
callq 0x32e0
movq %rax, -0x370(%rbp)
jmp 0x821a
movq -0x370(%rbp), %rdi
movq 0x1bda0(%rip), %rsi     # 0x23fc8
callq 0x3320
jmp 0x822f
jmp 0x83c0
leaq 0x11404(%rip), %rsi     # 0x1963f
leaq -0x208(%rbp), %rdi
callq 0x32e0
movq %rax, -0x378(%rbp)
jmp 0x8250
movq -0x268(%rbp), %rdi
addq $0x8, %rdi
movslq -0x23c(%rbp), %rsi
callq 0xc4f0
movq -0x378(%rbp), %rdi
movq (%rax), %rsi
addq $0x8, %rsi
callq 0x3290
movq %rax, -0x380(%rbp)
jmp 0x8283
movq -0x380(%rbp), %rdi
leaq 0x1173f(%rip), %rsi     # 0x199d0
callq 0x32e0
movq %rax, -0x388(%rbp)
jmp 0x829f
movq -0x388(%rbp), %rdi
movq 0x1bd1b(%rip), %rsi     # 0x23fc8
callq 0x3320
jmp 0x82b4
jmp 0x83c0
leaq 0x1137f(%rip), %rsi     # 0x1963f
leaq -0x208(%rbp), %rdi
callq 0x32e0
movq %rax, -0x390(%rbp)
jmp 0x82d5
movq -0x268(%rbp), %rdi
addq $0x8, %rdi
movslq -0x23c(%rbp), %rsi
callq 0xc4f0
movq -0x390(%rbp), %rdi
movq (%rax), %rsi
addq $0x8, %rsi
callq 0x3290
movq %rax, -0x398(%rbp)
jmp 0x8308
movq -0x398(%rbp), %rdi
leaq 0x116c6(%rip), %rsi     # 0x199dc
callq 0x32e0
movq %rax, -0x3a0(%rbp)
jmp 0x8324
movq -0x3a0(%rbp), %rdi
movq 0x1bc96(%rip), %rsi     # 0x23fc8
callq 0x3320
jmp 0x8339
jmp 0x83c0
leaq 0x112fa(%rip), %rsi     # 0x1963f
leaq -0x208(%rbp), %rdi
callq 0x32e0
movq %rax, -0x3a8(%rbp)
jmp 0x835a
movq -0x268(%rbp), %rdi
addq $0x8, %rdi
movslq -0x23c(%rbp), %rsi
callq 0xc4f0
movq -0x3a8(%rbp), %rdi
movq (%rax), %rsi
addq $0x8, %rsi
callq 0x3290
movq %rax, -0x3b0(%rbp)
jmp 0x838d
movq -0x3b0(%rbp), %rdi
leaq 0x1164d(%rip), %rsi     # 0x199e8
callq 0x32e0
movq %rax, -0x3b8(%rbp)
jmp 0x83a9
movq -0x3b8(%rbp), %rdi
movq 0x1bc11(%rip), %rsi     # 0x23fc8
callq 0x3320
jmp 0x83be
jmp 0x83c0
jmp 0x83c2
movl -0x24c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24c(%rbp)
jmp 0x7e3b
jmp 0x83d8
movl -0x23c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x23c(%rbp)
jmp 0x7dbc
movq 0x1bbd5(%rip), %rsi     # 0x23fc8
leaq -0x208(%rbp), %rdi
callq 0x3320
jmp 0x8401
jmp 0x8403
movl -0x218(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x218(%rbp)
jmp 0x7ad1
leaq -0x208(%rbp), %rdi
callq 0x3420
jmp 0x8425
leaq -0x208(%rbp), %rdi
callq 0x3440
addq $0x3c0, %rsp            # imm = 0x3C0
popq %rbp
retq
movq -0x210(%rbp), %rdi
callq 0x34e0
nopw %cs:(%rax,%rax)