-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
44 lines (35 loc) · 975 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
38
39
40
41
42
43
44
#include "main.h"
#include "ast/Functions/ast.h"
#include "ast/ast.h"
#include "globals.h"
#include <fstream>
#include <iostream>
#include <llvm/Support/raw_ostream.h>
#include <utility>
extern FILE* yyin;
extern int yyparse();
extern BlockAST* res;
using namespace llvm;
std::string externMalloc() {
std::vector<Type*> argTypes = {i32};
auto proto = std::make_unique<PrototypeAST>("malloc", std::move(argTypes), pi8);
return proto->out();
}
std::string externFree() {
std::vector<Type*> argTypes = {pi8};
auto proto = std::make_unique<PrototypeAST>("free", std::move(argTypes), i8);
return proto->out();
}
int main(int argc, char** argv) {
if(argc > 1) {
yyin = fopen(argv[1], "r");
} else {
throw std::invalid_argument("Did not receive file as second argument!");
}
yyparse();
auto output = externMalloc() + externFree() + res->out();
std::cout << output << std::endl;
std::ofstream outputFile;
outputFile.open(argv[2]);
outputFile << output;
}