Code for Sockets and ServerSockets. Doesn't support outgoing connections yet. Doesn...
[IRC.git] / Robust / src / Main / Main.java
1 package Main;
2
3 import java.io.Reader;
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;
11 import IR.State;
12 import IR.TypeUtil;
13
14 public class Main {
15
16   public static void main(String args[]) throws Exception {
17       String ClassLibraryPrefix="./ClassLibrary/";
18       State state=new State();
19       
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"))
29               state.main=args[++i];
30           else if (option.equals("-struct"))
31               state.structfile=args[++i];
32           else if (option.equals("-conscheck"))
33               state.CONSCHECK=true;
34           else if (option.equals("-task"))
35               state.TASK=true;
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");
42
43               System.out.println("-conscheck -- turn on consistency checking");
44               System.out.println("-help -- print out help");
45               System.exit(0);
46           } else {
47               readSourceFile(state, args[i]);
48           }
49       }
50       
51       readSourceFile(state, ClassLibraryPrefix+"Object.java");
52       readSourceFile(state, ClassLibraryPrefix+"System.java");
53       readSourceFile(state, ClassLibraryPrefix+"String.java");
54       if (state.TASK)      
55           readSourceFile(state, ClassLibraryPrefix+"StartupObject.java");
56
57       BuildIR bir=new BuildIR(state);
58       bir.buildtree();
59       
60       TypeUtil tu=new TypeUtil(state);
61       
62       SemanticCheck sc=new SemanticCheck(state,tu);
63       sc.semanticCheck();
64       tu.createFullTable();
65
66       BuildFlat bf=new BuildFlat(state);
67       bf.buildFlat();
68       
69       BuildCode bc=new BuildCode(state, bf.getMap(), tu);
70       bc.buildCode();
71       System.exit(0);
72   }
73     
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());
84         }
85     }
86 }