split option processing into its own file
authorbdemsky <bdemsky>
Fri, 17 Nov 2006 23:51:05 +0000 (23:51 +0000)
committerbdemsky <bdemsky>
Fri, 17 Nov 2006 23:51:05 +0000 (23:51 +0000)
Robust/src/IR/Flat/BuildCode.java
Robust/src/Runtime/option.c [new file with mode: 0644]
Robust/src/Runtime/option.h [new file with mode: 0644]
Robust/src/Runtime/runtime.c
Robust/src/buildscript
Robust/src/buildscriptrepair
Robust/src/buildscripttask
Robust/src/buildscripttaskerror

index 340feef68ec6ad8643fb9b0638cc623dbb23ebb6..bbddb9871a2c51fbb73306451776b5d33a745f23 100644 (file)
@@ -110,8 +110,9 @@ public class BuildCode {
            //Print out definition for array type
            outclassdefs.println("struct "+arraytype+" {");
            outclassdefs.println("  int type;");
+           outclassdefs.println("  int flag;");
+               
            if (state.TASK) {
-               outclassdefs.println("  int flag;");
                outclassdefs.println("  void * flagptr;");
            }
            printClassStruct(typeutil.getClass(TypeUtil.ObjectClass), outclassdefs);
@@ -663,8 +664,9 @@ public class BuildCode {
        /* Output class structure */
        classdefout.println("struct "+cn.getSafeSymbol()+" {");
        classdefout.println("  int type;");
+       classdefout.println("  int flag;");
+
        if (state.TASK) {
-           classdefout.println("  int flag;");
            classdefout.println("  void * flagptr;");
        }
        printClassStruct(cn, classdefout);
diff --git a/Robust/src/Runtime/option.c b/Robust/src/Runtime/option.c
new file mode 100644 (file)
index 0000000..d1500d6
--- /dev/null
@@ -0,0 +1,78 @@
+#include "option.h"
+#include <stdio.h>
+#include <string.h>
+#include "runtime.h"
+
+extern char *options;
+extern int injectfailures;
+extern float failurechance;
+extern int debugtask;
+extern int injectinstructionfailures;
+extern int failurecount;
+extern float instfailurechance;
+extern int numfailures;
+extern int instaccum;
+extern char ** environ;
+
+void processOptions() {
+  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,"-injectinstructionfailures",sizeof("-injectinstructionfailures")-1)==0) {
+      options=strchr(options,' ');
+      if (options!=NULL) options++;
+      if (options==NULL)
+       break;
+      sscanf(options, "%d", &failurecount);
+      options=strchr(options,' ');
+      if (options!=NULL) options++;
+      if (options==NULL)
+       break;
+
+      sscanf(options, "%f", &instfailurechance);
+      options=strchr(options,' ');
+      if (options!=NULL) options++;
+      if (options==NULL)
+       break;
+
+      sscanf(options, "%d", &numfailures);
+      options=strchr(options,' ');
+      if (options!=NULL) options++;
+
+      instaccum=failurecount;
+      instructioncount=failurecount;
+      injectinstructionfailures=1;
+      printf("Number of failures=%d\n",numfailures);
+      printf("Injecting errors with count=%d\n",failurecount);
+      printf("Injecting errors with chance=%f\n",instfailurechance);
+    } 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 if (strncmp(options, "-initializerandom", sizeof("-initializerandom")-1)==0) {
+      options=strchr(options,' ');
+      if (options!=NULL) options++;
+      printf("Initializing random number generator.\n");
+      srandomdev();
+    } else
+      break;
+  }
+}
diff --git a/Robust/src/Runtime/option.h b/Robust/src/Runtime/option.h
new file mode 100644 (file)
index 0000000..f9cd7ac
--- /dev/null
@@ -0,0 +1,4 @@
+#ifdef OPTION_H
+#define OPTION_H
+void processOptions();
+#endif
index 635df0570fed23860366c9f125ae1621bfb5fbf7..4da7565e1a27a11f268d281d9ad212d7dbf6be41 100644 (file)
@@ -9,6 +9,7 @@
 #include<errno.h>
 #include<signal.h>
 #include<stdio.h>
+#include "option.h"
 
 extern int classsize[];
 jmp_buf error_handler;
@@ -28,8 +29,6 @@ int instructioncount;
 struct Queue * activetasks;
 struct parameterwrapper * objectqueues[NUMCLASSES];
 struct genhashtable * failedtasks;
-/*struct genhashtable * failedobjects;*/
-extern char ** environ;
 char *options;
 int injectfailures=0;
 float failurechance=0;
@@ -40,71 +39,10 @@ float instfailurechance=0;
 int numfailures;
 int instaccum=0;
 
