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
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
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
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;
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
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
cd3486e4ba70 fix make error of twice
mir3636
parents: 254
diff changeset
74 while (<*.c>) {
cd3486e4ba70 fix make error of twice
mir3636
parents: 254
diff changeset
75 next if (/context.c/);
cd3486e4ba70 fix make error of twice
mir3636
parents: 254
diff changeset
76 &getStubInfo($_);
cd3486e4ba70 fix make error of twice
mir3636
parents: 254
diff changeset
77 }
cd3486e4ba70 fix make error of twice
mir3636
parents: 254
diff changeset
78
186
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
79 &generateContext();
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
80
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
81 sub getStubInfo {
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
82 my ($filename) = @_;
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
83 open my $fd,"<",$filename or die("can't open $filename $!");
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
84 while (<$fd>) {
208
b6ffdd99e525 fix generate_context
mir3636
parents: 202
diff changeset
85 if (/^__code (\w+)_stub\(struct Context\* context\)/ or /^\s__code (\w+)_stub\(struct Context\* context\)/) {
186
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
86 $codeGear{$1} = $filename;
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
87 }
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
88 }
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
89
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
90 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
91 my $inUnionData = 0;
186
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
92 while (<$cx>) {
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
93 if (! $inUnionData) {
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
94 if ( /^union Data/) {
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
95 $inUnionData = 1;
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
96 }
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
97 next;
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
98 }
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
99 last if (/union Data end/);
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
100 if (/struct (\w+) \{/) {
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
101 $dataGear{$1} = $1;
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
102 }
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
103 }
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
104 }
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
105
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
106 sub generateContext {
254
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
107 open my $fd,">","$ddir/extern.h" or die("can't open $ddir/extern.h $!");
186
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
108 for my $code ( sort keys %codeGear ) {
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
109 print $fd "extern __code ${code}_stub(struct Context*);\n";
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
110 }
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
111 print $fd "\n";
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
112
254
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
113 open my $fd,">","$ddir/enumCode.h" or die("can't open $ddir/enumCode.h $!");
186
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
114 print $fd "enum Code {\n";
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
115 for my $code ( sort keys %codeGear ) {
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
116 print $fd " C_${code},\n";
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
117 }
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
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
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
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
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
153
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
154
254
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
155 open my $fd,">","$ddir/enumData.h" or die("can't open $ddir/enumData.h $!");
186
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
156 print $fd "enum DataType {\n";
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
157 for my $data ( sort keys %dataGear ) {
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
158 print $fd " D_${data},\n";
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
159 }
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
160 print $fd "};\n\n";
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
161
254
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
162 open my $fd,">","$ddir/typedefData.h" or die("can't open $ddir/typedefData.h $!");
186
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
163 for my $data ( sort keys %dataGear ) {
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
164 print $fd "typedef struct ${data} ${data};\n";
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
165 }
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
166
254
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
167 open my $fd,">","$ddir/dataGearInit.c" or die("can't open $ddir/dataGearInit.c $!");
186
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
168 for my $data ( sort keys %dataGear ) {
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
169 print $fd " ALLOC_DATA(context, ${data});\n";
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
170 }
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
171 }
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
172
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
173 # end