-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
37 lines (29 loc) · 1016 Bytes
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "source/token/token.hpp"
#include "source/lexer/lexer.hpp"
#include "source/compiler/llvm_compiler.hpp"
#include "source/compiler/llvm_executable_builder.hpp"
#include "source/token/token_buffer/token_buffer.hpp"
int main(int argc, char** argv)
{
if(argc != 2)
{
std::cerr << "[-] Incorrect usage." << std::endl;
std::cerr << "[-] Correct usage: ./dust-lang [input.dust]" << std::endl;
exit(EXIT_FAILURE);
}
std::string source;
{
std::fstream file_input(argv[1], std::ios::in);
std::stringstream stream_input;
stream_input << file_input.rdbuf();
source = stream_input.str();
}
Lexer lexer(std::move(source));
std::vector<Token> tokens = lexer.tokenize();
LLVMCompiler compiler("dust_prog", std::move(TokenBuffer(std::move(tokens))));
compiler.generate();
compiler.verify_module();
LLVMExecutableBuilder exec(compiler.get_llvm_ir_as_string(), "out");
exec.build_executable();
return 0;
}