// File: /workspace/github_cpp_makefile_star2_O1/rfotino[P]consolite-compiler/src/parser.cpp
// Function: Parser::parse()
bool Parser::parse() {
  while (true) {
    // Get the type
    if (_tokenizer->peekNext().empty()) {
      // We have reached the end of the token stream without errors
      break;
    }
    TypeToken type;
    if (!type.parse(_tokenizer, _functions, _globals)) {
      return false;
    }

    // Get the name
    AtomToken name = _tokenizer->getNext();
    if (name.empty()) {
      _error("Error: Unexpected EOF, expected global or function name.");
      return false;
    }

    // Differentiate between function and global variable
    if ("(" == _tokenizer->peekNext().str()) {
      std::shared_ptr<FunctionToken> func(new FunctionToken(type, name.str()));
      if (!func->parse(_tokenizer, _functions, _globals)) {
        return false;
      }
    } else {
      std::shared_ptr<GlobalVarToken> var(new GlobalVarToken(type, name.str()));
      if (!var->parse(_tokenizer, _functions, _globals)) {
        return false;
      }
      _globals.push_back(var);
    }
  }
  // Make sure there is a 'void main()' function, which is the entry point.
  auto entryPoint = getFunction("main", _functions);
  if (!entryPoint ||
      "void" != entryPoint->type().name() ||
      0 != entryPoint->numParams()) {
    _error("No 'void main()' entry point found.");
    return false;
  }
  return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
leaq 0x20(%rdi), %rax
movq %rax, 0x90(%rsp)
movq %rdi, 0x30(%rsp)
leaq 0x8(%rdi), %rax
movq %rax, 0x98(%rsp)
leaq 0x80(%rsp), %rbx
movq %rsp, %r14
leaq 0x70(%rsp), %r12
movq %rbx, %r15
movq 0x30(%rsp), %rax
movq (%rax), %rsi
leaq 0x38(%rsp), %rdi
callq 0x33270
movq 0x48(%rsp), %rdi
movq 0x50(%rsp), %rbx
leaq 0x3d070(%rip), %rax     # 0x46ce0
movq %rax, 0x38(%rsp)
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x9c8c
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x72c0
testq %rbx, %rbx
je 0xa05f
movl $0xffffffff, 0x40(%rsp) # imm = 0xFFFFFFFF
leaq 0x3d07c(%rip), %rax     # 0x46d20
movq %rax, 0x38(%rsp)
leaq 0x58(%rsp), %rax
movq %rax, 0x48(%rsp)
xorl %ecx, %ecx
movq %rcx, 0x50(%rsp)
movb %cl, 0x58(%rsp)
movb %cl, 0x68(%rsp)
movw $0xffff, 0x6a(%rsp)     # imm = 0xFFFF
movq 0x30(%rsp), %rax
movq (%rax), %rsi
movq %rcx, 0xb0(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0xa0(%rsp)
movq %rcx, 0x10(%rsp)
movaps %xmm0, (%rsp)
leaq 0x38(%rsp), %rdi
movq 0x90(%rsp), %rdx
movq 0x98(%rsp), %rcx
leaq 0xa0(%rsp), %rbx
movq %rbx, %r8
movq %r14, %r9
callq 0x110e8
movq %r14, %rdi
movl %eax, %ebp
callq 0xb77e
movq %rbx, %rdi
callq 0xb6d8
testb %bpl, %bpl
movq %rbx, %rdi
movq %r15, %rbx
je 0x9ec8
movq 0x30(%rsp), %rax
movq (%rax), %rsi
callq 0x32f76
cmpq $0x0, 0xb8(%rsp)
je 0x9ecf
movq %r12, %rbp
movq 0x30(%rsp), %rax
movq (%rax), %rsi
movq %r14, %rdi
callq 0x33270
movq %rbx, 0x70(%rsp)
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
addq %rsi, %rdx
movq %rbp, %rdi
callq 0xc014
movq %rbp, %rdi
leaq 0x2c330(%rip), %rsi     # 0x360b9
callq 0x70c0
movl %eax, %ebp
movq 0x70(%rsp), %rdi
cmpq %rbx, %rdi
je 0x9daa
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x72c0
leaq 0x3cf2f(%rip), %rax     # 0x46ce0
movq %rax, (%rsp)
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x9dd1
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x72c0
testl %ebp, %ebp
je 0x9f22
movl $0xb0, %edi
callq 0x72b0
movq %rax, %rbp
leaq 0x10(%rsp), %rax
movq %rax, (%rsp)
movq 0xb0(%rsp), %rsi
movq 0xb8(%rsp), %rdx
addq %rsi, %rdx
movq %r14, %r13
movq %r14, %rdi
callq 0xc014
leaq 0x3cf3c(%rip), %rax     # 0x46d50
movq %rax, (%rbp)
movl $0xffffffff, 0x8(%rbp)  # imm = 0xFFFFFFFF
movq %rbp, %rdi
addq $0x10, %rdi
movb $0x1, %bl
leaq 0x38(%rsp), %rsi
movq %r13, %rdx
callq 0xb9ec
leaq 0x3d004(%rip), %rax     # 0x46e40
movq %rax, (%rbp)
xorps %xmm0, %xmm0
movups %xmm0, 0x98(%rbp)
movq $0x0, 0xa8(%rbp)
movq %rbp, 0x70(%rsp)
xorl %ebx, %ebx
leaq 0x78(%rsp), %rdi
movq %rbp, %rsi
callq 0xcae0
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x9e84
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x72c0
movq 0x70(%rsp), %rdi
movq 0x30(%rsp), %rax
movq (%rax), %rsi
movq 0x90(%rsp), %rdx
movq 0x98(%rsp), %rcx
callq 0x1778a
movl %eax, %ebp
movq %r15, %rbx
testb %al, %al
je 0x9fe2
movq 0x98(%rsp), %rdi
movq %r12, %rsi
callq 0xb924
jmp 0x9fc9
xorl %ebp, %ebp
jmp 0xa027
leaq 0x10(%rsp), %rax
movq %rax, (%rsp)
movq %r14, %r15
movq %r14, %rdi
leaq 0x2c19b(%rip), %rsi     # 0x36080
leaq 0x2c1cc(%rip), %rdx     # 0x360b8
callq 0xc0a4
movq %r15, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x34811
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x9ff1
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x72c0
jmp 0x9ff1
movl $0x140, %edi            # imm = 0x140
callq 0x72b0
movq %rax, %rbp
leaq 0x10(%rsp), %rax
movq %rax, (%rsp)
movq 0xb0(%rsp), %rsi
movq 0xb8(%rsp), %rdx
addq %rsi, %rdx
movq %r14, %r13
movq %r14, %rdi
callq 0xc014
movb $0x1, %bl
movq %rbp, %rdi
leaq 0x38(%rsp), %rsi
movq %r13, %rdx
callq 0xb7c6
movq %rbp, 0x70(%rsp)
xorl %ebx, %ebx
leaq 0x78(%rsp), %rdi
movq %rbp, %rsi
callq 0xca32
movq %r12, %rdi
movq %rbp, %rsi
callq 0xc422
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x9fa2
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x72c0
movq 0x70(%rsp), %rdi
movq 0x30(%rsp), %rax
movq (%rax), %rsi
movq 0x90(%rsp), %rdx
movq 0x98(%rsp), %rcx
callq 0x18d70
movl %eax, %ebp
movq %r15, %rbx
movq 0x78(%rsp), %rdi
testq %rdi, %rdi
je 0x9fd8
callq 0x81ea
testb %bpl, %bpl
je 0x9ff1
movb $0x1, %bpl
jmp 0x9ff3
movq 0x78(%rsp), %rdi
testq %rdi, %rdi
je 0x9ff1
callq 0x81ea
xorl %ebp, %ebp
leaq 0x3cce6(%rip), %rax     # 0x46ce0
movq %rax, 0xa0(%rsp)
movq 0xb0(%rsp), %rdi
leaq 0xc0(%rsp), %rax
cmpq %rax, %rdi
je 0xa027
movq 0xc0(%rsp), %rsi
incq %rsi
callq 0x72c0
leaq 0x3ccf2(%rip), %rax     # 0x46d20
movq %rax, 0x38(%rsp)
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0xa04f
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x72c0
testb %bpl, %bpl
jne 0x9c4a
xorl %ebx, %ebx
jmp 0xa1fb
leaq 0x48(%rsp), %rbx
movq %rbx, -0x10(%rbx)
leaq 0x2c0a0(%rip), %rsi     # 0x3610f
leaq 0x2c09d(%rip), %rdx     # 0x36113
leaq 0x38(%rsp), %rdi
callq 0xc0a4
leaq 0x70(%rsp), %rdi
leaq 0x38(%rsp), %rsi
movq 0x90(%rsp), %rdx
callq 0x34498
movq 0x38(%rsp), %rdi
cmpq %rbx, %rdi
je 0xa0ae
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x72c0
movq 0x70(%rsp), %r14
movb $0x1, %bl
testq %r14, %r14
je 0xa151
leaq 0x48(%rsp), %rdi
leaq 0x3cc86(%rip), %rax     # 0x46d50
movq %rax, -0x10(%rdi)
movl 0x28(%r14), %eax
movl %eax, -0x8(%rdi)
leaq 0x3cc44(%rip), %rax     # 0x46d20
movq %rax, -0x10(%rdi)
leaq 0x58(%rsp), %rax
movq %rax, (%rdi)
movq 0x30(%r14), %rsi
movq 0x38(%r14), %rdx
addq %rsi, %rdx
callq 0xc014
movl 0x50(%r14), %eax
movl %eax, 0x68(%rsp)
leaq 0xb0(%rsp), %rax
movq %rax, -0x10(%rax)
movq 0x48(%rsp), %rsi
movq 0x50(%rsp), %rdx
addq %rsi, %rdx
leaq 0xa0(%rsp), %rdi
callq 0xc014
leaq 0x2bf13(%rip), %rsi     # 0x36040
leaq 0xa0(%rsp), %rdi
callq 0x70c0
testl %eax, %eax
jne 0xa151
movq 0x70(%rsp), %rax
movq 0x80(%rax), %rcx
cmpq 0x78(%rax), %rcx
setne %bl
testq %r14, %r14
je 0xa19f
leaq 0xb0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xa177
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x72c0
leaq 0x3cba2(%rip), %rax     # 0x46d20
movq %rax, 0x38(%rsp)
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0xa19f
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x72c0
testb %bl, %bl
je 0xa1e9
movq %rsp, %rdi
leaq 0x10(%rsp), %rax
movq %rax, (%rdi)
leaq 0x2bf06(%rip), %rsi     # 0x360bb
leaq 0x2bf22(%rip), %rdx     # 0x360de
callq 0xc0a4
movq %rsp, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x34811
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0xa1e9
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x72c0
movq 0x78(%rsp), %rdi
testq %rdi, %rdi
je 0xa1f8
callq 0x81ea
xorb $0x1, %bl
movl %ebx, %eax
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0xa259
movq 0x10(%rsp), %rsi
jmp 0xa24c
jmp 0xa256
movq %rax, %r14
leaq 0x3caed(%rip), %rax     # 0x46d20
movq %rax, 0x38(%rsp)
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0xa259
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x72c0
jmp 0xa259
movq %rax, %r14
movq 0x78(%rsp), %rdi
testq %rdi, %rdi
je 0xa3df
callq 0x81ea
jmp 0xa3df
movq %rax, %r14
movq 0x38(%rsp), %rdi
cmpq %rbx, %rdi
je 0xa3df
movq 0x48(%rsp), %rsi
jmp 0xa3d7
movq %rax, %r14
jmp 0xa3df
jmp 0xa2f5
movq %rax, %r14
movb $0x1, %bl
jmp 0xa2ea
jmp 0xa330
movq %rax, %r14
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0xa364
movq 0x10(%rsp), %rsi
jmp 0xa32b
jmp 0xa330
movq %rax, %r14
movb $0x1, %bl
jmp 0xa353
jmp 0xa330
movq %rax, %r14
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0xa2ea
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x72c0
testb %bl, %bl
je 0xa364
movl $0x140, %esi            # imm = 0x140
jmp 0xa35c
movq %rax, %r14
movq 0x78(%rsp), %rdi
testq %rdi, %rdi
je 0xa364
callq 0x81ea
jmp 0xa364
movq %rax, %r14
leaq 0x3c9cd(%rip), %rax     # 0x46ce0
movq %rax, (%rsp)
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0xa364
movq 0x20(%rsp), %rsi
incq %rsi
jmp 0xa35f
movq %rax, %r14
jmp 0xa364
movq %rax, %r14
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0xa353
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x72c0
testb %bl, %bl
je 0xa364
movl $0xb0, %esi
movq %rbp, %rdi
callq 0x72c0
leaq 0x3c975(%rip), %rax     # 0x46ce0
movq %rax, 0xa0(%rsp)
movq 0xb0(%rsp), %rdi
leaq 0xc0(%rsp), %rax
cmpq %rax, %rdi
je 0xa3b7
movq 0xc0(%rsp), %rsi
incq %rsi
callq 0x72c0
jmp 0xa3b7
movq %rax, %r14
jmp 0xa3b7
movq %rax, %r14
movq %rsp, %rdi
callq 0xb77e
leaq 0xa0(%rsp), %rdi
callq 0xb6d8
leaq 0x3c962(%rip), %rax     # 0x46d20
movq %rax, 0x38(%rsp)
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0xa3df
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x72c0
movq %r14, %rdi
callq 0x74f0
nop