-void processOptions() {
-  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,"-injectinstructionfailures",sizeof("-injectinstructionfailures")-1)==0) {
-      options=strchr(options,' ');
-      if (options!=NULL) options++;
-      if (options==NULL)
-       break;
-      sscanf(options, "%d", &failurecount);
-      options=strchr(options,' ');
-      if (options!=NULL) options++;
-      if (options==NULL)
-       break;
-
-      sscanf(options, "%f", &instfailurechance);
-      options=strchr(options,' ');
-      if (options!=NULL) options++;
-      if (options==NULL)
-       break;
-
-      sscanf(options, "%d", &numfailures);
-      options=strchr(options,' ');
-      if (options!=NULL) options++;
-
-      instaccum=failurecount;
-      instructioncount=failurecount;
-      injectinstructionfailures=1;
-      printf("Number of failures=%d\n",numfailures);
-      printf("Injecting errors with count=%d\n",failurecount);
-      printf("Injecting errors with chance=%f\n",instfailurechance);
-    } 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 if (strncmp(options, "-initializerandom", sizeof("-initializerandom")-1)==0) {
-      options=strchr(options,' ');
-      if (options!=NULL) options++;
-      printf("Initializing random number generator.\n");
-      srandomdev();
-    } else
-      break;
-  }
-}
-
 int main(int argc, char **argv) {
+#ifdef BOEHM_GC
   GC_init(); // Initialize the garbage collector
+#endif
 #ifdef CONSCHECK
   initializemmap();
 #endif
@@ -117,8 +55,6 @@ int main(int argc, char **argv) {
   struct ArrayObject * stringarray=allocate_newarray(STRINGARRAYTYPE, argc-1); 
   failedtasks=genallocatehashtable((unsigned int (*)(void *)) &hashCodetpd, 
                                   (int (*)(void *,void *)) &comparetpd);
-  /*  failedobjects=genallocatehashtable(NULL,NULL);*/
-  
   activetasks=createQueue();
 
   /* Set flags */
@@ -157,13 +93,17 @@ int comparetpd(struct taskparamdescriptor *ftd1, struct taskparamdescriptor *ftd
   return 1;
 }
 
+/* This function updates the flag for object ptr.  It or's the flag
+   with the or mask and and's it with the andmask. */
+
 void flagorand(void * ptr, int ormask, int andmask) {
   int flag=((int *)ptr)[1];
   struct RuntimeHash *flagptr=(struct RuntimeHash *)(((int*)ptr)[2]);
   flag|=ormask;
   flag&=andmask;
   ((int*)ptr)[1]=flag;
-  /*Remove from all queues */
+
+  /*Remove object from all queues */
   while(flagptr!=NULL) {
     struct RuntimeHash *next;
     RuntimeHashget(flagptr, (int) ptr, (int *) &next);
@@ -251,6 +191,7 @@ void flagorand(void * ptr, int ormask, int andmask) {
 
 /* Handler for signals. The signals catch null pointer errors and
    arithmatic errors. */
+
 void myhandler(int sig, siginfo_t *info, void *uap) {
 #ifdef DEBUG
   printf("sig=%d\n",sig);
@@ -278,40 +219,6 @@ void removereadfd(int fd) {
   }
 }
 
-/*
-void restoreObject(void * obj) {
-  if (gencontains(failedobjects, obj)) {
-    struct tpdlist *tpd=gengettable(failedobjects, obj);
-    genfreekey(failedobjects, obj);
-    while(tpd!=NULL) {
-      int i;
-      struct taskparamdescriptor *task=tpd->task;
-      genfreekey(failedtasks, task);
-      for(i=0;i<task->numParameters;i++) {
-       void *objother=task->parameterArray[i];
-       struct tpdlist *tpdother=gengettable(failedobjects, objother);
-       struct tpdlist *tmpptr;
-       genfreekey(failedobjects, objother);
-       struct tpdlist **tpdptr=&tpdother;
-       while((*tpdptr)->task!=task)
-         tpdptr=&((*tpdptr)->next);
-       tmpptr=*tpdptr;
-       (*tpdptr)=(*tpdptr)->next;
-       RUNFREE(tmpptr);
-       if (tpdother!=NULL)
-         genputtable(failedobjects, objother, tpdother);
-      }
-      RUNFREE(task);
-      {
-       struct tpdlist *old=tpd;
-       tpd=tpd->next;
-       RUNFREE(old);
-      }
-    }
-  }
-}
-*/
-
 #ifdef PRECISE_GC
 #define OFFSET 2
 #else
@@ -508,12 +415,16 @@ void CALL01(___System______printString____L___String___,struct ___String___ * __
     }
 }
 
+/* Object allocation function */
+
 void * allocate_new(int type) {
   void * v=FREEMALLOC(classsize[type]);
   *((int *)v)=type;
   return v;
 }
 
+/* Array allocation function */
+
 struct ArrayObject * allocate_newarray(int type, int length) {
   struct ArrayObject * v=FREEMALLOC(sizeof(struct ArrayObject)+length*classsize[type]);
   v->type=type;
@@ -521,6 +432,8 @@ struct ArrayObject * allocate_newarray(int type, int length) {
   return v;
 }
 
+/* Converts C character arrays into Java strings */
+
 struct ___String___ * NewString(const char *str,int length) {
   struct ArrayObject * chararray=allocate_newarray(CHARARRAYTYPE, length);
   struct ___String___ * strobj=allocate_new(STRINGTYPE);
@@ -535,6 +448,7 @@ struct ___String___ * NewString(const char *str,int length) {
 }
 
 /* Generated code calls this if we fail a bounds check */
+
 void failedboundschk() {
 #ifndef TASK
   printf("Array out of bounds\n");
@@ -544,6 +458,7 @@ void failedboundschk() {
 #endif
 }
 
+/* Abort task call */
 void abort_task() {
 #ifdef TASK
   longjmp(error_handler,4);
index d11b87c07f8026a7b4be576836cd0c889834b58d..973219b9cd55aaaa832cb4fb997940fc3cbb4eb2 100755 (executable)
@@ -4,4 +4,4 @@ MAINFILE=$1
 shift
 mkdir tmpbuilddirectory
 java -cp $ROBUSTROOT/../cup/:$ROBUSTROOT Main.Main -classlibrary $ROBUSTROOT/ClassLibrary/ -dir tmpbuilddirectory -precise -mainclass $MAINFILE $@
-gcc -I$ROBUSTROOT/Runtime -Itmpbuilddirectory -DPRECISE_GC -O0 -g tmpbuilddirectory/methods.c $ROBUSTROOT/Runtime/runtime.c  $ROBUSTROOT/Runtime/file.c -o $MAINFILE.bin
\ No newline at end of file
+gcc -I$ROBUSTROOT/Runtime -Itmpbuilddirectory -DPRECISE_GC -O0 -g tmpbuilddirectory/methods.c $ROBUSTROOT/Runtime/runtime.c $ROBUSTROOT/Runtime/file.c $ROBUSTROOT/Runtime/option.c -o $MAINFILE.bin
\ No newline at end of file
index b8db54f7e9a50479e69ab4a79eef2f1bc0c7de85..bcdf48ce9b8f7ab91dffcf97bbd0b07057cd97d0 100755 (executable)
@@ -66,5 +66,6 @@ $ROBUSTROOT/Runtime/file.c \
 $ROBUSTROOT/Runtime/socket.c \
 $ROBUSTROOT/Runtime/Queue.c $ROBUSTROOT/Runtime/SimpleHash.c \
 $ROBUSTROOT/Runtime/checkpoint.c \
+$ROBUSTROOT/Runtime/option.c \
 $ROBUSTROOT/Runtime/GenericHashtable.c $BUILDDIR/specdir/*.o -o \
 $MAINFILE.bin
index 6762801b6a86fc3b46f553ce2683c3e17bc4ef5f..93edffbca4396867702dd0e9b502b626c5f1735c 100755 (executable)
@@ -4,4 +4,4 @@ MAINFILE=$1
 shift
 mkdir tmpbuilddirectory
 java -cp $ROBUSTROOT/../cup/:$ROBUSTROOT Main.Main -classlibrary $ROBUSTROOT/ClassLibrary/ -dir tmpbuilddirectory -precise -struct $MAINFILE -task $@
-gcc -DPRECISE_GC -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/socket.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
+gcc -DPRECISE_GC -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/socket.c $ROBUSTROOT/Runtime/Queue.c $ROBUSTROOT/Runtime/SimpleHash.c $ROBUSTROOT/Runtime/checkpoint.c $ROBUSTROOT/Runtime/GenericHashtable.c $ROBUSTROOT/Runtime/option.c -o $MAINFILE.bin
\ No newline at end of file
index 054758032ecf946153a9a2db7b9777f3de593f4d..8b4be7cd61bdd395c7ae37a0b381de22f6cc8530 100755 (executable)
@@ -4,5 +4,4 @@ MAINFILE=$1
 shift
 mkdir tmpbuilddirectory
 java -cp $ROBUSTROOT/../cup/:$ROBUSTROOT Main.Main -classlibrary $ROBUSTROOT/ClassLibrary/ -dir tmpbuilddirectory -struct $MAINFILE -task -instructionfailures $@
-#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/socket.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
+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/socket.c $ROBUSTROOT/Runtime/Queue.c $ROBUSTROOT/Runtime/SimpleHash.c $ROBUSTROOT/Runtime/checkpoint.c $ROBUSTROOT/Runtime/GenericHashtable.c $ROBUSTROOT/Runtime/option.c -o $MAINFILE.bin
\ No newline at end of file