-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.java
executable file
·99 lines (69 loc) · 2.27 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import semantic.visitor.*;
import semantic.detail.*;
import semantic.options.*;
import semantic.error.*;
import llvm.visitor.*;
import llvm.detail.*;
import syntaxtree.*;
import java.io.*;
class Main
{
static private int status = SemanticErrorManager.SUCCESS;
public static void main(String[] filenames)
{
if (filenames.length < 1)
{
System.err.println("Usage: java Main [FILE_1] [FILE_2] ... [FILE_N]");
System.exit(1);
}
FileInputStream fis = null;
for (String filename : filenames)
{
File file = new File(filename);
try
{
fis = new FileInputStream(file);
MiniJavaParser parser = new MiniJavaParser(fis);
DeclarationVisitor declarationVisitor = new DeclarationVisitor();
Goal goal = parser.Goal();
String structure = goal.accept(declarationVisitor);
Global global = declarationVisitor.getGlobal();
StatementVisitor statementVisitor = new StatementVisitor(global);
LLVMVisitor llvmVisitor = new LLVMVisitor(global);
statementVisitor.visit(declarationVisitor.getPending());
status = SemanticErrorManager.getStatus();
if (status == SemanticErrorManager.FAILURE)
{
SemanticErrorManager.flush(file.getName());
continue;
}
LLVM.open(filename);
goal.accept(llvmVisitor);
LLVM.close();
if (Options.PRINT_PROGRAM_STRUCTURE)
System.out.println(structure);
}
catch (ParseException ex)
{
System.err.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());
}
}
}
System.exit(status);
}
}