annotate src/parallel_execution/generate_context.pl @ 313:4addbc7469ee

fix
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Wed, 15 Feb 2017 11:36:10 +0900
parents 7dd5a7d52a67
children 0d720487291f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
186
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
1 #!/usr/bin/perl
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
2
210
ba56dab79dc4 separate code init for each executable
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 208
diff changeset
3 use Getopt::Std;
254
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
4 use strict;
186
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
5
254
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
6 #
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
7 # generrate Gears OS context heaader and initializer from CbC sources
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
8 #
186
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
9 # CodeGear
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
10 #
254
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
11 # get stub information from # *.c
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
12 # __code taskManager_stub(struct Context* context) {
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
13 #
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
14 # generate CodeGear indexn in context.h
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
15 # C_taskManager,
186
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
16 #
254
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
17 # generate CodeGear stub reference in context.h
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
18 # extern __code taskManager_stub(struct Context*);
186
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
19 #
254
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
20 # generate CodeGear stub reference in $name-context.h for each module
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
21 # context->code[C_taskManager] = taskManager_stub;
186
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
22 #
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
23 # DataGear
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
24 #
254
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
25 # get DataGear information from context.h
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
26 # struct Worker {
186
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
27 # int id;
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
28 # struct Context* contexts;
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
29 # enum Code execute;
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
30 # enum Code taskSend;
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
31 # enum Code taskRecive;
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
32 # enum Code shutdown;
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
33 # struct Queue* tasks;
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
34 # } Worker;
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
35 #
254
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
36 # generate typedefs and DataGear index in context.h
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
37 # typedef struct Worker Worker;
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
38 # D_Worker,
186
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
39 #
254
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
40 # generate DataGear allocator in context.h
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
41 # ALLOC_DATA(context, Worker);
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
42 #
186
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
43
254
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
44 my $ddir = "c";
186
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
45
254
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
46 our($opt_o,$opt_d,$opt_h);
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
47 getopts('o:d:h');
210
ba56dab79dc4 separate code init for each executable
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 208
diff changeset
48
284
e6bc0a4c2c36 generate C_start_code and C_exit_code
mir3636
parents: 280
diff changeset
49 my $name = $opt_o?$opt_o:"gears";
210
ba56dab79dc4 separate code init for each executable
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 208
diff changeset
50
254
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
51 if ($opt_d) {
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
52 $ddir = $opt_d;
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
53 }
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
54
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
55 if ( ! -d $ddir) {
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
56 mkdir $ddir;
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
57 }
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
58
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
59 if ($opt_h) {
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
60 print "$0 [-d distdir] [-h]\n";
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
61 exit;
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
62 }
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
63
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
64 my %codeGear;
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
65 my %dataGear;
277
9d671e63df74 generate extern
mir3636
parents: 259
diff changeset
66 my %constructor;
254
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
67
259
195518ab62fc fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 257
diff changeset
68 # gather module Information for code table initialization
210
ba56dab79dc4 separate code init for each executable
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 208
diff changeset
69 for (@ARGV) {
ba56dab79dc4 separate code init for each executable
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 208
diff changeset
70 next if (/context.c/);
ba56dab79dc4 separate code init for each executable
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 208
diff changeset
71 &getStubInfo($_);
ba56dab79dc4 separate code init for each executable
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 208
diff changeset
72 }
ba56dab79dc4 separate code init for each executable
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 208
diff changeset
73
ba56dab79dc4 separate code init for each executable
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 208
diff changeset
74 my (%mCodeGear) = (%codeGear);
ba56dab79dc4 separate code init for each executable
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 208
diff changeset
75
259
195518ab62fc fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 257
diff changeset
76 # anyway we gather all Gears Information
195518ab62fc fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 257
diff changeset
77 while (<*.c test/*.c>) {
257
cd3486e4ba70 fix make error of twice
mir3636
parents: 254
diff changeset
78 next if (/context.c/);
cd3486e4ba70 fix make error of twice
mir3636
parents: 254
diff changeset
79 &getStubInfo($_);
cd3486e4ba70 fix make error of twice
mir3636
parents: 254
diff changeset
80 }
cd3486e4ba70 fix make error of twice
mir3636
parents: 254
diff changeset
81
186
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
82 &generateContext();
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
83
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
84 sub getStubInfo {
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
85 my ($filename) = @_;
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
86 open my $fd,"<",$filename or die("can't open $filename $!");
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
87 while (<$fd>) {
312
7dd5a7d52a67 USE_CUDAWorker flag only for CUDAtwice
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 285
diff changeset
88 if (/^__code (\w+)_stub\(struct *Context *\* *context\)/) {
186
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
89 $codeGear{$1} = $filename;
312
7dd5a7d52a67 USE_CUDAWorker flag only for CUDAtwice
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 285
diff changeset
90 } elsif (/^(\w+)(\*)+ *create(\w+)\(([^]]*)\)/) {
277
9d671e63df74 generate extern
mir3636
parents: 259
diff changeset
91 my $interface = $1;
9d671e63df74 generate extern
mir3636
parents: 259
diff changeset
92 my $implementation = $3;
9d671e63df74 generate extern
mir3636
parents: 259
diff changeset
93 my $constructorArgs = $4;
9d671e63df74 generate extern
mir3636
parents: 259
diff changeset
94 $constructor{$implementation} = [$interface, $constructorArgs];
186
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
95 }
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
96 }
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
97
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
98 open my $cx,"<","context.h" or die("can't open context.h $!");
254
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
99 my $inUnionData = 0;
186
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
100 while (<$cx>) {
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
101 if (! $inUnionData) {
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
102 if ( /^union Data/) {
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
103 $inUnionData = 1;
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
104 }
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
105 next;
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
106 }
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
107 last if (/union Data end/);
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
108 if (/struct (\w+) \{/) {
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
109 $dataGear{$1} = $1;
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
110 }
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
111 }
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
112 }
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
113
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
114 sub generateContext {
284
e6bc0a4c2c36 generate C_start_code and C_exit_code
mir3636
parents: 280
diff changeset
115 $codeGear{"start_code"} = "$ddir/$name-context.c";
e6bc0a4c2c36 generate C_start_code and C_exit_code
mir3636
parents: 280
diff changeset
116 $codeGear{"exit_code"} = "$ddir/$name-context.c";
285
bc17237bc8cf fix generate_context
mir3636
parents: 284
diff changeset
117 $mCodeGear{"start_code"} = "$ddir/$name-context.c";
bc17237bc8cf fix generate_context
mir3636
parents: 284
diff changeset
118 $mCodeGear{"exit_code"} = "$ddir/$name-context.c";
254
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
119 open my $fd,">","$ddir/extern.h" or die("can't open $ddir/extern.h $!");
186
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
120 for my $code ( sort keys %codeGear ) {
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
121 print $fd "extern __code ${code}_stub(struct Context*);\n";
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
122 }
277
9d671e63df74 generate extern
mir3636
parents: 259
diff changeset
123 for my $impl ( sort keys %constructor ) {
9d671e63df74 generate extern
mir3636
parents: 259
diff changeset
124 my ($interface, $constructorArgs) = @{$constructor{$impl}};
278
23767f714f4a fix generate_stub
mir3636
parents: 277
diff changeset
125 print $fd "extern ${interface}* create${impl}($constructorArgs);\n";
277
9d671e63df74 generate extern
mir3636
parents: 259
diff changeset
126 }
186
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
127 print $fd "\n";
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
128
254
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
129 open my $fd,">","$ddir/enumCode.h" or die("can't open $ddir/enumCode.h $!");
186
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
130 print $fd "enum Code {\n";
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
131 for my $code ( sort keys %codeGear ) {
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
132 print $fd " C_${code},\n";
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
133 }
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
134 print $fd "};\n";
210
ba56dab79dc4 separate code init for each executable
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 208
diff changeset
135
ba56dab79dc4 separate code init for each executable
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 208
diff changeset
136 my $code_init = '';
ba56dab79dc4 separate code init for each executable
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 208
diff changeset
137 for my $code ( sort keys %mCodeGear ) {
ba56dab79dc4 separate code init for each executable
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 208
diff changeset
138 $code_init .= " context->code[C_${code}] = ${code}_stub;\n";
ba56dab79dc4 separate code init for each executable
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 208
diff changeset
139 }
ba56dab79dc4 separate code init for each executable
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 208
diff changeset
140
ba56dab79dc4 separate code init for each executable
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 208
diff changeset
141 my $context_c = << "EOFEOF";
ba56dab79dc4 separate code init for each executable
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 208
diff changeset
142 #include <stdlib.h>
ba56dab79dc4 separate code init for each executable
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 208
diff changeset
143
ba56dab79dc4 separate code init for each executable
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 208
diff changeset
144 #include "../context.h"
277
9d671e63df74 generate extern
mir3636
parents: 259
diff changeset
145
246
421ea91dd76c Change initContext type from __code to void
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 210
diff changeset
146 void initContext(struct Context* context) {
210
ba56dab79dc4 separate code init for each executable
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 208
diff changeset
147 context->heapLimit = sizeof(union Data)*ALLOCATE_SIZE;
ba56dab79dc4 separate code init for each executable
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 208
diff changeset
148 context->code = (__code(**) (struct Context*)) NEWN(ALLOCATE_SIZE, void*);
ba56dab79dc4 separate code init for each executable
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 208
diff changeset
149 context->data = NEWN(ALLOCATE_SIZE, union Data*);
ba56dab79dc4 separate code init for each executable
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 208
diff changeset
150 context->heapStart = NEWN(context->heapLimit, char);
ba56dab79dc4 separate code init for each executable
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 208
diff changeset
151 context->heap = context->heapStart;
ba56dab79dc4 separate code init for each executable
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 208
diff changeset
152
ba56dab79dc4 separate code init for each executable
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 208
diff changeset
153 // context->codeNum = Exit;
ba56dab79dc4 separate code init for each executable
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 208
diff changeset
154
ba56dab79dc4 separate code init for each executable
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 208
diff changeset
155 $code_init
ba56dab79dc4 separate code init for each executable
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 208
diff changeset
156
ba56dab79dc4 separate code init for each executable
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 208
diff changeset
157 #include "dataGearInit.c"
ba56dab79dc4 separate code init for each executable
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 208
diff changeset
158
ba56dab79dc4 separate code init for each executable
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 208
diff changeset
159 // context->data[D_ActiveQueue] = createSynchronizedQueue(context);
ba56dab79dc4 separate code init for each executable
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 208
diff changeset
160 // context->data[D_WaitQueue] = createSynchronizedQueue(context);
ba56dab79dc4 separate code init for each executable
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 208
diff changeset
161
ba56dab79dc4 separate code init for each executable
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 208
diff changeset
162 context->dataNum = D_Queue;
ba56dab79dc4 separate code init for each executable
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 208
diff changeset
163 }
ba56dab79dc4 separate code init for each executable
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 208
diff changeset
164 EOFEOF
ba56dab79dc4 separate code init for each executable
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 208
diff changeset
165
254
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
166 open my $fd,">","$ddir/$name-context.c" or die("can't open $ddir/$name-context.c $!");
210
ba56dab79dc4 separate code init for each executable
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 208
diff changeset
167 print $fd $context_c;
277
9d671e63df74 generate extern
mir3636
parents: 259
diff changeset
168
9d671e63df74 generate extern
mir3636
parents: 259
diff changeset
169 my $meta_call = <<"EOFEOF";
9d671e63df74 generate extern
mir3636
parents: 259
diff changeset
170
9d671e63df74 generate extern
mir3636
parents: 259
diff changeset
171 __code meta(struct Context* context, enum Code next) {
280
2c2e4e597eb0 generate no compile errors
mir3636
parents: 278
diff changeset
172 // printf("meta %d\\n",next);
277
9d671e63df74 generate extern
mir3636
parents: 259
diff changeset
173 goto (context->code[next])(context);
9d671e63df74 generate extern
mir3636
parents: 259
diff changeset
174 }
9d671e63df74 generate extern
mir3636
parents: 259
diff changeset
175
9d671e63df74 generate extern
mir3636
parents: 259
diff changeset
176 __code start_code(struct Context* context) {
9d671e63df74 generate extern
mir3636
parents: 259
diff changeset
177 goto meta(context, context->next);
9d671e63df74 generate extern
mir3636
parents: 259
diff changeset
178 }
9d671e63df74 generate extern
mir3636
parents: 259
diff changeset
179
9d671e63df74 generate extern
mir3636
parents: 259
diff changeset
180 __code start_code_stub(struct Context* context) {
9d671e63df74 generate extern
mir3636
parents: 259
diff changeset
181 goto start_code(context);
9d671e63df74 generate extern
mir3636
parents: 259
diff changeset
182 }
9d671e63df74 generate extern
mir3636
parents: 259
diff changeset
183
9d671e63df74 generate extern
mir3636
parents: 259
diff changeset
184 __code exit_code(struct Context* context) {
9d671e63df74 generate extern
mir3636
parents: 259
diff changeset
185 free(context->code);
9d671e63df74 generate extern
mir3636
parents: 259
diff changeset
186 free(context->data);
9d671e63df74 generate extern
mir3636
parents: 259
diff changeset
187 free(context->heapStart);
9d671e63df74 generate extern
mir3636
parents: 259
diff changeset
188 goto exit(0);
9d671e63df74 generate extern
mir3636
parents: 259
diff changeset
189 }
9d671e63df74 generate extern
mir3636
parents: 259
diff changeset
190
9d671e63df74 generate extern
mir3636
parents: 259
diff changeset
191 __code exit_code_stub(struct Context* context) {
9d671e63df74 generate extern
mir3636
parents: 259
diff changeset
192 goto exit_code(context);
9d671e63df74 generate extern
mir3636
parents: 259
diff changeset
193 }
9d671e63df74 generate extern
mir3636
parents: 259
diff changeset
194
280
2c2e4e597eb0 generate no compile errors
mir3636
parents: 278
diff changeset
195 // end context_c
277
9d671e63df74 generate extern
mir3636
parents: 259
diff changeset
196 EOFEOF
186
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
197
278
23767f714f4a fix generate_stub
mir3636
parents: 277
diff changeset
198 print $fd $meta_call;
23767f714f4a fix generate_stub
mir3636
parents: 277
diff changeset
199
254
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
200 open my $fd,">","$ddir/enumData.h" or die("can't open $ddir/enumData.h $!");
186
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
201 print $fd "enum DataType {\n";
259
195518ab62fc fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 257
diff changeset
202 print $fd " D_Code,\n";
186
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
203 for my $data ( sort keys %dataGear ) {
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
204 print $fd " D_${data},\n";
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
205 }
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
206 print $fd "};\n\n";
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
207
254
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
208 open my $fd,">","$ddir/typedefData.h" or die("can't open $ddir/typedefData.h $!");
186
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
209 for my $data ( sort keys %dataGear ) {
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
210 print $fd "typedef struct ${data} ${data};\n";
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
211 }
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
212
254
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
213 open my $fd,">","$ddir/dataGearInit.c" or die("can't open $ddir/dataGearInit.c $!");
186
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
214 for my $data ( sort keys %dataGear ) {
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
215 print $fd " ALLOC_DATA(context, ${data});\n";
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
216 }
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
217 }
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
218
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
219 # end