From 1ac19ae1b06036f6883e3a5f91b8a85ecab9ab72 Mon Sep 17 00:00:00 2001 From: bdemsky Date: Wed, 21 Apr 2004 21:16:15 +0000 Subject: [PATCH] Changes: 1) Cleaned up CLI/Compiler classes that Dan provided. 2) Typecheck Constraints. 3) Repair dependence analysis (to order repair of constraints) A) checks for functions 4) Added class to compute exact sizes of sets (and constraints which establish these sizes) --- Repair/RepairCompiler/MCC/CLI.java | 159 +------------ Repair/RepairCompiler/MCC/Compiler.java | 187 +++++---------- Repair/RepairCompiler/MCC/IR/Conjunction.java | 2 +- Repair/RepairCompiler/MCC/IR/Constraint.java | 1 - .../MCC/IR/ConstraintDependence.java | 216 ++++++++++++++++++ Repair/RepairCompiler/MCC/IR/DotExpr.java | 11 + Repair/RepairCompiler/MCC/IR/ExactSize.java | 73 ++++++ Repair/RepairCompiler/MCC/IR/Expr.java | 12 + .../RepairCompiler/MCC/IR/ExprPredicate.java | 6 + .../MCC/IR/InclusionPredicate.java | 9 + .../RepairCompiler/MCC/IR/LogicStatement.java | 13 ++ Repair/RepairCompiler/MCC/IR/OpExpr.java | 20 ++ .../RepairCompiler/MCC/IR/RelationExpr.java | 17 ++ .../MCC/IR/RepairGenerator.java | 33 +-- .../MCC/IR/SemanticChecker.java | 44 +++- Repair/RepairCompiler/MCC/IR/Sources.java | 4 + Repair/RepairCompiler/MCC/IR/Termination.java | 39 ++-- .../RepairCompiler/MCC/IR/VarDescriptor.java | 10 + Repair/RepairCompiler/MCC/IR/VarExpr.java | 12 +- 19 files changed, 530 insertions(+), 338 deletions(-) create mode 100755 Repair/RepairCompiler/MCC/IR/ConstraintDependence.java create mode 100755 Repair/RepairCompiler/MCC/IR/ExactSize.java diff --git a/Repair/RepairCompiler/MCC/CLI.java b/Repair/RepairCompiler/MCC/CLI.java index 609455a..f03831e 100755 --- a/Repair/RepairCompiler/MCC/CLI.java +++ b/Repair/RepairCompiler/MCC/CLI.java @@ -11,47 +11,9 @@ import java.util.StringTokenizer; * files. * * @author le01, 6.035 Staff (6.035-staff@mit.edu) - * @version $Id: CLI.java,v 1.2 2004/04/15 05:41:46 bdemsky Exp $ + * @version $Id: CLI.java,v 1.3 2004/04/21 21:15:48 bdemsky Exp $ */ public class CLI { - /** - * Target value indicating that the compiler should produce its - * default output. - */ - public static final int DEFAULT = 0; - - /** - * Target value indicating that the compiler should scan the input - * and stop. - */ - public static final int SCAN = 1; - - /** - * Target value indicating that the compiler should scan and parse - * its input, and stop. - */ - public static final int PARSE = 2; - - /** - * Target value indicating that the compiler should produce a - * high-level intermediate representation from its input, and stop. - * This is not one of the segment targets for Fall 2000, but you - * may wish to use it for your own purposes. - */ - public static final int INTER = 3; - - /** - * Target value indicating that the compiler should produce a - * low-level intermediate representation from its input, and stop. - */ - public static final int LOWIR = 4; - - /** - * Target value indicating that the compiler should produce - * assembly from its input. - */ - public static final int ASSEMBLY = 5; - /** * Array indicating which optimizations should be performed. If * a particular element is true, it indicates that the optimization @@ -84,42 +46,12 @@ public class CLI { */ public String infile; - /** - * The target stage. This should be one of the integer constants - * defined elsewhere in this package. - */ - public int target; - /** * The debug flag. This is true if -debug was passed on * the command line, requesting debugging output. */ public boolean debug; - /** - * Native MIPS architecture is specified by "-native". The default - * is SPIM. - */ - public boolean fNative; - - /** - * Runs IRVis on final node tree. - */ - public boolean fVis; - public String visClass; - public String visMethod; - - /** - * Dumps the before and after Node structure to two files that can be diffed. - */ - public boolean fDiff; - public String diffFile; - - /** - * Maximum optimization iterations. - */ - public int numIterations = 5; - /** * Verbose output */ @@ -134,16 +66,9 @@ public class CLI { public CLI() { outfile = null; infile = null; - target = DEFAULT; extras = new Vector(); extraopts = new Vector(); - fNative = false; - fVis = false; verbose = 0; - visClass = ""; - visMethod = ""; - fDiff = false; - diffFile = ""; } /** @@ -177,19 +102,8 @@ public class CLI { if (args[i].equals("-debug")) { context = 0; debug = true; - } else if (args[i].equals("-native")) { - context = 0; - fNative = true; } else if (args[i].equals("-checkonly")) { Compiler.REPAIR=false; - } else if (args[i].equals("-vis")) { - context = 4; - fVis = true; - } else if (args[i].equals("-diff")) { - context = 5; - fDiff = true; - } else if (args[i].equals("-i")) { - context = 6; } else if (args[i].equals("-verbose") || args[i].equals("-v")) { context = 0; verbose++; @@ -197,8 +111,6 @@ public class CLI { context = 1; else if (args[i].equals("-o")) context = 2; - else if (args[i].equals("-target")) - context = 3; else if (context == 1) { boolean hit = false; for (int j = 0; j < optnames.length; j++) { @@ -214,41 +126,9 @@ public class CLI { } if (!hit) extraopts.addElement(args[i]); - } - else if (context == 2) { + } else if (context == 2) { outfile = args[i]; context = 0; - } - else if (context == 3) { - // Process case insensitive. - String argSansCase = args[i].toLowerCase(); - // accept "scan" and "scanner" due to handout mistake - if (argSansCase.equals("scan") || - argSansCase.equals("scanner")) - target = SCAN; - else if (argSansCase.equals("parse")) - target = PARSE; - else if (argSansCase.equals("inter")) - target = INTER; - else if (argSansCase.equals("lowir")) - target = LOWIR; - else if (argSansCase.equals("assembly") || - argSansCase.equals("codegen")) - target = ASSEMBLY; - else - target = DEFAULT; // Anything else is just default - context = 0; - } else if (context == 4) { // -vis - StringTokenizer st = new StringTokenizer(args[i], "."); - visClass = st.nextToken(); - visMethod = st.nextToken(); - context = 0; - } else if (context == 5) { // -diff - diffFile = args[i]; // argument following is filename - context = 0; - } else if (context == 6) { // -i - numIterations = Integer.parseInt(args[i]); - context = 0; } else { boolean hit = false; for (int j = 0; j < optnames.length; j++) { @@ -275,40 +155,5 @@ public class CLI { } i++; } - - // create outfile name - switch (target) { - case SCAN: - ext = ".scan"; - break; - case PARSE: - ext = ".parse"; - break; - case INTER: - ext = ".ir"; - break; - case LOWIR: - ext = ".lowir"; - break; - case ASSEMBLY: - ext = ".s"; - break; - case DEFAULT: - default: - ext = ".out"; - break; - } - - if (outfile == null && infile != null) { - int dot = infile.lastIndexOf('.'); - int slash = infile.lastIndexOf('/'); - // Last dot comes after last slash means that the file - // has an extention. Note that the base case where dot - // or slash are -1 also work. - if (dot <= slash) - outfile = infile + ext; - else - outfile = infile.substring(0, dot) + ext; - } } } diff --git a/Repair/RepairCompiler/MCC/Compiler.java b/Repair/RepairCompiler/MCC/Compiler.java index 949ae87..c0dca65 100755 --- a/Repair/RepairCompiler/MCC/Compiler.java +++ b/Repair/RepairCompiler/MCC/Compiler.java @@ -46,111 +46,71 @@ public class Compiler { 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."); - - - 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 + ".cc"); - - - // do model optimizations - //(new Optimizer(state)).optimize(); - - - - FileOutputStream gcode2 = new FileOutputStream(cli.infile + "_aux.cc"); - 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); + 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."); + + + 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 + ".cc"); + + + // do model optimizations + //(new Optimizer(state)).optimize(); + + FileOutputStream gcode2 = new FileOutputStream(cli.infile + "_aux.cc"); + 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#"); - } - } 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#"); - } - } + 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) { @@ -158,31 +118,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]) { diff --git a/Repair/RepairCompiler/MCC/IR/Conjunction.java b/Repair/RepairCompiler/MCC/IR/Conjunction.java index 90e1f09..445e018 100755 --- a/Repair/RepairCompiler/MCC/IR/Conjunction.java +++ b/Repair/RepairCompiler/MCC/IR/Conjunction.java @@ -9,7 +9,7 @@ public class Conjunction { predicates.add(pred); } Conjunction(Vector preds){ - predicates=preds ; + predicates=preds; } String name() { String name=""; diff --git a/Repair/RepairCompiler/MCC/IR/Constraint.java b/Repair/RepairCompiler/MCC/IR/Constraint.java index f3fdcec..a506b03 100755 --- a/Repair/RepairCompiler/MCC/IR/Constraint.java +++ b/Repair/RepairCompiler/MCC/IR/Constraint.java @@ -96,6 +96,5 @@ public class Constraint implements Quantifiers { set.addAll(getRequiredDescriptorsFromLogicStatement()); return set; } - } diff --git a/Repair/RepairCompiler/MCC/IR/ConstraintDependence.java b/Repair/RepairCompiler/MCC/IR/ConstraintDependence.java new file mode 100755 index 0000000..49d4cb9 --- /dev/null +++ b/Repair/RepairCompiler/MCC/IR/ConstraintDependence.java @@ -0,0 +1,216 @@ +package MCC.IR; +import MCC.State; +import java.util.*; + +public class ConstraintDependence { + State state; + HashSet constnodes; + HashSet nodes; + Hashtable constonode; + Hashtable nodetonode; + Termination termination; + + ConstraintDependence(State state, Termination t) { + this.state=state; + this.termination=t; + constnodes=new HashSet(); + nodes=new HashSet(); + constonode=new Hashtable(); + nodetonode=new Hashtable(); + constructnodes(); + constructconjunctionnodes(); + constructconjunctionedges(); + } + + public void addNode(GraphNode gn) { + GraphNode gn2=new GraphNode(gn.getLabel(),gn.getTextLabel(),gn); + nodes.add(gn2); + nodetonode.put(gn,gn2); + } + + public void associateWithConstraint(GraphNode gn, Constraint c) { + GraphNode ggn=(GraphNode)nodetonode.get(gn); + GraphNode gc=(GraphNode)constonode.get(c); + GraphNode.Edge e=new GraphNode.Edge("associated",ggn); + gc.addEdge(e); + } + + public void requiresConstraint(GraphNode gn, Constraint c) { + GraphNode ggn=(GraphNode)nodetonode.get(gn); + GraphNode gc=(GraphNode)constonode.get(c); + GraphNode.Edge e=new GraphNode.Edge("requires",gc); + ggn.addEdge(e); + } + + /** Constructs a node for each Constraint */ + private void constructnodes() { + for(int i=0;i