Completed support for generating C code.
authorbdemsky <bdemsky>
Sat, 30 Oct 2004 21:01:37 +0000 (21:01 +0000)
committerbdemsky <bdemsky>
Sat, 30 Oct 2004 21:01:37 +0000 (21:01 +0000)
27 files changed:
Repair/RepairCompiler/MCC/CRuntime/buildruntime
Repair/RepairCompiler/MCC/IR/BooleanLiteralExpr.java
Repair/RepairCompiler/MCC/IR/CastExpr.java
Repair/RepairCompiler/MCC/IR/CodeWriter.java
Repair/RepairCompiler/MCC/IR/DotExpr.java
Repair/RepairCompiler/MCC/IR/ElementOfExpr.java
Repair/RepairCompiler/MCC/IR/ForQuantifier.java
Repair/RepairCompiler/MCC/IR/ImageSetExpr.java
Repair/RepairCompiler/MCC/IR/IntegerLiteralExpr.java
Repair/RepairCompiler/MCC/IR/LogicStatement.java
Repair/RepairCompiler/MCC/IR/OpExpr.java
Repair/RepairCompiler/MCC/IR/PrintWrapper.java
Repair/RepairCompiler/MCC/IR/RelationExpr.java
Repair/RepairCompiler/MCC/IR/RelationFunctionExpr.java
Repair/RepairCompiler/MCC/IR/RelationQuantifier.java
Repair/RepairCompiler/MCC/IR/RepairGenerator.java
Repair/RepairCompiler/MCC/IR/SetExpr.java
Repair/RepairCompiler/MCC/IR/SetQuantifier.java
Repair/RepairCompiler/MCC/IR/SizeofFunction.java
Repair/RepairCompiler/MCC/IR/Sources.java
Repair/RepairCompiler/MCC/IR/StandardCodeWriter.java
Repair/RepairCompiler/MCC/IR/StructureGenerator.java
Repair/RepairCompiler/MCC/IR/SumExpr.java
Repair/RepairCompiler/MCC/IR/TokenLiteralExpr.java
Repair/RepairCompiler/MCC/IR/TupleOfExpr.java
Repair/RepairCompiler/MCC/IR/UpdateNode.java
Repair/RepairCompiler/MCC/IR/VarExpr.java

index c056fb6832e06000d224f82e0cd23b01e7980bb2..3f66d459b1994a321e143fea25a22f7e6b1e955a 100755 (executable)
@@ -5,4 +5,5 @@ gcc $FLAG -c tmap.c
 gcc $FLAG -c instrument.c
 gcc $FLAG -c libredblack/redblack.c
 gcc $FLAG -c stack.c
