Mercurial > hg > GearsTemplate
annotate src/parallel_execution/generate_context.pl @ 257:cd3486e4ba70
fix make error of twice
author | mir3636 |
---|---|
date | Fri, 27 Jan 2017 21:20:07 +0900 |
parents | edb3aff688d0 |
children | 195518ab62fc |
rev | line source |
---|---|
186 | 1 #!/usr/bin/perl |
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 | 4 use strict; |
186 | 5 |
254 | 6 # |
7 # generrate Gears OS context heaader and initializer from CbC sources | |
8 # | |
186 | 9 # CodeGear |
10 # | |
254 | 11 # get stub information from # *.c |
12 # __code taskManager_stub(struct Context* context) { | |
13 # | |
14 # generate CodeGear indexn in context.h | |
15 # C_taskManager, | |
186 | 16 # |
254 | 17 # generate CodeGear stub reference in context.h |
18 # extern __code taskManager_stub(struct Context*); | |
186 | 19 # |
254 | 20 # generate CodeGear stub reference in $name-context.h for each module |
21 # context->code[C_taskManager] = taskManager_stub; | |
186 | 22 # |
23 # DataGear | |
24 # | |
254 | 25 # get DataGear information from context.h |
26 # struct Worker { | |
186 | 27 # int id; |
28 # struct Context* contexts; | |
29 # enum Code execute; | |
30 # enum Code taskSend; | |
31 # enum Code taskRecive; | |
32 # enum Code shutdown; | |
33 # struct Queue* tasks; | |
34 # } Worker; | |
35 # | |
254 | 36 # generate typedefs and DataGear index in context.h |
37 # typedef struct Worker Worker; | |
38 # D_Worker, | |
186 | 39 # |
254 | 40 # generate DataGear allocator in context.h |
41 # ALLOC_DATA(context, Worker); | |
42 # | |
186 | 43 |
254 | 44 my $ddir = "c"; |
186 | 45 |
254 | 46 our($opt_o,$opt_d,$opt_h); |
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 |
ba56dab79dc4
separate code init for each executable
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
208
diff
changeset
|
49 my $name = $opt_o; |
ba56dab79dc4
separate code init for each executable
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
208
diff
changeset
|
50 |
254 | 51 if ($opt_d) { |
52 $ddir = $opt_d; | |
53 } | |
54 | |
55 if ( ! -d $ddir) { | |
56 mkdir $ddir; | |
57 } | |
58 | |
59 if ($opt_h) { | |
60 print "$0 [-d distdir] [-h]\n"; | |
61 exit; | |
62 } | |
63 | |
64 my %codeGear; | |
65 my %dataGear; | |
66 | |
210
ba56dab79dc4
separate code init for each executable
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
208
diff
changeset
|
67 for (@ARGV) { |
ba56dab79dc4
separate code init for each executable
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
208
diff
changeset
|
68 next if (/context.c/); |
ba56dab79dc4
separate code init for each executable
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
208
diff
changeset
|
69 &getStubInfo($_); |
ba56dab79dc4
separate code init for each executable
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
208
diff
changeset
|
70 } |
ba56dab79dc4
separate code init for each executable
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
208
diff
changeset
|
71 |
ba56dab79dc4
separate code init for each executable
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
208
diff
changeset
|
72 my (%mCodeGear) = (%codeGear); |
ba56dab79dc4
separate code init for each executable
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
208
diff
changeset
|
73 |
257 | 74 while (<*.c>) { |
75 next if (/context.c/); | |
76 &getStubInfo($_); | |
77 } | |
78 | |
186 | 79 &generateContext(); |
80 | |
81 sub getStubInfo { | |
82 my ($filename) = @_; | |
83 open my $fd,"<",$filename or die("can't open $filename $!"); | |
84 while (<$fd>) { | |
208 | 85 if (/^__code (\w+)_stub\(struct Context\* context\)/ or /^\s__code (\w+)_stub\(struct Context\* context\)/) { |
186 | 86 $codeGear{$1} = $filename; |
87 } | |
88 } | |
89 | |
90 open my $cx,"<","context.h" or die("can't open context.h $!"); | |
254 | 91 my $inUnionData = 0; |
186 | 92 while (<$cx>) { |
93 if (! $inUnionData) { | |
94 if ( /^union Data/) { | |
95 $inUnionData = 1; | |
96 } | |
97 next; | |
98 } | |
99 last if (/union Data end/); | |
100 if (/struct (\w+) \{/) { | |
101 $dataGear{$1} = $1; | |
102 } | |
103 } | |
104 } | |
105 | |
106 sub generateContext { | |
254 | 107 open my $fd,">","$ddir/extern.h" or die("can't open $ddir/extern.h $!"); |
186 | 108 for my $code ( sort keys %codeGear ) { |
109 print $fd "extern __code ${code}_stub(struct Context*);\n"; | |
110 } | |
111 print $fd "\n"; | |
112 | |
254 | 113 open my $fd,">","$ddir/enumCode.h" or die("can't open $ddir/enumCode.h $!"); |
186 | 114 print $fd "enum Code {\n"; |
115 for my $code ( sort keys %codeGear ) { | |
116 print $fd " C_${code},\n"; | |
117 } | |
118 print $fd "};\n"; | |
210
ba56dab79dc4
separate code init for each executable
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
208
diff
changeset
|
119 |
ba56dab79dc4
separate code init for each executable
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
208
diff
changeset
|
120 my $code_init = ''; |
ba56dab79dc4
separate code init for each executable
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
208
diff
changeset
|
121 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
|
122 $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
|
123 } |
ba56dab79dc4
separate code init for each executable
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
208
diff
changeset
|
124 |
ba56dab79dc4
separate code init for each executable
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
208
diff
changeset
|
125 my $context_c = << "EOFEOF"; |
ba56dab79dc4
separate code init for each executable
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
208
diff
changeset
|
126 #include <stdlib.h> |
ba56dab79dc4
separate code init for each executable
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
208
diff
changeset
|
127 |
ba56dab79dc4
separate code init for each executable
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
208
diff
changeset
|
128 #include "../context.h" |
ba56dab79dc4
separate code init for each executable
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
208
diff
changeset
|
129 #include "extern.h" |
ba56dab79dc4
separate code init for each executable
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
208
diff
changeset
|
130 |
246
421ea91dd76c
Change initContext type from __code to void
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
210
diff
changeset
|
131 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
|
132 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
|
133 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
|
134 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
|
135 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
|
136 context->heap = context->heapStart; |
ba56dab79dc4
separate code init for each executable
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
208
diff
changeset
|
137 |
ba56dab79dc4
separate code init for each executable
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
208
diff
changeset
|
138 // context->codeNum = Exit; |
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 $code_init |
ba56dab79dc4
separate code init for each executable
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
208
diff
changeset
|
141 |
ba56dab79dc4
separate code init for each executable
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
208
diff
changeset
|
142 #include "dataGearInit.c" |
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 // 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
|
145 // 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
|
146 |
ba56dab79dc4
separate code init for each executable
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
208
diff
changeset
|
147 context->dataNum = D_Queue; |
ba56dab79dc4
separate code init for each executable
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
208
diff
changeset
|
148 } |
ba56dab79dc4
separate code init for each executable
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
208
diff
changeset
|
149 EOFEOF |
ba56dab79dc4
separate code init for each executable
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
208
diff
changeset
|
150 |
254 | 151 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
|
152 print $fd $context_c; |
186 | 153 |
154 | |
254 | 155 open my $fd,">","$ddir/enumData.h" or die("can't open $ddir/enumData.h $!"); |
186 | 156 print $fd "enum DataType {\n"; |
157 for my $data ( sort keys %dataGear ) { | |
158 print $fd " D_${data},\n"; | |
159 } | |
160 print $fd "};\n\n"; | |
161 | |
254 | 162 open my $fd,">","$ddir/typedefData.h" or die("can't open $ddir/typedefData.h $!"); |
186 | 163 for my $data ( sort keys %dataGear ) { |
164 print $fd "typedef struct ${data} ${data};\n"; | |
165 } | |
166 | |
254 | 167 open my $fd,">","$ddir/dataGearInit.c" or die("can't open $ddir/dataGearInit.c $!"); |
186 | 168 for my $data ( sort keys %dataGear ) { |
169 print $fd " ALLOC_DATA(context, ${data});\n"; | |
170 } | |
171 } | |
172 | |
173 # end |