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;
16 public static void main(String args[]) throws Exception {
17 String ClassLibraryPrefix="./ClassLibrary/";
18 State state=new State();
20 for(int i=0;i<args.length;i++) {
21 String option=args[i];
22 if (option.equals("-precise"))
23 IR.Flat.BuildCode.GENERATEPRECISEGC=true;
24 else if (option.equals("-dir"))
25 IR.Flat.BuildCode.PREFIX=args[++i]+"/";
26 else if (option.equals("-classlibrary"))
27 ClassLibraryPrefix=args[++i]+"/";
28 else if (option.equals("-mainclass"))
30 else if (option.equals("-struct"))
31 state.structfile=args[++i];
32 else if (option.equals("-conscheck"))
34 else if (option.equals("-task"))
36 else if (option.equals("-help")) {
37 System.out.println("-classlibrary classlibrarydirectory -- directory where classlibrary is located");
38 System.out.println("-dir outputdirectory -- output code in outputdirectory");
39 System.out.println("-struct structfile -- output structure declarations for repair tool");
40 System.out.println("-mainclass -- main function to call");
41 System.out.println("-precise -- use precise garbage collection");
43 System.out.println("-conscheck -- turn on consistency checking");
44 System.out.println("-help -- print out help");
47 readSourceFile(state, args[i]);
51 readSourceFile(state, ClassLibraryPrefix+"Object.java");
52 readSourceFile(state, ClassLibraryPrefix+"System.java");
53 readSourceFile(state, ClassLibraryPrefix+"String.java");
55 readSourceFile(state, ClassLibraryPrefix+"StartupObject.java");
57 BuildIR bir=new BuildIR(state);
60 TypeUtil tu=new TypeUtil(state);
62 SemanticCheck sc=new SemanticCheck(state,tu);
66 BuildFlat bf=new BuildFlat(state);
69 BuildCode bc=new BuildCode(state, bf.getMap(), tu);
74 private static void readSourceFile(State state, String sourcefile) throws Exception {
75 Reader fr = new BufferedReader(new FileReader(sourcefile));
76 Lex.Lexer l = new Lex.Lexer(fr);
77 java_cup.runtime.lr_parser g;
78 g = new Parse.Parser(l);
79 ParseNode p=(ParseNode) g./*debug_*/parse().value;
80 state.addParseNode(p);
81 if (l.numErrors()!=0) {
82 System.out.println("Error parsing Object.java");
83 System.exit(l.numErrors());