// File: /workspace/github_cpp_makefile_star2_O3/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
movq %rdi, %rbp
leaq 0x20(%rdi), %rax
movq %rax, 0x70(%rsp)
leaq 0x8(%rdi), %rax
movq %rax, 0x78(%rsp)
leaq 0xc0(%rsp), %rbx
leaq 0x40(%rsp), %r14
leaq 0xb0(%rsp), %r12
movq %rdi, 0xd0(%rsp)
movq %rbx, %r15
movq (%rbp), %rsi
leaq 0x8(%rsp), %rdi
callq 0x32bec
movq 0x18(%rsp), %rdi
movq 0x20(%rsp), %rbx
leaq 0x3c2ef(%rip), %rax     # 0x45d10
movq %rax, 0x8(%rsp)
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x9a3d
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x72c0
testq %rbx, %rbx
je 0x9e21
movl $0xffffffff, 0x10(%rsp) # imm = 0xFFFFFFFF
leaq 0x3c2fb(%rip), %rax     # 0x45d50
movq %rax, 0x8(%rsp)
leaq 0x28(%rsp), %rax
movq %rax, 0x18(%rsp)
xorl %eax, %eax
movq %rax, 0x20(%rsp)
movb %al, 0x28(%rsp)
movb %al, 0x38(%rsp)
movw $0xffff, 0x3a(%rsp)     # imm = 0xFFFF
movq (%rbp), %rsi
movq %rax, 0x90(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x80(%rsp)
movq %rax, 0x50(%rsp)
movaps %xmm0, 0x40(%rsp)
leaq 0x8(%rsp), %rdi
movq 0x70(%rsp), %rdx
movq 0x78(%rsp), %rcx
leaq 0x80(%rsp), %rbx
movq %rbx, %r8
movq %r14, %r9
callq 0x10df4
movq %r14, %rdi
movl %eax, %r13d
callq 0xb4aa
movq %rbx, %rdi
callq 0xb3fe
testb %r13b, %r13b
movq %rbx, %rdi
movq %r15, %rbx
je 0x9c91
movq (%rbp), %rsi
callq 0x32902
cmpq $0x0, 0x98(%rsp)
movq %r14, %r13
je 0x9c99
movq (%rbp), %rsi
movq %r13, %rdi
callq 0x32bec
movq %rbx, 0xb0(%rsp)
movq 0x50(%rsp), %rsi
movq 0x58(%rsp), %rdx
addq %rsi, %rdx
movq %r12, %r13
movq %r12, %rdi
callq 0xbd58
movq %r13, %rdi
leaq 0x2b589(%rip), %rsi     # 0x350b9
callq 0x70c0
movl %eax, %r13d
movq 0xb0(%rsp), %rdi
cmpq %rbx, %rdi
je 0x9b55
movq 0xc0(%rsp), %rsi
incq %rsi
callq 0x72c0
leaq 0x3c1b4(%rip), %rax     # 0x45d10
movq %rax, 0x40(%rsp)
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x9b7d
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x72c0
testl %r13d, %r13d
je 0x9ceb
movl $0xb0, %edi
callq 0x72b0
movq %rax, %r13
leaq 0x50(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0x90(%rsp), %rsi
movq 0x98(%rsp), %rdx
addq %rsi, %rdx
movq %r14, %rbp
movq %r14, %rdi
callq 0xbd58
leaq 0x3c1be(%rip), %rax     # 0x45d80
movq %rax, (%r13)
movl $0xffffffff, 0x8(%r13)  # imm = 0xFFFFFFFF
movq %r13, %rdi
addq $0x10, %rdi
movb $0x1, %bl
leaq 0x8(%rsp), %rsi
movq %rbp, %rdx
callq 0xb71a
leaq 0x3c285(%rip), %rax     # 0x45e70
movq %rax, (%r13)
xorps %xmm0, %xmm0
movups %xmm0, 0x98(%r13)
movq $0x0, 0xa8(%r13)
movq %r13, 0xb0(%rsp)
xorl %ebx, %ebx
leaq 0xb8(%rsp), %rdi
movq %r13, %rsi
callq 0xc836
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
movq 0xd0(%rsp), %rbp
je 0x9c43
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x72c0
movq 0xb0(%rsp), %rdi
movq (%rbp), %rsi
movq 0x70(%rsp), %rdx
movq 0x78(%rsp), %rcx
callq 0x1739a
movq %r15, %rbx
testb %al, %al
je 0x9da0
movq 0x78(%rsp), %rdi
movq %r12, %rsi
callq 0xb64c
movq 0xb8(%rsp), %rdi
testq %rdi, %rdi
je 0x9d9b
callq 0x8036
jmp 0x9d9b
xorl %r13d, %r13d
jmp 0x9de9
leaq 0x50(%rsp), %rax
movq %rax, 0x40(%rsp)
movq %r13, %rdi
leaq 0x2b3d3(%rip), %rsi     # 0x35080
leaq 0x2b404(%rip), %rdx     # 0x350b8
callq 0xbdee
movq %r13, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x34178
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0x9db2
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x72c0
jmp 0x9db2
movl $0x140, %edi            # imm = 0x140
callq 0x72b0
movq %rax, %r13
leaq 0x50(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0x90(%rsp), %rsi
movq 0x98(%rsp), %rdx
addq %rsi, %rdx
movq %r14, %rbp
movq %r14, %rdi
callq 0xbd58
movb $0x1, %bl
movq %r13, %rdi
leaq 0x8(%rsp), %rsi
movq %rbp, %rdx
callq 0xb4f8
xorl %ebx, %ebx
movq %r12, %rdi
movq %r13, %rsi
callq 0xc72c
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
movq 0xd0(%rsp), %rbp
je 0x9d63
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x72c0
movq 0xb0(%rsp), %rdi
movq (%rbp), %rsi
movq 0x70(%rsp), %rdx
movq 0x78(%rsp), %rcx
callq 0x18982
movl %eax, %r13d
movq %r15, %rbx
movq 0xb8(%rsp), %rdi
testq %rdi, %rdi
je 0x9d96
callq 0x8036
testb %r13b, %r13b
je 0x9db2
movb $0x1, %r13b
jmp 0x9db5
movq 0xb8(%rsp), %rdi
testq %rdi, %rdi
je 0x9db2
callq 0x8036
xorl %r13d, %r13d
leaq 0x3bf54(%rip), %rax     # 0x45d10
movq %rax, 0x80(%rsp)
movq 0x90(%rsp), %rdi
leaq 0xa0(%rsp), %rax
cmpq %rax, %rdi
je 0x9de9
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x72c0
leaq 0x3bf60(%rip), %rax     # 0x45d50
movq %rax, 0x8(%rsp)
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x9e11
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x72c0
testb %r13b, %r13b
jne 0x99ff
xorl %ebx, %ebx
jmp 0x9fa3
leaq 0x18(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x2b2de(%rip), %rsi     # 0x3510f
leaq 0x2b2db(%rip), %rdx     # 0x35113
leaq 0x8(%rsp), %rdi
callq 0xbdee
leaq 0x40(%rsp), %rdi
leaq 0x8(%rsp), %rsi
movq 0x70(%rsp), %rdx
callq 0x33e1d
movq 0x8(%rsp), %rdi
cmpq %r14, %rdi
je 0x9e6d
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x72c0
movq 0x40(%rsp), %rbx
testq %rbx, %rbx
je 0x9f51
movl 0x28(%rbx), %eax
leaq 0x18(%rsp), %rdi
movl %eax, -0x8(%rdi)
leaq 0x3bec3(%rip), %rax     # 0x45d50
movq %rax, -0x10(%rdi)
leaq 0x28(%rsp), %rax
movq %rax, (%rdi)
movq 0x30(%rbx), %rsi
movq 0x38(%rbx), %rdx
addq %rsi, %rdx
callq 0xbd58
movl 0x50(%rbx), %eax
movl %eax, 0x38(%rsp)
leaq 0x90(%rsp), %rbx
movq %rbx, -0x10(%rbx)
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdx
addq %rsi, %rdx
leaq 0x80(%rsp), %rdi
callq 0xbd58
leaq 0x2b163(%rip), %rsi     # 0x35040
leaq 0x80(%rsp), %rdi
callq 0x70c0
movb $0x1, %bpl
testl %eax, %eax
jne 0x9f05
movq 0x40(%rsp), %rax
movq 0x80(%rax), %rcx
cmpq 0x78(%rax), %rcx
setne %bpl
movq 0x80(%rsp), %rdi
cmpq %rbx, %rdi
je 0x9f22
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x72c0
leaq 0x3be27(%rip), %rax     # 0x45d50
movq %rax, 0x8(%rsp)
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x9f4a
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x72c0
movb $0x1, %bl
testb %bpl, %bpl
je 0x9f94
leaq 0x8(%rsp), %rdi
movq %r14, (%rdi)
leaq 0x2b15b(%rip), %rsi     # 0x350bb
leaq 0x2b177(%rip), %rdx     # 0x350de
callq 0xbdee
leaq 0x8(%rsp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x34178
movq 0x8(%rsp), %rdi
cmpq %r14, %rdi
je 0x9f92
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x72c0
xorl %ebx, %ebx
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x9fa3
callq 0x8036
movl %ebx, %eax
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r15
leaq 0x3bd8f(%rip), %rax     # 0x45d50
movq %rax, 0x8(%rsp)
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x9ffd
movq 0x28(%rsp), %rsi
jmp 0x9ff0
jmp 0x9ffa
movq %rax, %r15
movq 0x8(%rsp), %rdi
cmpq %r14, %rdi
je 0x9ffd
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x72c0
jmp 0x9ffd
movq %rax, %r15
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0xa188
callq 0x8036
jmp 0xa188
movq %rax, %r15
movq 0x8(%rsp), %rdi
cmpq %r14, %rdi
je 0xa188
movq 0x18(%rsp), %rsi
jmp 0xa180
movq %rax, %r15
jmp 0xa188
jmp 0xa097
movq %rax, %r15
jmp 0xa090
jmp 0xa0d6
movq %rax, %r15
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0xa10b
movq 0x50(%rsp), %rsi
jmp 0xa0d1
jmp 0xa0d6
movq %rax, %r15
jmp 0xa0fe
jmp 0xa0d6
movq %rax, %r15
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0xa08c
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x72c0
testb %bl, %bl
je 0xa10b
movl $0x140, %esi            # imm = 0x140
jmp 0xa103
movq %rax, %r15
movq 0xb8(%rsp), %rdi
testq %rdi, %rdi
je 0xa10b
callq 0x8036
jmp 0xa10b
movq %rax, %r15
leaq 0x3bc58(%rip), %rax     # 0x45d10
movq %rax, 0x40(%rsp)
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0xa10b
movq 0x60(%rsp), %rsi
incq %rsi
jmp 0xa106
movq %rax, %r15
jmp 0xa10b
movq %rax, %r15
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0xa0fa
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x72c0
testb %bl, %bl
je 0xa10b
movl $0xb0, %esi
movq %r13, %rdi
callq 0x72c0
leaq 0x3bbfe(%rip), %rax     # 0x45d10
movq %rax, 0x80(%rsp)
movq 0x90(%rsp), %rdi
leaq 0xa0(%rsp), %rax
cmpq %rax, %rdi
je 0xa160
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x72c0
jmp 0xa160
movq %rax, %r15
jmp 0xa160
movq %rax, %r15
leaq 0x40(%rsp), %rdi
callq 0xb4aa
leaq 0x80(%rsp), %rdi
callq 0xb3fe
leaq 0x3bbe9(%rip), %rax     # 0x45d50
movq %rax, 0x8(%rsp)
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0xa188
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x72c0
movq %r15, %rdi
callq 0x74f0