-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMain.java
76 lines (63 loc) · 2.46 KB
/
Main.java
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
import LLVM_Generation.GeneratorVisitor;
import TypeChecking.InitVisitor;
import TypeChecking.TypeCheckingVisitor;
import syntaxtree.Goal;
import java.io.*;
public class Main {
public static void main (String [] args){
for(String currFilePath : args) {
//
try {
File myObj = new File(currFilePath.substring(0,currFilePath.length()-5)+".ll");
if (myObj.createNewFile()) {
CheckFile(currFilePath,myObj);
} else {
System.out.println("File already exists.");
}
} catch (IOException e) {
System.out.println("An error occurred.");
e.printStackTrace();
}
//
}
}
public static void CheckFile(String filePath,File writeFile){
FileInputStream fis = null;
try{
fis = new FileInputStream(filePath);
MiniJavaParser parser = new MiniJavaParser(fis);
Goal root = parser.Goal();
//System.err.println("Program parsed successfully.");
try {
try {
FileWriter myWriter = new FileWriter(writeFile.getAbsolutePath());
//InitVisitor initializes some data structures.
InitVisitor init = new InitVisitor();
root.accept(init, null);
TypeCheckingVisitor typechecker = new TypeCheckingVisitor(init.GetSymbolTable());
root.accept(typechecker,null);
//System.err.println("Program is semantically correct.");
//typechecker.PrintOffsets();
GeneratorVisitor gen = new GeneratorVisitor(init.GetSymbolTable(),myWriter);
root.accept(gen,null);
myWriter.close();
} catch (IOException e) {
System.out.println("An error occurred.");
e.printStackTrace();
}
}catch(RuntimeException ex){
System.out.println(ex.toString());
}
} catch(ParseException ex){
System.out.println(ex.getMessage());
} catch(FileNotFoundException ex){
System.err.println(ex.getMessage());
} finally{
try{
if(fis != null) fis.close();
} catch(IOException ex){
System.err.println(ex.getMessage());
}
}
}
}