-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
79 lines (64 loc) · 2.56 KB
/
Main.java
File metadata and controls
79 lines (64 loc) · 2.56 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
67
68
69
70
71
72
73
74
75
76
77
import syntaxtree.*;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import myPackage.*;
public class Main {
public static void main(String[] args) throws Exception {
if(args.length < 1){
System.err.println("Usage: java Main <inputFile>");
System.exit(1);
}
for (String file : args){
System.out.println();
System.out.println("Checking file: " + file);
FileInputStream fis = null;
try{
fis = new FileInputStream(file);
MiniJavaParser parser = new MiniJavaParser(fis);
Goal root = parser.Goal();
System.err.println("Program parsed successfully.");
LookUpTable symbolTable = new LookUpTable();
SymbolTableVisitor symbolTableVisitor = new SymbolTableVisitor(symbolTable);
TypeCheckVisitor typeCheckVisitor = new TypeCheckVisitor(symbolTable);
IRGenVisitor IRVisitor = new IRGenVisitor(symbolTable);
root.accept(symbolTableVisitor, null);
root.accept(typeCheckVisitor, null);
System.out.println("Semantic Check Passed");
System.out.println("-----------------------");
symbolTable.printOffsets();
System.out.println("-----------------------");
symbolTable.genVtables();
root.accept(IRVisitor, null);
try {
String fileName = file.replace(".java", ".ll");
FileWriter llFile = new FileWriter(fileName, false);
llFile.write(symbolTable.getBuffer());
llFile.close();
System.out.println(fileName + " produced successfully");
}
catch(IOException ex){
System.err.println(ex.getMessage());
}
}
catch(ParseException ex){
System.out.println(ex.getMessage());
}
catch(FileNotFoundException ex){
System.err.println(ex.getMessage());
}
catch (TypeCheckError ex) {
System.err.println(ex.getMessage());
}
finally{
try{
if(fis != null) fis.close();
}
catch(IOException ex){
System.err.println(ex.getMessage());
}
}
}
}
}