-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
66 lines (56 loc) · 2.33 KB
/
Copy pathMain.java
File metadata and controls
66 lines (56 loc) · 2.33 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import syntaxtree.*;
import visitor.*;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
import SymbolTables.GlobalSymbolTable;
public class Main {
public static void main(String[] args) throws Exception {
if(args.length < 1){
System.err.println("Usage: java Main <inputFile1> <inputFile2> ...");
System.exit(1);
}
FileInputStream fis = null;
PrintWriter writer = new PrintWriter("test_results.txt");
for(int i = 0; i < args.length; i++){
try{
fis = new FileInputStream(args[i]);
MiniJavaParser parser = new MiniJavaParser(fis);
Goal root = parser.Goal();
System.err.println("Program parsed successfully.");
GlobalSymbolTable globalSymbolTable = new GlobalSymbolTable();
SymbolTableVisitor eval1 = new SymbolTableVisitor(globalSymbolTable);
root.accept(eval1, null);
TypeCheckVisitor eval2 = new TypeCheckVisitor(globalSymbolTable);
root.accept(eval2, null);
System.out.println("Type check success.");
globalSymbolTable.calculateOffsets();
PrintWriter llvmWriter = new PrintWriter(args[i].substring(0, args[i].length()-5) + ".ll");
LLVMGeneratingVisitor codeGen = new LLVMGeneratingVisitor(globalSymbolTable, llvmWriter);
root.accept(codeGen, null);
llvmWriter.close();
System.out.println("LLVM IR generation success.");
writer.println("Success: " + args[i]);
}
catch(FileNotFoundException ex){
System.err.println(ex.getMessage());
}
catch(Exception ex){
writer.println("Failed: " + args[i]);
System.out.println(ex.getMessage());
}
finally{
try{
if(fis != null) fis.close();
}
catch(IOException ex){
System.err.println(ex.getMessage());
}
}
}
writer.close();
}
}
class MyVisitor extends GJDepthFirst<String, Void>{
}