// File: /workspace/github_cpp_makefile_star2_O1/kiven-li[P]xbytes/xbytes.cpp
// Function: xbytes::xbytes::make_action_table()
void xbytes::make_action_table()
{
	for(int i = 0; i < states.size(); ++i)
	{
		lr_state* s = states[i];
		s->actions.resize(symbols.size());

		//goto & shift action
		for(goto_map::iterator it = s->gotomap.begin();it != s->gotomap.end(); ++it)
		{
			symbol* ss = it->first;

			action act;
			act.next_state = it->second;
			act.r = NULL;
			act.lookahead = ss;

			if(ss->type == ST_TERMINAL)
			{
				act.type = LR_ACTION_SHIFT;				
			}
			else if(ss->type == ST_NONTERMINAL)
			{
				act.type = LR_ACTION_GOTO;
			}

			s->actions[ss->index].push_back(act);
		}

		//reduce action
		for(int m = 0; m < s->terms.size(); ++m)
		{
			term* t = s->terms[m];
			if(t->dot != t->r->rights.size()) continue;

			for(int n = 0; n < s->actions.size(); ++n)
			{
				if(symbols[n]->type != ST_TERMINAL) continue;
				if(!is_symbol_in_set(symbols[n], t->forwards)) continue;//FOR LALR
				//if(!is_symbol_in_set(symbols[m], t->r->left->follow_set)) continue; //for SLR

				action act;
				act.type = LR_ACTION_REDUCE;
				act.next_state = 0;
				act.r = t->r;
				act.lookahead = symbols[n];

				s->actions[n].push_back(act);
			}
		}

		//accept action
		for(int m = 0; m < s->terms.size(); ++m)
		{
			term* t = s->terms[m];
			if(t->dot != t->r->rights.size() - 1) continue;

			if(t->r->rights[t->dot]->name == ACCEPT_TERMINAL)
			{
				action act;
				act.r = t->r;
				act.type = LR_ACTION_ACCEPT;
				act.next_state = 0;
				act.lookahead = t->r->rights[t->dot];

				s->actions[t->r->rights[t->dot]->index].push_back(act);
			}
		}
	}

	//error action
	for(int i = 0; i < states.size(); ++i)
	{
		lr_state* s = states[i];
		for(int m = 0; m < s->actions.size(); ++m)
		{
			action_array& aa = s->actions[m];
			if(aa.size() == 0)
			{
				action act;
				act.r = NULL;
				act.type = LR_ACTION_ERROR;
				act.next_state = 0;
				act.lookahead = NULL;

				aa.push_back(act);
			}
		}
	}

	//resolve conflict
	int conflict = 0;
	for(int i = 0; i < states.size(); ++i)
	{
		lr_state* s = states[i];
		for(int m = 0; m < s->actions.size(); ++m)
		{
			action_array& aa = s->actions[m];
			if(aa.size() < 2) continue;

			for(int n = 1; n < aa.size(); ++n)
			{
				conflict += resolve_conflict(aa[n-1], aa[n]);
			}
		}
	}

	std::cout << "conflict: " << conflict << std::endl;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %r15
movq 0x38(%rdi), %rax
movabsq $-0x5555555555555555, %r11 # imm = 0xAAAAAAAAAAAAAAAB
cmpq %rax, 0x40(%rdi)
movq %rdi, -0x58(%rbp)
je 0x5a7f
xorl %edx, %edx
movq %rdx, -0x48(%rbp)
movq (%rax,%rdx,8), %r14
leaq 0x50(%r14), %r12
movq 0x10(%r15), %rsi
subq 0x8(%r15), %rsi
sarq $0x3, %rsi
movq %r12, %rdi
callq 0xa294
movq 0x38(%r14), %r13
leaq 0x28(%r14), %rbx
cmpq %rbx, %r13
je 0x5843
movq 0x20(%r13), %rax
movl 0x28(%r13), %ecx
movl %ecx, -0x3c(%rbp)
movq $0x0, -0x38(%rbp)
movq %rax, -0x30(%rbp)
movl 0x48(%rax), %ecx
cmpl $0x2, %ecx
je 0x57f4
cmpl $0x1, %ecx
jne 0x57fb
movl $0x2, -0x40(%rbp)
jmp 0x57fb
movl $0x1, -0x40(%rbp)
movslq (%rax), %rax
movq (%r12), %rcx
leaq (%rax,%rax,2), %rax
leaq (%rcx,%rax,8), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x582a
movq -0x30(%rbp), %rax
movq %rax, 0x10(%rsi)
movups -0x40(%rbp), %xmm0
movups %xmm0, (%rsi)
addq $0x18, 0x8(%rdi)
jmp 0x5833
leaq -0x40(%rbp), %rdx
callq 0xb7ce
movq %r13, %rdi
callq 0x3180
movq %rax, %r13
cmpq %rbx, %rax
jne 0x57c7
movq %r12, -0x50(%rbp)
movq 0x8(%r14), %rax
cmpq %rax, 0x10(%r14)
movabsq $-0x5555555555555555, %r11 # imm = 0xAAAAAAAAAAAAAAAB
je 0x597e
xorl %r13d, %r13d
movq (%rax,%r13,8), %r12
movslq 0x8(%r12), %rax
movq (%r12), %rcx
movq 0x38(%rcx), %rdx
subq 0x30(%rcx), %rdx
sarq $0x3, %rdx
cmpq %rax, %rdx
jne 0x5963
movq 0x50(%r14), %rax
cmpq %rax, 0x58(%r14)
je 0x5963
xorl %ebx, %ebx
movq 0x8(%r15), %rcx
movq (%rcx,%rbx,8), %rdx
cmpl $0x1, 0x48(%rdx)
jne 0x5944
movq 0x10(%r12), %rdi
movq 0x18(%r12), %rsi
subq %rdi, %rsi
setne %r8b
je 0x58ec
sarq $0x3, %rsi
cmpq $0x1, %rsi
movq %rsi, %r8
adcq $0x0, %r8
cmpq %rdx, (%rdi)
je 0x58f1
movl $0x1, %r10d
movq %r10, %r9
cmpq %r10, %r8
je 0x58e5
leaq 0x1(%r9), %r10
cmpq %rdx, (%rdi,%r9,8)
jne 0x58d3
cmpq %r9, %rsi
seta %r8b
testb %r8b, %r8b
je 0x5944
movq $0x3, -0x40(%rbp)
movq (%r12), %rdx
movq %rdx, -0x38(%rbp)
movq (%rcx,%rbx,8), %rcx
movq %rcx, -0x30(%rbp)
leaq (%rbx,%rbx,2), %rcx
leaq (%rax,%rcx,8), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x5931
movq -0x30(%rbp), %rax
movq %rax, 0x10(%rsi)
movups -0x40(%rbp), %xmm0
movups %xmm0, (%rsi)
addq $0x18, 0x8(%rdi)
jmp 0x5944
leaq -0x40(%rbp), %rdx
callq 0xb7ce
movabsq $-0x5555555555555555, %r11 # imm = 0xAAAAAAAAAAAAAAAB
incq %rbx
movq 0x50(%r14), %rax
movq 0x58(%r14), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
imulq %r11, %rcx
cmpq %rbx, %rcx
ja 0x5894
incq %r13
movq 0x8(%r14), %rax
movq 0x10(%r14), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %r13, %rcx
ja 0x5862
movq 0x8(%r14), %rax
cmpq %rax, 0x10(%r14)
leaq 0x780c(%rip), %r12      # 0xd199
je 0x5a5c
xorl %ebx, %ebx
movq (%rax,%rbx,8), %r15
movslq 0x8(%r15), %rax
movq (%r15), %rdx
movq 0x30(%rdx), %rcx
movq 0x38(%rdx), %rdx
subq %rcx, %rdx
sarq $0x3, %rdx
decq %rdx
cmpq %rax, %rdx
jne 0x5a41
movq (%rcx,%rax,8), %rdi
addq $0x8, %rdi
movq %r12, %rsi
callq 0x30a0
movabsq $-0x5555555555555555, %r11 # imm = 0xAAAAAAAAAAAAAAAB
testl %eax, %eax
jne 0x5a41
movq (%r15), %rax
movq %rax, -0x38(%rbp)
movq $0x4, -0x40(%rbp)
movslq 0x8(%r15), %rcx
movq 0x30(%rax), %rax
movq (%rax,%rcx,8), %rdx
movq %rdx, -0x30(%rbp)
movq (%rax,%rcx,8), %rax
movslq (%rax), %rax
movq -0x50(%rbp), %rcx
movq (%rcx), %rcx
leaq (%rax,%rax,2), %rax
leaq (%rcx,%rax,8), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x5a2e
movq -0x30(%rbp), %rax
movq %rax, 0x10(%rsi)
movups -0x40(%rbp), %xmm0
movups %xmm0, (%rsi)
addq $0x18, 0x8(%rdi)
jmp 0x5a41
leaq -0x40(%rbp), %rdx
callq 0xb7ce
movabsq $-0x5555555555555555, %r11 # imm = 0xAAAAAAAAAAAAAAAB
incq %rbx
movq 0x8(%r14), %rax
movq 0x10(%r14), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %rbx, %rcx
ja 0x5995
movq -0x48(%rbp), %rdx
incq %rdx
movq -0x58(%rbp), %r15
movq 0x38(%r15), %rax
movq 0x40(%r15), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %rdx, %rcx
ja 0x579a
movq 0x38(%r15), %rax
cmpq %rax, 0x40(%r15)
je 0x5b37
xorl %ebx, %ebx
xorps %xmm1, %xmm1
movq (%rax,%rbx,8), %r12
movq 0x50(%r12), %rax
cmpq %rax, 0x58(%r12)
je 0x5b1c
xorl %r13d, %r13d
xorl %r14d, %r14d
movq 0x8(%rax,%r13), %rcx
cmpq (%rax,%r13), %rcx
jne 0x5afb
leaq (%rax,%r13), %rdi
movups %xmm1, -0x38(%rbp)
movq $0x5, -0x40(%rbp)
movq 0x8(%rax,%r13), %rsi
cmpq 0x10(%rax,%r13), %rsi
je 0x5ae5
movq -0x30(%rbp), %rax
movq %rax, 0x10(%rsi)
movups -0x40(%rbp), %xmm0
movups %xmm0, (%rsi)
addq $0x18, 0x8(%rdi)
jmp 0x5afb
leaq -0x40(%rbp), %rdx
callq 0xb7ce
xorps %xmm1, %xmm1
movabsq $-0x5555555555555555, %r11 # imm = 0xAAAAAAAAAAAAAAAB
incq %r14
movq 0x50(%r12), %rax
movq 0x58(%r12), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
imulq %r11, %rcx
addq $0x18, %r13
cmpq %r14, %rcx
ja 0x5aa8
incq %rbx
movq 0x38(%r15), %rax
movq 0x40(%r15), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %rbx, %rcx
ja 0x5a92
movq 0x38(%r15), %rax
cmpq %rax, 0x40(%r15)
je 0x5c2d
xorl %edx, %edx
xorl %r14d, %r14d
movq %rdx, -0x48(%rbp)
movq (%rax,%rdx,8), %rcx
movq 0x50(%rcx), %rax
movq %rcx, -0x50(%rbp)
cmpq %rax, 0x58(%rcx)
je 0x5c0c
xorl %r12d, %r12d
leaq (%r12,%r12,2), %rcx
movq 0x8(%rax,%rcx,8), %rdx
subq (%rax,%rcx,8), %rdx
sarq $0x3, %rdx
imulq %r11, %rdx
cmpq $0x2, %rdx
jb 0x5be5
leaq (%rax,%rcx,8), %rbx
movq (%rbx), %rdx
movq 0x8(%rbx), %rax
subq %rdx, %rax
sarq $0x3, %rax
imulq %r11, %rax
cmpq $0x2, %rax
jb 0x5be5
movl $0x1, %r13d
movl $0x18, %r15d
leaq (%rdx,%r15), %rsi
addq $-0x18, %rsi
addq %r15, %rdx
callq 0x76e6
movabsq $-0x5555555555555555, %r11 # imm = 0xAAAAAAAAAAAAAAAB
addl %eax, %r14d
incq %r13
movq (%rbx), %rdx
movq 0x8(%rbx), %rax
subq %rdx, %rax
sarq $0x3, %rax
imulq %r11, %rax
addq $0x18, %r15
cmpq %r13, %rax
ja 0x5baa
incq %r12
movq -0x50(%rbp), %rcx
movq 0x50(%rcx), %rax
movq 0x58(%rcx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
imulq %r11, %rcx
cmpq %r12, %rcx
movq -0x58(%rbp), %r15
ja 0x5b67
movq -0x48(%rbp), %rdx
incq %rdx
movq 0x38(%r15), %rax
movq 0x40(%r15), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %rdx, %rcx
ja 0x5b4a
jmp 0x5c30
xorl %r14d, %r14d
movq 0xb3a1(%rip), %rbx      # 0x10fd8
leaq 0x75ac(%rip), %rsi      # 0xd1ea
movl $0xa, %edx
movq %rbx, %rdi
callq 0x32b0
movq %rbx, %rdi
movl %r14d, %esi
callq 0x33b0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3230
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3170
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop