annotate src/parallel_execution/generate_context.pl @ 195:119c035e0e36

replace Array and Stack for array and stack
author ikkun
date Fri, 16 Dec 2016 23:27:14 +0900
parents bacc37265386
children 9c85c3a34726
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
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
3
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
4 # CodeGear
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
5 #
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
6 # *.c
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
7 # __code taskManager_stub(struct Context* context) {
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
8 #
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
9 # context.h
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
10 # C_taskManager,
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
11 #
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
12 # context.c
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
13 # extern __code taskManager_stub(struct Context*);
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
14 #
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
15 # context->code[C_taskManager] = taskManager_stub;
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
16 #
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
17 # DataGear
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
18 #
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
19 # context.h
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
20 # struct Worker {
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
21 # int id;
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
22 # struct Context* contexts;
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
23 # enum Code execute;
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
24 # enum Code taskSend;
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
25 # enum Code taskRecive;
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
26 # enum Code shutdown;
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
27 # struct Queue* tasks;
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
28 # } Worker;
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
29 #
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
30 # typedef struct Worker Worker;
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
31 # D_Worker,
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
32 #
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
33 # context.c
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
34 # ALLOC_DATA(context, Worker);
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
35
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
36 system "rm -rf c";
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
37 system "mkdir c";
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
38
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
39 while (<*.c>) {
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
40 next if (/context.c/);
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
41 &getStubInfo($_);
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
42 }
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
43
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
44 &generateContext();
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
45
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
46 sub getStubInfo {
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
47 my ($filename) = @_;
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
48 open my $fd,"<",$filename or die("can't open $filename $!");
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
49 while (<$fd>) {
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
50 if (/__code (\w+)_stub\(struct Context\* context\)/) {
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
51 $codeGear{$1} = $filename;
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
52 }
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
53 }
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
54
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
55 open my $cx,"<","context.h" or die("can't open context.h $!");
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
56 while (<$cx>) {
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
57 if (! $inUnionData) {
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
58 if ( /^union Data/) {
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
59 $inUnionData = 1;
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
60 }
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
61 next;
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
62 }
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
63 last if (/union Data end/);
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
64 if (/struct (\w+) \{/) {
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
65 $dataGear{$1} = $1;
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
66 }
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
67 }
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
68 }
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
69
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
70 sub generateContext {
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
71 open my $fd,">","c/extern.h" or die("can't open c/extern.h $!");
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
72 for my $code ( sort keys %codeGear ) {
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
73 print $fd "extern __code ${code}_stub(struct Context*);\n";
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
74 }
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
75 print $fd "\n";
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
76
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
77 open my $fd,">","c/enumCode.h" or die("can't open c/enumCode.h $!");
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
78 print $fd "enum Code {\n";
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
79 for my $code ( sort keys %codeGear ) {
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
80 print $fd " C_${code},\n";
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
81 }
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
82 print $fd "};\n";
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
83
187
bacc37265386 main.o fixed
mir3636
parents: 186
diff changeset
84 open my $fd,">","c/codeGearInit.c" or die("can't open c/codeGearInit.c $!");
186
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
85 for my $code ( sort keys %codeGear ) {
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
86 print $fd " context->code[C_${code}] = ${code}_stub;\n";
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 open my $fd,">","c/enumData.h" or die("can't open c/enumData.h $!");
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
90 print $fd "enum DataType {\n";
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
91 for my $data ( sort keys %dataGear ) {
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
92 print $fd " D_${data},\n";
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
93 }
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
94 print $fd "};\n\n";
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
95
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
96 open my $fd,">","c/typedefData.h" or die("can't open c/typedefData.h $!");
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
97 for my $data ( sort keys %dataGear ) {
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
98 print $fd "typedef struct ${data} ${data};\n";
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
99 }
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
100
187
bacc37265386 main.o fixed
mir3636
parents: 186
diff changeset
101 open my $fd,">","c/dataGearInit.c" or die("can't open c/dataGearInit.c $!");
186
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
102 for my $data ( sort keys %dataGear ) {
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
103 print $fd " ALLOC_DATA(context, ${data});\n";
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
dbc064c26b98 generate context script
mir3636
parents:
diff changeset
107 # end