Added environment options.
authorbdemsky <bdemsky>
Wed, 1 Nov 2006 23:21:03 +0000 (23:21 +0000)
committerbdemsky <bdemsky>
Wed, 1 Nov 2006 23:21:03 +0000 (23:21 +0000)
Use
export BRISTLECONE="-debugtask" to print out debug information.

Robust/src/IR/Flat/BuildCode.java
Robust/src/IR/State.java
Robust/src/Main/Main.java
Robust/src/Runtime/runtime.c
Robust/src/buildscripttaskdebug [deleted file]

index 809fd147b9dd7bcb85713245acd80c52d22d576a..c3b05d5c84089fdc8ee9e2a6f33a4fa4052b43b4 100644 (file)
@@ -131,6 +131,7 @@ public class BuildCode {
                outtask.println("void * taskptr;");
                outtask.println("int numParameters;");
                outtask.println("struct parameterdescriptor **descriptorarray;");
+               outtask.println("char * name;");
                outtask.println("};");
                outtask.println("extern struct taskdescriptor * taskarray[];");
                outtask.println("extern numtasks;");
@@ -205,18 +206,22 @@ public class BuildCode {
                generateTaskDescriptor(outtaskdefs, td);
            }
 
-           taskit=state.getTaskSymbolTable().getDescriptorsIterator();
-           outtaskdefs.println("struct taskdescriptor * taskarray[]= {");
-           boolean first=true;
-           while(taskit.hasNext()) {
-               TaskDescriptor td=(TaskDescriptor)taskit.next();
-               if (first)
-                   first=false;
-               else
-                   outtaskdefs.println(",");
-               outtaskdefs.print("&task_"+td.getSafeSymbol());
+           {
+               //Output task descriptors
+               taskit=state.getTaskSymbolTable().getDescriptorsIterator();
+               outtaskdefs.println("struct taskdescriptor * taskarray[]= {");
+               boolean first=true;
+               while(taskit.hasNext()) {
+                   TaskDescriptor td=(TaskDescriptor)taskit.next();
+                   if (first)
+                       first=false;
+                   else
+                       outtaskdefs.println(",");
+                   outtaskdefs.print("&task_"+td.getSafeSymbol());
+               }
+               outtaskdefs.println("};");
            }
-           outtaskdefs.println("};");
+
            outtaskdefs.println("int numtasks="+state.getTaskSymbolTable().getValueSet().size()+";");
 
        } else if (state.main!=null) {
@@ -366,7 +371,8 @@ public class BuildCode {
        output.println("struct taskdescriptor task_"+task.getSafeSymbol()+"={");
        output.println("&"+task.getSafeSymbol()+",");
        output.println("/* number of parameters */" +task.numParameters() + ",");
-       output.println("parameterdescriptors_"+task.getSafeSymbol());
+       output.println("parameterdescriptors_"+task.getSafeSymbol()+",");
+       output.println("\""+task.getSymbol()+"\"");
        output.println("};");
     }
 
@@ -848,8 +854,6 @@ public class BuildCode {
                }
            }
        }
-       if (task!=null&&state.TASKDEBUG)
-           output.println("printf(\"ENTER "+task.getSymbol()+"\\n\");");
 
        //Do the actual code generation
        tovisit=new HashSet();
