annotate src/parallel_execution/generate_stub.pl @ 195:bd96dffaa76a

generate_stub
author mir3636
date Fri, 16 Dec 2016 22:04:05 +0900
parents 081607dcf893
children 207aff30ed34
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
194
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
1 #!/usr/bin/perl
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
2
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
3 # interface.cbc
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
4 # typedef struct Worker {
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
5 # int id;
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
6 # struct Context* contexts;
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
7 # enum Code execute;
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
8 # enum Code taskSend;
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
9 # enum Code taskRecive;
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
10 # enum Code shutdown;
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
11 # struct Queue* tasks;
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
12 # } Worker;
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
13
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
14 system "rm -rf d";
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
15 system "mkdir d";
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
16
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
17 while (<*.cbc>) {
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
18 &getDataGear($_);
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
19 }
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
20
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
21 &generateDataGear();
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
22
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
23 sub getDataGear {
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
24 my ($filename) = @_;
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
25 open my $fd,"<",$filename or die("can't open $filename $!");
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
26 while (<$fd>) {
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
27 if (! $inTypedef) {
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
28 if (/^typedef struct (\w+) {/) {
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
29 $inTypedef = 1;
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
30 $name = $1;
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
31 $dataGear{$name} = $_;
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
32 }
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
33 next;
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
34 }
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
35 $dataGear{$name} .= $_;
195
bd96dffaa76a generate_stub
mir3636
parents: 194
diff changeset
36 if (/(\w+);$/ and !/^} (\w+)/) {
bd96dffaa76a generate_stub
mir3636
parents: 194
diff changeset
37 $var{$name} .= $1 . "\n";
bd96dffaa76a generate_stub
mir3636
parents: 194
diff changeset
38 $tmp = $`;
bd96dffaa76a generate_stub
mir3636
parents: 194
diff changeset
39 $tmp =~ s/^\s*//;
bd96dffaa76a generate_stub
mir3636
parents: 194
diff changeset
40 $type{$name} .= $tmp . "\n";
bd96dffaa76a generate_stub
mir3636
parents: 194
diff changeset
41 }
194
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
42 if (/^}/) {
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
43 $inTypedef = 0;
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
44 }
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
45 }
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
46 }
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
47
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
48 sub generateDataGear {
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
49 open my $fd,">","d/extern.h" or die("can't open d/extern.h $!");
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
50 for my $name ( sort keys %dataGear ) {
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
51 print $fd $dataGear{$name},"\n";
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
52 }
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
53 print $fd "\n";
195
bd96dffaa76a generate_stub
mir3636
parents: 194
diff changeset
54
bd96dffaa76a generate_stub
mir3636
parents: 194
diff changeset
55 open my $fd,">","d/stub.h" or die("can't open d/stub.h $!");
bd96dffaa76a generate_stub
mir3636
parents: 194
diff changeset
56 for my $name ( sort keys %dataGear ) {
bd96dffaa76a generate_stub
mir3636
parents: 194
diff changeset
57 print $fd $var{$name},"\n";
bd96dffaa76a generate_stub
mir3636
parents: 194
diff changeset
58 }
bd96dffaa76a generate_stub
mir3636
parents: 194
diff changeset
59 for my $name ( sort keys %dataGear ) {
bd96dffaa76a generate_stub
mir3636
parents: 194
diff changeset
60 print $fd $type{$name},"\n";
bd96dffaa76a generate_stub
mir3636
parents: 194
diff changeset
61 }
bd96dffaa76a generate_stub
mir3636
parents: 194
diff changeset
62 print $fd "\n";
194
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
63 }
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
64
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
65 # end