-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
73 lines (68 loc) · 1.31 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
68
69
70
71
72
73
#pragma once
#include<iostream>
#include<fstream>
#include<string>
#include<vector>
#include<memory>
#include<map>
#include"src/Lexer.h"
#include"src/TokenStream.h"
#include"src/Parser.h"
#include"src/LLVMManager.h"
#include"src/Compiler.h"
int main(int argc, char* argv[]) {
Compiler compiler;
if (argc < 2)
{
std::cerr << "You must specify the parameters!" << std::endl;
return 0;
}
try
{
for (size_t i = 0; i < argc; i++)
{
if (i == 0)
{
continue;
}
std::string parameter(argv[i]);
if (parameter == "-O0")
{
compiler.setOptimizationLevel(OptimizationLevel::O0);
}
else if (parameter == "-O1")
{
compiler.setOptimizationLevel(OptimizationLevel::O1);
}
else if (parameter == "-O2")
{
compiler.setOptimizationLevel(OptimizationLevel::O2);
}
else if (parameter == "-O3")
{
compiler.setOptimizationLevel(OptimizationLevel::O3);
}
else if (parameter == "-input")
{
i++;
if (i >= argc)
{
std::cerr << "You must specify the path to input file!" << std::endl;
return 0;
}
compiler.setInputFile(argv[i]);
}
else
{
std::cerr << "Unknown parameter!" << std::endl;
return 0;
}
}
compiler.compile();
}
catch (const std::exception& e)
{
std::cout << e.what() << std::endl;
}
return 0;
}