public static String arraytype="ArrayObject";
Virtual virtualcalls;
TypeUtil typeutil;
-
+ private int maxtaskparams=0;
public BuildCode(State st, Hashtable temptovar, TypeUtil typeutil) {
state=st;
outtask.println("int type;");
outtask.println("int numberterms;");
outtask.println("int *intarray;");
+ outtask.println("void * queue;");
outtask.println("};");
outtask.println("struct taskdescriptor {");
ClassDescriptor cn=(ClassDescriptor)it.next();
generateCallStructs(cn, outclassdefs, outstructs, outmethodheader);
}
- outstructs.close();
+
if (state.TASK) {
/* Map flags to integers */
}
outmethod.println("}");
}
+ if (state.TASK)
+ outstructs.println("#define MAXTASKPARAMS "+maxtaskparams);
+ outstructs.close();
outmethod.close();
}
output.println("struct parameterdescriptor parameter_"+i+"_"+task.getSafeSymbol()+"={");
output.println("/* type */"+param_type.getClassDesc().getId()+",");
output.println("/* number of DNF terms */"+dflag.size()+",");
- output.println("parameterdnf_"+i+"_"+task.getSafeSymbol());
+ output.println("parameterdnf_"+i+"_"+task.getSafeSymbol()+",");
+ output.println("0");
output.println("};");
}
/* 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++) {
output.println(" struct "+temp.getType().getSafeSymbol()+" * "+temp.getSafeSymbol()+";");
}
output.println("};\n");
+ if (objectparams.numPointers()>maxtaskparams)
+ maxtaskparams=objectparams.numPointers();
}
/* Output temp structure */
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)
- 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());
- }
+ } else
+ headersout.print("void * parameterarray[]");
headersout.println(");\n");
}
}
generateHeader(md!=null?md:task,output);
/* Print code */
- output.println(" {");
if (GENERATEPRECISEGC) {
if (md!=null)
printcomma=true;
}
- for(int i=0;i<objectparams.numPrimitives();i++) {
- TempDescriptor temp=objectparams.getPrimitive(i);
- if (printcomma)
- output.print(", ");
- printcomma=true;
- if (temp.getType().isClass()||temp.getType().isArray())
- output.print("struct "+temp.getType().getSafeSymbol()+" * "+temp.getSafeSymbol());
- else
- output.print(temp.getType().getSafeSymbol()+" "+temp.getSafeSymbol());
- }
- output.print(")");
+ if (md!=null) {
+ for(int i=0;i<objectparams.numPrimitives();i++) {
+ TempDescriptor temp=objectparams.getPrimitive(i);
+ if (printcomma)
+ output.print(", ");
+ printcomma=true;
+ if (temp.getType().isClass()||temp.getType().isArray())
+ output.print("struct "+temp.getType().getSafeSymbol()+" * "+temp.getSafeSymbol());
+ else
+ output.print(temp.getType().getSafeSymbol()+" "+temp.getSafeSymbol());
+ }
+ output.println(") {");
+ } else if (!GENERATEPRECISEGC) {
+ output.println("void * parameterarray[]) {");
+ for(int i=0;i<objectparams.numPrimitives();i++) {
+ TempDescriptor temp=objectparams.getPrimitive(i);
+ output.println("struct "+temp.getType().getSafeSymbol()+" * "+temp.getSafeSymbol()+"=parameterarray["+i+"];");
+ }
+ if (objectparams.numPrimitives()>maxtaskparams)
+ maxtaskparams=objectparams.numPrimitives();
+ } else output.println(" {");
}
public void generateFlatFlagActionNode(FlatMethod fm, FlatFlagActionNode ffan, PrintWriter output) {
#include <string.h>
extern int classsize[];
-#ifdef BOEHM_GC
-#include "gc.h"
-#define FREEMALLOC(x) GC_malloc(x)
-#else
-#define FREEMALLOC(x) calloc(1,x)
-#endif
+#include "mem.h"
#ifdef TASK
-#include "tasks.h"
+#include "Queue.h"
+#include "SimpleHash.h"
+#include "task.h"
+struct SimpleHash * activetasks;
+struct parameterwrapper * objectqueues[NUMCLASSES];
int main(int argc, char **argv) {
int i;
/* Allocate startup object */
struct ___StartupObject___ *startupobject=(struct ___StartupObject___*) allocate_new(STARTUPTYPE);
+ struct ArrayObject * stringarray=allocate_newarray(STRINGARRAYTYPE, argc);
+
+ activetasks=allocateSimpleHash(50);
+
/* Set flags */
+ processtasks();
flagorand(startupobject,1,0xFFFFFFFF);
/* Build array of strings */
- struct ArrayObject * stringarray=allocate_newarray(STRINGARRAYTYPE, argc);
+
startupobject->___parameters___=stringarray;
for(i=0;i<argc;i++) {
struct ___String___ *newstring=NewString(argv[i],length);
((void **)(((char *)& stringarray->___length___)+sizeof(int)))[i]=newstring;
}
- processtasks();
+ executetasks();
}
void flagorand(void * ptr, int ormask, int andmask) {
- ((int *)ptr)[1]|=ormask;
- ((int *)ptr)[1]&=andmask;
+ int flag=((int *)ptr)[1];
+ struct QueueItem *flagptr=(struct QueueItem *)(((int*)ptr)[2]);
+ flag|=ormask;
+ flag&=andmask;
+ ((int*)ptr)[1]=flag;
+ /*Remove from all queues */
+ while(flagptr!=NULL) {
+ struct QueueItem * next=flagptr->nextqueue;
+ removeItem(flagptr->queue, flagptr);
+ flagptr=next;
+ }
+
+ {
+ struct QueueItem *tmpptr;
+ struct parameterwrapper * parameter=objectqueues[((int *)ptr)[0]];
+ int i;
+ flagptr=NULL;
+ for(i=0;i<parameter->numberofterms;i++) {
+ int andmask=parameter->intarray[i*2];
+ int checkmask=parameter->intarray[i*2+1];
+ if ((flag&andmask)==checkmask) {
+ struct QueueItem * qitem=addNewItem(parameter->queue, ptr);
+ if (flagptr==NULL) {
+ flagptr=qitem;
+ tmpptr=flagptr;
+ } else {
+ tmpptr->nextqueue=qitem;
+ tmpptr=qitem;
+ }
+ SimpleHashadd(activetasks, (int)parameter->task, (int)parameter->task);
+ break;
+ }
+ }
+ ((struct QueueItem **)ptr)[2]=flagptr;
+ }
+}
+
+void executetasks() {
+ void * pointerarray[MAXTASKPARAMS];
+ while(1) {
+ newtask:
+ {
+ struct taskdescriptor * task=(struct taskdescriptor *) SimpleHashfirstkey(activetasks);
+ int i;
+ if (task==NULL)
+ break;
+ for(i=0;i<task->numParameters;i++) {
+ struct parameterwrapper * parameter=(struct parameterwrapper *) task->descriptorarray[i]->queue;
+ struct Queue * queue=parameter->queue;
+ if (isEmpty(queue)) {
+ SimpleHashremove(activetasks, (int)task, (int)task);
+ goto newtask;
+ }
+ pointerarray[i]=getTail(queue)->objectptr;
+ }
+ ((void (*) (void **)) task->taskptr)(pointerarray);
+ }
+ }
}
void processtasks() {
int i;
-
for(i=0;i<numtasks;i++) {
struct taskdescriptor * task=taskarray[i];
int j;
for(j=0;j<task->numParameters;j++) {
struct parameterdescriptor *param=task->descriptorarray[j];
-
+ struct parameterwrapper * parameter=RUNMALLOC(sizeof(struct parameterwrapper));
+ struct parameterwrapper ** ptr=&objectqueues[param->type];
+
+ param->queue=parameter;
+ parameter->queue=createQueue();
+ parameter->numberofterms=param->numberterms;
+ parameter->intarray=param->intarray;
+ parameter->task=task;
+ /* Link new queue in */
+ while(*ptr!=NULL)
+ ptr=&((*ptr)->next);
+ (*ptr)=parameter;
}
}
-
}
#endif
#ifndef RUNTIME
#define RUNTIME
-#include<stdlib.h>
-#include<stdio.h>
void * allocate_new(int type);
void failedboundschk();
void failednullptr();
+
+#ifdef TASK
+#include "Queue.h"
void flagorand(void * ptr, int ormask, int andmask);
+void executetasks();
+void processtasks();
+struct parameterwrapper {
+ struct parameterwrapper *next;
+ struct Queue * queue;
+ int numberofterms;
+ int * intarray;
+ struct taskdescriptor * task;
+}
+#endif
#endif
shift
mkdir tmpbuilddirectory
java -cp $ROBUSTROOT/../cup/:$ROBUSTROOT Main.Main -classlibrary $ROBUSTROOT/ClassLibrary/ -dir tmpbuilddirectory -task $@
-gcc -I$ROBUSTROOT/Runtime -Itmpbuilddirectory -O0 -DTASK -g tmpbuilddirectory/methods.c $ROBUSTROOT/Runtime/runtime.c -o $MAINFILE.bin
\ No newline at end of file
+gcc -I$ROBUSTROOT/Runtime -Itmpbuilddirectory -O0 -DTASK -g tmpbuilddirectory/methods.c $ROBUSTROOT/Runtime/runtime.c $ROBUSTROOT/Runtime/Queue.c $ROBUSTROOT/Runtime/SimpleHash.c -o $MAINFILE.bin
\ No newline at end of file