4 import java.io.BufferedReader;
5 import java.io.FileReader;
6 import IR.Tree.ParseNode;
7 import IR.Tree.BuildIR;
8 import IR.Tree.SemanticCheck;
9 import IR.Flat.BuildFlat;
10 import IR.Flat.BuildCode;
13 //import IR.PrintTree;
14 import Analysis.TaskStateAnalysis.TaskAnalysis;
18 /** Main method for the compiler. */
20 public static void main(String args[]) throws Exception {
21 String ClassLibraryPrefix="./ClassLibrary/";
22 State state=new State();
24 for(int i=0;i<args.length;i++) {
25 String option=args[i];
26 if (option.equals("-precise"))
27 IR.Flat.BuildCode.GENERATEPRECISEGC=true;
28 else if (option.equals("-dir"))
29 IR.Flat.BuildCode.PREFIX=args[++i]+"/";
30 else if (option.equals("-classlibrary"))
31 ClassLibraryPrefix=args[++i]+"/";
32 else if (option.equals("-mainclass"))
34 else if (option.equals("-struct"))
35 state.structfile=args[++i];
36 else if (option.equals("-conscheck"))
38 else if (option.equals("-task"))
40 else if (option.equals("-thread"))
42 else if (option.equals("-instructionfailures"))
43 state.INSTRUCTIONFAILURE=true;
44 else if (option.equals("-help")) {
45 System.out.println("-classlibrary classlibrarydirectory -- directory where classlibrary is located");
46 System.out.println("-dir outputdirectory -- output code in outputdirectory");
47 System.out.println("-struct structfile -- output structure declarations for repair tool");
48 System.out.println("-mainclass -- main function to call");
49 System.out.println("-precise -- use precise garbage collection");
51 System.out.println("-conscheck -- turn on consistency checking");
52 System.out.println("-task -- compiler for tasks");
53 System.out.println("-thread -- threads");
54 System.out.println("-instructionfailures -- insert code for instruction level failures");
55 System.out.println("-help -- print out help");
58 readSourceFile(state, args[i]);
63 readSourceFile(state, ClassLibraryPrefix+"System.java");
64 readSourceFile(state, ClassLibraryPrefix+"String.java");
65 readSourceFile(state, ClassLibraryPrefix+"HashSet.java");
66 readSourceFile(state, ClassLibraryPrefix+"HashMap.java");
67 readSourceFile(state, ClassLibraryPrefix+"HashMapIterator.java");
68 readSourceFile(state, ClassLibraryPrefix+"HashEntry.java");
69 readSourceFile(state, ClassLibraryPrefix+"Integer.java");
70 readSourceFile(state, ClassLibraryPrefix+"StringBuffer.java");
71 readSourceFile(state, ClassLibraryPrefix+"FileInputStream.java");
72 readSourceFile(state, ClassLibraryPrefix+"FileOutputStream.java");
73 readSourceFile(state, ClassLibraryPrefix+"File.java");
74 readSourceFile(state, ClassLibraryPrefix+"InetAddress.java");
77 readSourceFile(state, ClassLibraryPrefix+"Thread.java");
78 readSourceFile(state, ClassLibraryPrefix+"ObjectJava.java");
80 readSourceFile(state, ClassLibraryPrefix+"Object.java");
83 readSourceFile(state, ClassLibraryPrefix+"StartupObject.java");
84 readSourceFile(state, ClassLibraryPrefix+"Socket.java");
85 readSourceFile(state, ClassLibraryPrefix+"ServerSocket.java");
87 readSourceFile(state, ClassLibraryPrefix+"SocketJava.java");
88 readSourceFile(state, ClassLibraryPrefix+"ServerSocketJava.java");
91 BuildIR bir=new BuildIR(state);
94 // PrintTree ptree=new PrintTree(state);
97 TypeUtil tu=new TypeUtil(state);
99 SemanticCheck sc=new SemanticCheck(state,tu);
101 tu.createFullTable();
103 BuildFlat bf=new BuildFlat(state,tu);
106 // System.out.println("Flat");
107 // PrintTree ptree1=new PrintTree(state);
108 // ptree1.buildtree();
110 TaskAnalysis ta=new TaskAnalysis(state,bf.getMap());
112 // ta.printAdjList();
116 BuildCode bc=new BuildCode(state, bf.getMap(), tu);
121 /** Reads in a source file and adds the parse tree to the state object. */
123 private static void readSourceFile(State state, String sourcefile) throws Exception {
124 Reader fr = new BufferedReader(new FileReader(sourcefile));
125 Lex.Lexer l = new Lex.Lexer(fr);
126 java_cup.runtime.lr_parser g;
127 g = new Parse.Parser(l);
130 p=(ParseNode) g./*debug_*/parse().value;
131 } catch (Exception e) {
132 System.err.println("Error parsing file:"+sourcefile);
136 state.addParseNode(p);
137 if (l.numErrors()!=0) {
138 System.out.println("Error parsing "+sourcefile);
139 System.exit(l.numErrors());