8 * The main compiler module, which does the following:
15 * @author <b>Daniel Roy</b> droy (at) mit (dot) edu
19 public class Compiler {
20 /* Set this flag to false to turn repairs off */
21 public static boolean REPAIR=true;
22 public static boolean AGGRESSIVESEARCH=false;
23 public static boolean PRUNEQUANTIFIERS=false;
24 public static boolean GENERATEDEBUGHOOKS=false;
25 public static boolean GENERATEDEBUGPRINT=false;
26 public static boolean GENERATEINSTRUMENT=false;
27 public static boolean ALLOCATECPLUSPLUS=false;
29 public static Vector debuggraphs=new Vector();
31 public static void main(String[] args) {
33 boolean success = true;
36 printArgInfo(cli); // prints debugging information and warning
39 State.currentState = state;
40 State.debug = cli.debug;
41 State.verbose = cli.verbose;
42 State.infile = cli.infile;
43 State.outfile = cli.outfile;
46 * added: terminates with an error message if no input file
47 * specified at command line
50 System.out.println("MCC v0.0.1 - MIT LCS (Author: Daniel Roy, Brian Demsky)\n");
52 if (cli.infile == null) {
53 System.err.println("\nError: no input file specified");
58 System.out.println("Compiling " + cli.infile + ".");
61 success = scan(state) || error(state, "Scanning failed, not attempting to parse.");
62 success = parse(state) || error(state, "Parsing failed, not attempting semantic analysis.");
63 success = semantics(state) || error(state, "Semantic analysis failed, not attempting variable initialization.");
66 state.setanalysis=new SetAnalysis(state);
67 Termination termination=null;
68 /* Check partition constraints */
69 (new ImplicitSchema(state)).update();
70 termination=new Termination(state);
73 (new DependencyBuilder(state)).calculate();
76 Vector nodes = new Vector(state.constraintnodes.values());
77 nodes.addAll(state.rulenodes.values());
79 FileOutputStream dotfile;
80 dotfile = new FileOutputStream(cli.infile + ".dependencies.edgelabels.dot");
81 GraphNode.useEdgeLabels = true;
82 GraphNode.DOTVisitor.visit(dotfile, nodes);
85 dotfile = new FileOutputStream(cli.infile + ".dependencies.dot");
86 GraphNode.useEdgeLabels = false;
87 GraphNode.DOTVisitor.visit(dotfile, nodes);
89 } catch (Exception e) {
95 FileOutputStream gcode = new FileOutputStream(cli.infile + ".cc");
98 // do model optimizations
99 //(new Optimizer(state)).optimize();
101 FileOutputStream gcode2 = new FileOutputStream(cli.infile + "_aux.cc");
102 FileOutputStream gcode3 = new FileOutputStream(cli.infile + "_aux.h");
103 RepairGenerator wg = new RepairGenerator(state,termination);
104 wg.generate(gcode,gcode2,gcode3, cli.infile + "_aux.h");
108 WorklistGenerator ng = new WorklistGenerator(state);
109 SetInclusion.worklist=true;
110 RelationInclusion.worklist=true;
114 } catch (Exception e) {
120 System.out.println("Compilation of " + state.infile + " successful.");
121 System.out.println("#SUCCESS#");
125 private static void printArgInfo(CLI cli) {
127 System.out.println("Printing debugging information...");
128 System.out.println("Input filename: " + cli.infile);
129 System.out.println("Output filename: " + cli.outfile);
131 for (int i = 0; i < cli.opts.length; i++) {
133 System.out.println("Optimization");
138 for (int i = 0; i < cli.extraopts.size(); i++) {
139 System.err.println("Warning: optimization \"" +
140 cli.extraopts.elementAt(i) +
141 "\" not recognized");
144 for (int i = 0; i < cli.extras.size(); i++) {
145 System.err.println("Warning: option \"" +
146 cli.extras.elementAt(i) +
147 "\" not recognized");
151 private static boolean error(State state, String error) {
152 System.err.println(error);
154 System.out.println("#ERROR#");
160 public static boolean semantics(State state) {
161 SimpleIRErrorReporter er = new SimpleIRErrorReporter();
162 SemanticChecker checker = new SemanticChecker();
166 ok = checker.check(state, er);
167 } catch (Exception e) {
168 er.report(null, e.toString());
174 er.report(null, "Semantic check failed.");
177 System.out.print(er.toString());
182 public static void debugMessage(int level, String s) {
183 if (State.currentState.verbose >= level) {
184 System.err.println(s);
188 public static boolean parse(State state) {
190 /* parse structure file */
192 debugMessage(1, "Parsing structure file");
194 FileInputStream infile = new FileInputStream(state.infile + ".struct");
195 TDLParser parser = new TDLParser(new Lexer(infile));
196 parser.filename = state.infile + ".struct";
197 CUP$TDLParser$actions.debug = state.verbose > 1 ;
198 state.ptStructures = (ParseNode) parser.parse().value;
199 } catch (FileNotFoundException fnfe) {
200 System.err.println("Unable to open file: " + state.infile + ".struct");
202 } catch (Exception e) {
203 System.out.println(e);
208 /* parse model file */
210 debugMessage(1, "Parsing model file");
212 FileInputStream infile = new FileInputStream(state.infile + ".model");
213 MDLParser parser = new MDLParser(new Lexer(infile));
214 parser.filename = state.infile + ".model";
215 CUP$MDLParser$actions.debug = state.verbose > 1 ;
216 state.ptModel = (ParseNode) parser.parse().value;
217 } catch (FileNotFoundException fnfe) {
218 System.err.println("Unable to open file: " + state.infile + ".model");
220 } catch (Exception e) {
221 System.out.println(e);
226 /* parse space file */
228 debugMessage(1, "Parsing space file");
230 FileInputStream infile = new FileInputStream(state.infile + ".space");
231 SDLParser parser = new SDLParser(new Lexer(infile));
232 parser.filename = state.infile + ".space";
233 CUP$SDLParser$actions.debug = state.verbose > 1 ;
234 state.ptSpace = (ParseNode) parser.parse().value;
235 } catch (FileNotFoundException fnfe) {
236 System.err.println("Unable to open file: " + state.infile + ".space");
238 } catch (Exception e) {
239 System.out.println(e);
244 /* parse constraints file */
246 debugMessage(1, "Parsing constraints file");
248 FileInputStream infile = new FileInputStream(state.infile + ".constraints");
249 CDLParser parser = new CDLParser(new Lexer(infile));
250 parser.filename = state.infile + ".constraints";
251 CUP$CDLParser$actions.debug = state.verbose > 1 ;
252 state.ptConstraints = (ParseNode) parser.parse().value;
253 } catch (FileNotFoundException fnfe) {
254 System.err.println("Unable to open file: " + state.infile + ".constraints");
256 } catch (Exception e) {
257 System.out.println(e);
263 !CUP$TDLParser$actions.errors &&
264 !CUP$SDLParser$actions.errors &&
265 !CUP$CDLParser$actions.errors &&
266 !CUP$MDLParser$actions.errors;
269 // if verbosity is on, then output parse trees as .dot files
270 if (success && state.verbose > 0) {
272 FileOutputStream dotfile;
274 dotfile = new FileOutputStream(state.infile + ".struct.dot");
275 ParseNodeDOTVisitor.visit(dotfile, state.ptStructures);
278 dotfile = new FileOutputStream(state.infile + ".model.dot");
279 ParseNodeDOTVisitor.visit(dotfile, state.ptModel);
282 dotfile = new FileOutputStream(state.infile + ".space.dot");
283 ParseNodeDOTVisitor.visit(dotfile, state.ptSpace);
286 dotfile = new FileOutputStream(state.infile + ".constraints.dot");
287 ParseNodeDOTVisitor.visit(dotfile, state.ptConstraints);
289 } catch (Exception e) {
299 public static boolean scan(State state) {
300 FileInputStream infile = null;
302 boolean errors = false;
303 String files[] = { new String(state.infile + ".struct"),
304 new String(state.infile + ".model"),
305 new String(state.infile + ".constraints"),
306 new String(state.infile + ".space") };
310 for (int i = 0; i < files.length; i++) {
312 String filename = files[i];
315 infile = new FileInputStream(filename);
316 } catch (FileNotFoundException fnfe) {
317 System.err.println("Unable to open file: " + filename);
321 lexer = new Lexer(infile);
326 java_cup.runtime.Symbol symbol;
328 symbol = lexer.next_token();
330 if (symbol.sym == Sym.EOF) {
332 } else if (symbol.sym == Sym.BAD) {
336 if (State.verbose > 2) {
337 System.out.println("Got token: " + symbol.value);
340 } catch (Exception e) {