// File: 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
movq %rsp, %rbp
subq $0x360, %rsp            # imm = 0x360
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x2a8(%rbp)
movq -0x2a8(%rbp), %rax
movq (%rax), %rsi
leaq -0x40(%rbp), %rdi
movq %rdi, -0x2b8(%rbp)
callq 0x6bae0
movq -0x2b8(%rbp), %rdi
callq 0xd490
movb %al, -0x2a9(%rbp)
jmp 0xb218
leaq -0x40(%rbp), %rdi
callq 0x99b0
movb -0x2a9(%rbp), %al
testb $0x1, %al
jne 0xb22d
jmp 0xb24c
jmp 0xb83c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x99b0
jmp 0xbb29
leaq -0x88(%rbp), %rdi
movq %rdi, -0x2f0(%rbp)
callq 0xd4c0
movq -0x2a8(%rbp), %rax
movq (%rax), %rcx
movq %rcx, -0x2e8(%rbp)
movq %rax, %rcx
addq $0x20, %rcx
movq %rcx, -0x2e0(%rbp)
addq $0x8, %rax
movq %rax, -0x2d8(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0x300(%rbp)
movaps %xmm0, -0xa0(%rbp)
movq $0x0, -0x90(%rbp)
leaq -0xa0(%rbp), %rdi
movq %rdi, -0x2d0(%rbp)
callq 0xd470
movaps -0x300(%rbp), %xmm0
movaps %xmm0, -0xc0(%rbp)
movq $0x0, -0xb0(%rbp)
leaq -0xc0(%rbp), %rdi
movq %rdi, -0x2c8(%rbp)
callq 0xd510
movq -0x2f0(%rbp), %rdi
movq -0x2e8(%rbp), %rsi
movq -0x2e0(%rbp), %rdx
movq -0x2d8(%rbp), %rcx
movq -0x2d0(%rbp), %r8
movq -0x2c8(%rbp), %r9
callq 0x1d3e0
movb %al, -0x2b9(%rbp)
jmp 0xb31b
movb -0x2b9(%rbp), %al
xorb $-0x1, %al
movb %al, -0x301(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0xd530
leaq -0xa0(%rbp), %rdi
callq 0xd380
movb -0x301(%rbp), %al
testb $0x1, %al
jne 0xb34d
jmp 0xb389
movb $0x0, -0x1(%rbp)
movl $0x1, -0xc4(%rbp)
jmp 0xb7fd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0xd530
leaq -0xa0(%rbp), %rdi
callq 0xd380
jmp 0xb82b
movq -0x2a8(%rbp), %rax
movq (%rax), %rsi
leaq -0xf8(%rbp), %rdi
callq 0x6ae20
jmp 0xb3a1
leaq -0xf8(%rbp), %rdi
callq 0xd490
movb %al, -0x302(%rbp)
jmp 0xb3b5
movb -0x302(%rbp), %al
testb $0x1, %al
jne 0xb3c4
jmp 0xb48a
leaq -0x119(%rbp), %rdi
movq %rdi, -0x310(%rbp)
callq 0x8760
movq -0x310(%rbp), %rdx
leaq 0x63c8f(%rip), %rsi     # 0x6f074
leaq -0x118(%rbp), %rdi
callq 0xced0
jmp 0xb3f3
leaq -0x118(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x6d960
jmp 0xb406
leaq -0x118(%rbp), %rdi
callq 0x8848
leaq -0x119(%rbp), %rdi
callq 0x8460
movb $0x0, -0x1(%rbp)
movl $0x1, -0xc4(%rbp)
jmp 0xb7f1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0xb82b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0xb81f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0xb479
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x118(%rbp), %rdi
callq 0x8848
leaq -0x119(%rbp), %rdi
callq 0x8460
jmp 0xb81f
movq -0x2a8(%rbp), %rax
movq (%rax), %rsi
leaq -0x170(%rbp), %rdi
callq 0x6bae0
jmp 0xb4a2
leaq -0x140(%rbp), %rdi
leaq -0x170(%rbp), %rsi
callq 0xd5c0
jmp 0xb4b7
leaq 0x63bef(%rip), %rdi     # 0x6f0ad
leaq -0x140(%rbp), %rsi
callq 0xd590
movb %al, -0x311(%rbp)
jmp 0xb4d2
leaq -0x140(%rbp), %rdi
callq 0x8848
leaq -0x170(%rbp), %rdi
callq 0x99b0
movb -0x311(%rbp), %al
testb $0x1, %al
jne 0xb4f9
jmp 0xb686
movl $0x140, %edi            # imm = 0x140
callq 0x83e0
movq %rax, -0x320(%rbp)
jmp 0xb50c
movb $0x1, -0x1a1(%rbp)
leaq -0x1a0(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
callq 0xd5c0
jmp 0xb528
movq -0x320(%rbp), %rdi
leaq -0x88(%rbp), %rsi
leaq -0x1a0(%rbp), %rdx
callq 0xd5f0
jmp 0xb544
movq -0x320(%rbp), %rsi
movb $0x0, -0x1a1(%rbp)
leaq -0x180(%rbp), %rdi
callq 0xd750
jmp 0xb560
leaq -0x1a0(%rbp), %rdi
callq 0x8848
leaq -0x180(%rbp), %rdi
callq 0xd780
movq -0x2a8(%rbp), %rcx
movq %rax, %rdi
movq (%rcx), %rsi
movq %rcx, %rdx
addq $0x20, %rdx
addq $0x8, %rcx
callq 0x26860
movb %al, -0x321(%rbp)
jmp 0xb59d
movb -0x321(%rbp), %al
testb $0x1, %al
jne 0xb65b
jmp 0xb5ad
movb $0x0, -0x1(%rbp)
movl $0x1, -0xc4(%rbp)
jmp 0xb665
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0xb5e6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x140(%rbp), %rdi
callq 0x8848
leaq -0x170(%rbp), %rdi
callq 0x99b0
jmp 0xb81f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0xb61d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x1a0(%rbp), %rdi
callq 0x8848
testb $0x1, -0x1a1(%rbp)
jne 0xb628
jmp 0xb639
movq -0x320(%rbp), %rdi
movl $0x140, %esi            # imm = 0x140
callq 0x83f0
jmp 0xb81f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x180(%rbp), %rdi
callq 0x94c0
jmp 0xb81f
movl $0x0, -0xc4(%rbp)
leaq -0x180(%rbp), %rdi
callq 0x94c0
movl -0xc4(%rbp), %eax
testl %eax, %eax
jne 0xb7f1
jmp 0xb681
jmp 0xb7e7
movl $0xb0, %edi
callq 0x83e0
movq %rax, -0x330(%rbp)
jmp 0xb699
movb $0x1, -0x1d9(%rbp)
leaq -0x1d8(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
callq 0xd5c0
jmp 0xb6b5
movq -0x330(%rbp), %rdi
leaq -0x88(%rbp), %rsi
leaq -0x1d8(%rbp), %rdx
callq 0xd7a0
jmp 0xb6d1
movq -0x330(%rbp), %rsi
movb $0x0, -0x1d9(%rbp)
leaq -0x1b8(%rbp), %rdi
callq 0xd800
jmp 0xb6ed
leaq -0x1d8(%rbp), %rdi
callq 0x8848
leaq -0x1b8(%rbp), %rdi
callq 0xd830
movq -0x2a8(%rbp), %rcx
movq %rax, %rdi
movq (%rcx), %rsi
movq %rcx, %rdx
addq $0x20, %rdx
addq $0x8, %rcx
callq 0x24c10
movb %al, -0x331(%rbp)
jmp 0xb72a
movb -0x331(%rbp), %al
testb $0x1, %al
jne 0xb7aa
jmp 0xb736
movb $0x0, -0x1(%rbp)
movl $0x1, -0xc4(%rbp)
jmp 0xb7cd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0xb76f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x1d8(%rbp), %rdi
callq 0x8848
testb $0x1, -0x1d9(%rbp)
jne 0xb77a
jmp 0xb78b
movq -0x330(%rbp), %rdi
movl $0xb0, %esi
callq 0x83f0
jmp 0xb81f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x1b8(%rbp), %rdi
callq 0x9880
jmp 0xb81f
movq -0x2a8(%rbp), %rdi
addq $0x8, %rdi
leaq -0x1b8(%rbp), %rsi
callq 0xd850
jmp 0xb7c3
movl $0x0, -0xc4(%rbp)
leaq -0x1b8(%rbp), %rdi
callq 0x9880
movl -0xc4(%rbp), %eax
testl %eax, %eax
jne 0xb7f1
jmp 0xb7e5
jmp 0xb7e7
movl $0x0, -0xc4(%rbp)
leaq -0xf8(%rbp), %rdi
callq 0x99b0
leaq -0x88(%rbp), %rdi
callq 0xd440
movl -0xc4(%rbp), %eax
testl %eax, %eax
je 0xb81a
jmp 0xb815
jmp 0xbb1b
jmp 0xb1ea
leaq -0xf8(%rbp), %rdi
callq 0x99b0
leaq -0x88(%rbp), %rdi
callq 0xd440
jmp 0xbb29
leaq -0x211(%rbp), %rdi
movq %rdi, -0x340(%rbp)
callq 0x8760
movq -0x340(%rbp), %rdx
leaq 0x638a6(%rip), %rsi     # 0x6f103
leaq -0x210(%rbp), %rdi
callq 0xced0
jmp 0xb86b
movq -0x2a8(%rbp), %rdx
addq $0x20, %rdx
leaq -0x1f0(%rbp), %rdi
leaq -0x210(%rbp), %rsi
callq 0x6d580
jmp 0xb88b
leaq -0x210(%rbp), %rdi
callq 0x8848
leaq -0x211(%rbp), %rdi
callq 0x8460
leaq -0x1f0(%rbp), %rdi
callq 0xd8c0
movb %al, %cl
movb $0x0, -0x271(%rbp)
movb $0x0, -0x272(%rbp)
movb $0x1, %al
testb $0x1, %cl
movb %al, -0x341(%rbp)
jne 0xb8d1
jmp 0xb973
leaq -0x1f0(%rbp), %rdi
callq 0xd780
movq %rax, %rsi
leaq -0x270(%rbp), %rdi
callq 0xd910
jmp 0xb8ee
movb $0x1, -0x271(%rbp)
leaq -0x238(%rbp), %rdi
leaq -0x270(%rbp), %rsi
callq 0xd940
jmp 0xb90a
movb $0x1, -0x272(%rbp)
leaq 0x6371c(%rip), %rdi     # 0x6f034
leaq -0x238(%rbp), %rsi
callq 0xd8e0
movb %al, -0x342(%rbp)
jmp 0xb92c
movb -0x342(%rbp), %cl
movb $0x1, %al
testb $0x1, %cl
movb %al, -0x341(%rbp)
jne 0xb973
jmp 0xb941
leaq -0x1f0(%rbp), %rdi
callq 0xd780
movq %rax, %rdi
callq 0xd970
movq %rax, -0x350(%rbp)
jmp 0xb95e
movq -0x350(%rbp), %rcx
xorl %eax, %eax
cmpq %rcx, %rax
setne %al
movb %al, -0x341(%rbp)
movb -0x341(%rbp), %al
movb %al, -0x351(%rbp)
testb $0x1, -0x272(%rbp)
jne 0xb98a
jmp 0xb996
leaq -0x238(%rbp), %rdi
callq 0x8848
testb $0x1, -0x271(%rbp)
jne 0xb9a1
jmp 0xb9ad
leaq -0x270(%rbp), %rdi
callq 0xd440
movb -0x351(%rbp), %al
testb $0x1, %al
jne 0xb9bc
jmp 0xbaf1
leaq -0x299(%rbp), %rdi
movq %rdi, -0x360(%rbp)
callq 0x8760
movq -0x360(%rbp), %rdx
leaq 0x636d2(%rip), %rsi     # 0x6f0af
leaq -0x298(%rbp), %rdi
callq 0xced0
jmp 0xb9eb
leaq -0x298(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x6d960
jmp 0xb9fe
leaq -0x298(%rbp), %rdi
callq 0x8848
leaq -0x299(%rbp), %rdi
callq 0x8460
movb $0x0, -0x1(%rbp)
movl $0x1, -0xc4(%rbp)
jmp 0xbaff
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0xba4f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x210(%rbp), %rdi
callq 0x8848
leaq -0x211(%rbp), %rdi
callq 0x8460
jmp 0xbb29
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0xbb0d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0xbaa4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
testb $0x1, -0x272(%rbp)
jne 0xba96
jmp 0xbaa2
leaq -0x238(%rbp), %rdi
callq 0x8848
jmp 0xbaa4
testb $0x1, -0x271(%rbp)
jne 0xbaaf
jmp 0xbabb
leaq -0x270(%rbp), %rdi
callq 0xd440
jmp 0xbb0d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0xbae3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x298(%rbp), %rdi
callq 0x8848
leaq -0x299(%rbp), %rdi
callq 0x8460
jmp 0xbb0d
movb $0x1, -0x1(%rbp)
movl $0x1, -0xc4(%rbp)
leaq -0x1f0(%rbp), %rdi
callq 0x94c0
jmp 0xbb1b
leaq -0x1f0(%rbp), %rdi
callq 0x94c0
jmp 0xbb29
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x360, %rsp            # imm = 0x360
popq %rbp
retq
movq -0x48(%rbp), %rdi
callq 0x8750
nopw %cs:(%rax,%rax)