// File: kram[P]kram/./src/lexer/lexer.cpp
// Function: lexer::Lexer::parse_file(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
std::vector<Token*> Lexer::parse_file(std::string filename) {
	std::vector<Token*> result;

	std::ifstream file(filename);

	if (file.fail()) {
		std::cout << "Could not open " << filename << "\n";
		exit(0);
	}

    while (std::getline(file, this->row))
    {
    	this->index = 0;

    	while (true) {
        	Token* tok = this->next();

        	this->index++;

        	if (tok->type == Type::IGNORE) {
        		continue;
        	}

        	result.push_back(tok);

        	if (tok->type == Type::T_EOF || tok->type == Type::T_EOL) {
        		break;
        	}
        }
    }

    // Indicate end of file
    result.push_back(new Token(Type::T_EOF));

    return result;
}

// Assembly:
subq $0x2a8, %rsp            # imm = 0x2A8
movq %rdx, 0x58(%rsp)
movq %rdi, 0x40(%rsp)
movq %rdi, %rax
movq %rax, 0x48(%rsp)
movq %rdi, 0x2a0(%rsp)
movq %rsi, 0x298(%rsp)
movq %rdx, 0x290(%rsp)
movq 0x298(%rsp), %rax
movq %rax, 0x50(%rsp)
movb $0x0, 0x28f(%rsp)
callq 0x8f80
movq 0x58(%rsp), %rsi
leaq 0x80(%rsp), %rdi
movl $0x8, %edx
callq 0x3420
jmp 0x7bd4
movq 0x80(%rsp), %rax
movq -0x18(%rax), %rax
leaq 0x80(%rsp,%rax), %rdi
callq 0x3030
movb %al, 0x3f(%rsp)
jmp 0x7bf3
movb 0x3f(%rsp), %al
testb $0x1, %al
jne 0x7bfd
jmp 0x7c6d
movq 0x323d4(%rip), %rdi     # 0x39fd8
leaq 0x23623(%rip), %rsi     # 0x2b22e
callq 0x32d0
movq %rax, 0x30(%rsp)
jmp 0x7c17
movq 0x58(%rsp), %rsi
movq 0x30(%rsp), %rdi
callq 0x32a0
movq %rax, 0x28(%rsp)
jmp 0x7c2d
movq 0x28(%rsp), %rdi
leaq 0x23c28(%rip), %rsi     # 0x2b861
callq 0x32d0
jmp 0x7c40
xorl %edi, %edi
callq 0x3330
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x78(%rsp)
movl %eax, 0x74(%rsp)
jmp 0x7dbe
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x78(%rsp)
movl %eax, 0x74(%rsp)
jmp 0x7d98
jmp 0x7c6f
movq 0x50(%rsp), %rsi
addq $0x38, %rsi
leaq 0x80(%rsp), %rdi
callq 0x3070
movq %rax, 0x20(%rsp)
jmp 0x7c8c
movq 0x20(%rsp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x3340
movb %al, 0x1f(%rsp)
jmp 0x7ca6
movb 0x1f(%rsp), %al
testb $0x1, %al
jne 0x7cb0
jmp 0x7d25
movq 0x50(%rsp), %rax
movq $0x0, 0x58(%rax)
jmp 0x7cbf
movq 0x50(%rsp), %rdi
callq 0x7de0
movq %rax, 0x10(%rsp)
jmp 0x7cd0
movq 0x50(%rsp), %rax
movq 0x10(%rsp), %rcx
movq %rcx, 0x68(%rsp)
movq 0x58(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x58(%rax)
movq 0x68(%rsp), %rax
cmpl $0x2, (%rax)
jne 0x7cf7
jmp 0x7cbd
movq 0x40(%rsp), %rdi
leaq 0x68(%rsp), %rsi
callq 0x8f90
jmp 0x7d08
movq 0x68(%rsp), %rax
cmpl $0x0, (%rax)
je 0x7d1c
movq 0x68(%rsp), %rax
cmpl $0x1, (%rax)
jne 0x7d1e
jmp 0x7d20
jmp 0x7cbd
jmp 0x7c6f
movl $0x28, %edi
callq 0x32e0
movq %rax, 0x8(%rsp)
jmp 0x7d36
movq 0x8(%rsp), %rdi
xorl %esi, %esi
callq 0xaf20
jmp 0x7d44
movq 0x40(%rsp), %rdi
movq 0x8(%rsp), %rax
movq %rax, 0x60(%rsp)
leaq 0x60(%rsp), %rsi
callq 0x9000
jmp 0x7d5f
movb $0x1, 0x28f(%rsp)
leaq 0x80(%rsp), %rdi
callq 0x30c0
testb $0x1, 0x28f(%rsp)
jne 0x7db1
jmp 0x7da7
movq 0x8(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x78(%rsp)
movl %eax, 0x74(%rsp)
callq 0x32b0
leaq 0x80(%rsp), %rdi
callq 0x30c0
jmp 0x7dbe
movq 0x40(%rsp), %rdi
callq 0x41e0
movq 0x48(%rsp), %rax
addq $0x2a8, %rsp            # imm = 0x2A8
retq
movq 0x40(%rsp), %rdi
callq 0x41e0
movq 0x78(%rsp), %rdi
callq 0x3490
nopw %cs:(%rax,%rax)