-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdj2ll.cpp
66 lines (58 loc) · 1.67 KB
/
dj2ll.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
#include "dj2ll.hpp"
#include "test.hpp"
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <string>
ASTree *wholeProgram;
ASTree *mainExprs;
int numMainBlockLocals;
VarDecl *mainBlockST;
int numClasses;
ClassDecl *classesST;
std::string inputFile;
int instanceOfSeen;
int printNatSeen;
int readNatSeen;
bool findCLIOption(char **begin, char **end, const std::string &flag) {
return std::find(begin, end, flag) != end;
}
void runClang() {
auto outputFile = trimFromLastOccurrence(inputFile, "/");
std::string command = "clang " + inputFile + ".o" + " -o " + outputFile;
std::system(command.c_str());
std::string rmCommand = "rm " + inputFile + ".o";
std::system(rmCommand.c_str());
}
void dj2ll(std::map<std::string, bool> compilerFlags, std::string fileName,
char **argv) {
std::string extension = fileName.substr(fileName.size() - 3, fileName.size());
inputFile = fileName.substr(0, fileName.size() - 3);
if (extension != ".dj") {
printf("ERROR: %s must be called on files ending with \".dj\"\n", argv[0]);
exit(-1);
}
yyin = fopen(fileName.c_str(), "r");
if (yyin == nullptr) {
printf("ERROR: could not open file %s\n", fileName.c_str());
exit(-1);
}
yyparse();
fclose(yyin);
setupSymbolTables(pgmAST);
typecheckProgram();
auto LLProgram = translateAST(wholeProgram);
if (compilerFlags["verbose"]) {
LLProgram.print();
}
if (compilerFlags["codegen"]) {
LLProgram.runOptimizations = compilerFlags["optimizations"];
LLProgram.emitLLVM = compilerFlags["emitLLVM"];
symbolTable ST; /*throwaway*/
LLProgram.codeGen(ST);
}
runClang();
}