// File: /workspace/github_c_makefile_star2_O2/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 $0x118, %rsp            # imm = 0x118
movq %rdi, %r14
leaq 0x10(%rsp), %rcx
andl $0x0, -0x8(%rcx)
xorps %xmm0, %xmm0
movups %xmm0, (%rcx)
leaq 0x11f4(%rip), %rax      # 0xb266
movq %rax, 0x18(%rcx)
leaq 0x11eb(%rip), %rax      # 0xb268
movq %rax, 0x10(%rcx)
leaq 0xe0(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x3538(%rip), %rbx      # 0xd5d4
leaq 0x8(%rsp), %rbp
leaq 0x35f0(%rip), %r15      # 0xd698
leaq 0xd0(%rsp), %r13
movq (%r14), %rdi
callq 0x53b6
cmpl $0x10, %eax
ja 0xa69e
movl %eax, %eax
movslq (%rbx,%rax,4), %rax
addq %rbx, %rax
jmpq *%rax
movq %rbp, %rdi
pushq $0x1
popq %rsi
callq 0xadd4
movq (%r14), %rsi
addq $0x10, %rsi
leaq 0xb2bb(%rip), %rdi      # 0x153a0
callq 0xb8f8
testq %rax, %rax
je 0xa6d0
movups 0x28(%rax), %xmm0
movaps %xmm0, 0x30(%rsp)
movq 0x8(%r14), %rax
leaq 0x240(%rax), %rdi
movl 0x248(%rax), %ecx
subl 0x240(%rax), %ecx
addl 0x34(%rsp), %ecx
movl %ecx, 0x330(%rax)
movzbl 0x30(%rsp), %esi
callq 0xaf24
movq %r14, %rdi
leaq 0x30(%rsp), %rsi
callq 0xa80a
movq (%r14), %rdi
movq %r15, %rsi
callq 0x5c8b
jmp 0xa0b0
andq $0x0, 0x98(%rsp)
movq %r14, 0x90(%rsp)
leaq 0xae4(%rip), %rax       # 0xac40
movq %rax, 0xa8(%rsp)
leaq 0xae7(%rip), %rax       # 0xac52
movq %rax, 0xa0(%rsp)
movq %rbp, %rdi
pushq $0x1
popq %rsi
leaq 0x90(%rsp), %r12
movq %r12, %rdx
callq 0xb112
movq %r12, %rdi
callq 0xb146
movq (%r14), %rdi
movq %r13, %rsi
callq 0x5c9c
movq %rax, %rdi
movq %r15, %rsi
callq 0x5c8b
movq 0x8(%r14), %r12
leaq 0xa0(%r12), %rdi
movq %r13, %rsi
callq 0xb162
addq $0x240, %r12            # imm = 0x240
movq %r12, %rdi
movq %rax, %rsi
callq 0x7832
jmp 0xa0b0
movq (%r14), %rdi
movq %r13, %rsi
callq 0x5c9c
leaq 0x70(%rsp), %r12
movq %rax, %rdi
leaq 0x30(%rsp), %rsi
callq 0x5cc4
movq %rax, %rdi
movq %r12, %rsi
callq 0x5cc4
movq %rax, %rdi
movq %r15, %rsi
callq 0x5c8b
movq 0x8(%r14), %rdi
movl $0x110, %eax            # imm = 0x110
addq %rax, %rdi
movq %r13, %rsi
callq 0xb0e6
movq %rax, %rbp
movq 0x8(%r14), %rdi
movl $0x1f0, %eax            # imm = 0x1F0
addq %rax, %rdi
movq %r13, %rsi
callq 0x7166
movw %ax, (%rbp)
movb 0x30(%rsp), %al
movb 0x70(%rsp), %cl
movb %al, 0x2(%rbp)
movb %cl, 0x3(%rbp)
leaq 0x8(%rsp), %rbp
jmp 0xa0b0
movq (%r14), %rdi
movq %r13, %rsi
callq 0x5c9c
movq %rax, %rdi
movq %r15, %rsi
callq 0x5c8b
movq (%r14), %rsi
leaq 0x30(%rsp), %rdi
callq 0x5d32
movq 0x8(%r14), %rdi
movl $0x180, %eax            # imm = 0x180
addq %rax, %rdi
movq %r13, %rsi
callq 0xb09e
movq %rax, %rbp
movq 0x8(%r14), %rdi
movl $0x1f0, %eax            # imm = 0x1F0
addq %rax, %rdi
leaq 0x30(%rsp), %rsi
callq 0x7166
movw %ax, (%rbp)
movq 0x8(%r14), %rdi
movl $0x110, %eax            # imm = 0x110
addq %rax, %rdi
leaq 0x50(%rsp), %rsi
callq 0xaf58
movb %al, 0x5(%rbp)
movq 0x8(%r14), %r12
leaq 0x70(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0xaa44
addq $0x1f0, %r12            # imm = 0x1F0
movq %r12, %rdi
movq %r15, %rsi
callq 0x7166
movw %ax, 0x2(%rbp)
movq %r15, %rdi
callq 0x3528
leaq 0x30(%rsp), %rdi
callq 0xb0d0
leaq 0x8(%rsp), %rbp
leaq 0x3397(%rip), %r15      # 0xd698
jmp 0xa0b0
movq %rbp, %rdi
pushq $0x2
popq %rsi
callq 0xadd4
movq 0x8(%r14), %rdi
movl $0x338, %eax            # imm = 0x338
addq %rax, %rdi
movq (%r14), %rax
movss 0x38(%rax), %xmm0
callq 0xaf44
jmp 0xa0b0
movq %rbp, %rdi
pushq $0x2
popq %rsi
callq 0xadd4
movq 0x8(%r14), %rdi
movl $0x338, %eax            # imm = 0x338
addq %rax, %rdi
movq (%r14), %rax
movzbl 0x34(%rax), %esi
callq 0xaf24
jmp 0xa0b0
movq %rbp, %rdi
pushq $0x2
popq %rsi
callq 0xadd4
movq 0x8(%r14), %rdi
movl $0x338, %eax            # imm = 0x338
addq %rax, %rdi
movq (%r14), %rax
movl 0x30(%rax), %esi
callq 0xaf34
jmp 0xa0b0
movq (%r14), %rdi
movq %r13, %rsi
callq 0x5c9c
movq %rax, %rdi
movq %r15, %rsi
callq 0x5c8b
movq 0x8(%r14), %rdi
movl $0x240, %eax            # imm = 0x240
addq %rax, %rdi
movq %r13, %rsi
callq 0x732e
jmp 0xa0b0
leaq 0x40(%rsp), %rax
movq %rax, 0x30(%rsp)
andq $0x0, 0x38(%rsp)
movb $0x0, 0x40(%rsp)
movq (%r14), %rdi
leaq 0x30(%rsp), %rsi
callq 0x5c9c
movq %rax, %rdi
movq %r13, %rsi
callq 0x5c9c
movq %rax, %rdi
movq %r15, %rsi
callq 0x5c8b
movq 0x8(%r14), %rdi
movl $0x390, %eax            # imm = 0x390
addq %rax, %rdi
movq %r13, %rsi
callq 0x703a
leaq 0x30(%rsp), %rdi
callq 0x3528
jmp 0xa0b0
movq %rbp, %rdi
pushq $0x2
popq %rsi
callq 0xadd4
movq 0x8(%r14), %rdi
movl $0x338, %eax            # imm = 0x338
addq %rax, %rdi
movq (%r14), %rsi
addq $0x40, %rsi
callq 0x7234
jmp 0xa0b0
movq %rbp, %rdi
pushq $0x1
popq %rsi
callq 0xadd4
leaq 0x40(%rsp), %rax
movq %rax, 0x30(%rsp)
andq $0x0, 0x38(%rsp)
movb $0x0, 0x40(%rsp)
movq (%r14), %rdi
leaq 0x30(%rsp), %rsi
callq 0x5c9c
movq %rax, %rdi
movq %r13, %rsi
callq 0x5c9c
movq %rax, %rdi
movq %r15, %rsi
callq 0x5c8b
movq 0x8(%r14), %r12
leaq 0x70(%rsp), %r15
movq %r15, %rdi
leaq 0x30(%rsp), %rsi
callq 0x9dfb
addq $0x240, %r12            # imm = 0x240
movq %r12, %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x7646
movq %r15, %rdi
callq 0x3528
leaq 0x30(%rsp), %rdi
callq 0x3528
leaq 0x31e1(%rip), %r15      # 0xd698
jmp 0xa0b0
andq $0x0, 0xb8(%rsp)
movq %r14, 0xb0(%rsp)
leaq 0x734(%rip), %rax       # 0xac08
movq %rax, 0xc8(%rsp)
leaq 0x737(%rip), %rax       # 0xac1a
movq %rax, 0xc0(%rsp)
movq %rbp, %rdi
pushq $0x2
popq %rsi
leaq 0xb0(%rsp), %r12
movq %r12, %rdx
callq 0xb112
movq %r12, %rdi
callq 0xb146
movq (%r14), %rdi
movq %r13, %rsi
callq 0x5c9c
movq %rax, %rdi
movq %r15, %rsi
callq 0x5c8b
movq 0x8(%r14), %rdi
movl $0x338, %eax            # imm = 0x338
addq %rax, %rdi
movq %r13, %rsi
callq 0x725a
jmp 0xa0b0
movq (%r14), %rdi
movq %r13, %rsi
callq 0x5c9c
movq %rax, %rdi
movq %r15, %rsi
callq 0x5c8b
movq 0x8(%r14), %rdi
movl $0xa0, %eax
addq %rax, %rdi
movq %r13, %rsi
callq 0xaf58
movl %eax, %ebp
movq 0x8(%r14), %rdi
addq $0x30, %rdi
movq %r13, %rsi
callq 0xb06c
movq %rax, %r12
movq 0x8(%r14), %rdi
movl $0x1f0, %eax            # imm = 0x1F0
addq %rax, %rdi
movq %r13, %rsi
callq 0x7166
movw %ax, (%r12)
movb %bpl, 0x2(%r12)
leaq 0x8(%rsp), %rbp
jmp 0xa0b0
movq (%r14), %rdi
movq %r13, %rsi
callq 0x5c9c
movq %rax, %rdi
leaq 0x30(%rsp), %rsi
callq 0x5cc4
movq %rax, %rdi
leaq 0x70(%rsp), %rsi
callq 0x5cc4
movq %rax, %rdi
movq %r15, %rsi
callq 0x5c8b
movq 0x8(%r14), %rdi
movl $0x1f0, %eax            # imm = 0x1F0
addq %rax, %rdi
movq %r13, %rsi
callq 0x7166
movq 0x8(%r14), %rcx
movw %ax, 0x6(%rcx)
movb 0x30(%rsp), %al
movb 0x70(%rsp), %dl
movb %al, 0x8(%rcx)
movb %dl, 0x9(%rcx)
jmp 0xa0b0
movq %rbp, %rdi
pushq $0x1
popq %rsi
callq 0xadd4
movq (%r14), %rdi
movq %r13, %rsi
callq 0x5c9c
movq %rax, %rdi
movq %r15, %rsi
callq 0x5c8b
movq 0x8(%r14), %rdi
movl $0x240, %eax            # imm = 0x240
addq %rax, %rdi
movq %r13, %rsi
callq 0x762c
jmp 0xa0b0
xorps %xmm0, %xmm0
leaq 0xf0(%rsp), %rdx
movaps %xmm0, (%rdx)
leaq 0x1961(%rip), %rax      # 0xbfae
movq %rax, 0x18(%rdx)
leaq 0x1958(%rip), %rax      # 0xbfb0
movq %rax, 0x10(%rdx)
leaq 0x8(%rsp), %rdi
xorl %esi, %esi
callq 0xb112
leaq 0xf0(%rsp), %rdi
callq 0xb146
leaq 0xd0(%rsp), %rdi
callq 0x3528
leaq 0x10(%rsp), %rdi
callq 0xb146
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x10
popq %rdi
callq 0x3170
movq %rax, %r14
leaq 0x304a(%rip), %rsi      # 0xd6fa
movq %rax, %rdi
callq 0x33b0
movq 0xa909(%rip), %rsi      # 0x14fc8
movq 0xa8e2(%rip), %rdx      # 0x14fa8
movq %r14, %rdi
callq 0x3470
jmp 0xa71b
pushq $0x10
popq %rdi
callq 0x3170
movq %rax, %r15
movq (%r14), %rsi
addq $0x10, %rsi
leaq 0x2ffb(%rip), %rdx      # 0xd6e4
leaq 0x30(%rsp), %rdi
callq 0x4721
movb $0x1, %bpl
leaq 0x30(%rsp), %rsi
movq %r15, %rdi
callq 0x3440
xorl %ebp, %ebp
movq 0xa8dc(%rip), %rsi      # 0x14fe8
movq 0xa885(%rip), %rdx      # 0x14f98
movq %r15, %rdi
callq 0x3470
movq %rax, %rbx
leaq 0xf0(%rsp), %rdi
jmp 0xa7ae
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x3528
testb %bpl, %bpl
leaq 0x10(%rsp), %r14
jne 0xa74f
jmp 0xa7ec
movq %rax, %rbx
leaq 0x10(%rsp), %r14
movq %r15, %rdi
callq 0x3210
jmp 0xa7ec
jmp 0xa7e4
movq %rax, %rbx
movq %r14, %rdi
callq 0x3210
jmp 0xa7e7
jmp 0xa7bd
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x3528
jmp 0xa7c0
jmp 0xa7e4
jmp 0xa7e4
jmp 0xa7e4
jmp 0xa7d1
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x3528
jmp 0xa7d4
movq %rax, %rbx
leaq 0x90(%rsp), %rdi
jmp 0xa7ae
movq %rax, %rbx
leaq 0xb0(%rsp), %rdi
callq 0xb146
jmp 0xa7e7
jmp 0xa7e4
jmp 0xa7e4
jmp 0xa7e4
jmp 0xa7d1
movq %rax, %rbx
leaq 0x10(%rsp), %r14
leaq 0x30(%rsp), %rdi
callq 0xb0d0
jmp 0xa7ec
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x3528
jmp 0xa7e7
jmp 0xa7e4
jmp 0xa7e4
movq %rax, %rbx
leaq 0x10(%rsp), %r14
leaq 0xd0(%rsp), %rdi
callq 0x3528
movq %r14, %rdi
callq 0xb146
movq %rbx, %rdi
callq 0x3490
nop