From 55074e3d7754f030e6e56a2ca9b6412bfd7ad743 Mon Sep 17 00:00:00 2001 From: bdemsky Date: Wed, 8 Aug 2007 08:06:29 +0000 Subject: [PATCH] more organizing code --- Robust/src/IR/Flat/BuildCode.java | 43 ++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/Robust/src/IR/Flat/BuildCode.java b/Robust/src/IR/Flat/BuildCode.java index 56fa8c20..8f6d04a7 100644 --- a/Robust/src/IR/Flat/BuildCode.java +++ b/Robust/src/IR/Flat/BuildCode.java @@ -96,10 +96,6 @@ public class BuildCode { // These could mutually reference each other outputClassDeclarations(outclassdefs); - /* Outputs task structures if this is a task program */ - if (state.TASK) - outputTaskTypes(outtask); - // Output function prototypes and structures for parameters Iterator it=state.getClassSymbolTable().getDescriptorsIterator(); while(it.hasNext()) { @@ -118,26 +114,25 @@ public class BuildCode { } /* Generate Tasks */ generateTaskStructs(outstructs, outmethodheader); + + /* Outputs generic task structures if this is a task + program */ + outputTaskTypes(outtask); } /* Build the actual methods */ outputMethods(outmethod); if (state.TASK) { + /* Output code for tasks */ outputTaskCode(outtaskdefs, outmethod); outtaskdefs.close(); + /* Record maximum number of task parameters */ + outstructs.println("#define MAXTASKPARAMS "+maxtaskparams); } else if (state.main!=null) { /* Generate main method */ outputMainMethod(outmethod); } - outmethodheader.println("#endif"); - outmethodheader.close(); - outmethod.close(); - - if (state.TASK) - outstructs.println("#define MAXTASKPARAMS "+maxtaskparams); - outstructs.println("#endif"); - outstructs.close(); /* Generate information for task with optional parameters */ if (state.TASK&&state.OPTIONAL){ @@ -150,8 +145,19 @@ public class BuildCode { buildRepairStructs(outrepairstructs); outrepairstructs.close(); } + + /* Close files */ + outmethodheader.println("#endif"); + outmethodheader.close(); + outmethod.close(); + outstructs.println("#endif"); + outstructs.close(); } + /* This code just generates the main C method for java programs. + * The main C method packs up the arguments into a string array + * and passes it to the java main method. */ + private void outputMainMethod(PrintWriter outmethod) { outmethod.println("int main(int argc, const char *argv[]) {"); outmethod.println(" int i;"); @@ -196,6 +202,8 @@ public class BuildCode { outmethod.println("}"); } + /* This method outputs code for each task. */ + private void outputTaskCode(PrintWriter outtaskdefs, PrintWriter outmethod) { /* Compile task based program */ outtaskdefs.println("#include \"task.h\""); @@ -225,6 +233,11 @@ public class BuildCode { outtaskdefs.println("int numtasks="+state.getTaskSymbolTable().getValueSet().size()+";"); } + /* This method outputs most of the methods.c file. This includes + * some standard includes and then an array with the sizes of + * objets and array that stores supertype and then the code for + * the Java methods.. */ + private void outputMethods(PrintWriter outmethod) { outmethod.println("#include \"methodheaders.h\""); outmethod.println("#include \"virtualtable.h\""); @@ -331,8 +344,9 @@ public class BuildCode { outclassdefs.println("extern int supertypes[];"); } + /** Prints out definitions for generic task structures */ + private void outputTaskTypes(PrintWriter outtask) { - //Print out definitions for task types outtask.println("#ifndef _TASK_H"); outtask.println("#define _TASK_H"); outtask.println("struct parameterdescriptor {"); @@ -356,6 +370,7 @@ public class BuildCode { outtask.println("#endif"); } + private void buildRepairStructs(PrintWriter outrepairstructs) { Iterator classit=state.getClassSymbolTable().getDescriptorsIterator(); while(classit.hasNext()) { @@ -386,7 +401,6 @@ public class BuildCode { */ outrepairstructs.println("}\n"); } - } private void printRepairStruct(ClassDescriptor cn, PrintWriter output) { @@ -423,7 +437,6 @@ public class BuildCode { output.println("0x0, 0x0 };"); dnfterms=1; } else { - DNFFlag dflag=param_flag.getDNF(); dnfterms=dflag.size(); -- 2.34.1