@@ -867,8 +871,6 @@ public class BuildCode {
                output.print("   ");
                generateFlatNode(fm, current_node, output);
                if (current_node.kind()!=FKind.FlatReturnNode) {
-                   if (task!=null&&state.TASKDEBUG)
-                       output.println("printf(\"EXIT "+task.getSymbol()+"\\n\");");
                    output.println("   return;");
                }
                current_node=null;
@@ -1198,8 +1200,6 @@ public class BuildCode {
 
     private void generateFlatReturnNode(FlatMethod fm, FlatReturnNode frn, PrintWriter output) {
        
-       if (fm.getTask()!=null&&state.TASKDEBUG)
-           output.println("printf(\"EXIT "+fm.getTask().getSymbol()+"\\n\");");
        if (frn.getReturnTemp()!=null)
            output.println("return "+generateTemp(fm, frn.getReturnTemp())+";");
        else
index 4797a6bef03541cfa81636c0c854d4f502d0c262..a40ed70d3b675d649db6dff2b39baa82d6000fbd 100644 (file)
@@ -22,7 +22,6 @@ public class State {
     /** Boolean flag which indicates whether compiler is compiling a task-based
      * program. */
     public boolean TASK;
-    public boolean TASKDEBUG;
     public String structfile;
     public String main;
     public boolean CONSCHECK=false;
index 9ccb839e3f9e0a1aa3fe9c1ae99cc9c4fa069178..75487a3f315006a66b1bdb6df308c07343eebae5 100644 (file)
@@ -33,8 +33,6 @@ public class Main {
              state.CONSCHECK=true;
          else if (option.equals("-task"))
              state.TASK=true;
-         else if (option.equals("-taskdebug"))
-             state.TASKDEBUG=true;
          else if (option.equals("-help")) {
              System.out.println("-classlibrary classlibrarydirectory -- directory where classlibrary is located");
              System.out.println("-dir outputdirectory -- output code in outputdirectory");
index 05e014c487ff1ce6126f8a5cffc6f885c546e579..86d4e0717e580052f46abd8d0bfbdd217748deb8 100644 (file)
@@ -30,12 +30,49 @@ jmp_buf error_handler;
 struct Queue * activetasks;
 struct parameterwrapper * objectqueues[NUMCLASSES];
 struct genhashtable * failedtasks;
+extern char ** environ;
+char *options;
+int injectfailures=0;
+float failurechance=0;
+int debugtask=0;
 
 int main(int argc, char **argv) {
   GC_init();
 #ifdef CONSCHECK
   initializemmap();
 #endif
+  {
+    int i;
+    options=NULL;
+    for(i=0;environ[i]!=0;i++) {
+      if (strncmp(environ[i],"BRISTLECONE=",12)==0) {
+       options=environ[i]+12;
+       break;
+      }
+    }
+
+    while(options!=NULL) {
+      if (strncmp(options,"-injectfailures",sizeof("-injectfailures")-1)==0) {
+       options=strchr(options,' ');
+       if (options!=NULL) options++;
+       if (options==NULL)
+         break;
+       sscanf(options, "%f", &failurechance);
+       injectfailures=1;
+       printf("Injecting errors with chance=%f\n",failurechance);
+       options=strchr(options,' ');
+       if (options!=NULL) options++;
+      } else if (strncmp(options, "-debugtask",sizeof("-debugtask")-1)==0) {
+       options=strchr(options,' ');
+       if (options!=NULL) options++;
+       debugtask=1;
+       printf("Debug task option on\n");
+      } else
+       break;
+    }
+  }
+
+
   {
   int i;
   /* Allocate startup object */
@@ -268,17 +305,29 @@ void executetasks() {
        struct RuntimeHash * forward=allocateRuntimeHash(100);
        struct RuntimeHash * reverse=allocateRuntimeHash(100);
        void ** checkpoint=makecheckpoint(tpd->task->numParameters, taskpointerarray, forward, reverse);
-       if (setjmp(error_handler)) {
+       int x;
+       if (x=setjmp(error_handler)) {
          /* Recover */
          int h;
 #ifdef DEBUG
-         printf("Fatal Error! Recovering!\n");
+         printf("Fatal Error=%d, Recovering!\n",x);
 #endif
          genputtable(failedtasks,tpd,tpd);
          restorecheckpoint(tpd->task->numParameters, taskpointerarray, checkpoint, forward, reverse);
        } else {
+         if (injectfailures) {
+           if ((((double)random())/RAND_MAX)<failurechance) {
+             printf("\nINJECTING TASK FAILURE to %s\n", tpd->task->name);
+             longjmp(error_handler,10);
+           }
+         }
          /* Actually call task */
-         ((void (*) (void **)) tpd->task->taskptr)(taskpointerarray);
+         if (debugtask) {
+           printf("ENTER %s\n",tpd->task->name);
+           ((void (*) (void **)) tpd->task->taskptr)(taskpointerarray);
+           printf("EXIT %s\n",tpd->task->name);
+         } else
+           ((void (*) (void **)) tpd->task->taskptr)(taskpointerarray);
        }
       }
     }
diff --git a/Robust/src/buildscripttaskdebug b/Robust/src/buildscripttaskdebug
deleted file mode 100755 (executable)
index ab704ab..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-#!/bin/bash
-ROBUSTROOT=~/research/Robust/src
-MAINFILE=$1
-shift
-mkdir tmpbuilddirectory
-java -cp $ROBUSTROOT/../cup/:$ROBUSTROOT Main.Main -classlibrary $ROBUSTROOT/ClassLibrary/ -dir tmpbuilddirectory -struct $MAINFILE -task -taskdebug $@
-#gcc -I$ROBUSTROOT/Runtime -Itmpbuilddirectory -O0 -DTASK -g tmpbuilddirectory/methods.c tmpbuilddirectory/taskdefs.c $ROBUSTROOT/Runtime/runtime.c $ROBUSTROOT/Runtime/Queue.c $ROBUSTROOT/Runtime/SimpleHash.c $ROBUSTROOT/Runtime/checkpoint.c $ROBUSTROOT/Runtime/GenericHashtable.c -o $MAINFILE.bin
-gcc -I$ROBUSTROOT/Runtime -I. -IRuntime/include -Itmpbuilddirectory -O0 -DBOEHM_GC -LRuntime/lib/ -lgc -DTASK -DDEBUG -g tmpbuilddirectory/methods.c tmpbuilddirectory/taskdefs.c $ROBUSTROOT/Runtime/runtime.c $ROBUSTROOT/Runtime/file.c $ROBUSTROOT/Runtime/Queue.c $ROBUSTROOT/Runtime/SimpleHash.c $ROBUSTROOT/Runtime/checkpoint.c $ROBUSTROOT/Runtime/GenericHashtable.c -o $MAINFILE.bin
\ No newline at end of file