-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
49 lines (37 loc) · 1.18 KB
/
Copy pathmain.cpp
File metadata and controls
49 lines (37 loc) · 1.18 KB
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
#include <iostream>
#include <fstream>
#include <sstream>
#include "./generator.h"
int main(const int argc, char* argv[]) {
if (argc != 2) {
std::cerr << "Incorrect Usage" << std::endl;
std::cerr << "hydro <input.hy>" << std::endl;
exit(EXIT_FAILURE);
}
std::string contents;
{
std::stringstream content_stream;
std::fstream input(argv[1], std::ios::in);
if (!input) {
std::cerr << "Failed to open file: " << argv[1] << "\n";
exit(EXIT_FAILURE);
}
content_stream << input.rdbuf();
contents = content_stream.str();
}
Tokenizer tokenizer(std::move(contents));
std::vector<Token> tokens = tokenizer.tokenize();
Parser parser(std::move(tokens));
std::optional<NodeProgram> program = parser.parse_program();
if (!program.has_value()) {
std::cerr << "Invalid program" << std::endl;
}
{
Generator generator(program.value());
std::fstream file("output.s", std::ios::out);
file << generator.generateProgram() ;
}
system("clang -c -o output.o output.s");
system("clang -o out output.o");
exit(EXIT_SUCCESS);
}