This update generates partial code for tasks...
authorbdemsky <bdemsky>
Wed, 2 Aug 2006 08:32:20 +0000 (08:32 +0000)
committerbdemsky <bdemsky>
Wed, 2 Aug 2006 08:32:20 +0000 (08:32 +0000)
Robust/src/IR/Flat/BuildCode.java
Robust/src/IR/Flat/BuildFlat.java
Robust/src/IR/Flat/FlatMethod.java
Robust/src/IR/Flat/ParamsObject.java
Robust/src/IR/Flat/TempObject.java
Robust/src/IR/State.java
Robust/src/IR/Tree/BuildIR.java

index ccebda635d8aa7c546f5a899f1c08ece64754234..c4c2ac055824909ea55dcaebc1a015e358fea5cc 100644 (file)
@@ -62,7 +62,7 @@ public class BuildCode {
        outstructs.println("#define CHARARRAYTYPE "+
                           (state.getArrayNumber((new TypeDescriptor(TypeDescriptor.CHAR)).makeArray(state))+state.numClasses()));
 
-       // Output the C declarations
+       // Output the C class declarations
        // These could mutually reference each other
        outclassdefs.println("struct "+arraytype+";");
        while(it.hasNext()) {
@@ -78,17 +78,19 @@ public class BuildCode {
            outclassdefs.println("  int ___length___;");
            outclassdefs.println("};\n");
        }
+
+       // Output function prototypes and structures for parameters
        it=state.getClassSymbolTable().getDescriptorsIterator();
        while(it.hasNext()) {
            ClassDescriptor cn=(ClassDescriptor)it.next();
            generateCallStructs(cn, outclassdefs, outstructs, outmethodheader);
        }
-
-
-
        outstructs.close();
        outmethodheader.close();
 
+       if (state.TASK)
+           generateTaskStructs(outstructs, outmethodheader);
+
        /* Build the actual methods */
        outmethod.println("#include \"methodheaders.h\"");
        outmethod.println("#include \"virtualtable.h\"");
@@ -110,7 +112,17 @@ public class BuildCode {
                    generateFlatMethod(fm,outmethod);
            }
        }
-       if (state.main!=null) {
+
+       if (state.TASK) {
+           /* Compile task based program */
+           Iterator taskit=state.getTaskSymbolTable().getDescriptorsIterator();
+           while(taskit.hasNext()) {
+               TaskDescriptor td=(TaskDescriptor)taskit.next();
+               FlatMethod fm=state.getMethodFlat(td);
+               generateFlatMethod(fm, outmethod);
+           }
+       } else if (state.main!=null) {
+           /* Compile method based program */
            outmethod.println("int main(int argc, const char *argv[]) {");
            ClassDescriptor cd=typeutil.getClass(state.main);
            Set mainset=cd.getMethodTable().getSet("main");
@@ -188,6 +200,10 @@ public class BuildCode {
        }
     }
 
+    /** Generate array that contains the sizes of class objects.  The
+     * object allocation functions in the runtime use this
+     * information. */
+
     private void generateSizeArray(PrintWriter outclassdefs) {
        outclassdefs.print("int classsize[]={");
        Iterator it=state.getClassSymbolTable().getDescriptorsIterator();
@@ -227,10 +243,20 @@ public class BuildCode {
        outclassdefs.println("};");
     }
 
+    /** Constructs params and temp objects for each method or task.
+     * These objects tell the compiler which temps need to be
+     * allocated.  */
+
     private void generateTempStructs(FlatMethod fm) {
        MethodDescriptor md=fm.getMethod();
-       ParamsObject objectparams=new ParamsObject(md,tag++);
-       paramstable.put(md, objectparams);
+       TaskDescriptor task=fm.getTask();
+
+       ParamsObject objectparams=md!=null?new ParamsObject(md,tag++):new ParamsObject(task, tag++);
+       if (md!=null)
+           paramstable.put(md, objectparams);
+       else
+           paramstable.put(task, objectparams);
+
        for(int i=0;i<fm.numParameters();i++) {
            TempDescriptor temp=fm.getParameter(i);
            TypeDescriptor type=temp.getType();
@@ -240,8 +266,12 @@ public class BuildCode {
                objectparams.addPrim(temp);
        }
 
-       TempObject objecttemps=new TempObject(objectparams,md,tag++);
-       tempstable.put(md, objecttemps);
+       TempObject objecttemps=md!=null?new TempObject(objectparams,md,tag++):new TempObject(objectparams, task, tag++);
+       if (md!=null)
+           tempstable.put(md, objecttemps);
+       else
+           tempstable.put(task, objecttemps);
+
        for(Iterator nodeit=fm.getNodeSet().iterator();nodeit.hasNext();) {
            FlatNode fn=(FlatNode)nodeit.next();
            TempDescriptor[] writes=fn.writesTemps();
@@ -256,7 +286,8 @@ public class BuildCode {
        }
     }
     
-    /* Force consistent field ordering between inherited classes */
+    /* Force consistent field ordering between inherited classes. */
+
     private void printClassStruct(ClassDescriptor cn, PrintWriter classdefout) {
        ClassDescriptor sp=cn.getSuperDesc();
        if (sp!=null)
@@ -283,6 +314,10 @@ public class BuildCode {
        }
     }
 
+    /** This function outputs (1) structures that parameters are
+     * passed in (when PRECISE GC is enabled) and (2) function
+     * prototypes for the methods */
+
     private void generateCallStructs(ClassDescriptor cn, PrintWriter classdefout, PrintWriter output, PrintWriter headersout) {
        /* Output class structure */
        classdefout.println("struct "+cn.getSafeSymbol()+" {");
@@ -345,6 +380,76 @@ public class BuildCode {
                printcomma=true;
            }
 
+           //output parameter list
+           for(int i=0;i<objectparams.numPrimitives();i++) {
+               TempDescriptor temp=objectparams.getPrimitive(i);
+               if (printcomma)
+                   headersout.print(", ");
+               printcomma=true;
+               if (temp.getType().isClass()||temp.getType().isArray())
+                   headersout.print("struct " + temp.getType().getSafeSymbol()+" * "+temp.getSafeSymbol());
+               else
+                   headersout.print(temp.getType().getSafeSymbol()+" "+temp.getSafeSymbol());
+           }
+           headersout.println(");\n");
+       }
+    }
+
+
+    /** This function outputs (1) structures that parameters are
+     * passed in (when PRECISE GC is enabled) and (2) function
+     * prototypes for the tasks */
+
+    private void generateTaskStructs(PrintWriter output, PrintWriter headersout) {
+       /* Cycle through tasks */
+       Iterator taskit=state.getTaskSymbolTable().getDescriptorsIterator();
+
+       while(taskit.hasNext()) {
+           /* Classify parameters */
+           TaskDescriptor task=(TaskDescriptor)taskit.next();
+           FlatMethod fm=state.getMethodFlat(task);
+           generateTempStructs(fm);
+
+           ParamsObject objectparams=(ParamsObject) paramstable.get(task);
+           TempObject objecttemps=(TempObject) tempstable.get(task);
+
+           /* Output parameter structure */
+           if (GENERATEPRECISEGC) {
+               output.println("struct "+task.getSafeSymbol()+"_params {");
+               output.println("  int type;");
+               output.println("  void * next;");
+               for(int i=0;i<objectparams.numPointers();i++) {
+                   TempDescriptor temp=objectparams.getPointer(i);
+                   output.println("  struct "+temp.getType().getSafeSymbol()+" * "+temp.getSafeSymbol()+";");
+               }
+               output.println("};\n");
+           }
+
+           /* Output temp structure */
+           if (GENERATEPRECISEGC) {
+               output.println("struct "+task.getSafeSymbol()+"_locals {");
+               output.println("  int type;");
+               output.println("  void * next;");
+               for(int i=0;i<objecttemps.numPointers();i++) {
+                   TempDescriptor temp=objecttemps.getPointer(i);
+                   if (temp.getType().isNull())
+                       output.println("  void * "+temp.getSafeSymbol()+";");
+                   else
+                       output.println("  struct "+temp.getType().getSafeSymbol()+" * "+temp.getSafeSymbol()+";");
+               }
+               output.println("};\n");
+           }
+           
+           /* Output task declaration */
+           headersout.print("void " + task.getSafeSymbol()+"_"+"(");
+           
+           boolean printcomma=false;
+           if (GENERATEPRECISEGC) {
+               headersout.print("struct "+task.getSafeSymbol()+"_params * "+paramsprefix);
+               printcomma=true;
+           }
+
+           //output parameter list
            for(int i=0;i<objectparams.numPrimitives();i++) {
                TempDescriptor temp=objectparams.getPrimitive(i);
                if (printcomma)
@@ -361,17 +466,24 @@ public class BuildCode {
 
     private void generateFlatMethod(FlatMethod fm, PrintWriter output) {
        MethodDescriptor md=fm.getMethod();
-               ClassDescriptor cn=md.getClassDesc();
-       ParamsObject objectparams=(ParamsObject)paramstable.get(md);
+       TaskDescriptor task=fm.getTask();
+
+               ClassDescriptor cn=md!=null?md.getClassDesc():null;
+
+       ParamsObject objectparams=(ParamsObject)paramstable.get(md!=null?md:task);
+
+       generateHeader(md!=null?md:task,output);
 
-       generateHeader(md,output);
        /* Print code */
        output.println(" {");
        
        if (GENERATEPRECISEGC) {
-           output.println("   struct "+cn.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_locals "+localsprefix+";");
+           if (md!=null)
+               output.println("   struct "+cn.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_locals "+localsprefix+";");
+           else
+               output.println("   struct "+task.getSafeSymbol()+"_locals "+localsprefix+";");
        }
-       TempObject objecttemp=(TempObject) tempstable.get(md);
+       TempObject objecttemp=(TempObject) tempstable.get(md!=null?md:task);
        for(int i=0;i<objecttemp.numPrimitives();i++) {
            TempDescriptor td=objecttemp.getPrimitive(i);
            TypeDescriptor type=td.getType();
@@ -459,7 +571,8 @@ public class BuildCode {
 
     private String generateTemp(FlatMethod fm, TempDescriptor td) {
        MethodDescriptor md=fm.getMethod();
-       TempObject objecttemps=(TempObject) tempstable.get(md);
+       TaskDescriptor task=fm.getTask();
+       TempObject objecttemps=(TempObject) tempstable.get(md!=null?md:task);
        if (objecttemps.isLocalPrim(td)||objecttemps.isParamPrim(td)) {
            return td.getSafeSymbol();
        }
@@ -509,6 +622,9 @@ public class BuildCode {
        case FKind.FlatNop:
            output.println("/* nop */");
            return;
+       case FKind.FlatFlagActionNode:
+           generateFlatFlagActionNode(fm, (FlatFlagActionNode) fn, output);
+           return;
        }
        throw new Error();
 
@@ -721,12 +837,19 @@ public class BuildCode {
        output.println("if (!"+generateTemp(fm, fcb.getTest())+") goto "+label+";");
     }
 
-    private void generateHeader(MethodDescriptor md, PrintWriter output) {
+    private void generateHeader(Descriptor des, PrintWriter output) {
        /* Print header */
-       ParamsObject objectparams=(ParamsObject)paramstable.get(md);
-       ClassDescriptor cn=md.getClassDesc();
+       ParamsObject objectparams=(ParamsObject)paramstable.get(des);
+       MethodDescriptor md=null;
+       TaskDescriptor task=null;
+       if (des instanceof MethodDescriptor)
+           md=(MethodDescriptor) des;
+       else
+           task=(TaskDescriptor) des;
+
+       ClassDescriptor cn=md!=null?md.getClassDesc():null;
        
-       if (md.getReturnType()!=null) {
+       if (md!=null&&md.getReturnType()!=null) {
            if (md.getReturnType().isClass()||md.getReturnType().isArray())
                output.print("struct " + md.getReturnType().getSafeSymbol()+" * ");
            else
@@ -734,12 +857,17 @@ public class BuildCode {
        } else 
            //catch the constructor case
            output.print("void ");
-
-       output.print(cn.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"(");
+       if (md!=null)
+           output.print(cn.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"(");
+       else
+           output.print(task.getSafeSymbol()+"(");
        
        boolean printcomma=false;
        if (GENERATEPRECISEGC) {
-           output.print("struct "+cn.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params * "+paramsprefix);
+           if (md!=null)
+               output.print("struct "+cn.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params * "+paramsprefix);
+           else
+               output.print("struct "+task.getSafeSymbol()+"_params * "+paramsprefix);
            printcomma=true;
        } 
 
@@ -755,4 +883,8 @@ public class BuildCode {
        }
        output.print(")");
     }
+
+    public void generateFlatFlagActionNode(FlatMethod fm, FlatFlagActionNode ffann, PrintWriter output) {
+       output.print("/* FlatFlagActionNode will go here */");
+    }
 }
index a0fcb722459f336e72df484443efd88278d908ca..1b39c02596188e204df987025056c47b2a5cb8db 100644 (file)
@@ -76,7 +76,6 @@ public class BuildFlat {
            for(int i=0;i<md.numParameters();i++) {
                fm.addParameterTemp(getTempforVar(md.getParameter(i)));
            }
-           System.out.println(fm.printMethod());
            state.addFlatCode(md,fm);
        }
     }
index 9e6cf652dfc7d998169d5c6e272a39531d692ba3..1cb6a6af79792efb3eaa9e0357efb17476b5d232 100644 (file)
@@ -30,6 +30,10 @@ public class FlatMethod extends FlatNode {
     public MethodDescriptor getMethod() {
        return method;
     }
+
+    public TaskDescriptor getTask() {
+       return task;
+    }
     
     public void addParameterTemp(TempDescriptor t) {
        parameterTemps.add(t);
index 1fbf9be2e53fa6710201992575b1f1863fe710e4..8133a4a9ab20d5b79c98d4325062f300f8a37edf 100644 (file)
@@ -6,6 +6,7 @@ public class ParamsObject {
     private Vector pointerparams;
     private Vector primitiveparams;
     private MethodDescriptor method;
+    private TaskDescriptor task;
     private int tag;
     private Hashtable paramtotemp;
     private Hashtable temptostore;
@@ -21,6 +22,16 @@ public class ParamsObject {
        count=0;
     }
 
+    public ParamsObject(TaskDescriptor task, int tag) {
+       pointerparams=new Vector();
+       primitiveparams=new Vector();
+       paramtotemp=new Hashtable();
+       temptostore=new Hashtable();
+       this.task=task;
+       this.tag=tag;
+       count=0;
+    }
+
     public int getUID() {
        return tag;
     }
index b7c93fc317e58b522bd2247fe3620199fa6163c4..f4e95e4880b37a4b231ff1119b91716e60b162ee 100644 (file)
@@ -7,6 +7,7 @@ public class TempObject {
     private Vector pointerparams;
     private Vector primitiveparams;
     private MethodDescriptor method;
+    private TaskDescriptor task;
     private int tag;
     private Hashtable paramtotemp;
     private Hashtable temptostore;
@@ -23,6 +24,17 @@ public class TempObject {
        count=0;
     }
 
+    public TempObject(ParamsObject p, TaskDescriptor task, int tag) {
+       params=p;
+       pointerparams=new Vector();
+       primitiveparams=new Vector();
+       paramtotemp=new Hashtable();
+       temptostore=new Hashtable();
+       this.task=task;
+       this.tag=tag;
+       count=0;
+    }
+
     public void addPtr(TempDescriptor t) {
        if (!params.containsTemp(t)&&!pointerparams.contains(t)) {
            Position p=new Position(true, pointerparams.size());
index ac160634bdd26bdc163e8e0062b5f0f09e0f8c66..7f6e485c110e9fe84570ed88c49e4b7c34060e1e 100644 (file)
@@ -92,10 +92,18 @@ public class State {
        return tasks;
     }
 
+    /** Returns Flat IR representation of MethodDescriptor md. */
+
     public FlatMethod getMethodFlat(MethodDescriptor md) {
        return (FlatMethod)flatmethodmap.get(md);
     }
 
+    /** Returns Flat IR representation of TaskDescriptor td. */
+
+    public FlatMethod getMethodFlat(TaskDescriptor td) {
+       return (FlatMethod)flatmethodmap.get(td);
+    }
+
     public void addTreeCode(MethodDescriptor md, BlockNode bn) {
        treemethodmap.put(md,bn);
     }
index 96cbf846e273189d54ec1f9a3670b2fe6f6fc022..12ae4bdbb5c3714e3dfa8d7ca5a5187bef76ce27 100644 (file)
@@ -71,12 +71,13 @@ public class BuildIR {
     public void parseFlagEffect(FlagEffects fes, ParseNode pn) {
        ParseNodeVector pnv=pn.getChildren();
        for(int i=0;i<pnv.size();i++) {
+           ParseNode pn2=pnv.elementAt(i);
            boolean status=true;
-           if (pn.getChild("not")!=null) {
+           if (isNode(pn2,"not")) {
                status=false;
-               pn=pn.getChild("not");
+               pn2=pn2.getChild("name");
            }
-           String name=pn.getChild("name").getTerminal();
+           String name=pn2.getTerminal();
            fes.addEffect(new FlagEffect(name,status));
        }
     }