-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
67 lines (59 loc) · 1.52 KB
/
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <filesystem>
#include <fstream>
#include <iostream>
#include "ArgumentParser.h"
#include "backend.h"
#include "lexer.h"
#include "platform.h"
int main(int argc, char** argv)
{
ArgumentParser argparse(argv[0]);
argparse.addOption("-o", "outputFilename");
argparse.addOption("inputFile");
std::map<std::string, std::string> args;
try
{
args = argparse.parse(argc, argv);
}
catch (const ArgumentParser::ParseError& err)
{
std::cerr << err.what();
return 1;
}
const std::string inputFile = args["inputFile"];
std::ifstream inputStream(inputFile);
if (!inputStream)
{
std::cerr << "Input file " << inputFile << " does not exist\n";
return 2;
}
std::filesystem::path inputPath(inputFile);
ErrorReporter errors(std::cerr, inputStream, inputFile);
Lexer lexer(inputStream, errors, {false});
while (lexer.hasNext())
lexer.next();
if (errors.hasErrors())
return 1;
std::filesystem::path outputPath;
if (args.find("-o") != args.end())
{
outputPath = args["-o"];
}
else
{
outputPath = inputPath.stem();
outputPath += ".out";
}
std::filesystem::path llvmIrPath(inputPath.stem());
llvmIrPath += ".ll";
// TODO: actually do the work
{
std::ofstream llvmIrStream(llvmIrPath);
llvmIrStream << R"(
define i32 @main() {
ret i32 0
} )";
}
generateExecutableFromBytecode(Platform(), llvmIrPath, outputPath);
return 0;
}