-
+gcc $FLAG -c size.c
+gcc $FLAG -c cache_aux.c
index 727381825ab777eaaa69f57fceaf796399978ab8..da76e0e16d2311fc622e23ab66fc14718a0fe290 100755 (executable)
@@ -35,7 +35,8 @@ public class BooleanLiteralExpr extends LiteralExpr {
     }
 
     public void generate(CodeWriter writer, VarDescriptor dest) {
-        writer.outputline("int " + dest.getSafeSymbol() + " = " + (value ? "1" : "0") + ";");
+        writer.addDeclaration("int", dest.getSafeSymbol());
+        writer.outputline(dest.getSafeSymbol() + " = " + (value ? "1" : "0") + ";");
     }
 
     public void prettyPrint(PrettyPrinter pp) {
index 263460f5bc1667bef1152f9342da9c96fbe8a785..c72590f65f29833ee568bc2c7cf41bba2a4075cc 100755 (executable)
@@ -73,7 +73,8 @@ public class CastExpr extends Expr {
     public void generate(CodeWriter writer, VarDescriptor dest) {
         VarDescriptor vd = VarDescriptor.makeNew("expr");
         expr.generate(writer, vd);
-        writer.outputline("int " + dest.getSafeSymbol() + " = (int) " + vd.getSafeSymbol() + ";");
+        writer.addDeclaration("int", dest.getSafeSymbol());
+        writer.outputline(dest.getSafeSymbol() + " = (int) " + vd.getSafeSymbol() + ";");
     }
 
     public void prettyPrint(PrettyPrinter pp) {
index 9118096e2d3b57d52f897013202139acd8c11093..17229806a7bc61e2da15c65f91636dc5052d1217 100755 (executable)
@@ -8,6 +8,10 @@ public interface CodeWriter extends PrettyPrinter{
     public void startblock();
     public void endblock();
 
+    public void startBuffer();
+    public void emptyBuffer();
+    public void addDeclaration(String type, String varname);
+    public void addDeclaration(String function);
     public void pushSymbolTable(SymbolTable st);
     public SymbolTable popSymbolTable();
     public SymbolTable getSymbolTable();
index be4341561fe19513de825e9f9292ca41a71e27cc..4f550a4cce8231f1c18b72f3229785be1f6ed6f9 100755 (executable)
@@ -167,8 +167,8 @@ public class DotExpr extends Expr {
 
        if (writer.getInvariantValue()!=null&&
            writer.getInvariantValue().isInvariant(this)) {
-           writer.outputline(getType().getGenerateType().getSafeSymbol()+
-                             " "+dest.getSafeSymbol()+"="+writer.getInvariantValue().getValue(this).getSafeSymbol()+";");
+           writer.addDeclaration(getType().getGenerateType().getSafeSymbol().toString(), dest.getSafeSymbol());
+           writer.outputline(dest.getSafeSymbol()+"="+writer.getInvariantValue().getValue(this).getSafeSymbol()+";");
            writer.outputline("maybe="+writer.getInvariantValue().getMaybe(this).getSafeSymbol()+";");
            return;
        }
@@ -200,7 +200,8 @@ public class DotExpr extends Expr {
        boolean doboundscheck=true;
        boolean performedboundscheck=false;
 
-       writer.outputline(getType().getGenerateType() + " " + dest.getSafeSymbol()+"=0;");
+       writer.addDeclaration(getType().getGenerateType().toString(),dest.getSafeSymbol());
+       writer.outputline(dest.getSafeSymbol()+"=0;");
 
         if (intindex != null) {
             if (intindex instanceof IntegerLiteralExpr && ((IntegerLiteralExpr) intindex).getValue() == 0) {
@@ -261,11 +262,13 @@ public class DotExpr extends Expr {
 
        /* derive offset in bytes */
        VarDescriptor offset = VarDescriptor.makeNew("offset");
-       writer.outputline("int " + offset.getSafeSymbol() + " = " + ob.getSafeSymbol() + " >> 3;");
+       writer.addDeclaration("int", offset.getSafeSymbol());
+       writer.outputline(offset.getSafeSymbol() + " = " + ob.getSafeSymbol() + " >> 3;");
 
        if (fd.getType() instanceof ReservedTypeDescriptor && !fd.getPtr()) {
            VarDescriptor shift = VarDescriptor.makeNew("shift");
-           writer.outputline("int " + shift.getSafeSymbol() + " = " + ob.getSafeSymbol() +
+           writer.addDeclaration("int", shift.getSafeSymbol());
+           writer.outputline(shift.getSafeSymbol() + " = " + ob.getSafeSymbol() +
                              " - (" + offset.getSafeSymbol() + " << 3);");
            int mask = bitmask(((IntegerLiteralExpr)fd.getType().getSizeExpr()).getValue());
 
@@ -287,10 +290,12 @@ public class DotExpr extends Expr {
                writer.startblock();
                VarDescriptor typevar=VarDescriptor.makeNew("typechecks");
                if (DOMEMCHECKS&&(!DOTYPECHECKS)) {
-                   writer.outputline("bool "+typevar.getSafeSymbol()+"=assertvalidmemory(" + dest.getSafeSymbol() + ", " + this.td.getId() + ");");
+                   writer.addDeclaration("bool", typevar.getSafeSymbol());
+                   writer.outputline(typevar.getSafeSymbol()+"=assertvalidmemory(" + dest.getSafeSymbol() + ", " + this.td.getId() + ");");
                    dotypecheck = true;
                } else if (DOTYPECHECKS) {
-                   writer.outputline("bool "+typevar.getSafeSymbol()+"=assertvalidtype(" + dest.getSafeSymbol() + ", " + this.td.getId() + ");");
+                   writer.addDeclaration("bool", typevar.getSafeSymbol());
+                   writer.outputline(typevar.getSafeSymbol()+"=assertvalidtype(" + dest.getSafeSymbol() + ", " + this.td.getId() + ");");
                }
 
                if (DOTYPECHECKS||DOMEMCHECKS) {
index 6de61f4de9718c337e345a214b9b93eb9bae2a43..3799435fd8869b11ed5fa78ea682cde078526e50 100755 (executable)
@@ -55,7 +55,8 @@ public class ElementOfExpr extends Expr {
     public void generate(CodeWriter writer, VarDescriptor dest) {
         VarDescriptor ed = VarDescriptor.makeNew("element");
         element.generate(writer, ed);
-        writer.outputline("int " + dest.getSafeSymbol() + " = SimpleHashcontainskey("+set.getSafeSymbol() +"_hash ,"+ ed.getSafeSymbol() + ");");
+        writer.addDeclaration("int", dest.getSafeSymbol());
+        writer.outputline(dest.getSafeSymbol() + " = SimpleHashcontainskey("+set.getSafeSymbol() +"_hash ,"+ ed.getSafeSymbol() + ");");
     }
 
     public void prettyPrint(PrettyPrinter pp) {
index 317d12c33c8b8f1139366bf56c7326cf2875c5a9..20a0356fb0f3f0c25c9f408557d1ee7a7c999b96 100755 (executable)
@@ -39,8 +39,8 @@ public class ForQuantifier extends Quantifier {
         VarDescriptor ud = VarDescriptor.makeNew();
         lower.generate(writer, ld);
         upper.generate(writer, ud);
-        
-        writer.outputline("for (int " + var.getSafeSymbol() + " = " + ld.getSafeSymbol() + "; " + var.getSafeSymbol() + " <= " + ud.getSafeSymbol() + "; " + var.getSafeSymbol() + "++)");
+        writer.addDeclaration("int",var.getSafeSymbol());
+        writer.outputline("for (" + var.getSafeSymbol() + " = " + ld.getSafeSymbol() + "; " + var.getSafeSymbol() + " <= " + ud.getSafeSymbol() + "; " + var.getSafeSymbol() + "++)");
         writer.startblock();
     }
 
@@ -51,7 +51,8 @@ left,String right) {
 
     public int generate_worklistload(CodeWriter writer, int offset) {        
         String varname = var.getSafeSymbol();
-        writer.outputline("int " + varname + " = wi->word" + offset + ";"); 
+       writer.addDeclaration("int",varname);
+        writer.outputline(varname + " = wi->word" + offset + ";"); 
         return offset + 1;       
     }
 
index 7c5dc064f9dbd494d56798584336899d6f29cc7b..a6d2f1a8fb6bd82a8949362494b03bfe77bdcbc5 100755 (executable)
@@ -124,12 +124,14 @@ public class ImageSetExpr extends SetExpr {
     public void generate_inclusion(CodeWriter writer, VarDescriptor dest, VarDescriptor element) {
         String hash = inverse ? "_hashinv, " : "_hash, " ;
        if (!isimageset) {
-           writer.outputline("int " + dest.getSafeSymbol() + " = SimpleHashcontainskeydata(" + rd.getSafeSymbol() + hash + vd.getSafeSymbol() + ", " + element.getSafeSymbol() + ");");
+           writer.addDeclaration("int", dest.getSafeSymbol());
+           writer.outputline(dest.getSafeSymbol() + " = SimpleHashcontainskeydata(" + rd.getSafeSymbol() + hash + vd.getSafeSymbol() + ", " + element.getSafeSymbol() + ");");
        } else {
            VarDescriptor newset=VarDescriptor.makeNew("newset");
            generate_set(writer,newset);
-           writer.outputline("int "+dest.getSafeSymbol()+"=SimpleHashcontainskey("+newset.getSafeSymbol()+","+element.getSafeSymbol()+");");
-           writer.outputline("delete "+newset.getSafeSymbol()+";");
+           writer.addDeclaration("int", dest.getSafeSymbol());
+           writer.outputline(dest.getSafeSymbol()+"=SimpleHashcontainskey("+newset.getSafeSymbol()+","+element.getSafeSymbol()+");");
+           writer.outputline("freeSimpleHash("+newset.getSafeSymbol()+");");
        }
     }
 
@@ -138,47 +140,54 @@ public class ImageSetExpr extends SetExpr {
         assert rd != null;
        if (!isimageset) {
            String hash = inverse ? "_hashinv, " : "_hash, " ;
-           writer.outputline("int " + dest.getSafeSymbol() + " = SimpleHashcount(" + rd.getSafeSymbol() + hash + vd.getSafeSymbol() + ");");
+           writer.addDeclaration("int", dest.getSafeSymbol());
+           writer.outputline(dest.getSafeSymbol() + " = SimpleHashcount(" + rd.getSafeSymbol() + hash + vd.getSafeSymbol() + ");");
        } else {
            VarDescriptor newset=VarDescriptor.makeNew("newset");
            generate_set(writer,newset);
-           writer.outputline("int "+dest.getSafeSymbol()+"=SimpleHashcountset("+newset.getSafeSymbol()+");");
-           writer.outputline("delete "+newset.getSafeSymbol()+";");
+           writer.addDeclaration("int", dest.getSafeSymbol());
+           writer.outputline(dest.getSafeSymbol()+"=SimpleHashcountset("+newset.getSafeSymbol()+");");
+           writer.outputline("freeSimpleHash("+newset.getSafeSymbol()+");");
        }
     }
 
     public void generate_leftside(CodeWriter writer, VarDescriptor dest) {
        if (!isimageset) {
-           writer.outputline(vd.getType().getGenerateType()+" "+dest.getSafeSymbol()+" = "+vd.getSafeSymbol()+";");
+           writer.addDeclaration(vd.getType().getGenerateType().toString(), dest.getSafeSymbol());
+           writer.outputline(dest.getSafeSymbol()+" = "+vd.getSafeSymbol()+";");
        } else {
            VarDescriptor iseset=VarDescriptor.makeNew("set");
            ise.generate_set(writer,iseset);
-           writer.outputline("int "+dest.getSafeSymbol()+" = SimpleHashfirstkey("+iseset.getSafeSymbol()+");");
-           writer.outputline("delete "+iseset.getSafeSymbol()+";");
+           writer.addDeclaration("int",dest.getSafeSymbol());
+           writer.outputline(dest.getSafeSymbol()+" = SimpleHashfirstkey("+iseset.getSafeSymbol()+");");
+           writer.outputline("freeSimpleHash("+iseset.getSafeSymbol()+");");
        }
     }
 
     public void generate_set(CodeWriter writer, VarDescriptor dest) {
        if (!isimageset) {
            String hash = inverse ? "_hashinv, " : "_hash, " ;
-           writer.outputline("struct SimpleHash * "+dest.getSafeSymbol()+"=SimpleHashimageSet("+rd.getSafeSymbol()+hash+vd.getSafeSymbol()+");");
+           writer.addDeclaration("struct SimpleHash *",dest.getSafeSymbol());
+           writer.outputline(dest.getSafeSymbol()+"=SimpleHashimageSet("+rd.getSafeSymbol()+hash+vd.getSafeSymbol()+");");
        } else {
            VarDescriptor iseset=VarDescriptor.makeNew("set");
            ise.generate_set(writer,iseset);
 
            VarDescriptor itvd=VarDescriptor.makeNew("iterator");
-           writer.outputline("struct SimpleIterator "+itvd.getSafeSymbol()+";");
+           writer.addDeclaration("struct SimpleIterator",itvd.getSafeSymbol());
            writer.outputline("SimpleHashiterator("+iseset.getSafeSymbol()+",&"+itvd.getSafeSymbol()+");");
-
-           writer.outputline("struct SimpleHash *"+dest.getSafeSymbol()+"=allocateSimpleHash(10);");
+           writer.addDeclaration("struct SimpleHash *", dest.getSafeSymbol());
+           writer.outputline(dest.getSafeSymbol()+"=allocateSimpleHash(10);");
            writer.outputline("while (hasNext(&"+itvd.getSafeSymbol()+")) {");
 
            VarDescriptor keyvd=VarDescriptor.makeNew("key");
 
-           writer.outputline("int "+keyvd.getSafeSymbol()+"=next(&"+itvd.getSafeSymbol()+");");
+           writer.addDeclaration("int",keyvd.getSafeSymbol());
+           writer.outputline(keyvd.getSafeSymbol()+"=next(&"+itvd.getSafeSymbol()+");");
            String hash = inverse ? "_hashinv, " : "_hash, " ;
            VarDescriptor newset=VarDescriptor.makeNew("newset");
-           writer.outputline("SimpleHash * "+newset.getSafeSymbol()+"=SimpleHashimageSet("+rd.getSafeSymbol()+hash+keyvd.getSafeSymbol()+");");
+           writer.addDeclaration("struct SimpleHash *", newset.getSafeSymbol());
+           writer.outputline(newset.getSafeSymbol()+"=SimpleHashimageSet("+rd.getSafeSymbol()+hash+keyvd.getSafeSymbol()+");");
            writer.outputline("SimpleHashaddAll("+dest.getSafeSymbol()+", "+ newset.getSafeSymbol()+");");
            writer.outputline("freeSimpleHash("+newset.getSafeSymbol()+");");
            writer.outputline("}");
index be4db265e6dca7c291888b1525f22dcb1c083907..e1c91c2b309ff37fe5e50d432696a79e2f83d8f9 100755 (executable)
@@ -35,7 +35,8 @@ public class IntegerLiteralExpr extends LiteralExpr {
     }
 
     public void generate(CodeWriter writer, VarDescriptor dest) {
-        writer.outputline("int " + dest.getSafeSymbol() + " = " + value + ";");
+        writer.addDeclaration("int", dest.getSafeSymbol());
+        writer.outputline(dest.getSafeSymbol() + " = " + value + ";");
     }
 
     public void prettyPrint(PrettyPrinter pp) {
index 7d520cd6bb716585554c2ff824286d234c5440a8..b750ffd83fe3fd53f85e5b1d84b07292dbc76f13 100755 (executable)
@@ -103,7 +103,7 @@ public class LogicStatement {
 
     public void generate(CodeWriter writer, VarDescriptor dest) {
 
-        writer.outputline("int " + dest.getSafeSymbol() + ";");
+        writer.addDeclaration("int", dest.getSafeSymbol());
 
         if (op == NOT) {
 
@@ -121,13 +121,15 @@ public class LogicStatement {
             VarDescriptor leftd = VarDescriptor.makeNew("leftboolean");
             String lm = (VarDescriptor.makeNew("leftmaybe")).getSafeSymbol();
             left.generate(writer, leftd);
-            writer.outputline("int " + lm + " = maybe;");
+            writer.addDeclaration("int", lm);
+            writer.outputline(lm + " = maybe;");
             writer.outputline("maybe=0;");
             VarDescriptor rightd = VarDescriptor.makeNew("rightboolean");
             String rm = (VarDescriptor.makeNew("rightmaybe")).getSafeSymbol();
             assert right != null;
             right.generate(writer, rightd);
-            writer.outputline("int " + rm + " = maybe;");
+            writer.addDeclaration("int", rm);
+            writer.outputline(rm + " = maybe;");
 
             String l = leftd.getSafeSymbol();
             String r = rightd.getSafeSymbol();
index 0c5082b485040794909712d7823624b9f5b3a40e..c5f6b270e7b1dd86074e2efee592a7060c876af2 100755 (executable)
@@ -351,7 +351,8 @@ public class OpExpr extends Expr {
        /* Check for loop invariant hoisting. */
        if (writer.getInvariantValue()!=null&&
            writer.getInvariantValue().isInvariant(this)) {
-           writer.outputline("int "+dest.getSafeSymbol()+"="+writer.getInvariantValue().getValue(this).getSafeSymbol()+";");
+           writer.addDeclaration("int",dest.getSafeSymbol());
+           writer.outputline(dest.getSafeSymbol()+"="+writer.getInvariantValue().getValue(this).getSafeSymbol()+";");
            writer.outputline("maybe="+writer.getInvariantValue().getMaybe(this).getSafeSymbol()+";");
            return;
        }
@@ -364,7 +365,8 @@ public class OpExpr extends Expr {
         if (right != null) {
            if ((opcode==Opcode.OR)||
                (opcode==Opcode.AND)) {
-               writer.outputline("int "+lm.getSafeSymbol()+"=maybe;");
+               writer.addDeclaration("int",lm.getSafeSymbol());
+               writer.outputline(lm.getSafeSymbol()+"=maybe;");
                writer.outputline("maybe=0;");
            }
 
@@ -374,27 +376,35 @@ public class OpExpr extends Expr {
 
         String code;
        if (opcode == Opcode.RND) {
-           writer.outputline("int " +dest.getSafeSymbol() + " = (" +
+           writer.addDeclaration("int",dest.getSafeSymbol());
+           writer.outputline(dest.getSafeSymbol() + " = (" +
                              ld.getSafeSymbol() + ">>3)<<3; ");
            writer.outputline("if ("+ld.getSafeSymbol()+" % 8) "+dest.getSafeSymbol()+"+=8;");
        } else if (opcode == Opcode.NOP) {
-           writer.outputline("int " +dest.getSafeSymbol() + " = " +
+           writer.addDeclaration("int", dest.getSafeSymbol());
+           writer.outputline(dest.getSafeSymbol() + " = " +
                              ld.getSafeSymbol() +"; ");
         } else if (opcode == Opcode.AND) {
-           writer.outputline("int "+rm.getSafeSymbol()+"=maybe;");
+           writer.addDeclaration("int",rm.getSafeSymbol());
+           writer.outputline(rm.getSafeSymbol()+"=maybe;");
            writer.outputline("maybe = (" + ld.getSafeSymbol() + " && " + rm.getSafeSymbol() + ") || (" + rd.getSafeSymbol() + " && " + lm.getSafeSymbol() + ") || (" + lm.getSafeSymbol() + " && " + rm.getSafeSymbol() + ");");
-           writer.outputline("int "+dest.getSafeSymbol() + " = " + ld.getSafeSymbol() + " && " + rd.getSafeSymbol() + ";");
+           writer.addDeclaration("int",dest.getSafeSymbol());
+           writer.outputline(dest.getSafeSymbol() + " = " + ld.getSafeSymbol() + " && " + rd.getSafeSymbol() + ";");
        } else if (opcode == Opcode.OR) {
-           writer.outputline("int "+rm.getSafeSymbol()+"=maybe;");
+           writer.addDeclaration("int",rm.getSafeSymbol());
+           writer.outputline(rm.getSafeSymbol()+"=maybe;");
            writer.outputline("maybe = (!" + ld.getSafeSymbol() + " && " + rm.getSafeSymbol() + ") || (!" + rd.getSafeSymbol() +
                              " && " + lm.getSafeSymbol() + ") || (" + lm.getSafeSymbol() + " && " + rm.getSafeSymbol() + ");");
-           writer.outputline("int "+dest.getSafeSymbol() + " = " + ld.getSafeSymbol() + " || " + rd.getSafeSymbol() + ";");
+           writer.addDeclaration("int",dest.getSafeSymbol());
+           writer.outputline(dest.getSafeSymbol() + " = " + ld.getSafeSymbol() + " || " + rd.getSafeSymbol() + ";");
        } else if (opcode != Opcode.NOT) { /* two operands */
             assert rd != null;
-           writer.outputline("int " + dest.getSafeSymbol() + " = " +
+           writer.addDeclaration("int", dest.getSafeSymbol());
+           writer.outputline(dest.getSafeSymbol() + " = " +
                              ld.getSafeSymbol() + " " + opcode.toString() + " " + rd.getSafeSymbol() + ";");
         } else if (opcode == Opcode.NOT) {
-            writer.outputline("int " + dest.getSafeSymbol() + " = !" + ld.getSafeSymbol() + ";");
+            writer.addDeclaration("int", dest.getSafeSymbol());
+            writer.outputline(dest.getSafeSymbol() + " = !" + ld.getSafeSymbol() + ";");
         }
     }
 
index 8a649b55ffbe63fbae1c47433a43416a9c66f933..a855aaf77ec9aafda4d36d51c31a5ac79965e638 100755 (executable)
@@ -3,16 +3,17 @@ import java.util.*;
 
 public class PrintWrapper {
   java.io.PrintWriter output;
-  String buffered="";
+  StringBuffer buffered=new StringBuffer("");
   boolean buffer=false;
   Hashtable vartable=new Hashtable();
+  public int indent=0;
 
   public PrintWrapper(java.io.PrintWriter output) {
     this.output=output;
   }
   void print(String s) {
     if (buffer)
-      buffered+=s;
+      buffered.append(s);
     else
       output.print(s);
   }
@@ -22,7 +23,7 @@ public class PrintWrapper {
   }
   void println(String s) {
     if (buffer)
-      buffered+=s+"\n";
+      buffered.append(s+"\n");
     else
       output.println(s);
   }
@@ -35,8 +36,8 @@ public class PrintWrapper {
       String var=(String)it.next();
       output.println(((String)vartable.get(var))+" "+var+";");
     }
-    output.print(buffered);
-    buffered="";
+    output.print(buffered.toString());
+    buffered=new StringBuffer("");
     vartable=new Hashtable();
     buffer=false;
   }
@@ -53,4 +54,10 @@ public class PrintWrapper {
     } else
       output.println(type+" "+varname+";");
   }
+  void addDeclaration(String f) {
+    if (buffer) {
+       buffered.insert(0,f+"\n");
+    } else
+      output.println(f);
+  }
 }
index 4eefc7005b6c3f83176c991454fcebc3d81c15dc..4026b31c0368ad56ae2c5430d8ecac83be206dfe 100755 (executable)
@@ -106,8 +106,9 @@ public class RelationExpr extends Expr {
         String strinverse = inverse ? "inv" : "";
         String found = (VarDescriptor.makeNew("found")).getSafeSymbol();
         expr.generate(writer, domain);
-        writer.outputline(relation.getRange().getType().getGenerateType().getSafeSymbol() + " " + dest.getSafeSymbol() + ";");
-       writer.outputline("int "+found+" = SimpleHashget(" +relation.getSafeSymbol()+"_hash"+strinverse+", "+ domain.getSafeSymbol() + ", & " + dest.getSafeSymbol() + ");");
+        writer.addDeclaration(relation.getRange().getType().getGenerateType().getSafeSymbol(), dest.getSafeSymbol());
+       writer.addDeclaration("int",found);
+       writer.outputline(found+" = SimpleHashget(" +relation.getSafeSymbol()+"_hash"+strinverse+", "+ domain.getSafeSymbol() + ", & " + dest.getSafeSymbol() + ");");
        writer.outputline("if (!" + found + ") { maybe = 1; }");
     }
 
index 2ae18f9cba948eb9ec145b25cca25325673319c2..d5b3cf058d542a154a6c42956375c894b7c72c6b 100755 (executable)
@@ -49,7 +49,7 @@ public class RelationFunctionExpr extends Expr {
     public void generate(CodeWriter cr, VarDescriptor dest) {
 
         String destname = dest.getSafeSymbol();
-        cr.outputline("int " + destname + ";");
+        cr.addDeclaration("int", destname);
 
         // ok... destination is declared... we gotta expand this rule inplace... and instead of the inclusion we
         // set the destination in the guard ... otherwise maybe!
@@ -66,8 +66,10 @@ public class RelationFunctionExpr extends Expr {
             String tempvar = (VarDescriptor.makeNew("tempvar")).getSafeSymbol();
 
             // this is to be safe about name overlap because int t = t; sets t to 0!
-            cr.outputline("int " + tempvar + " = " + domain.getSafeSymbol() + ";");
-            cr.outputline("int " + rulebinding.getSafeSymbol() + " = " + tempvar + ";");
+            cr.addDeclaration("int", tempvar);
+            cr.outputline(tempvar + " = " + domain.getSafeSymbol() + ";");
+            cr.addDeclaration("int", rulebinding.getSafeSymbol());
+            cr.outputline(rulebinding.getSafeSymbol() + " = " + tempvar + ";");
 
             /* pretty print! */
             cr.outputline("/* about to inbed relational function*/");
index e759aa768c65466753e188dcfc6bbc7cf863bcdf..858f338636f4fe07a158ef8c998f8373699b37fa 100755 (executable)
@@ -33,25 +33,29 @@ public class RelationQuantifier extends Quantifier {
     }
 
     public void generate_open(CodeWriter writer) {
-       writer.outputline("struct SimpleIterator "+x.getSafeSymbol()+"_iterator;");
-        writer.outputline("for (SimpleHashiterator("+relation.getSafeSymbol()+"_hash, "+x.getSafeSymbol()+"_iterator); hasNext("+x.getSafeSymbol()+"_iterator); )");
+       writer.addDeclaration("struct SimpleIterator",x.getSafeSymbol()+"_iterator");
+        writer.outputline("for (SimpleHashiterator("+relation.getSafeSymbol()+"_hash, &"+x.getSafeSymbol()+"_iterator); hasNext(&"+x.getSafeSymbol()+"_iterator); )");
         writer.startblock();
-        writer.outputline(y.getType().getGenerateType() + " " + y.getSafeSymbol() + " = (" + y.getType().getGenerateType() + ") next("+x.getSafeSymbol()+"_iterator);");
+        writer.addDeclaration(y.getType().getGenerateType().toString(), y.getSafeSymbol());        
+       writer.outputline(y.getSafeSymbol() + " = (" + y.getType().getGenerateType() + ") next(&"+x.getSafeSymbol()+"_iterator);");
         // #ATTN#: key is called second because next() forwards ptr and key does not!
-        writer.outputline(x.getType().getGenerateType() + " " + x.getSafeSymbol() + " = (" + x.getType().getGenerateType() + ") key("+x.getSafeSymbol()+"_iterator);");
+        writer.addDeclaration(x.getType().getGenerateType().toString(), x.getSafeSymbol());        
+       writer.outputline(x.getSafeSymbol() + " = (" + x.getType().getGenerateType() + ") key(&"+x.getSafeSymbol()+"_iterator);");
     }
 
     public void generate_open(CodeWriter writer, String type,int number, String left,String right) {
        VarDescriptor tmp=VarDescriptor.makeNew("flag");
-        writer.outputline("struct SimpleIterator * " + x.getSafeSymbol() + "_iterator = SimpleHashcreateiterator("+relation.getSafeSymbol()+"_hash);");
-       writer.outputline("int "+tmp.getSafeSymbol()+"=0;");
+        writer.addDeclaration("struct SimpleIterator", x.getSafeSymbol() + "_iterator");
+        writer.outputline("SimpleHashiterator("+relation.getSafeSymbol()+"_hash,& "+x.getSafeSymbol()+"_iterator);");
+       writer.addDeclaration("int",tmp.getSafeSymbol());
+       writer.outputline(tmp.getSafeSymbol()+"=0;");
        writer.outputline("if ("+type+"=="+number+")");
        writer.outputline(tmp.getSafeSymbol()+"=1;");
 
-       writer.outputline("while("+tmp.getSafeSymbol()+"||(("+type+"!="+number+")&& hasNext("+x.getSafeSymbol()+"_iterator)))");
+       writer.outputline("while("+tmp.getSafeSymbol()+"||(("+type+"!="+number+")&& hasNext(&"+x.getSafeSymbol()+"_iterator)))");
         writer.startblock();
-        writer.outputline(x.getType().getGenerateType() + " " + x.getSafeSymbol() + ";");
-        writer.outputline(y.getType().getGenerateType() + " " + y.getSafeSymbol() + ";");
+        writer.addDeclaration(x.getType().getGenerateType().toString(), x.getSafeSymbol());
+        writer.addDeclaration(y.getType().getGenerateType().toString(), y.getSafeSymbol());
        writer.outputline("if ("+type+"=="+number+")");
        writer.startblock();
        writer.outputline(tmp.getSafeSymbol()+"=0;");
@@ -60,8 +64,8 @@ public class RelationQuantifier extends Quantifier {
        writer.endblock();
        writer.outputline("else");
        writer.startblock();
-        writer.outputline(y.getSafeSymbol() + " = (" + y.getType().getGenerateType() + ") next("+x.getSafeSymbol()+"_iterator);");
-        writer.outputline(x.getSafeSymbol() + " = (" + x.getType().getGenerateType() + ") key("+x.getSafeSymbol()+"_iterator);");
+        writer.outputline(y.getSafeSymbol() + " = (" + y.getType().getGenerateType() + ") next(&"+x.getSafeSymbol()+"_iterator);");
+        writer.outputline(x.getSafeSymbol() + " = (" + x.getType().getGenerateType() + ") key(&"+x.getSafeSymbol()+"_iterator);");
        writer.endblock();
     }
 
index 332e58cd3932b2151e277e1be5a3b998ea8b35c6..b0bd167a9adc5dd283532d69ed4141c4c1b75f05 100755 (executable)
@@ -7,9 +7,9 @@ import MCC.Compiler;
 
 public class RepairGenerator {
     State state;
-    java.io.PrintWriter outputrepair = null;
-    java.io.PrintWriter outputaux = null;
-    java.io.PrintWriter outputhead = null;
+    PrintWrapper outputrepair = null;
+    PrintWrapper outputaux = null;
+    PrintWrapper outputhead = null;
     String name="foo";
     String headername;
     static VarDescriptor oldmodel=null;
@@ -74,9 +74,9 @@ public class RepairGenerator {
     }
 
     public void generate(OutputStream outputrepair, OutputStream outputaux,OutputStream outputhead, String st) {
-        this.outputrepair = new java.io.PrintWriter(outputrepair, true);
-        this.outputaux = new java.io.PrintWriter(outputaux, true);
-        this.outputhead = new java.io.PrintWriter(outputhead, true);
+        this.outputrepair = new PrintWrapper(new java.io.PrintWriter(outputrepair, true));
+        this.outputaux = new PrintWrapper(new java.io.PrintWriter(outputaux, true));
+        this.outputhead = new PrintWrapper(new java.io.PrintWriter(outputhead, true));
 
         headername=st;
        name_updates();
@@ -107,7 +107,8 @@ public class RepairGenerator {
         generate_teardown();
        CodeWriter crhead = new StandardCodeWriter(this.outputhead);
        craux = new StandardCodeWriter(this.outputaux);
-       craux.outputline("}");
+       craux.emptyBuffer();
+       craux.endblock();
 
        if (Compiler.GENERATEDEBUGHOOKS) {
            crhead.outputline("void debughook();");
@@ -166,7 +167,9 @@ public class RepairGenerator {
                        craux.outputline("void "+methodname+"(struct "+name+"_state * "+ststate+", struct "+name+" * "+stmodel+", struct RepairHash * "+strepairtable+", int "+stleft+")");
                    }
                    craux.startblock();
-                   craux.outputline("int maybe=0;");
+                   craux.startBuffer();
+                   craux.addDeclaration("int","maybe");
+                   craux.outputline("maybe=0;");
                    if (Compiler.GENERATEINSTRUMENT)
                        craux.outputline("updatecount++;");
 
@@ -176,6 +179,7 @@ public class RepairGenerator {
                     };
                    un.generate(cr, false, false, stleft,stright, null,this);
                    craux.outputline("if (maybe) printf(\"REALLY BAD\");");
+                   craux.emptyBuffer();
                    craux.endblock();
                    break;
                case MultUpdateNode.REMOVE: {
@@ -200,7 +204,9 @@ public class RepairGenerator {
                    crhead.outputline(methodcall+";");
                    craux.outputline(methodcall);
                    craux.startblock();
-                   craux.outputline("int maybe=0;");
+                   craux.startBuffer();
+                   craux.addDeclaration("int","maybe");
+                   craux.outputline("maybe=0;");
                    if (Compiler.GENERATEINSTRUMENT)
                        craux.outputline("updatecount++;");
                    final SymbolTable st2 = un.getRule().getSymbolTable();
@@ -209,6 +215,7 @@ public class RepairGenerator {
                     };
                    un.generate(cr2, true, false, null,null, null,this);
                    craux.outputline("if (maybe) printf(\"REALLY BAD\");");
+                   craux.emptyBuffer();
                    craux.endblock();
                }
                    break;
@@ -235,6 +242,7 @@ public class RepairGenerator {
                    crhead.outputline(methodcall+";");
                    craux.outputline(methodcall);
                    craux.startblock();
+                   craux.startBuffer();
                    craux.outputline("int maybe=0;");
                    if (Compiler.GENERATEINSTRUMENT)
                        craux.outputline("updatecount++;");
@@ -244,6 +252,7 @@ public class RepairGenerator {
                     };
                    un.generate(cr2, false, true, stleft, stright, stnew, this);
                    craux.outputline("if (maybe) printf(\"REALLY BAD\");");
+                   craux.emptyBuffer();
                    craux.endblock();
                }
                    break;
@@ -258,7 +267,8 @@ public class RepairGenerator {
     private void generate_call() {
         CodeWriter cr = new StandardCodeWriter(outputrepair);
        VarDescriptor vdstate=VarDescriptor.makeNew("repairstate");
-       cr.outputline("struct "+ name+"_state * "+vdstate.getSafeSymbol()+"=allocate"+name+"_state();");
+       cr.addDeclaration("struct "+ name+"_state *", vdstate.getSafeSymbol());
+       cr.outputline(vdstate.getSafeSymbol()+"=allocate"+name+"_state();");
        Iterator globals=state.stGlobals.descriptors();
        while (globals.hasNext()) {
            VarDescriptor vd=(VarDescriptor) globals.next();
@@ -316,8 +326,11 @@ public class RepairGenerator {
                public SymbolTable getSymbolTable() { return st; }
            };
 
-       cr.outputline("void "+name+"_statecomputesizes(struct "+name+"_state * thisvar,int *sizearray,int **numele) {");
-       cr.outputline("int maybe=0;");
+       cr.outputline("void "+name+"_statecomputesizes(struct "+name+"_state * thisvar,int *sizearray,int **numele)");
+       cr.startblock();
+       cr.startBuffer();
+       cr.addDeclaration("int","maybe");
+       cr.outputline("maybe=0;");
        for(int i=0;i<max;i++) {
            TypeDescriptor td=tdarray[i];
            Expr size=td.getSizeExpr();
@@ -342,7 +355,8 @@ public class RepairGenerator {
            }
        }
        cr.outputline("if (maybe) printf(\"BAD ERROR\");");
-       cr.outputline("}");
+       cr.emptyBuffer();
+       cr.endblock();
     }
 
     private void generate_recomputesizes() {
@@ -356,8 +370,11 @@ public class RepairGenerator {
        CodeWriter cr = new StandardCodeWriter(outputaux) {
                public SymbolTable getSymbolTable() { return st; }
            };
-       cr.outputline("void "+name+"_staterecomputesizes(struct "+name+"_state * thisvar) {");
-       cr.outputline("int maybe=0;");
+       cr.outputline("void "+name+"_staterecomputesizes(struct "+name+"_state * thisvar)");
+       cr.startblock();
+       cr.startBuffer();
+       cr.addDeclaration("int","maybe");
+       cr.outputline("maybe=0;");
        for(int i=0;i<max;i++) {
            TypeDescriptor td=tdarray[i];
            Expr size=td.getSizeExpr();
@@ -380,7 +397,8 @@ public class RepairGenerator {
            }
        }
        cr.outputline("if (maybe) printf(\"BAD ERROR\");");
-       cr.outputline("}");
+       cr.emptyBuffer();
+       cr.endblock();
     }
 
 
@@ -417,12 +435,14 @@ public class RepairGenerator {
                }
            }
        }
-        craux.outputline("struct "+ name+"* "+name+"() {");
+        craux.outputline("struct "+ name+"* "+name+"()");
+       craux.startblock();
         craux.outputline("/* creating hashtables */");
 
         /* build sets */
         Iterator sets = state.stSets.descriptors();
-        craux.outputline("struct "+name+"* thisvar=(struct "+name+"*) malloc(sizeof(struct "+name+"));");
+        craux.addDeclaration("struct "+name+"*", "thisvar");
+        craux.outputline("thisvar=(struct "+name+"*) malloc(sizeof(struct "+name+"));");
 
         /* first pass create all the hash tables */
         while (sets.hasNext()) {
@@ -462,9 +482,10 @@ public class RepairGenerator {
             }
         }
 
-        craux.outputline("}");
+        craux.endblock();
         crhead.outputline("};");
-        craux.outputline("void free"+name+"(struct "+ name +"* thisvar) {");
+        craux.outputline("void free"+name+"(struct "+ name +"* thisvar)");
+       craux.startblock();
         craux.outputline("/* deleting hashtables */");
 
         /* build destructor */
@@ -492,7 +513,7 @@ public class RepairGenerator {
             }
         }
         craux.outputline("free(thisvar);");
-        craux.outputline("}");
+        craux.endblock();
     }
 
     private void generate_start() {
@@ -513,6 +534,7 @@ public class RepairGenerator {
        crhead.outputline("void doanalysis(struct "+name+"_state *);");
        craux.outputline("void doanalysis(struct "+name+"_state * thisvar)");
        craux.startblock();
+       craux.startBuffer();
        if (Compiler.TIME) {
            craux.outputline("struct timeval _begin_time,_end_time;");
            craux.outputline("gettimeofday(&_begin_time,NULL);");
@@ -522,16 +544,21 @@ public class RepairGenerator {
            craux.outputline("rebuildcount=0;");
            craux.outputline("abstractcount=0;");
        }
-       craux.outputline("int highmark;");
-       craux.outputline("struct "+name+ " * "+oldmodel.getSafeSymbol()+"=0;");
-        craux.outputline("struct WorkList * "+worklist.getSafeSymbol()+" = allocateWorkList();");
-       craux.outputline("struct RepairHash * "+repairtable.getSafeSymbol()+"=0;");
+       craux.addDeclaration("int","highmark");
+
+       craux.addDeclaration("struct "+name+ " * ",oldmodel.getSafeSymbol());
+       craux.outputline(oldmodel.getSafeSymbol()+"=0;");
+        craux.addDeclaration("struct WorkList * ",worklist.getSafeSymbol());
+        craux.outputline(worklist.getSafeSymbol()+" = allocateWorkList();");
+       craux.addDeclaration("struct RepairHash * ",repairtable.getSafeSymbol());
+       craux.outputline(repairtable.getSafeSymbol()+"=0;");
        craux.outputline("initializestack(&highmark);");
        craux.outputline("computesizes(thisvar);");
        craux.outputline(name+"_staterecomputesizes(thisvar);");
        craux.outputline("while (1)");
        craux.startblock();
-       craux.outputline("struct "+name+ " * "+newmodel.getSafeSymbol()+"=allocate"+name+"();");
+       craux.addDeclaration("struct "+name+ " * ",newmodel.getSafeSymbol());
+       craux.outputline(newmodel.getSafeSymbol()+"=allocate"+name+"();");
        craux.outputline("WorkListreset("+worklist.getSafeSymbol()+");");
        if (Compiler.GENERATEINSTRUMENT)
            craux.outputline("rebuildcount++;");
@@ -576,11 +603,12 @@ public class RepairGenerator {
            cr.startblock();
            cr.outputline("/* printing set " + setname+"*/");
            cr.outputline("printf(\"\\nPrinting set " + sd.getSymbol() + " - %d elements \\n\", SimpleHashcountset("+setname+"_hash));");
-           cr.outputline("struct SimpleIterator __setiterator;");
-           cr.outputline("SimpleHashiterator(&"+setname+"_hash,__setiterator);");
+           cr.addDeclaration("struct SimpleIterator","__setiterator");
+           cr.outputline("SimpleHashiterator("+setname+"_hash,&__setiterator);");
            cr.outputline("while (hasNext(&__setiterator))");
            cr.startblock();
-           cr.outputline("int __setval = (int) next(&__setiterator);");
+           cr.addDeclaration("int","__setval");
+           cr.outputline("__setval = (int) next(&__setiterator);");
 
            TypeDescriptor td = sd.getType();
            if (td instanceof StructureTypeDescriptor) {
@@ -625,7 +653,8 @@ public class RepairGenerator {
 
                        cr.outputline("/* build " +escape(rule.toString())+"*/");
                        cr.startblock();
-                       cr.outputline("int maybe=0;");
+                       cr.addDeclaration("int","maybe");
+                       cr.outputline("maybe=0;");
 
                        Expr ruleexpr=rule.getGuardExpr();
                        HashSet invariantvars=new HashSet();
@@ -656,7 +685,8 @@ public class RepairGenerator {
                            VarDescriptor tmpvd=VarDescriptor.makeNew("tmpvar");
                            VarDescriptor maybevd=VarDescriptor.makeNew("maybevar");
                            invexpr.generate(cr,tmpvd);
-                           cr.outputline("int "+maybevd.getSafeSymbol()+"=maybe;");
+                           cr.addDeclaration("int ",maybevd.getSafeSymbol());
+                           cr.outputline(maybevd.getSafeSymbol()+"=maybe;");
                            cr.outputline("maybe=0;");
                            ivalue.assignPair(invexpr,tmpvd,maybevd);
                             openparencount++;
@@ -706,7 +736,8 @@ public class RepairGenerator {
                cr2.outputline("while (WorkListhasMoreElements("+worklist.getSafeSymbol()+"))");
                cr2.startblock();
                VarDescriptor idvar=VarDescriptor.makeNew("id");
-               cr2.outputline("int "+idvar.getSafeSymbol()+"=WorkListgetid("+worklist.getSafeSymbol()+");");
+               cr2.addDeclaration("int ",idvar.getSafeSymbol());
+               cr2.outputline(idvar.getSafeSymbol()+"=WorkListgetid("+worklist.getSafeSymbol()+");");
 
                String elseladder = "if";
 
@@ -725,13 +756,17 @@ public class RepairGenerator {
                        cr.indent();
                        cr.outputline(elseladder + " ("+idvar.getSafeSymbol()+" == " + dispatchid + ")");
                        cr.startblock();
-                       cr.outputline("int maybe=0;");
+                       cr.addDeclaration("int","maybe");
+                       cr.outputline("maybe=0;");
                        VarDescriptor typevar=VarDescriptor.makeNew("type");
                        VarDescriptor leftvar=VarDescriptor.makeNew("left");
                        VarDescriptor rightvar=VarDescriptor.makeNew("right");
-                       cr.outputline("int "+typevar.getSafeSymbol()+"= WorkListgettype("+worklist.getSafeSymbol()+");");
-                       cr.outputline("int "+leftvar.getSafeSymbol()+"= WorkListgetlvalue("+worklist.getSafeSymbol()+");");
-                       cr.outputline("int "+rightvar.getSafeSymbol()+"= WorkListgetrvalue("+worklist.getSafeSymbol()+");");
+                       cr.addDeclaration("int",typevar.getSafeSymbol());
+                       cr.outputline(typevar.getSafeSymbol()+"= WorkListgettype("+worklist.getSafeSymbol()+");");
+                       cr.addDeclaration("int",leftvar.getSafeSymbol());
+                       cr.outputline(leftvar.getSafeSymbol()+"= WorkListgetlvalue("+worklist.getSafeSymbol()+");");
+                       cr.addDeclaration("int",rightvar.getSafeSymbol());
+                       cr.outputline(rightvar.getSafeSymbol()+"= WorkListgetrvalue("+worklist.getSafeSymbol()+");");
                        cr.outputline("/* build " +escape(rule.toString())+"*/");
 
 
@@ -824,7 +859,8 @@ public class RepairGenerator {
                     quantifier.generate_open(cr);
                 }
 
-                cr.outputline("int maybe = 0;");
+                cr.addDeclaration("int","maybe");
+                cr.outputline("maybe = 0;");
 
                 /* now we have to generate the guard test */
 
@@ -859,10 +895,11 @@ public class RepairGenerator {
                dnfconst.addAll((Set)termination.conjunctionmap.get(constraint));
 
                if (dnfconst.size()<=1) {
-                   cr.outputline("int "+mincostindex.getSafeSymbol()+"=0;");
+                   cr.addDeclaration("int",mincostindex.getSafeSymbol());
+                   cr.outputline(mincostindex.getSafeSymbol()+"=0;");
                }
                if (dnfconst.size()>1) {
-                   cr.outputline("int "+mincostindex.getSafeSymbol()+";");
+                   cr.addDeclaration("int",mincostindex.getSafeSymbol());
                    boolean first=true;
                    for(int j=0;j<dnfconst.size();j++) {
                        GraphNode gn=(GraphNode)dnfconst.get(j);
@@ -881,9 +918,10 @@ public class RepairGenerator {
                            boolean negate=dpred.isNegated();
                            VarDescriptor predvalue=VarDescriptor.makeNew("Predicatevalue");
                            p.generate(cr,predvalue);
-                           if (k==0)
-                               cr.outputline("int "+costvar.getSafeSymbol()+"=0;");
-
+                           if (k==0) {
+                               cr.addDeclaration("int",costvar.getSafeSymbol());
+                               cr.outputline(costvar.getSafeSymbol()+"=0;");
+                           }
                            if (negate)
                                cr.outputline("if (maybe||"+predvalue.getSafeSymbol()+")");
                            else
@@ -902,7 +940,8 @@ public class RepairGenerator {
                        first=false;
                    }
                }
-               cr.outputline("switch("+mincostindex.getSafeSymbol()+") {");
+               cr.outputline("switch("+mincostindex.getSafeSymbol()+")");
+               cr.startblock();
                for(int j=0;j<dnfconst.size();j++) {
                    GraphNode gn=(GraphNode)dnfconst.get(j);
                    Conjunction conj=((TermNode)gn.getOwner()).getConjunction();
@@ -938,7 +977,7 @@ public class RepairGenerator {
                    cr.endblock();
                    cr.outputline("break;");
                }
-               cr.outputline("}");
+               cr.endblock();
 
                cr.outputline("if ("+oldmodel.getSafeSymbol()+")");
                cr.outputline("free"+name+"("+oldmodel.getSafeSymbol()+");");
@@ -1060,13 +1099,14 @@ public class RepairGenerator {
            System.out.println("Warning:  need to have individual remove operations for"+dpred.name());
            needremoveloop=false;
        }
-       if (needremoveloop)
-           cr.outputline("while (1) {");
-
+       if (needremoveloop) {
+           cr.outputline("while (1)");
+           cr.startblock();
+       }
        if (!inverted) {
            ((RelationExpr)expr.getLeftExpr()).getExpr().generate(cr,leftside);
            expr.getRightExpr().generate(cr,newvalue);
-           cr.outputline(rd.getRange().getType().getGenerateType().getSafeSymbol()+" "+rightside.getSafeSymbol()+";");
+           cr.addDeclaration(rd.getRange().getType().getGenerateType().getSafeSymbol(),rightside.getSafeSymbol());
            cr.outputline("SimpleHashget("+rd.getSafeSymbol()+"_hash,"+leftside.getSafeSymbol()+", &"+rightside.getSafeSymbol()+");");
        } else {
            ((RelationExpr)expr.getLeftExpr()).getExpr().generate(cr,rightside);
@@ -1102,9 +1142,11 @@ public class RepairGenerator {
 
        if (needremoveloop) {
            if (!inverted) {
-               cr.outputline("if (SimpleHashcontainskey("+rd.getSafeSymbol()+"_hash, "+leftside.getSafeSymbol()+")) {");
+               cr.outputline("if (SimpleHashcontainskey("+rd.getSafeSymbol()+"_hash, "+leftside.getSafeSymbol()+"))");
+               cr.startblock();
            } else {
-               cr.outputline("if (SimpleHashcontainskey("+rd.getSafeSymbol()+"_hashinv, "+rightside.getSafeSymbol()+")) {");
+               cr.outputline("if (SimpleHashcontainskey("+rd.getSafeSymbol()+"_hashinv, "+rightside.getSafeSymbol()+"))");
+               cr.startblock();
            }
            for(int i=0;i<state.vRules.size();i++) {
                Rule r=(Rule)state.vRules.get(i);
@@ -1120,7 +1162,7 @@ public class RepairGenerator {
                }
            }
            cr.outputline("continue;");
-           cr.outputline("}");
+           cr.endblock();
        }
 
        if (usageimage) {
@@ -1179,7 +1221,7 @@ public class RepairGenerator {
        }
        if (needremoveloop) {
            cr.outputline("break;");
-           cr.outputline("}");
+           cr.endblock();
        }
     }
 
@@ -1203,7 +1245,7 @@ public class RepairGenerator {
        VarDescriptor sizevar=VarDescriptor.makeNew("size");
        ((OpExpr)expr).left.generate(cr, sizevar);
        VarDescriptor change=VarDescriptor.makeNew("change");
-       cr.outputline("int "+change.getSafeSymbol()+";");
+       cr.addDeclaration("int",change.getSafeSymbol());
        boolean generateadd=false;
        boolean generateremove=false;
        if (opcode==Opcode.GT) {
@@ -1252,15 +1294,16 @@ public class RepairGenerator {
            if (d instanceof RelationDescriptor) {
                if (ep.inverted()) {
                    ((ImageSetExpr)((SizeofExpr)expr.left).setexpr).generate_leftside(cr,rightvar);
-                   cr.outputline("int "+leftvar.getSafeSymbol()+";");
+                   cr.addDeclaration("int",leftvar.getSafeSymbol());
                    cr.outputline("SimpleHashget("+d.getSafeSymbol()+"_hashinv,(int)"+rightvar.getSafeSymbol()+", &"+leftvar.getSafeSymbol()+");");
                } else {
                    ((ImageSetExpr)((SizeofExpr)expr.left).setexpr).generate_leftside(cr,leftvar);
-                   cr.outputline("int "+rightvar.getSafeSymbol()+"=0;");
+                   cr.addDeclaration("int",rightvar.getSafeSymbol());
                    cr.outputline("SimpleHashget("+d.getSafeSymbol()+"_hash ,(int)"+leftvar.getSafeSymbol()+", &"+rightvar.getSafeSymbol()+");");
                }
            } else {
-               cr.outputline("int "+leftvar.getSafeSymbol()+"= SimpleHashfirstkey("+d.getSafeSymbol()+"_hash);");
+               cr.addDeclaration("int",leftvar.getSafeSymbol());
+               cr.outputline(leftvar.getSafeSymbol()+"= SimpleHashfirstkey("+d.getSafeSymbol()+"_hash);");
            }
            /* Generate abstract remove instruction */
            if (d instanceof RelationDescriptor) {
@@ -1314,17 +1357,17 @@ public class RepairGenerator {
                    /* Set Source */
                    SetDescriptor sd=termination.sources.relgetSourceSet(rd,!ep.inverted());
                    VarDescriptor iterator=VarDescriptor.makeNew("iterator");
-                   cr.outputline(sd.getType().getGenerateType().getSafeSymbol() +" "+newobject.getSafeSymbol()+";");
-                   cr.outputline("struct SimpleIterator "+iterator.getSafeSymbol()+";");
-                   cr.outputline("for(SimpleHashiterator(& "+sd.getSafeSymbol()+"_hash ,"+ iterator.getSafeSymbol() +");"+iterator.getSafeSymbol()+".hasNext();)");
+                   cr.addDeclaration(sd.getType().getGenerateType().getSafeSymbol(),newobject.getSafeSymbol());
+                   cr.addDeclaration("struct SimpleIterator",iterator.getSafeSymbol());
+                   cr.outputline("for(SimpleHashiterator("+sd.getSafeSymbol()+"_hash , &"+ iterator.getSafeSymbol() +"); hasNext(&"+iterator.getSafeSymbol()+");)");
                    cr.startblock();
                    if (ep.inverted()) {
                        cr.outputline("if (!SimpleHashcontainskeydata("+rd.getSafeSymbol()+"_hashinv,"+iterator.getSafeSymbol()+".key(),"+otherside.getSafeSymbol()+"))");
                    } else {
                        cr.outputline("if (!SimpleHashcontainskeydata("+rd.getSafeSymbol()+"_hash, "+otherside.getSafeSymbol()+","+iterator.getSafeSymbol()+".key()))");
                    }
-                   cr.outputline(newobject.getSafeSymbol()+"=key("+iterator.getSafeSymbol()+");");
-                   cr.outputline("next("+iterator.getSafeSymbol()+");");
+                   cr.outputline(newobject.getSafeSymbol()+"=key(&"+iterator.getSafeSymbol()+");");
+                   cr.outputline("next(&"+iterator.getSafeSymbol()+");");
                    cr.endblock();
                } else if (termination.sources.relallocSource(rd,!ep.inverted())) {
                    /* Allocation Source*/
@@ -1359,13 +1402,13 @@ public class RepairGenerator {
                    /* Set Source */
                    SetDescriptor sourcesd=termination.sources.getSourceSet(sd);
                    VarDescriptor iterator=VarDescriptor.makeNew("iterator");
-                   cr.outputline(sourcesd.getType().getGenerateType().getSafeSymbol() +" "+newobject.getSafeSymbol()+";");
-                   cr.outputline("SimpleIterator "+iterator.getSafeSymbol()+";");
-                   cr.outputline("for(SimpleHashiterator("+sourcesd.getSafeSymbol()+"_hash, "+iterator.getSafeSymbol()+");"+iterator.getSafeSymbol()+".hasNext();)");
+                   cr.addDeclaration(sourcesd.getType().getGenerateType().getSafeSymbol(), newobject.getSafeSymbol());
+                   cr.addDeclaration("struct SimpleIterator",iterator.getSafeSymbol());
+                   cr.outputline("for(SimpleHashiterator("+sourcesd.getSafeSymbol()+"_hash, &"+iterator.getSafeSymbol()+"); hasNext(&"+iterator.getSafeSymbol()+");)");
                    cr.startblock();
-                   cr.outputline("if (!SimpleHashcontainskey("+sd.getSafeSymbol()+"_hash, key("+iterator.getSafeSymbol()+")))");
-                   cr.outputline(newobject.getSafeSymbol()+"=key("+iterator.getSafeSymbol()+");");
-                   cr.outputline("next("+iterator.getSafeSymbol()+");");
+                   cr.outputline("if (!SimpleHashcontainskey("+sd.getSafeSymbol()+"_hash, key(&"+iterator.getSafeSymbol()+")))");
+                   cr.outputline(newobject.getSafeSymbol()+"=key(&"+iterator.getSafeSymbol()+");");
+                   cr.outputline("next(&"+iterator.getSafeSymbol()+");");
                    cr.endblock();
                } else if (termination.sources.allocSource(sd)) {
                    /* Allocation Source*/
@@ -1559,7 +1602,8 @@ public class RepairGenerator {
                    /* Have update to call into */
                    VarDescriptor mdfyptr=VarDescriptor.makeNew("modifyptr");
                    VarDescriptor ismdfyptr=VarDescriptor.makeNew("ismodifyptr");
-                   cr.outputline("int "+ismdfyptr.getSafeSymbol()+"=RepairHashismodify("+repairtable.getSafeSymbol()+","+rd.getNum()+","+currentrule.getNum()+","+leftvar+","+rightvar+");");
+                   cr.addDeclaration("int ",ismdfyptr.getSafeSymbol());
+                   cr.outputline(ismdfyptr.getSafeSymbol()+"=RepairHashismodify("+repairtable.getSafeSymbol()+","+rd.getNum()+","+currentrule.getNum()+","+leftvar+","+rightvar+");");
 
 
 
@@ -1571,10 +1615,10 @@ public class RepairGenerator {
                        else
                            parttype=parttype+", int";
                    }
-                   VarDescriptor funptr=VarDescriptor.makeNew("updateptr");
+
                    VarDescriptor tmpptr=VarDescriptor.makeNew("tempupdateptr");
 
-                   String methodcall="("+funptr.getSafeSymbol()+") (thisvar,"+oldmodel.getSafeSymbol()+","+repairtable.getSafeSymbol();
+                   String methodcall="(thisvar,"+oldmodel.getSafeSymbol()+","+repairtable.getSafeSymbol();
                    for(int i=0;i<currentrule.numQuantifiers();i++) {
                        Quantifier q=currentrule.getQuantifier(i);
                        if (q instanceof SetQuantifier) {
@@ -1592,21 +1636,29 @@ public class RepairGenerator {
 
 
 
-                   cr.outputline("void *"+tmpptr.getSafeSymbol()+"=");
+                   cr.addDeclaration("void *",tmpptr.getSafeSymbol());
+                   cr.outputline(tmpptr.getSafeSymbol()+"=");
                    cr.outputline("(void *) RepairHashgetrelation("+repairtable.getSafeSymbol()+","+rd.getNum()+","+currentrule.getNum()+","+leftvar+","+rightvar+");");
                    cr.outputline("if ("+ismdfyptr.getSafeSymbol()+")");
                    {
+                       VarDescriptor funptr=VarDescriptor.makeNew("updateptr");
+                       String methodcallprefix="("+funptr.getSafeSymbol()+") ";
                        cr.startblock();
-                       cr.outputline("int "+mdfyptr.getSafeSymbol()+"=RepairHashgetrelation2("+repairtable.getSafeSymbol()+","+rd.getNum()+","+currentrule.getNum()+","+leftvar+","+rightvar+");");
-                       cr.outputline("void (*"+funptr.getSafeSymbol()+") (struct "+name+"_state *, struct "+name+"*, struct RepairHash *"+parttype+",int,int,int)="+"(void (*) (struct "+name+"_state *, struct "+name+"*, struct RepairHash *"+parttype+",int,int,int)) "+tmpptr.getSafeSymbol()+";");
-                       cr.outputline(methodcall+","+leftvar+", "+rightvar+", "+mdfyptr.getSafeSymbol() +");");
+                       cr.addDeclaration("int",mdfyptr.getSafeSymbol());
+                       cr.outputline(mdfyptr.getSafeSymbol()+"=RepairHashgetrelation2("+repairtable.getSafeSymbol()+","+rd.getNum()+","+currentrule.getNum()+","+leftvar+","+rightvar+");");
+                       cr.addDeclaration("void (*"+funptr.getSafeSymbol()+") (struct "+name+"_state *, struct "+name+"*, struct RepairHash *"+parttype+",int,int,int);");
+                       cr.outputline(funptr.getSafeSymbol()+"="+"(void (*) (struct "+name+"_state *, struct "+name+"*, struct RepairHash *"+parttype+",int,int,int)) "+tmpptr.getSafeSymbol()+";");
+                       cr.outputline(methodcallprefix+methodcall+","+leftvar+", "+rightvar+", "+mdfyptr.getSafeSymbol() +");");
                        cr.endblock();
                    }
                    cr.outputline("else ");
                    {
+                       VarDescriptor funptr=VarDescriptor.makeNew("updateptr");
+                       String methodcallprefix="("+funptr.getSafeSymbol()+") ";
                        cr.startblock();
-                       cr.outputline("void (*"+funptr.getSafeSymbol()+") (struct "+name+"_state *, struct "+name+"*,struct RepairHash *"+parttype+")="+"(void (*) (struct "+name+"_state *,struct "+name+"*,struct RepairHash *"+parttype+")) "+tmpptr.getSafeSymbol()+";");
-                       cr.outputline(methodcall+");");
+                       cr.addDeclaration("void (*"+funptr.getSafeSymbol()+") (struct "+name+"_state *, struct "+name+"*,struct RepairHash *"+parttype+");");
+                       cr.outputline(funptr.getSafeSymbol()+"="+"(void (*) (struct "+name+"_state *,struct "+name+"*,struct RepairHash *"+parttype+")) "+tmpptr.getSafeSymbol()+";");
+                       cr.outputline(methodcallprefix+methodcall+");");
                        cr.endblock();
                    }
                    cr.outputline("free"+name+"("+newmodel.getSafeSymbol()+");");
@@ -1645,7 +1697,8 @@ public class RepairGenerator {
 
         String addeditem = (VarDescriptor.makeNew("addeditem")).getSafeSymbol();
         cr.startblock();
-       cr.outputline("int " + addeditem + "=0;");
+       cr.addDeclaration("int" , addeditem);
+       cr.outputline(addeditem + "=0;");
 
        String ifstring="if (!maybe";
        if (rd.getDomain().getType() instanceof StructureTypeDescriptor)  {
@@ -1727,7 +1780,8 @@ public class RepairGenerator {
                        else
                            parttype=parttype+", int";
                    }
-                   cr.outputline("void (*"+funptr.getSafeSymbol()+") (struct "+name+"_state *,struct "+name+"*,struct RepairHash *"+parttype+")=");
+                   cr.addDeclaration("void (*"+funptr.getSafeSymbol()+") (struct "+name+"_state *,struct "+name+"*,struct RepairHash *"+parttype+");");
+                   cr.outputline(funptr.getSafeSymbol()+"=");
                    cr.outputline("(void (*) (struct "+name+"_state *,struct "+name+"*,struct RepairHash *"+parttype+")) RepairHashgetset("+repairtable.getSafeSymbol()+","+sd.getNum()+","+currentrule.getNum()+","+setvar+");");
                    String methodcall="("+funptr.getSafeSymbol()+") (thisvar,"+oldmodel.getSafeSymbol()+","+
                        repairtable.getSafeSymbol();
@@ -1800,7 +1854,8 @@ public class RepairGenerator {
 
         cr.startblock();
         String addeditem = (VarDescriptor.makeNew("addeditem")).getSafeSymbol();
-       cr.outputline("int " + addeditem + " = 0;");
+       cr.addDeclaration("int", addeditem);
+       cr.outputline(addeditem + " = 0;");
        if (sd.getType() instanceof StructureTypeDescriptor)  {
            cr.outputline("if (!maybe&&"+setvar+")");
        } else
index d166e6e9cce2554395bbc9c0bfa506210d7c9fdc..5ffd93186f2f6be0479385923dd431d33e5f7cae 100755 (executable)
@@ -57,11 +57,13 @@ public class SetExpr extends Expr {
     }
 
     public void generate_inclusion(CodeWriter writer, VarDescriptor dest, VarDescriptor element) {
-        writer.outputline("int " + dest.getSafeSymbol() + " = SimpleHashcontainskey(" +sd.getSafeSymbol()+ "_hash, "+element.getSafeSymbol() + ");");
+        writer.addDeclaration("int", dest.getSafeSymbol());
+        writer.outputline(dest.getSafeSymbol() + " = SimpleHashcontainskey(" +sd.getSafeSymbol()+ "_hash, "+element.getSafeSymbol() + ");");
     }
 
     public void generate_size(CodeWriter writer, VarDescriptor dest) {
-        writer.outputline("int " + dest.getSafeSymbol() + " = SimpleHashcountset("+sd.getSafeSymbol()+"_hash);");
+        writer.addDeclaration("int", dest.getSafeSymbol());
+        writer.outputline(dest.getSafeSymbol() + " = SimpleHashcountset("+sd.getSafeSymbol()+"_hash);");
     }
 
     public void prettyPrint(PrettyPrinter pp) {
index d17505eeb96620d141df54f4278b69bcf16fb47f..2aa7090ef6468d77d0ed65b5a6959854480ef0f5 100755 (executable)
@@ -38,23 +38,25 @@ public class SetQuantifier extends Quantifier {
     }
 
     public void generate_open(CodeWriter writer) {
-       writer.outputline("struct SimpleIterator "+var.getSafeSymbol()+"_iterator;");
+       writer.addDeclaration("struct SimpleIterator",var.getSafeSymbol()+"_iterator");
         writer.outputline("for (SimpleHashiterator("+set.getSafeSymbol()+"_hash, & "+ var.getSafeSymbol()+"_iterator); hasNext(&"+var.getSafeSymbol()+"_iterator); )");
         writer.startblock();
-        writer.outputline(var.getType().getGenerateType() + " " + var.getSafeSymbol() + " = (" + var.getType().getGenerateType() + ") next(&"+var.getSafeSymbol()+"_iterator);");
+        writer.addDeclaration(var.getType().getGenerateType().toString(), var.getSafeSymbol());
+        writer.outputline(var.getSafeSymbol() + " = (" + var.getType().getGenerateType() + ") next(&"+var.getSafeSymbol()+"_iterator);");
     }
 
     public void generate_open(CodeWriter writer, String type,int number, String left,String right) {
        VarDescriptor tmp=VarDescriptor.makeNew("flag");
-       writer.outputline("struct SimpleIterator "+var.getSafeSymbol()+"_iterator;");
+       writer.addDeclaration("struct SimpleIterator",var.getSafeSymbol()+"_iterator");
         writer.outputline("SimpleHashiterator("+set.getSafeSymbol()+"_hash, &"+var.getSafeSymbol()+"_iterator);");
-       writer.outputline("int "+tmp.getSafeSymbol()+"=0;");
+       writer.addDeclaration("int",tmp.getSafeSymbol());
+       writer.outputline(tmp.getSafeSymbol()+"=0;");
        writer.outputline("if ("+type+"=="+number+")");
        writer.outputline(tmp.getSafeSymbol()+"=1;");
 
        writer.outputline("while("+tmp.getSafeSymbol()+"||(("+type+"!="+number+")&&hasNext(&"+var.getSafeSymbol()+"_iterator)))");
         writer.startblock();
-        writer.outputline(var.getType().getGenerateType() + " " + var.getSafeSymbol() + ";");
+        writer.addDeclaration(var.getType().getGenerateType().toString(), var.getSafeSymbol());
        writer.outputline("if ("+type+"=="+number+")");
        writer.startblock();
        writer.outputline(tmp.getSafeSymbol()+"=0;");
@@ -66,7 +68,8 @@ public class SetQuantifier extends Quantifier {
 
     public int generate_worklistload(CodeWriter writer, int offset) {
         String varname = var.getSafeSymbol();
-        writer.outputline("int " + varname + " = wi->word" + offset + ";");
+        writer.addDeclaration("int", varname);
+        writer.outputline(varname + " = wi->word" + offset + ";");
         return offset + 1;
     }
 
index 3e053684025ae70ebac6076472dc19546564ccbe..71b1f228481d4cb45c0fa9a1cca5d8188c6fdf3a 100755 (executable)
@@ -37,7 +37,7 @@ public class SizeofFunction extends Expr {
         // is expand the guard of the rule and if its true then its 1 otherwise 0
 
         String destname = dest.getSafeSymbol();
-        cr.outputline("int " + destname + ";");
+        cr.addDeclaration("int", destname);
 
         // ok... destination is declared... we gotta expand this rule inplace... and instead of the inclusion we
         // set the destination in the guard ... otherwise maybe!
@@ -53,8 +53,10 @@ public class SizeofFunction extends Expr {
             String tempvar = (VarDescriptor.makeNew("tempvar")).getSafeSymbol();
 
             // this is to be safe about name overlap because int t = t; sets t to 0!
-            cr.outputline("int " + tempvar + " = " + domain.getSafeSymbol() + ";");
-            cr.outputline("int " + rulebinding.getSafeSymbol() + " = " + tempvar + ";");
+            cr.addDeclaration("int", tempvar);
+            cr.outputline(tempvar + " = " + domain.getSafeSymbol() + ";");
+            cr.addDeclaration("int", rulebinding.getSafeSymbol());
+            cr.outputline(rulebinding.getSafeSymbol() + " = " + tempvar + ";");
 
             /* pretty print! */
             cr.outputline("/* about to inbed relational function*/");
index 797644a12dd42383fcd3db436b755a2272e45aad..7072ba810938022d1f066dc4d21001428f380f0f 100755 (executable)
@@ -44,7 +44,8 @@ public class Sources {
        cr.pushSymbolTable(state.stGlobals);
        e.generate(cr, size);
        cr.popSymbolTable();
-       cr.outputline(td.getGenerateType().getSafeSymbol()+" "+vd.getSafeSymbol()+"=("+td.getGenerateType().getSafeSymbol()+") calloc(1,"+size.getSafeSymbol()+");");
+       cr.addDeclaration(td.getGenerateType().getSafeSymbol(), vd.getSafeSymbol());
+       cr.outputline(vd.getSafeSymbol()+"=("+td.getGenerateType().getSafeSymbol()+") calloc(1,"+size.getSafeSymbol()+");");
        cr.outputline("alloc((void *) "+vd.getSafeSymbol()+","+size.getSafeSymbol()+");");
        if (Compiler.ALLOCATECPLUSPLUS) {
            if (td instanceof StructureTypeDescriptor) {
index ebe552e12a370326ea7fc666e6da66ecbb2d7d3c..123da041d059cd8ebd0cc7b0fe9372dd502fe263 100755 (executable)
@@ -2,15 +2,22 @@ package MCC.IR;
 
 import java.util.*;
 
-public class StandardCodeWriter implements CodeWriter { 
+public class StandardCodeWriter implements CodeWriter {
 
     boolean linestarted = false;
-    int indent = 0;
-    java.io.PrintWriter output;
+    PrintWrapper output;
     Stack symboltables = new Stack();
     InvariantValue ivalue;
 
-    public StandardCodeWriter(java.io.PrintWriter output) { this.output = output; }
+    public StandardCodeWriter(PrintWrapper output) { this.output = output; }
+    public StandardCodeWriter(java.io.PrintWriter output) { this.output = new PrintWrapper(output);}
+
+    public void startBuffer() {
+       output.startBuffer();
+    }
+    public void emptyBuffer() {
+       output.emptyBuffer();
+    }
 
     public void startblock() {
         indent();
@@ -21,22 +28,28 @@ public class StandardCodeWriter implements CodeWriter {
         outputline("}");
         unindent();
     }
-    
-    public void indent() { 
-        indent++; 
+    public void addDeclaration(String type, String varname) {
+       output.addDeclaration(type,varname);
     }
-    
-    public void unindent() { 
-        indent--; 
+    public void addDeclaration(String f) {
+       output.addDeclaration(f);
     }
     
+    public void indent() {
+        output.indent++;
+    }
+
+    public void unindent() {
+        output.indent--;
+    }
+
     private void doindent() {
-        for (int i = 0; i < indent; i++) { 
+        for (int i = 0; i < output.indent; i++) {
             output.print("  ");
         }
         linestarted = true;
     }
-    
+
     public void outputline(String s) {
         if (!linestarted) {
             doindent();
@@ -44,14 +57,14 @@ public class StandardCodeWriter implements CodeWriter {
         output.println(s);
         linestarted = false;
         output.flush();
-    }                 
-    
+    }
+
     public void output(String s) {
         if (!linestarted) {
             doindent();
         }
         output.print(s);
-        output.flush(); 
+        output.flush();
     }
 
     public void pushSymbolTable(SymbolTable st) {
@@ -62,9 +75,9 @@ public class StandardCodeWriter implements CodeWriter {
         return (SymbolTable) symboltables.pop();
     }
 
-    public SymbolTable getSymbolTable() { 
+    public SymbolTable getSymbolTable() {
         if (symboltables.empty()) {
-            throw new IRException(); 
+            throw new IRException();
         }
         return (SymbolTable) symboltables.peek();
     }
index 284302b96fc4d9d6a44898454de673949bd1a406..b3a6664b89d26462d5d9c61d961e970f671c1270 100755 (executable)
@@ -57,7 +57,7 @@ public class StructureGenerator {
                str+="};";
                cr.outputline(str);
            } else
-               cr.outputline("int arnumelement"+ttd.getId()+"[0];");
+               cr.outputline("int arnumelement"+ttd.getId()+"[1];"); // c doesn't like 0 length arrays
        }
        String str="int* arnumelements["+String.valueOf(max)+"]={";
        for(int i=0;i<max;i++) {
@@ -128,7 +128,7 @@ public class StructureGenerator {
                str+="};";
                cr.outputline(str);
            } else
-               cr.outputline("int argetfield"+ttd.getId()+"[0];");
+               cr.outputline("int argetfield"+ttd.getId()+"[1];"); //c doesn't like zero length arrays
        }
        int max=TypeDescriptor.counter;
        String str="int* argetfield["+String.valueOf(max)+"]={";
@@ -186,7 +186,7 @@ public class StructureGenerator {
                str+="};";
                cr.outputline(str);
            } else
-               cr.outputline("int arisArray"+ttd.getId()+"[0];");
+               cr.outputline("int arisArray"+ttd.getId()+"[1];"); // c doesn't like 0 length arrays
        }
        int max=TypeDescriptor.counter;
        String str="int* arisArray["+String.valueOf(max)+"]={";
@@ -222,7 +222,7 @@ public class StructureGenerator {
                str+="};";
                cr.outputline(str);
            } else
-               cr.outputline("int arisPtr"+ttd.getId()+"[0];");
+               cr.outputline("int arisPtr"+ttd.getId()+"[1];"); // c doesn't like 0 length arrays
        }
        int max=TypeDescriptor.counter;
        String str="int* arisPtr["+String.valueOf(max)+"]={";
index 310f2412314ad7e1c4c99c19454b8cbf1656546b..4c22d37890439cda08718785fcab64334de19cf0 100755 (executable)
@@ -54,16 +54,19 @@ public class SumExpr extends Expr {
     }
 
     public void generate(CodeWriter writer, VarDescriptor dest) {
-        writer.outputline("int "+dest.getSafeSymbol()+"=0;");
+        writer.addDeclaration("int",dest.getSafeSymbol());
+        writer.outputline(dest.getSafeSymbol()+"=0;");
+
 
         VarDescriptor itvd=VarDescriptor.makeNew("iterator");
-        writer.outputline("struct SimpleIterator "+itvd.getSafeSymbol()+";");
+        writer.addDeclaration("struct SimpleIterator",itvd.getSafeSymbol());
         writer.outputline("SimpleHashiterator("+sd.getSafeSymbol()+"_hash , &"+itvd.getSafeSymbol()+");");
         writer.outputline("while (hasNext(&"+itvd.getSafeSymbol()+")) {");
         VarDescriptor keyvd=VarDescriptor.makeNew("key");
-        writer.outputline("int "+keyvd.getSafeSymbol()+"=next(&"+itvd.getSafeSymbol()+");");
+        writer.addDeclaration("int",keyvd.getSafeSymbol());
+        writer.outputline(keyvd.getSafeSymbol()+"=next(&"+itvd.getSafeSymbol()+");");
         VarDescriptor tmpvar=VarDescriptor.makeNew("tmp");
-        writer.outputline("int "+tmpvar.getSafeSymbol()+";");
+        writer.addDeclaration("int",tmpvar.getSafeSymbol());
         writer.outputline("SimpleHashget("+rd.getSafeSymbol()+"_hash, "+keyvd.getSafeSymbol()+", &"+tmpvar.getSafeSymbol()+");");
         writer.outputline(dest.getSafeSymbol()+"+="+tmpvar.getSafeSymbol()+";");
         writer.outputline("}");
index 9033ad205c0a5430e36d9082bb4a3aabd1215c7a..3261dfd8e14a0fe06b594922a258596040103279 100755 (executable)
@@ -41,7 +41,8 @@ public class TokenLiteralExpr extends LiteralExpr {
     }
 
     public void generate(CodeWriter writer, VarDescriptor dest) {
-        writer.outputline("int " + dest.getSafeSymbol() + " = " + num.toString().toString() + ";");
+        writer.addDeclaration("int", dest.getSafeSymbol());
+        writer.outputline(dest.getSafeSymbol() + " = " + num.toString().toString() + ";");
     }
     
     public void prettyPrint(PrettyPrinter pp) {
index 962ee775ef0fac5f2bcb6f083005fbc409397a53..9b56fabe42c55bc23885b6f0f48ca8d665bfbb00 100755 (executable)
@@ -75,7 +75,9 @@ public class TupleOfExpr extends Expr {
         VarDescriptor rd = VarDescriptor.makeNew();
         right.generate(writer, rd);
 
-        writer.outputline("int " + dest.getSafeSymbol() + " = SimpleHashcontainskeydata("
+        writer.addDeclaration("int", dest.getSafeSymbol());
+
+        writer.outputline(dest.getSafeSymbol() + " = SimpleHashcontainskeydata("
                           +relation.getSafeSymbol() +"_hash, "+
                           ld.getSafeSymbol() + ", " +
                           rd.getSafeSymbol() + ");");
index c22084434a3b59b177229cbb91bea3aa3a5eb9eb..ee6bdac134c291c4ecd870f71e8324ee7b8e8de8 100755 (executable)
@@ -377,13 +377,16 @@ class UpdateNode {
                break;
            case Updates.POSITION:
            case Updates.ACCESSPATH:
-               if (u.getRightPos()==0)
-                   cr.outputline("int "+right.getSafeSymbol()+"="+slot0+";");
-               else if (u.getRightPos()==1)
-                   cr.outputline("int "+right.getSafeSymbol()+"="+slot1+";");
-               else if (u.getRightPos()==2)
-                   cr.outputline("int "+right.getSafeSymbol()+"="+slot2+";");
-               else throw new Error("Error w/ Position");
+               if (u.getRightPos()==0) {
+                   cr.addDeclaration("int", right.getSafeSymbol());
+                   cr.outputline(right.getSafeSymbol()+"="+slot0+";");
+               } else if (u.getRightPos()==1) {
+                   cr.addDeclaration("int", right.getSafeSymbol());
+                   cr.outputline(right.getSafeSymbol()+"="+slot1+";");
+               } else if (u.getRightPos()==2) {
+                   cr.addDeclaration("int", right.getSafeSymbol());
+                   cr.outputline(right.getSafeSymbol()+"="+slot2+";");
+               } else throw new Error("Error w/ Position");
                break;
            default:
                throw new Error();
@@ -490,7 +493,8 @@ class UpdateNode {
        ArrayAnalysis.AccessPath ap=u.getAccessPath();
        VarDescriptor init=VarDescriptor.makeNew("init");
        if (ap.isSet()) {
-           cr.outputline("int "+init.getSafeSymbol()+"= SimpleHashfirstkey("+ap.getSet().getSafeSymbol()+"_hash);");
+           cr.addDeclaration("int", init.getSafeSymbol());
+           cr.outputline(init.getSafeSymbol()+"= SimpleHashfirstkey("+ap.getSet().getSafeSymbol()+"_hash);");
            init.td=ap.getSet().getType();
        } else {
            init=ap.getVar();
@@ -540,7 +544,8 @@ class UpdateNode {
 
            if (b.getType()==Binding.SEARCH) {
                VarDescriptor vd=b.getVar();
-               cr.outputline(vd.getType().getGenerateType().getSafeSymbol()+" "+vd.getSafeSymbol()+"=SimpleHashfirstkey("+b.getSet().getSafeSymbol()+"_hash);");
+               cr.addDeclaration(vd.getType().getGenerateType().getSafeSymbol(), vd.getSafeSymbol());
+               cr.outputline(vd.getSafeSymbol()+"=SimpleHashfirstkey("+b.getSet().getSafeSymbol()+"_hash);");
            } else if (b.getType()==Binding.CREATE) {
                throw new Error("Creation not supported");
                //              source.generateSourceAlloc(cr,vd,b.getSet());
@@ -548,10 +553,12 @@ class UpdateNode {
                VarDescriptor vd=b.getVar();
                switch(b.getPosition()) {
                case 0:
-                   cr.outputline(vd.getType().getGenerateType().getSafeSymbol()+" "+vd.getSafeSymbol()+"="+slot0+";");
+                   cr.addDeclaration(vd.getType().getGenerateType().getSafeSymbol(), vd.getSafeSymbol());
+                   cr.outputline(vd.getSafeSymbol()+"="+slot0+";");
                    break;
                case 1:
-                   cr.outputline(vd.getType().getGenerateType().getSafeSymbol()+" "+vd.getSafeSymbol()+"="+slot1+";");
+                   cr.addDeclaration(vd.getType().getGenerateType().getSafeSymbol(), vd.getSafeSymbol());
+                   cr.outputline(vd.getSafeSymbol()+"="+slot1+";");
                    break;
                default:
                    throw new Error("Slot >1 doesn't exist.");
index 8ba05d93db7cef087cf65f794009d3628941b756..3720a4cc6e1976d83a75f4d16353ccbf4a9f81ab 100755 (executable)
@@ -115,22 +115,26 @@ public class VarExpr extends Expr {
 
        if (writer.getInvariantValue()!=null&&
            writer.getInvariantValue().isInvariant(this)) {
-           writer.outputline(vd.getType().getGenerateType().getSafeSymbol()+
-                             " "+dest.getSafeSymbol()+"="+writer.getInvariantValue().getValue(this).getSafeSymbol()+";");
+           writer.addDeclaration(vd.getType().getGenerateType().getSafeSymbol(),dest.getSafeSymbol());
+           writer.outputline(dest.getSafeSymbol()+"="+writer.getInvariantValue().getValue(this).getSafeSymbol()+";");
            writer.outputline("maybe="+writer.getInvariantValue().getMaybe(this).getSafeSymbol()+";");
            return;
        }
 
-        writer.outputline(vd.getType().getGenerateType().getSafeSymbol() + " " + dest.getSafeSymbol() +
+        writer.addDeclaration(vd.getType().getGenerateType().getSafeSymbol(),dest.getSafeSymbol());
+        writer.outputline(dest.getSafeSymbol() +
                           " = (" + vd.getType().getGenerateType().getSafeSymbol() + ") " + vd.getSafeSymbol() + "; /*varexpr*/");
        if (vd.isGlobal() && (DOTYPECHECKS||DOMEMCHECKS) && (td instanceof StructureTypeDescriptor)) {
            VarDescriptor typevar=VarDescriptor.makeNew("typechecks");
            writer.outputline("if ("+dest.getSafeSymbol()+")");
            writer.startblock();
-           if (DOTYPECHECKS)
-               writer.outputline("bool "+typevar.getSafeSymbol()+"=assertvalidtype(" + dest.getSafeSymbol() + ", " + td.getId() + ");");
-           else
-               writer.outputline("bool "+typevar.getSafeSymbol()+"=assertvalidmemory(" + dest.getSafeSymbol() + ", " + td.getId() + ");");
+           if (DOTYPECHECKS) {
+               writer.addDeclaration("bool",typevar.getSafeSymbol());
+               writer.outputline(typevar.getSafeSymbol()+"=assertvalidtype(" + dest.getSafeSymbol() + ", " + td.getId() + ");");
+           } else {
+               writer.addDeclaration("bool",typevar.getSafeSymbol());
+               writer.outputline(typevar.getSafeSymbol()+"=assertvalidmemory(" + dest.getSafeSymbol() + ", " + td.getId() + ");");
+           }
            writer.outputline("if (!"+typevar.getSafeSymbol()+")");
            writer.startblock();
            writer.outputline(dest.getSafeSymbol()+"=0;");