Make merging nodes an option.
[repair.git] / Repair / RepairCompiler / MCC / Compiler.java
index 8f9054063f1d83437e1d94fd2588c426a4eefba9..6fad5086b8eb5ab02dc3d5fa200eac4905444c23 100755 (executable)
@@ -9,16 +9,28 @@ import MCC.IR.*;
  * <ul>
  *  <li>
  *   nothing.
- *  </li> 
+ *  </li>
  * <ul>
  *
  * @author <b>Daniel Roy</b> droy (at) mit (dot) edu
- * @version %I, %G 
+ * @version %I, %G
  */
 
 public class Compiler {
+    /* Set this flag to false to turn repairs off */
     public static boolean REPAIR=true;
-    
+    public static boolean AGGRESSIVESEARCH=false;
+    public static boolean PRUNEQUANTIFIERS=false;
+    public static boolean GENERATEDEBUGHOOKS=false;
+    public static boolean GENERATEDEBUGPRINT=false;
+    public static boolean GENERATEINSTRUMENT=false;
+    public static boolean ALLOCATECPLUSPLUS=false;
+    public static boolean OMITCOMP=false;
+    public static boolean MERGENODES=false;
+    public static boolean TIME=false;
+
+    public static Vector debuggraphs=new Vector();
+
     public static void main(String[] args) {
         State state = null;
         boolean success = true;
@@ -38,104 +50,79 @@ public class Compiler {
          * specified at command line
          */
 
-        System.out.println("\nMCC v0.0.1 - MIT LCS (Author: Daniel Roy, Brian Demsky)");
+        System.out.println("MCC v0.0.1 - MIT LCS (Author: Daniel Roy, Brian Demsky)\n");
 
        if (cli.infile == null) {
            System.err.println("\nError: no input file specified");
            System.exit(-1);
        }
-        
-       if (cli.target == CLI.ASSEMBLY || cli.target == CLI.DEFAULT) {
-           if (state.debug) {
-               System.out.println("Compiling " + cli.infile + ".");
-           }
-
-           success = scan(state) || error(state, "Scanning failed, not attempting to parse.");
-           success = parse(state) || error(state, "Parsing failed, not attempting semantic analysis.");
-           success = semantics(state) || error(state, "Semantic analysis failed, not attempting variable initialization.");
-
-           if (REPAIR)
-               (new ImplicitSchema(state)).update();
-
-            
-            (new DependencyBuilder(state)).calculate();
-            
-            try {
-                Vector nodes = new Vector(state.constraintnodes.values());
-                nodes.addAll(state.rulenodes.values());
 
-                FileOutputStream dotfile;
-                dotfile = new FileOutputStream(cli.infile + ".dependencies.edgelabels.dot");
-                GraphNode.useEdgeLabels = true;
-                GraphNode.DOTVisitor.visit(dotfile, nodes);                
-                dotfile.close();
+       if (state.debug) {
+           System.out.println("Compiling " + cli.infile + ".");
+       }
 
-                dotfile = new FileOutputStream(cli.infile + ".dependencies.dot");
-                GraphNode.useEdgeLabels = false;
-                GraphNode.DOTVisitor.visit(dotfile, nodes);                
-                dotfile.close();
-            } catch (Exception e) {
-                e.printStackTrace();
-                System.exit(-1);
-            }
-            
-            try {
-                FileOutputStream gcode = new FileOutputStream(cli.infile + ".cc");
+       success = scan(state) || error(state, "Scanning failed, not attempting to parse.");
+       success = parse(state) || error(state, "Parsing failed, not attempting semantic analysis.");
+       success = semantics(state) || error(state, "Semantic analysis failed, not attempting variable initialization.");
 
-                // do model optimizations
-                //(new Optimizer(state)).optimize();
 
-                NaiveGenerator ng = new NaiveGenerator(state);
-                ng.generate(gcode);
-                //WorklistGenerator wg = new WorklistGenerator(state);
-                //wg.generate(gcode);
-                gcode.close();
-            } catch (Exception e) {
-                e.printStackTrace();
-                System.exit(-1);
-            }
-            
-           if (state.debug) {
-               System.out.println("Compilation of " + state.infile + " successful.");
-               System.out.println("#SUCCESS#");
-           }
-       } else if (cli.target == CLI.INTER) {
-           if (state.debug) {
-               System.out.println("Semantic analysis for " + cli.infile + ".");
-           }
-
-           success = scan(state) || error(state, "Scanning failed, not attempting to parse.");
-           success = parse(state) || error(state, "Parsing failed, not attempting semantic analysis.");
-           success = semantics(state) || error(state, "Semantic analysis failed.");
-
-           if (state.debug) {
-               System.out.println("Semantic analysis of " + state.infile + " successful.");
-               System.out.println("#SUCCESS#");
-           }
-       } else if (cli.target == CLI.PARSE) {
-           if (state.debug) {
-               System.out.println("Parsing " + cli.infile + ".");
-           }
-
-           success = scan(state) || error(state, "Scanning failed, not attempting to parse.");
-           success = parse(state) || error(state, "Parsing failed.");
-
-           if (state.debug) {
-               System.out.println("Parsing of " + state.infile + " successful.");
-               System.out.println("#SUCCESS#");
-           }
-        } else if (cli.target == CLI.SCAN) {
-           if (state.debug) {
-               System.out.println("Scanning " + cli.infile + ".");
-           }
-
-           success = scan(state) || error(state, "Scanning failed.");
-
-           if (state.debug) {
-               System.out.println("Scanning of " + state.infile + " successful.");
-               System.out.println("#SUCCESS#");
-           }
-        }
+       state.setanalysis=new SetAnalysis(state);
+       Termination termination=null;
+       /* Check partition constraints */
+       (new ImplicitSchema(state)).update();
+       termination=new Termination(state);
+
+       state.printall();
+       (new DependencyBuilder(state)).calculate();
+
+       try {
+           Vector nodes = new Vector(state.constraintnodes.values());
+           nodes.addAll(state.rulenodes.values());
+
+           FileOutputStream dotfile;
+           dotfile = new FileOutputStream(cli.infile + ".dependencies.edgelabels.dot");
+           GraphNode.useEdgeLabels = true;
+           GraphNode.DOTVisitor.visit(dotfile, nodes);
+           dotfile.close();
+
+           dotfile = new FileOutputStream(cli.infile + ".dependencies.dot");
+           GraphNode.useEdgeLabels = false;
+           GraphNode.DOTVisitor.visit(dotfile, nodes);
+           dotfile.close();
+       } catch (Exception e) {
+           e.printStackTrace();
+           System.exit(-1);
+       }
+
+       try {
+           FileOutputStream gcode = new FileOutputStream(cli.infile + ".c");
+
+
+           // do model optimizations
+           //(new Optimizer(state)).optimize();
+
+           FileOutputStream gcode2 = new FileOutputStream(cli.infile + "_aux.c");
+           FileOutputStream gcode3 = new FileOutputStream(cli.infile + "_aux.h");
+           RepairGenerator wg = new RepairGenerator(state,termination);
+           wg.generate(gcode,gcode2,gcode3, cli.infile + "_aux.h");
+           gcode2.close();
+           gcode3.close();
+           /*          } else {
+                       WorklistGenerator ng = new WorklistGenerator(state);
+                   SetInclusion.worklist=true;
+                   RelationInclusion.worklist=true;
+                   ng.generate(gcode);
+                   }*/
+           gcode.close();
+       } catch (Exception e) {
+           e.printStackTrace();
+           System.exit(-1);
+       }
+
+       if (state.debug) {
+           System.out.println("Compilation of " + state.infile + " successful.");
+           System.out.println("#SUCCESS#");
+       }
     }
 
     private static void printArgInfo(CLI cli) {
@@ -143,31 +130,6 @@ public class Compiler {
             System.out.println("Printing debugging information...");
             System.out.println("Input filename: " + cli.infile);
             System.out.println("Output filename: " + cli.outfile);
-            System.out.print("Target: ");
-
-            switch(cli.target) {
-            case CLI.ASSEMBLY:
-                System.out.println("ASSEMBLY");
-                break;
-            case CLI.DEFAULT:
-                System.out.println("DEFAULT");
-                break;
-            case CLI.INTER:
-                System.out.println("INTER");
-                break;
-            case CLI.LOWIR:
-                System.out.println("LOWIR");
-                break;
-            case CLI.PARSE:
-                System.out.println("PARSE");
-                break;
-            case CLI.SCAN:
-                System.out.println("SCAN");
-                break;
-            default:
-                System.out.println("not recognized");
-                break;
-            }
 
             for (int i = 0; i < cli.opts.length; i++) {
                 if (cli.opts[i]) {
@@ -227,21 +189,22 @@ public class Compiler {
     }
 
     public static boolean parse(State state) {
-        
+
         /* parse structure file */
         try {
             debugMessage(1, "Parsing structure file");
             LineCount.reset();
             FileInputStream infile = new FileInputStream(state.infile + ".struct");
             TDLParser parser = new TDLParser(new Lexer(infile));
+           parser.filename = state.infile + ".struct";
             CUP$TDLParser$actions.debug = state.verbose > 1 ;
             state.ptStructures = (ParseNode) parser.parse().value;
         } catch (FileNotFoundException fnfe) {
             System.err.println("Unable to open file: " + state.infile + ".struct");
             System.exit(-1);
        } catch (Exception e) {
-           //      System.out.println(e);
-           //      e.printStackTrace();
+           System.out.println(e);
+           e.printStackTrace();
            return false;
        }
 
@@ -251,14 +214,15 @@ public class Compiler {
             LineCount.reset();
             FileInputStream infile = new FileInputStream(state.infile + ".model");
             MDLParser parser = new MDLParser(new Lexer(infile));
+           parser.filename = state.infile + ".model";
             CUP$MDLParser$actions.debug = state.verbose > 1 ;
             state.ptModel = (ParseNode) parser.parse().value;
         } catch (FileNotFoundException fnfe) {
             System.err.println("Unable to open file: " + state.infile + ".model");
             System.exit(-1);
        } catch (Exception e) {
-           //      System.out.println(e);
-           //      e.printStackTrace();
+           System.out.println(e);
+           e.printStackTrace();
            return false;
        }
 
@@ -268,14 +232,15 @@ public class Compiler {
             LineCount.reset();
             FileInputStream infile = new FileInputStream(state.infile + ".space");
             SDLParser parser = new SDLParser(new Lexer(infile));
+           parser.filename = state.infile + ".space";
             CUP$SDLParser$actions.debug = state.verbose > 1 ;
             state.ptSpace = (ParseNode) parser.parse().value;
         } catch (FileNotFoundException fnfe) {
             System.err.println("Unable to open file: " + state.infile + ".space");
             System.exit(-1);
        } catch (Exception e) {
-           //      System.out.println(e);
-           //      e.printStackTrace();
+           System.out.println(e);
+           e.printStackTrace();
            return false;
        }
 
@@ -285,50 +250,51 @@ public class Compiler {
             LineCount.reset();
             FileInputStream infile = new FileInputStream(state.infile + ".constraints");
             CDLParser parser = new CDLParser(new Lexer(infile));
+           parser.filename = state.infile + ".constraints";
             CUP$CDLParser$actions.debug = state.verbose > 1 ;
             state.ptConstraints = (ParseNode) parser.parse().value;
         } catch (FileNotFoundException fnfe) {
             System.err.println("Unable to open file: " + state.infile + ".constraints");
             System.exit(-1);
        } catch (Exception e) {
-           //      System.out.println(e);
-           //      e.printStackTrace();
+           System.out.println(e);
+           e.printStackTrace();
            return false;
        }
 
-        boolean success = 
-            !CUP$TDLParser$actions.errors && 
-            !CUP$SDLParser$actions.errors && 
-            !CUP$CDLParser$actions.errors && 
+        boolean success =
+            !CUP$TDLParser$actions.errors &&
+            !CUP$SDLParser$actions.errors &&
+            !CUP$CDLParser$actions.errors &&
             !CUP$MDLParser$actions.errors;
 
-                
+
         // if verbosity is on, then output parse trees as .dot files
         if (success && state.verbose > 0) {
             try {
                 FileOutputStream dotfile;
 
                 dotfile = new FileOutputStream(state.infile + ".struct.dot");
-                ParseNodeDOTVisitor.visit(dotfile, state.ptStructures);                
+                ParseNodeDOTVisitor.visit(dotfile, state.ptStructures);
                 dotfile.close();
 
                 dotfile = new FileOutputStream(state.infile + ".model.dot");
-                ParseNodeDOTVisitor.visit(dotfile, state.ptModel);                
+                ParseNodeDOTVisitor.visit(dotfile, state.ptModel);
                 dotfile.close();
 
                 dotfile = new FileOutputStream(state.infile + ".space.dot");
-                ParseNodeDOTVisitor.visit(dotfile, state.ptSpace);                
+                ParseNodeDOTVisitor.visit(dotfile, state.ptSpace);
                 dotfile.close();
 
                 dotfile = new FileOutputStream(state.infile + ".constraints.dot");
-                ParseNodeDOTVisitor.visit(dotfile, state.ptConstraints);                
+                ParseNodeDOTVisitor.visit(dotfile, state.ptConstraints);
                 dotfile.close();
             } catch (Exception e) {
                 e.printStackTrace();
                 return false;
             }
         }
-            
+
        return success;
     }
 
@@ -354,22 +320,22 @@ public class Compiler {
                 System.err.println("Unable to open file: " + filename);
                 System.exit(-1);
             }
-            
+
             lexer = new Lexer(infile);
 
-            
+
             try {
                 while (true) {
                     java_cup.runtime.Symbol symbol;
-                    
+
                     symbol = lexer.next_token();
-                    
+
                     if (symbol.sym == Sym.EOF) {
                         break;
                     } else if (symbol.sym == Sym.BAD) {
                         errors = true;
                     }
-                    
+
                     if (State.verbose > 2) {
                         System.out.println("Got token: " + symbol.value);
                     }
@@ -384,4 +350,3 @@ public class Compiler {
 
 
 }
-