Bug fixes and switches
authorbdemsky <bdemsky>
Mon, 3 Apr 2006 16:57:38 +0000 (16:57 +0000)
committerbdemsky <bdemsky>
Mon, 3 Apr 2006 16:57:38 +0000 (16:57 +0000)
Robust/src/IR/Flat/BuildCode.java
Robust/src/IR/Flat/BuildFlat.java
Robust/src/IR/Tree/SemanticCheck.java
Robust/src/IR/TypeDescriptor.java
Robust/src/Main/Main.java

index c778b1d69af3443467c8d06bb40b48e63dba27a0..4302ab6bfd8a9e9203818f7b2e52b85049c8c40a 100644 (file)
@@ -11,7 +11,8 @@ public class BuildCode {
     int tag=0;
     String localsprefix="___locals___";
     String paramsprefix="___params___";
-    private static final boolean GENERATEPRECISEGC=true;
+    public static boolean GENERATEPRECISEGC=false;
+    public static String PREFIX="";
 
     public BuildCode(State st, Hashtable temptovar) {
        state=st;
@@ -27,13 +28,13 @@ public class BuildCode {
        PrintWriter outmethodheader=null;
        PrintWriter outmethod=null;
        try {
-           OutputStream str=new FileOutputStream("structdefs.h");
+           OutputStream str=new FileOutputStream(PREFIX+"structdefs.h");
            outstructs=new java.io.PrintWriter(str, true);
-           str=new FileOutputStream("methodheaders.h");
+           str=new FileOutputStream(PREFIX+"methodheaders.h");
            outmethodheader=new java.io.PrintWriter(str, true);
-           str=new FileOutputStream("classdefs.h");
+           str=new FileOutputStream(PREFIX+"classdefs.h");
            outclassdefs=new java.io.PrintWriter(str, true);
-           str=new FileOutputStream("methods.c");
+           str=new FileOutputStream(PREFIX+"methods.c");
            outmethod=new java.io.PrintWriter(str, true);
        } catch (Exception e) {
            e.printStackTrace();
@@ -60,6 +61,7 @@ public class BuildCode {
 
        /* Build the actual methods */
        outmethod.println("#include \"methodheaders.h\"");
+       outmethod.println("#include <runtime.h>");
        Iterator classit=state.getClassSymbolTable().getDescriptorsIterator();
        while(classit.hasNext()) {
            ClassDescriptor cn=(ClassDescriptor)classit.next();
@@ -176,7 +178,10 @@ public class BuildCode {
                if (printcomma)
                    headersout.print(", ");
                printcomma=true;
-               headersout.print(temp.getType().getSafeSymbol()+" "+temp.getSafeSymbol());
+               if (temp.getType().isClass())
+                   headersout.print("struct " + temp.getType().getSafeSymbol()+" * "+temp.getSafeSymbol());
+               else
+                   headersout.print(temp.getType().getSafeSymbol()+" "+temp.getSafeSymbol());
            }
            headersout.println(");\n");
        }
@@ -184,7 +189,7 @@ public class BuildCode {
 
     private void generateFlatMethod(FlatMethod fm, PrintWriter output) {
        MethodDescriptor md=fm.getMethod();
-       ClassDescriptor cn=md.getClassDesc();
+               ClassDescriptor cn=md.getClassDesc();
        ParamsObject objectparams=(ParamsObject)paramstable.get(md);
 
        generateHeader(md,output);
@@ -198,7 +203,10 @@ public class BuildCode {
        for(int i=0;i<objecttemp.numPrimitives();i++) {
            TempDescriptor td=objecttemp.getPrimitive(i);
            TypeDescriptor type=td.getType();
-           if (type.isClass())
+           System.out.println(td.getSafeSymbol());
+           if (type.isNull())
+               output.println("   void * "+td.getSafeSymbol()+";");
+           else if (type.isClass())
                output.println("   struct "+type.getSafeSymbol()+" * "+td.getSafeSymbol()+";");
            else
                output.println("   "+type.getSafeSymbol()+" "+td.getSafeSymbol()+";");
@@ -361,6 +369,11 @@ public class BuildCode {
        if (GENERATEPRECISEGC) {
            output.print("&__parameterlist__");
            needcomma=true;
+       } else {
+           if (fc.getThis()!=null) {
+               output.print(generateTemp(fm,fc.getThis()));
+               needcomma=true;
+           }
        }
        for(int i=0;i<fc.numArgs();i++) {
            VarDescriptor var=md.getParameter(i);
@@ -459,7 +472,10 @@ public class BuildCode {
            if (printcomma)
                output.print(", ");
            printcomma=true;
-           output.print(temp.getType().getSafeSymbol()+" "+temp.getSafeSymbol());
+           if (temp.getType().isClass())
+               output.print("struct "+temp.getType().getSafeSymbol()+" * "+temp.getSafeSymbol());
+           else
+               output.print(temp.getType().getSafeSymbol()+" "+temp.getSafeSymbol());
        }
        output.print(")");
     }
index 85175514a48831a27177bcad1ab6e62e6228e84c..6c58090e6c740c4dc6c5488a6cc07a069017363d 100644 (file)
@@ -227,6 +227,27 @@ public class BuildFlat {
        TempDescriptor temp_left=TempDescriptor.tempFactory("leftop",on.getLeft().getType());
        TempDescriptor temp_right=null;
 
+       Operation op=on.getOp();
+       if (op.getOp()==Operation.POSTINC||
+           op.getOp()==Operation.POSTDEC||
+           op.getOp()==Operation.PREINC||
+           op.getOp()==Operation.PREDEC) {
+           LiteralNode ln=new LiteralNode("int",new Integer(1));
+           ln.setType(new TypeDescriptor(TypeDescriptor.INT));
+           AssignmentNode an=new AssignmentNode(on.getLeft(),ln,
+                              new AssignOperation((op.getOp()==Operation.POSTINC||op.getOp()==Operation.PREINC)?AssignOperation.PLUSEQ:AssignOperation.MINUSEQ));
+           if (op.getOp()==Operation.POSTINC||
+               op.getOp()==Operation.POSTDEC) {
+               NodePair left=flattenExpressionNode(on.getLeft(),out_temp);
+               NodePair assign=flattenAssignmentNode(an,temp_left);
+               left.getEnd().addNext(assign.getBegin());
+               return new NodePair(left.getBegin(),assign.getEnd());
+           } else {
+               NodePair assign=flattenAssignmentNode(an,out_temp);
+               return assign;
+           }
+       } 
+       
        NodePair left=flattenExpressionNode(on.getLeft(),temp_left);
        NodePair right;
        if (on.getRight()!=null) {
@@ -236,7 +257,35 @@ public class BuildFlat {
            FlatNop nop=new FlatNop();
            right=new NodePair(nop,nop);
        }
-       Operation op=on.getOp();
+
+       if (op.getOp()==Operation.LOGIC_OR) {
+           /* Need to do shortcircuiting */
+           FlatCondBranch fcb=new FlatCondBranch(temp_left);
+           FlatOpNode fon1=new FlatOpNode(out_temp,temp_left,null,new Operation(Operation.ASSIGN));
+           FlatOpNode fon2=new FlatOpNode(out_temp,temp_right,null,new Operation(Operation.ASSIGN));
+           FlatNop fnop=new FlatNop();
+           left.getEnd().addNext(fcb);
+           fcb.addFalseNext(right.getBegin());
+           right.getEnd().addNext(fon2);
+           fon2.addNext(fnop);
+           fcb.addTrueNext(fon1);
+           fon1.addNext(fnop);
+           return new NodePair(left.getBegin(), fnop);
+       } else if (op.getOp()==Operation.LOGIC_AND) {
+           /* Need to do shortcircuiting */
+           FlatCondBranch fcb=new FlatCondBranch(temp_left);
+           FlatOpNode fon1=new FlatOpNode(out_temp,temp_left,null,new Operation(Operation.ASSIGN));
+           FlatOpNode fon2=new FlatOpNode(out_temp,temp_right,null,new Operation(Operation.ASSIGN));
+           FlatNop fnop=new FlatNop();
+           left.getEnd().addNext(fcb);
+           fcb.addTrueNext(right.getBegin());
+           right.getEnd().addNext(fon2);
+           fon2.addNext(fnop);
+           fcb.addFalseNext(fon1);
+           fon1.addNext(fnop);
+           return new NodePair(left.getBegin(), fnop);
+       }
+
        FlatOpNode fon=new FlatOpNode(out_temp,temp_left,temp_right,op);
        left.getEnd().addNext(right.getBegin());
        right.getEnd().addNext(fon);
index ee1968c4e2fbf2994443acd287ab590401ab9e7b..6e777c07e37ae8968026574beb6592bca6d6e401 100644 (file)
@@ -462,6 +462,15 @@ public class SemanticCheck {
        if (bestmd==null)
            throw new Error("No method found for :"+min.printNode(0));
        min.setMethod(bestmd);
+       /* Check whether we need to set this parameter to implied this */
+       if (!bestmd.isStatic()) {
+           if (min.getExpression()==null) {
+               ExpressionNode en=new NameNode(new NameDescriptor("this"));
+               min.setExpression(en);
+               checkExpressionNode(md, nametable, min.getExpression(), null);
+           }
+       }
+
     }
 
 
index c1bbc74c8f2427885587aaa171011f849a045d0c..4a880e2ac13e37bf5c7c0c966db80e5fadd15717 100644 (file)
@@ -45,7 +45,7 @@ public class TypeDescriptor extends Descriptor {
            return "double";
        else if (isFloat())
            return "float";
-       else throw new Error();
+       else throw new Error("Error Type: "+type);
     }
 
     public String getSafeDescriptor() {
index 874d31384135367f8c0a77bdc651b31e073c9d29..a9200774cb7ce9f0bcf00a3d6dd5d90c0b2ade5f 100644 (file)
@@ -14,30 +14,43 @@ import IR.TypeUtil;
 public class Main {
   public static void main(String args[]) throws Exception {
       if (args.length<1) {
-       System.out.println("Must input source file");
-       System.exit(-1);
+         System.out.println("Must input source file");
+         System.exit(-1);
       }
-    Reader fr = new BufferedReader(new FileReader(args[0]));
-    Lex.Lexer l = new Lex.Lexer(fr);
-    java_cup.runtime.lr_parser g;
-    g = new Parse.Parser(l);
-    ParseNode p=(ParseNode) g./*debug_*/parse().value;
-    State state=new State(p);
-
-    BuildIR bir=new BuildIR(state);
-    bir.buildtree();
-
-    TypeUtil tu=new TypeUtil(state);
-    
-    SemanticCheck sc=new SemanticCheck(state,tu);
-    sc.semanticCheck();
-    
-    BuildFlat bf=new BuildFlat(state);
-    bf.buildFlat();
-
-    BuildCode bc=new BuildCode(state, bf.getMap());
-    bc.buildCode();
-
-    System.exit(l.numErrors());
+      for(int i=1;i<args.length;i++) {
+         String option=args[i];
+         if (option.equals("-precise"))
+             IR.Flat.BuildCode.GENERATEPRECISEGC=true;
+         else if (option.equals("-dir"))
+             IR.Flat.BuildCode.PREFIX=args[++i]+"/";
+         else if (option.equals("-help")) {
+             System.out.println("-dir outputdirectory -- output code in outputdirectory");
+             System.out.println("-precise -- use precise garbage collection");
+             System.out.println("-help -- print out help");
+             System.exit(0);
+         }
+      }
+      Reader fr = new BufferedReader(new FileReader(args[0]));
+      Lex.Lexer l = new Lex.Lexer(fr);
+      java_cup.runtime.lr_parser g;
+      g = new Parse.Parser(l);
+      ParseNode p=(ParseNode) g./*debug_*/parse().value;
+      State state=new State(p);
+      
+      BuildIR bir=new BuildIR(state);
+      bir.buildtree();
+      
+      TypeUtil tu=new TypeUtil(state);
+      
+      SemanticCheck sc=new SemanticCheck(state,tu);
+      sc.semanticCheck();
+      
+      BuildFlat bf=new BuildFlat(state);
+      bf.buildFlat();
+      
+      BuildCode bc=new BuildCode(state, bf.getMap());
+      bc.buildCode();
+      
+      System.exit(l.numErrors());
   }
 }