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