e929260ae459693532c9873f1d62dd7ee91a3733
[IRC.git] / Robust / src / Runtime / runtime.h
1 #ifndef RUNTIME
2 #define RUNTIME
3 #include <setjmp.h>
4 extern jmp_buf error_handler;
5 extern int instructioncount;
6 extern int failurecount;
7 #ifdef DSTM
8 #include "dstm.h"
9 #endif
10
11 extern void * curr_heapbase;
12 extern void * curr_heaptop;
13
14 #define TAGARRAYINTERVAL 10
15 #define OBJECTARRAYINTERVAL 10
16
17 #define ARRAYSET(array, type, index, value) \
18 ((type *)(&(& array->___length___)[1]))[index]=value
19
20 #define ARRAYGET(array, type, index) \
21 ((type *)(&(& array->___length___)[1]))[index]
22
23 #ifdef OPTIONAL
24 #define OPTARG(x) , x
25 #else
26 #define OPTARG(x)
27 #endif
28
29 #ifdef DSTM
30 void * allocate_newglobal(transrecord_t *, int type);
31 struct ArrayObject * allocate_newarrayglobal(transrecord_t *, int type, int length);
32 #endif
33
34 #ifdef PRECISE_GC
35 #include "garbage.h"
36 void * allocate_new(void *, int type);
37 struct ArrayObject * allocate_newarray(void *, int type, int length);
38 struct ___String___ * NewString(void *, const char *str,int length);
39 struct ___TagDescriptor___ * allocate_tag(void *ptr, int index);
40 #else
41 void * allocate_new(int type);
42 struct ArrayObject * allocate_newarray(int type, int length);
43 struct ___String___ * NewString(const char *str,int length);
44 struct ___TagDescriptor___ * allocate_tag(int index);
45 #endif
46
47
48
49 void initializeexithandler();
50 void failedboundschk();
51 void failednullptr();
52 void abort_task();
53 void injectinstructionfailure();
54 void createstartupobject();
55
56 #ifdef PRECISE_GC
57 #define VAR(name) ___params___->name
58 #define CALL00(name) name(struct name ## _params * ___params___)
59 #define CALL01(name, alt) name(struct name ## _params * ___params___)
60 #define CALL02(name, alt1, alt2) name(struct name ## _params * ___params___)
61 #define CALL11(name,rest, alt) name(struct name ## _params * ___params___, rest)
62 #define CALL12(name,rest, alt1, alt2) name(struct name ## _params * ___params___, rest)
63 #define CALL22(name, rest, rest2, alt1, alt2) name(struct name ## _params * ___params___, rest, rest2)
64 #define CALL23(name, rest, rest2, alt1, alt2, alt3) name(struct name ## _params * ___params___, rest, rest2)
65 #define CALL24(name, rest, rest2, alt1, alt2, alt3, alt4) name(struct name ## _params * ___params___, rest, rest2)
66 #define CALL34(name, rest, rest2, rest3, alt1, alt2, alt3, alt4) name(struct name ## _params * ___params___, rest, rest2, rest3)
67 #else
68 #define VAR(name) name
69 #define CALL00(name) name()
70 #define CALL01(name, alt) name(alt)
71 #define CALL02(name, alt1, alt2) name(alt1, alt2)
72 #define CALL11(name,rest, alt) name(alt)
73 #define CALL12(name,rest, alt1, alt2) name(alt1, alt2)
74 #define CALL22(name, rest, rest2, alt1, alt2) name(alt1, alt2)
75 #define CALL23(name, rest, rest2, alt1, alt2, alt3) name(alt1, alt2, alt3)
76 #define CALL24(name, rest, rest2, alt1, alt2, alt3, alt4) name(alt1, alt2, alt3, alt4)
77 #define CALL34(name, rest, rest2, rest3, alt1, alt2, alt3, alt4) name(alt1, alt2, alt3, alt4)
78 #endif
79
80 #ifdef TASK
81 #include "SimpleHash.h"
82 #ifndef MULTICORE
83 #include "ObjectHash.h"
84 #include "structdefs.h"
85 #endif
86 #include "task.h"
87 #ifdef OPTIONAL
88 #include "optionalstruct.h"
89 #endif
90
91 #ifdef OPTIONAL
92 struct failedtasklist {
93   struct taskdescriptor *task;
94   int index;
95   int numflags;
96   int *flags;
97   struct failedtasklist *next;
98 };
99 #endif
100
101 #ifdef MULTICORE
102 void flagorand(void * ptr, int ormask, int andmask, struct parameterwrapper ** queues, int length);
103 void flagorandinit(void * ptr, int ormask, int andmask);
104 void enqueueObject(void * ptr, struct parameterwrapper ** queues, int length);
105 #else
106 void flagorand(void * ptr, int ormask, int andmask);
107 void flagorandinit(void * ptr, int ormask, int andmask);
108 void enqueueObject(void * ptr);
109 #endif
110 void executetasks();
111 void processtasks();
112
113 #ifdef MULTICORE
114 void transferObject(void * ptr, int targetcore);
115 #endif
116
117 #ifndef MULTICORE
118 struct tagobjectiterator {
119   int istag; /* 0 if object iterator, 1 if tag iterator */
120   struct ObjectIterator it; /* Object iterator */
121   struct ObjectHash * objectset;
122 #ifdef OPTIONAL
123   int failedstate;
124 #endif
125   int slot;
126   int tagobjindex; /* Index for tag or object depending on use */
127   /*if tag we have an object binding */
128   int tagid;
129   int tagobjectslot;
130   /*if object, we may have one or more tag bindings */
131   int numtags;
132   int tagbindings[MAXTASKPARAMS-1]; /* list slots */
133 };
134
135 struct parameterwrapper {
136   struct parameterwrapper *next;
137   struct ObjectHash * objectset;
138   int numberofterms;
139   int * intarray;
140   int numbertags;
141   int * tagarray;
142   struct taskdescriptor * task;
143   int slot;
144   struct tagobjectiterator iterators[MAXTASKPARAMS-1];
145 };
146 #endif
147
148 struct taskparamdescriptor {
149   struct taskdescriptor * task;
150   int numParameters;
151   void ** parameterArray;
152 #ifdef OPTIONAL
153   int * failed;
154 #endif
155 };
156
157 int hashCodetpd(struct taskparamdescriptor *);
158 int comparetpd(struct taskparamdescriptor *, struct taskparamdescriptor *);
159
160 void toiReset(struct tagobjectiterator * it);
161 int toiHasNext(struct tagobjectiterator *it, void ** objectarray OPTARG(int * failed));
162 void toiNext(struct tagobjectiterator *it , void ** objectarray OPTARG(int * failed));
163 void processobject(struct parameterwrapper *parameter, int index, struct parameterdescriptor *pd, int *iteratorcount, int * statusarray, int numparams);
164 void processtags(struct parameterdescriptor *pd, int index, struct parameterwrapper *parameter, int * iteratorcount, int *statusarray, int numparams);
165 void builditerators(struct taskdescriptor * task, int index, struct parameterwrapper * parameter);
166 int enqueuetasks(struct parameterwrapper *parameter, struct parameterwrapper *prevptr, struct ___Object___ *ptr, int * enterflags, int numenterflags);
167
168 #endif
169
170 #endif