// File: /workspace/github_c_makefile_star2_O1/almk277[P]ROSE/rasm/parser.cpp
// Function: parser::parse()
void parser::parse()
{
	parser_state state;
	string name;

	bool more_tok = true;
	while (more_tok) {
		switch (s.next()) {
		case tok::STRING:
		{
			state.ensure(parser_state::SUB);
			auto it = instr.find(s.str());
			if (it == instr.end())
				throw error(s.str() + ": no such instruction");
			instruction i = it->second;
			m.text.set_next_addr(i.len);
			m.text.put(i.opcode);
			parse_operands(i);
			s >> eol;
			break;
		}
		case tok::LABEL:
			s >> name >> eol;
			m.text.add_label(name);
			break;
		case tok::BYTE:
			state.ensure(parser_state::STR);
			m.str.put(s.num_byte());
			break;
		case tok::INT:
			state.ensure(parser_state::STR);
			m.str.put(s.num_int());
			break;
		case tok::FLOAT:
			state.ensure(parser_state::STR);
			m.str.put(s.num_flt());
			break;
		case tok::ARRAY:
			state.ensure(parser_state::STR);
			m.str.put(s.array());
			break;
		case tok::NEWLINE:
			break;
		case tok::END:
			more_tok = false;
			break;
		case tok::ARG:
		{
			state.ensure(parser_state::SUB);
			string type;
			s >> type >> name >> eol;
			m.text.add_arg(name, mangle(type));
			break;
		}
		case tok::DATA:
		{
			string type;
			s >> type >> name >> eol;
			m.data.add(name);
			break;
		}
		case tok::EXPORT:
		{
			s >> name >> eol;
			auto slot = m.ptbl[name];
			auto &exp = m.exp.add(name);
			exp.name = m.sym.add(name);
			exp.idx = slot;
			break;
		}
		case tok::EXTERN:
		{
			s >> name >> eol;
			auto ss = s.string_pair();
			auto &imp = m.imp.add(name);
			imp.name = m.sym.add(ss.first);
			imp.module = m.mtbl[ss.second];
			imp.type = m.sym.add(read_types());
			break;
		}
		case tok::IMPORT:
		{
			unsigned char maj, min;
			s >> name >> maj >> min >> eol;
			auto &mod = m.mtbl.add(name);
			mod.name = m.sym.add(name);
			mod.version = { maj, min };
			break;
		}
		case tok::MODULE:
		{
			unsigned char maj, min;
			s >> name >> maj >> min >> eol;
			m.header.name = m.sym.add(name);
			m.header.version = { maj, min };
			break;
		}
		case tok::STR:
			state.set(parser_state::STR, [this]{ m.str.finish(); });
			s >> name >> eol;
			m.str.start(name);
			break;
		case tok::SUB:
			state.set(parser_state::SUB, [this]{ m.text.finish(); });
			s >> name >> eol;
			m.text.start(&m.ptbl.add(name));
			break;
		case tok::VAR:
			state.ensure(parser_state::SUB);
			s >> name >> eol;
			m.text.add_var(name);
			break;
		default: throw std::logic_error("bad token type");
		}
	} //while (more_tok)

	state.set(parser_state::NONE);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x128, %rsp            # imm = 0x128
movq %rdi, %r14
leaq 0xa0(%rsp), %rcx
movl $0x0, -0x8(%rcx)
xorps %xmm0, %xmm0
movups %xmm0, (%rcx)
leaq 0x18a4(%rip), %rax      # 0xc67c
movq %rax, 0x18(%rcx)
leaq 0x189b(%rip), %rax      # 0xc67e
movq %rax, 0x10(%rcx)
leaq 0x88(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x20(%rsp), %r13
movb $0x1, %r15b
leaq 0x3783(%rip), %rbp      # 0xe590
leaq 0x78(%rsp), %r12
movq (%r14), %rdi
callq 0x56b4
cmpl $0x10, %eax
ja 0xb5ca
movl %eax, %eax
movslq (%rbp,%rax,4), %rax
addq %rbp, %rax
jmpq *%rax
leaq 0x98(%rsp), %rdi
movl $0x1, %esi
callq 0xbfae
movq (%r14), %rsi
addq $0x10, %rsi
leaq 0x9551(%rip), %rdi      # 0x143a0
callq 0xcdd2
testq %rax, %rax
je 0xb57b
movups 0x28(%rax), %xmm0
movaps %xmm0, 0x10(%rsp)
movq 0x8(%r14), %rax
leaq 0x240(%rax), %rdi
movl 0x248(%rax), %ecx
subl 0x240(%rax), %ecx
addl 0x14(%rsp), %ecx
movl %ecx, 0x330(%rax)
movzbl 0x10(%rsp), %esi
callq 0xc1f4
movq %r14, %rdi
leaq 0x10(%rsp), %rsi
callq 0xb7d6
movq (%r14), %rdi
leaq 0x37ac(%rip), %rsi      # 0xe654
callq 0x6251
jmp 0xb4cc
leaq 0x98(%rsp), %rdi
movl $0x1, %esi
callq 0xbfae
movq (%r14), %rdi
movq %r12, %rsi
callq 0x6264
movq %rax, %rdi
leaq 0x377b(%rip), %rsi      # 0xe654
callq 0x6251
movq 0x8(%r14), %rdi
movl $0x240, %eax            # imm = 0x240
addq %rax, %rdi
movq %r12, %rsi
callq 0x7fbe
jmp 0xb4cc
xorps %xmm0, %xmm0
movaps %xmm0, 0xe0(%rsp)
movaps %xmm0, 0xf0(%rsp)
movq %r14, 0xe0(%rsp)
leaq 0xd73(%rip), %rax       # 0xbc8c
movq %rax, 0xf8(%rsp)
leaq 0xd76(%rip), %rax       # 0xbc9e
movq %rax, 0xf0(%rsp)
leaq 0x98(%rsp), %rdi
movl $0x2, %esi
leaq 0xe0(%rsp), %rdx
callq 0xc4f8
movq 0xf0(%rsp), %rax
testq %rax, %rax
je 0xaf69
leaq 0xe0(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq (%r14), %rdi
movq %r12, %rsi
callq 0x6264
movq %rax, %rdi
leaq 0x36d6(%rip), %rsi      # 0xe654
callq 0x6251
movq 0x8(%r14), %rdi
movl $0x338, %eax            # imm = 0x338
addq %rax, %rdi
movq %r12, %rsi
callq 0x7a24
jmp 0xb4cc
movq (%r14), %rdi
movq %r12, %rsi
callq 0x6264
movq %rax, %rdi
leaq 0x36a3(%rip), %rsi      # 0xe654
callq 0x6251
movq (%r14), %rsi
leaq 0x10(%rsp), %rdi
callq 0x6300
movq 0x8(%r14), %rdi
movl $0x180, %eax            # imm = 0x180
addq %rax, %rdi
movq %r12, %rsi
callq 0xc46c
movq %rax, %rbx
movq 0x8(%r14), %rdi
movl $0x1f0, %eax            # imm = 0x1F0
addq %rax, %rdi
leaq 0x10(%rsp), %rsi
callq 0x792e
movw %ax, (%rbx)
movq 0x8(%r14), %rdi
movl $0x110, %eax            # imm = 0x110
addq %rax, %rdi
leaq 0x30(%rsp), %rsi
callq 0xc294
movb %al, 0x5(%rbx)
movq 0x8(%r14), %r12
leaq 0x58(%rsp), %r13
movq %r13, %rdi
movq %r14, %rsi
callq 0xba4a
addq $0x1f0, %r12            # imm = 0x1F0
movq %r12, %rdi
movq %r13, %rsi
callq 0x792e
movw %ax, 0x2(%rbx)
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
leaq 0x20(%rsp), %r13
je 0xb057
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x3260
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
leaq 0x78(%rsp), %r12
je 0xb18f
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x3260
jmp 0xb18f
leaq 0x98(%rsp), %rdi
movl $0x2, %esi
callq 0xbfae
movq 0x8(%r14), %rdi
movl $0x338, %eax            # imm = 0x338
addq %rax, %rdi
movq (%r14), %rax
movl 0x30(%rax), %esi
callq 0xc210
jmp 0xb4cc
movq (%r14), %rdi
movq %r12, %rsi
callq 0x6264
movq %rax, %rdi
leaq 0x58(%rsp), %rsi
callq 0x628c
movq %rax, %rdi
leaq 0xf(%rsp), %rsi
callq 0x628c
movq %rax, %rdi
leaq 0x3576(%rip), %rsi      # 0xe654
callq 0x6251
movq 0x8(%r14), %rbx
leaq 0x110(%rbx), %rdi
movq %r12, %rsi
callq 0x7768
leaq 0x168(%rbx), %rdi
movl $0x0, 0x10(%rsp)
leaq 0x10(%rsp), %rsi
callq 0xd0e6
movq 0x170(%rbx), %rbx
movq 0x8(%r14), %rdi
movl $0x1f0, %eax            # imm = 0x1F0
addq %rax, %rdi
movq %r12, %rsi
callq 0x792e
movw %ax, -0x4(%rbx)
movb 0x58(%rsp), %al
movb 0xf(%rsp), %cl
movb %al, -0x2(%rbx)
movb %cl, -0x1(%rbx)
jmp 0xb4cc
movq %r13, 0x10(%rsp)
movq $0x0, 0x18(%rsp)
movb $0x0, 0x20(%rsp)
movq (%r14), %rdi
leaq 0x10(%rsp), %rsi
callq 0x6264
movq %rax, %rdi
movq %r12, %rsi
callq 0x6264
movq %rax, %rdi
leaq 0x34de(%rip), %rsi      # 0xe654
callq 0x6251
movq 0x8(%r14), %rdi
movl $0x390, %eax            # imm = 0x390
addq %rax, %rdi
movq %r12, %rsi
callq 0x7768
movq 0x10(%rsp), %rdi
cmpq %r13, %rdi
jne 0xb4bf
jmp 0xb4cc
movq (%r14), %rdi
movq %r12, %rsi
callq 0x6264
movq %rax, %rdi
leaq 0x349d(%rip), %rsi      # 0xe654
callq 0x6251
movq 0x8(%r14), %rdi
movl $0x240, %eax            # imm = 0x240
addq %rax, %rdi
movq %r12, %rsi
callq 0x7b18
jmp 0xb4cc
xorps %xmm0, %xmm0
movaps %xmm0, 0xc0(%rsp)
movaps %xmm0, 0xd0(%rsp)
movq %r14, 0xc0(%rsp)
leaq 0xacd(%rip), %rax       # 0xbcc4
movq %rax, 0xd8(%rsp)
leaq 0xad0(%rip), %rax       # 0xbcd6
movq %rax, 0xd0(%rsp)
leaq 0x98(%rsp), %rdi
movl $0x1, %esi
leaq 0xc0(%rsp), %rdx
callq 0xc4f8
movq 0xd0(%rsp), %rax
testq %rax, %rax
je 0xb247
leaq 0xc0(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq (%r14), %rdi
movq %r12, %rsi
callq 0x6264
movq %rax, %rdi
leaq 0x33f8(%rip), %rsi      # 0xe654
callq 0x6251
movq 0x8(%r14), %rbx
leaq 0xa0(%rbx), %rdi
movq %r12, %rsi
callq 0xc53a
addq $0x240, %rbx            # imm = 0x240
movq %rbx, %rdi
movq %rax, %rsi
callq 0x8262
jmp 0xb4cc
leaq 0x98(%rsp), %rdi
movl $0x2, %esi
callq 0xbfae
movq 0x8(%r14), %rdi
movl $0x338, %eax            # imm = 0x338
addq %rax, %rdi
movq (%r14), %rax
movzbl 0x34(%rax), %esi
callq 0xc1f4
jmp 0xb4cc
xorl %r15d, %r15d
jmp 0xb4cc
leaq 0x98(%rsp), %rdi
movl $0x2, %esi
callq 0xbfae
movq 0x8(%r14), %rdi
movl $0x338, %eax            # imm = 0x338
addq %rax, %rdi
movq (%r14), %rax
movss 0x38(%rax), %xmm0
callq 0xc250
jmp 0xb4cc
movq (%r14), %rdi
movq %r12, %rsi
callq 0x6264
movq %rax, %rdi
leaq 0x10(%rsp), %rsi
callq 0x628c
movq %rax, %rdi
leaq 0x58(%rsp), %rsi
callq 0x628c
movq %rax, %rdi
leaq 0x3333(%rip), %rsi      # 0xe654
callq 0x6251
movq 0x8(%r14), %rdi
movl $0x1f0, %eax            # imm = 0x1F0
addq %rax, %rdi
movq %r12, %rsi
callq 0x792e
movq 0x8(%r14), %rcx
movw %ax, 0x6(%rcx)
movb 0x10(%rsp), %al
movb 0x58(%rsp), %dl
movb %al, 0x8(%rcx)
movb %dl, 0x9(%rcx)
jmp 0xb4cc
leaq 0x98(%rsp), %rdi
movl $0x2, %esi
callq 0xbfae
movq 0x8(%r14), %rdi
movl $0x338, %eax            # imm = 0x338
addq %rax, %rdi
movq (%r14), %rsi
addq $0x40, %rsi
callq 0x79fe
jmp 0xb4cc
movq (%r14), %rdi
movq %r12, %rsi
callq 0x6264
movq %rax, %rdi
leaq 0x32bb(%rip), %rsi      # 0xe654
callq 0x6251
movq 0x8(%r14), %rdi
movl $0xa0, %eax
addq %rax, %rdi
movq %r12, %rsi
callq 0xc294
movl %eax, %ebx
movq %r12, %rsi
movq 0x8(%r14), %r12
leaq 0x30(%r12), %rdi
callq 0x7768
leaq 0x88(%r12), %rdi
movw $0x0, 0x10(%rsp)
movb $0x0, 0x12(%rsp)
leaq 0x10(%rsp), %rsi
callq 0xce0c
movq 0x90(%r12), %r12
movq 0x8(%r14), %rdi
movl $0x1f0, %eax            # imm = 0x1F0
addq %rax, %rdi
leaq 0x78(%rsp), %rsi
callq 0x792e
movw %ax, -0x4(%r12)
movb %bl, -0x2(%r12)
leaq 0x20(%rsp), %r13
leaq 0x78(%rsp), %r12
jmp 0xb4cc
leaq 0x98(%rsp), %rdi
movl $0x1, %esi
callq 0xbfae
movq %r13, 0x10(%rsp)
movq $0x0, 0x18(%rsp)
movb $0x0, 0x20(%rsp)
movq (%r14), %rdi
leaq 0x10(%rsp), %rsi
callq 0x6264
movq %rax, %rdi
movq %r12, %rsi
callq 0x6264
movq %rax, %rdi
leaq 0x31f2(%rip), %rsi      # 0xe654
callq 0x6251
movq 0x8(%r14), %rbx
leaq 0x58(%rsp), %r12
movq %r12, %rdi
leaq 0x10(%rsp), %rsi
callq 0xab33
addq $0x240, %rbx            # imm = 0x240
movq %rbx, %rdi
leaq 0x78(%rsp), %rsi
movq %r12, %rdx
callq 0x7fd8
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0xb4b0
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x3260
movq 0x10(%rsp), %rdi
cmpq %r13, %rdi
leaq 0x78(%rsp), %r12
je 0xb4cc
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x3260
testb $0x1, %r15b
jne 0xae12
xorps %xmm0, %xmm0
leaq 0x100(%rsp), %rdx
movaps %xmm0, (%rdx)
leaq 0x1edb(%rip), %rax      # 0xd3c6
movq %rax, 0x18(%rdx)
leaq 0x1ed2(%rip), %rax      # 0xd3c8
movq %rax, 0x10(%rdx)
leaq 0x98(%rsp), %rdi
xorl %esi, %esi
callq 0xc4f8
movq 0x110(%rsp), %rax
testq %rax, %rax
je 0xb528
leaq 0x100(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
je 0xb54a
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x3260
movq 0xb0(%rsp), %rax
testq %rax, %rax
je 0xb569
leaq 0xa0(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x10, %edi
callq 0x3150
movq %rax, %r15
movq (%r14), %rsi
addq $0x10, %rsi
leaq 0x310a(%rip), %rdx      # 0xe6a0
leaq 0x10(%rsp), %rdi
callq 0x49df
movb $0x1, %bpl
leaq 0x10(%rsp), %rsi
movq %r15, %rdi
callq 0x3440
xorl %ebp, %ebp
movq 0x8a37(%rip), %rsi      # 0x13ff0
movq 0x89f0(%rip), %rdx      # 0x13fb0
movq %r15, %rdi
callq 0x3480
jmp 0xb5fc
movl $0x10, %edi
callq 0x3150
movq %rax, %r14
leaq 0x30d8(%rip), %rsi      # 0xe6b6
movq %rax, %rdi
callq 0x33b0
movq 0x89e3(%rip), %rsi      # 0x13fd0
movq 0x89cc(%rip), %rdx      # 0x13fc0
movq %r14, %rdi
callq 0x3480
jmp 0xb7ce
jmp 0xb7ce
jmp 0xb782
movq %rax, %rbx
movq %r14, %rdi
jmp 0xb646
movq %rax, %rbx
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0xb63a
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x3260
jmp 0xb63a
movq %rax, %rbx
movb $0x1, %bpl
testb %bpl, %bpl
je 0xb785
movq %r15, %rdi
callq 0x31f0
jmp 0xb785
movq %rax, %rbx
movq 0x110(%rsp), %rax
testq %rax, %rax
je 0xb785
leaq 0x100(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
jmp 0xb785
jmp 0xb7ce
jmp 0xb7ce
jmp 0xb7ce
movq %rax, %rbx
movq 0xf0(%rsp), %rax
testq %rax, %rax
je 0xb785
leaq 0xe0(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
jmp 0xb785
jmp 0xb7ce
movq %rax, %rbx
movq 0xd0(%rsp), %rax
testq %rax, %rax
je 0xb785
leaq 0xc0(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
jmp 0xb785
jmp 0xb7ce
jmp 0xb782
movq %rax, %rbx
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0xb73e
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x3260
jmp 0xb73e
jmp 0xb73b
jmp 0xb782
movq %rax, %rbx
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0xb754
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x3260
jmp 0xb754
jmp 0xb751
jmp 0xb782
jmp 0xb782
movq %rax, %rbx
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
jne 0xb771
jmp 0xb785
jmp 0xb782
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0xc4c2
jmp 0xb785
jmp 0xb782
jmp 0xb782
movq %rax, %rbx
movq 0x10(%rsp), %rdi
cmpq %r13, %rdi
je 0xb785
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x3260
jmp 0xb785
jmp 0xb782
movq %rax, %rbx
movq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
je 0xb7a7
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x3260
movq 0xb0(%rsp), %rax
testq %rax, %rax
je 0xb7c6
leaq 0xa0(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq %rbx, %rdi
callq 0x34a0
movq %rax, %rdi
callq 0x4acf