Mercurial > hg > Members > tobaru > CbC_xv6
comparison src/gearsTools/generate_context.pl @ 52:214d21c891c7
rename to cbc
__ncode is not handled as interfaces
author | kono |
---|---|
date | Mon, 03 Jun 2019 18:12:44 +0900 |
parents | 233a68a261fe |
children | 435bfab09924 |
comparison
equal
deleted
inserted
replaced
51:fadfd62d6b14 | 52:214d21c891c7 |
---|---|
7 # generrate Gears OS context heaader and initializer from CbC sources | 7 # generrate Gears OS context heaader and initializer from CbC sources |
8 # | 8 # |
9 # CodeGear | 9 # CodeGear |
10 # | 10 # |
11 # get stub information from # *.c | 11 # get stub information from # *.c |
12 # __code taskManager_stub(struct Context* context) { | 12 # __code taskManager_stub(struct Context* cbc_context) { |
13 # | 13 # |
14 # generate CodeGear indexn in context.h | 14 # generate CodeGear indexn in context.h |
15 # C_taskManager, | 15 # C_taskManager, |
16 # | 16 # |
17 # generate CodeGear stub reference in context.h | 17 # generate CodeGear stub reference in context.h |
18 # extern __code taskManager_stub(struct Context*); | 18 # extern __code taskManager_stub(struct Context*); |
19 # | 19 # |
20 # generate CodeGear stub reference in $name-context.h for each module | 20 # generate CodeGear stub reference in $name-context.h for each module |
21 # context->code[C_taskManager] = taskManager_stub; | 21 # cbc_context->code[C_taskManager] = taskManager_stub; |
22 # | 22 # |
23 # DataGear | 23 # DataGear |
24 # | 24 # |
25 # get DataGear information from context.h | 25 # get DataGear information from context.h |
26 # struct Worker { | 26 # struct Worker { |
83 | 83 |
84 sub getStubInfo { | 84 sub getStubInfo { |
85 my ($filename) = @_; | 85 my ($filename) = @_; |
86 open my $fd,"<",$filename or die("can't open $filename $!"); | 86 open my $fd,"<",$filename or die("can't open $filename $!"); |
87 while (<$fd>) { | 87 while (<$fd>) { |
88 if (/^__code (\w+)_stub\(struct *Context *\* *context\)/) { | 88 if (/^__code (\w+)_stub\(struct *Context *\* *cbc_context\)/) { |
89 $codeGear{$1} = $filename; | 89 $codeGear{$1} = $filename; |
90 } elsif (/^(\w+)(\*)+ *create(\w+)\(([^]]*)\)/) { | 90 } elsif (/^(\w+)(\*)+ *create(\w+)\(([^]]*)\)/) { |
91 my $interface = $1; | 91 my $interface = $1; |
92 my $implementation = $3; | 92 my $implementation = $3; |
93 my $constructorArgs = $4; | 93 my $constructorArgs = $4; |
136 } | 136 } |
137 print $fd "};\n"; | 137 print $fd "};\n"; |
138 | 138 |
139 my $code_init = ''; | 139 my $code_init = ''; |
140 for my $code ( sort keys %mCodeGear ) { | 140 for my $code ( sort keys %mCodeGear ) { |
141 $code_init .= " context->code[C_${code}] = ${code}_stub;\n"; | 141 $code_init .= " cbc_context->code[C_${code}] = ${code}_stub;\n"; |
142 } | 142 } |
143 | 143 |
144 my $data_num = keys(%dataGear); | 144 my $data_num = keys(%dataGear); |
145 $data_num++; | 145 $data_num++; |
146 my $context_c = << "EOFEOF"; | 146 my $context_c = << "EOFEOF"; |
148 #include <stdlib.h> | 148 #include <stdlib.h> |
149 #endif | 149 #endif |
150 | 150 |
151 #include "../context.h" | 151 #include "../context.h" |
152 | 152 |
153 void initContext(struct Context* context) { | 153 void initContext(struct Context* cbc_context) { |
154 context->heapLimit = sizeof(union Data)*ALLOCATE_SIZE; | 154 cbc_context->heapLimit = sizeof(union Data)*ALLOCATE_SIZE; |
155 context->code = (__code(**) (struct Context*)) NEWN(ALLOCATE_SIZE, void*); | 155 cbc_context->code = (__code(**) (struct Context*)) NEWN(ALLOCATE_SIZE, void*); |
156 context->data = NEWN(ALLOCATE_SIZE, union Data*); | 156 cbc_context->data = NEWN(ALLOCATE_SIZE, union Data*); |
157 context->heapStart = NEWN(context->heapLimit, char); | 157 cbc_context->heapStart = NEWN(cbc_context->heapLimit, char); |
158 context->heap = context->heapStart; | 158 cbc_context->heap = cbc_context->heapStart; |
159 // context->codeNum = Exit; | 159 // cbc_context->codeNum = Exit; |
160 | 160 |
161 $code_init | 161 $code_init |
162 | 162 |
163 #include "dataGearInit.c" | 163 #include "dataGearInit.c" |
164 context->dataNum = $data_num; | 164 cbc_context->dataNum = $data_num; |
165 } | 165 } |
166 EOFEOF | 166 EOFEOF |
167 | 167 |
168 open my $fd,">","$ddir/$name-context.c" or die("can't open $ddir/$name-context.c $!"); | 168 open my $fd,">","$ddir/$name-context.c" or die("can't open $ddir/$name-context.c $!"); |
169 print $fd $context_c; | 169 print $fd $context_c; |
170 | 170 |
171 my $meta_call = <<"EOFEOF"; | 171 my $meta_call = <<"EOFEOF"; |
172 __code meta(struct Context* context, enum Code next) { | 172 __code meta(struct Context* cbc_context, enum Code next) { |
173 // printf("meta %d\\n",next); | 173 // printf("meta %d\\n",next); |
174 goto (context->code[next])(context); | 174 goto (cbc_context->code[next])(cbc_context); |
175 } | 175 } |
176 | 176 |
177 __code parGotoMeta(struct Context* context, enum Code next) { | 177 __code parGotoMeta(struct Context* cbc_context, enum Code next) { |
178 context->task = NULL; | 178 cbc_context->task = NULL; |
179 context->taskList = NULL; | 179 cbc_context->taskList = NULL; |
180 goto (context->code[Gearef(context, TaskManager)->taskManager->TaskManager.spawnTasks])(context); | 180 goto (cbc_context->code[Gearef(context, TaskManager)->taskManager->TaskManager.spawnTasks])(cbc_context); |
181 } | 181 } |
182 | 182 |
183 __code start_code(struct Context* context) { | 183 __code start_code(struct Context* cbc_context) { |
184 goto meta(context, context->next); | 184 goto meta(context, cbc_context->next); |
185 } | 185 } |
186 | 186 |
187 __code start_code_stub(struct Context* context) { | 187 __code start_code_stub(struct Context* cbc_context) { |
188 goto start_code(context); | 188 goto start_code(cbc_context); |
189 } | 189 } |
190 | 190 |
191 __code exit_code(struct Context* context) { | 191 __code exit_code(struct Context* cbc_context) { |
192 free(context->code); | 192 free(cbc_context->code); |
193 free(context->data); | 193 free(cbc_context->data); |
194 free(context->heapStart); | 194 free(cbc_context->heapStart); |
195 goto exit(0); | 195 goto exit(0); |
196 } | 196 } |
197 | 197 |
198 __code exit_code_stub(struct Context* context) { | 198 __code exit_code_stub(struct Context* cbc_context) { |
199 goto exit_code(context); | 199 goto exit_code(cbc_context); |
200 } | 200 } |
201 | 201 |
202 // end context_c | 202 // end context_c |
203 EOFEOF | 203 EOFEOF |
204 | 204 |
219 } | 219 } |
220 } | 220 } |
221 | 221 |
222 open my $fd,">","$ddir/dataGearInit.c" or die("can't open $ddir/dataGearInit.c $!"); | 222 open my $fd,">","$ddir/dataGearInit.c" or die("can't open $ddir/dataGearInit.c $!"); |
223 for my $data ( sort keys %dataGear ) { | 223 for my $data ( sort keys %dataGear ) { |
224 print $fd " ALLOC_DATA(context, ${data});\n"; | 224 print $fd " ALLOC_DATA(cbc_context, ${data});\n"; |
225 } | 225 } |
226 } | 226 } |
227 | 227 |
228 # end | 228 # end |