// File: /workspace/github_cpp_makefile_star2_O2/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 $0xc8, %rsp
movq %rdi, %r15
leaq 0x20(%rdi), %rax
movq %rax, (%rsp)
leaq 0x8(%rdi), %r13
leaq 0x8(%rsp), %r12
leaq 0x60(%rsp), %r14
movq (%r15), %rsi
movq %r12, %rdi
callq 0x279a6
movq 0x20(%rsp), %rbx
movq %r12, %rdi
callq 0x7b20
testq %rbx, %rbx
je 0x89e5
orl $-0x1, 0x10(%rsp)
leaq 0x35555(%rip), %rax     # 0x3dd50
movq %rax, 0x8(%rsp)
leaq 0x28(%rsp), %rax
movq %rax, 0x18(%rsp)
andq $0x0, 0x20(%rsp)
xorl %eax, %eax
movb %al, 0x28(%rsp)
movb %al, 0x38(%rsp)
orw $-0x1, 0x3a(%rsp)
movq (%r15), %rsi
xorps %xmm0, %xmm0
movaps %xmm0, 0x90(%rsp)
andq $0x0, 0xa0(%rsp)
movaps %xmm0, 0x60(%rsp)
andq $0x0, 0x70(%rsp)
movq %r12, %rdi
movq (%rsp), %rdx
movq %r13, %rcx
leaq 0x90(%rsp), %rbx
movq %rbx, %r8
movq %r14, %r9
callq 0xe2ac
movl %eax, %ebp
movq %r14, %rdi
callq 0x97bc
movq %rbx, %rdi
callq 0x9786
testb %bpl, %bpl
je 0x8ac3
movq (%r15), %rsi
movq %rbx, %rdi
callq 0x2772c
cmpq $0x0, 0xa8(%rsp)
leaq 0x40(%rsp), %rbx
je 0x8a7d
movq (%r15), %rsi
movq %r14, %rdi
callq 0x279a6
movq %rbx, %rdi
leaq 0x70(%rsp), %rsi
callq 0x73e0
leaq 0x207f1(%rip), %rdi     # 0x290a9
movq %rbx, %rsi
callq 0x97dd
movl %eax, %ebp
movq %rbx, %rdi
callq 0x75c8
movq %r14, %rdi
callq 0x7b20
testb %bpl, %bpl
je 0x8951
movl $0x140, %edi            # imm = 0x140
callq 0x72b0
movq %rax, %rbp
movq %r14, %rdi
leaq 0xa0(%rsp), %rsi
callq 0x73e0
movb $0x1, %bl
movq %rbp, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x97f4
xorl %ebx, %ebx
leaq 0x40(%rsp), %rdi
movq %rbp, %rsi
callq 0xad4c
movq %r14, %rdi
callq 0x75c8
movq 0x40(%rsp), %rdi
movq (%r15), %rsi
movq (%rsp), %rdx
movq %r13, %rcx
callq 0x12b90
movl %eax, %ebp
leaq 0x48(%rsp), %rdi
callq 0x7a34
testb %bpl, %bpl
leaq 0x90(%rsp), %rbx
jne 0x89d0
jmp 0x8ab6
movl $0xb0, %edi
callq 0x72b0
movq %rax, %rbp
movq %r14, %rdi
leaq 0xa0(%rsp), %rsi
callq 0x73e0
movb $0x1, %bl
movq %rbp, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x9910
xorl %ebx, %ebx
leaq 0x40(%rsp), %rdi
movq %rbp, %rsi
callq 0xae24
movq %r14, %rdi
callq 0x75c8
movq 0x40(%rsp), %rdi
movq (%r15), %rsi
movq (%rsp), %rdx
movq %r13, %rcx
callq 0x11ef0
leaq 0x90(%rsp), %rbx
testb %al, %al
je 0x8aac
movq %r13, %rdi
leaq 0x40(%rsp), %rsi
callq 0x994a
leaq 0x48(%rsp), %rdi
callq 0x7a34
movq %rbx, %rdi
callq 0x7b20
movq %r12, %rdi
callq 0x97a8
jmp 0x87ce
leaq 0x20713(%rip), %rsi     # 0x290ff
leaq 0x8(%rsp), %rdi
leaq 0x90(%rsp), %rdx
callq 0x9502
leaq 0x60(%rsp), %rdi
leaq 0x8(%rsp), %rsi
movq (%rsp), %rdx
callq 0x283f4
leaq 0x8(%rsp), %rdi
callq 0x75c8
movq 0x60(%rsp), %rsi
testq %rsi, %rsi
je 0x8afd
addq $0x20, %rsi
leaq 0x8(%rsp), %rdi
callq 0x9b54
leaq 0x18(%rsp), %rsi
leaq 0x90(%rsp), %rdi
callq 0x73e0
leaq 0x205e0(%rip), %rdi     # 0x29030
leaq 0x90(%rsp), %rsi
callq 0x9976
testb %al, %al
je 0x8ad1
leaq 0x90(%rsp), %rdi
callq 0x75c8
leaq 0x8(%rsp), %rdi
callq 0x97a8
jmp 0x8afd
leaq 0x205ec(%rip), %rsi     # 0x29070
leaq 0x60(%rsp), %rdi
leaq 0x40(%rsp), %rdx
callq 0x9502
leaq 0x60(%rsp), %rdi
pushq $-0x1
popq %rsi
callq 0x285f3
leaq 0x60(%rsp), %rdi
callq 0x75c8
jmp 0x8ab6
leaq 0x48(%rsp), %rdi
callq 0x7a34
leaq 0x90(%rsp), %rdi
callq 0x7b20
leaq 0x8(%rsp), %rdi
callq 0x97a8
xorl %ebx, %ebx
jmp 0x8b39
movq 0x60(%rsp), %rax
movq 0x80(%rax), %rbx
movq 0x78(%rax), %r14
leaq 0x90(%rsp), %rdi
callq 0x75c8
leaq 0x8(%rsp), %rdi
callq 0x97a8
cmpq %r14, %rbx
je 0x8b4d
leaq 0x205a7(%rip), %rsi     # 0x290ab
leaq 0x8(%rsp), %rdi
leaq 0x90(%rsp), %rdx
callq 0x9502
leaq 0x8(%rsp), %rdi
pushq $-0x1
popq %rsi
callq 0x285f3
leaq 0x8(%rsp), %rdi
callq 0x75c8
xorl %ebx, %ebx
leaq 0x68(%rsp), %rdi
callq 0x7a34
movl %ebx, %eax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movb $0x1, %bl
jmp 0x8b2f
movq %rax, %r14
leaq 0x8(%rsp), %rdi
callq 0x97a8
jmp 0x8b74
jmp 0x8b71
movq %rax, %r14
leaq 0x8(%rsp), %rdi
callq 0x75c8
jmp 0x8b74
movq %rax, %r14
leaq 0x68(%rsp), %rdi
callq 0x7a34
jmp 0x8c34
movq %rax, %r14
leaq 0x60(%rsp), %rdi
callq 0x75c8
jmp 0x8c1d
jmp 0x8c1a
movq %rax, %r14
leaq 0x8(%rsp), %rdi
callq 0x75c8
jmp 0x8c34
movq %rax, %r14
jmp 0x8c34
movq %rax, %r14
jmp 0x8bfc
jmp 0x8c1a
jmp 0x8bc4
movq %rax, %r14
jmp 0x8be4
jmp 0x8c1a
movq %rax, %r14
leaq 0x48(%rsp), %rdi
callq 0x7a34
jmp 0x8c1d
movq %rax, %r14
leaq 0x60(%rsp), %rdi
callq 0x75c8
testb %bl, %bl
je 0x8c1d
movl $0x140, %esi            # imm = 0x140
jmp 0x8c01
movq %rax, %r14
leaq 0x60(%rsp), %rdi
callq 0x75c8
testb %bl, %bl
je 0x8c1d
movl $0xb0, %esi
movq %rbp, %rdi
callq 0x72c0
jmp 0x8c1d
movq %rax, %r14
leaq 0x60(%rsp), %rdi
callq 0x7b20
jmp 0x8c1d
movq %rax, %r14
leaq 0x90(%rsp), %rdi
callq 0x7b20
leaq 0x8(%rsp), %rdi
callq 0x97a8
movq %r14, %rdi
callq 0x7510
movq %rax, %r14
jmp 0x8c2a
movq %rax, %r14
leaq 0x60(%rsp), %rdi
callq 0x97bc
leaq 0x90(%rsp), %rdi
callq 0x9786
jmp 0x8c2a
nop