annotate src/gearsTools/generate_context.pl @ 111:239bd73abac6

add gen context.h at generate_context.pl
author anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Thu, 28 Nov 2019 12:17:05 +0900
parents 435bfab09924
children f9df567f7f2d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 #!/usr/bin/perl
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 use Getopt::Std;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 use strict;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 #
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 # generrate Gears OS context heaader and initializer from CbC sources
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 #
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 # CodeGear
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 #
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 # get stub information from # *.c
52
214d21c891c7 rename to cbc
kono
parents: 47
diff changeset
12 # __code taskManager_stub(struct Context* cbc_context) {
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 #
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 # generate CodeGear indexn in context.h
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 # C_taskManager,
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 #
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 # generate CodeGear stub reference in context.h
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 # extern __code taskManager_stub(struct Context*);
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 #
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 # generate CodeGear stub reference in $name-context.h for each module
52
214d21c891c7 rename to cbc
kono
parents: 47
diff changeset
21 # cbc_context->code[C_taskManager] = taskManager_stub;
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 #
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 # DataGear
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 #
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 # get DataGear information from context.h
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 # struct Worker {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 # int id;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 # struct Context* contexts;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 # enum Code execute;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 # enum Code taskSend;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 # enum Code taskRecive;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 # enum Code shutdown;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 # struct Queue* tasks;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 # } Worker;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 #
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 # generate typedefs and DataGear index in context.h
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 # typedef struct Worker Worker;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 # D_Worker,
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 #
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 # generate DataGear allocator in context.h
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 # ALLOC_DATA(context, Worker);
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 #
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
43
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 my $ddir = "c";
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
45
111
239bd73abac6 add gen context.h at generate_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 53
diff changeset
46 our($opt_o,$opt_d,$opt_h,$opt_w);
239bd73abac6 add gen context.h at generate_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 53
diff changeset
47 getopts('o:d:hw');
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
48
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 my $name = $opt_o?$opt_o:"gears";
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
50
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 if ($opt_d) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 $ddir = $opt_d;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
54
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
55 if ( ! -d $ddir) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 mkdir $ddir;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
58
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 if ($opt_h) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 print "$0 [-d distdir] [-h]\n";
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 exit;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
63
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
64 my %codeGear;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 my %dataGear;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 my %constructor;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
67
111
239bd73abac6 add gen context.h at generate_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 53
diff changeset
68 {
239bd73abac6 add gen context.h at generate_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 53
diff changeset
69 use FindBin;
239bd73abac6 add gen context.h at generate_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 53
diff changeset
70 use lib "$FindBin::Bin/lib";
239bd73abac6 add gen context.h at generate_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 53
diff changeset
71
239bd73abac6 add gen context.h at generate_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 53
diff changeset
72 use File::Spec;
239bd73abac6 add gen context.h at generate_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 53
diff changeset
73 use Cwd 'getcwd';
239bd73abac6 add gen context.h at generate_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 53
diff changeset
74
239bd73abac6 add gen context.h at generate_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 53
diff changeset
75 use Gears::Context;
239bd73abac6 add gen context.h at generate_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 53
diff changeset
76 use Getopt::Std;
239bd73abac6 add gen context.h at generate_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 53
diff changeset
77
239bd73abac6 add gen context.h at generate_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 53
diff changeset
78 my $output = $opt_w ? "context.h" : "stdout";
239bd73abac6 add gen context.h at generate_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 53
diff changeset
79
239bd73abac6 add gen context.h at generate_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 53
diff changeset
80 my @cbc_files;
239bd73abac6 add gen context.h at generate_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 53
diff changeset
81 map { push(@cbc_files,File::Spec->rel2abs($_)); } @ARGV;
239bd73abac6 add gen context.h at generate_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 53
diff changeset
82 my $gears = Gears::Context->new(compile_sources => \@cbc_files, find_root => "$FindBin::Bin/../", output => $output);
239bd73abac6 add gen context.h at generate_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 53
diff changeset
83 my $data_gears = $gears->extraction_dg_compile_sources();
239bd73abac6 add gen context.h at generate_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 53
diff changeset
84 my $g = $gears->set_data_gear_header_path();
239bd73abac6 add gen context.h at generate_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 53
diff changeset
85
239bd73abac6 add gen context.h at generate_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 53
diff changeset
86 #use DDP {deparse =>1};
239bd73abac6 add gen context.h at generate_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 53
diff changeset
87 my $dg2path = $gears->update_dg_each_header_path($data_gears,$g);
239bd73abac6 add gen context.h at generate_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 53
diff changeset
88 my $tree = $gears->createImplTree_from_header($dg2path);
239bd73abac6 add gen context.h at generate_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 53
diff changeset
89 $gears->tree2create_context_h($tree);
239bd73abac6 add gen context.h at generate_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 53
diff changeset
90 }
239bd73abac6 add gen context.h at generate_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 53
diff changeset
91
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
92 # gather module Information for code table initialization
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
93 for (@ARGV) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
94 next if (/context.c/);
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
95 &getStubInfo($_);
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
96 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
97
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
98 my (%mCodeGear) = (%codeGear);
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
99
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
100 # anyway we gather all Gears Information
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
101 while (<*.c test/*.c>) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
102 next if (/context.c/);
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
103 &getStubInfo($_);
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
104 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
105
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
106 &generateContext();
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
107
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
108 sub getStubInfo {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
109 my ($filename) = @_;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
110 open my $fd,"<",$filename or die("can't open $filename $!");
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
111 while (<$fd>) {
52
214d21c891c7 rename to cbc
kono
parents: 47
diff changeset
112 if (/^__code (\w+)_stub\(struct *Context *\* *cbc_context\)/) {
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
113 $codeGear{$1} = $filename;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
114 } elsif (/^(\w+)(\*)+ *create(\w+)\(([^]]*)\)/) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
115 my $interface = $1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
116 my $implementation = $3;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
117 my $constructorArgs = $4;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
118 $constructor{$implementation} = [$interface, $constructorArgs];
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
119 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
120 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
121
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
122 open my $cx,"<","context.h" or die("can't open context.h $!");
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
123 my $inUnionData = 0;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
124 while (<$cx>) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
125 if (! $inUnionData) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
126 if ( /^union Data/) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
127 $inUnionData = 1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
128 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
129 next;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
130 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
131 last if (/union Data end/);
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
132 if (/struct (\w+) \{/) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
133 $dataGear{$1} = 'struct';
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
134 } elsif (/^\s{4}(\w+) (\w+);/) { # primitive type
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
135 $dataGear{$1} = 'primitive';
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
136 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
137 $dataGear{"Context"} = "struct";
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
138 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
139 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
140
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
141 sub generateContext {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
142 $codeGear{"start_code"} = "$ddir/$name-context.c";
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
143 $codeGear{"exit_code"} = "$ddir/$name-context.c";
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
144 $mCodeGear{"start_code"} = "$ddir/$name-context.c";
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
145 $mCodeGear{"exit_code"} = "$ddir/$name-context.c";
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
146 open my $fd,">","$ddir/extern.h" or die("can't open $ddir/extern.h $!");
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
147 for my $code ( sort keys %codeGear ) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
148 print $fd "extern __code ${code}_stub(struct Context*);\n";
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
149 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
150 for my $impl ( sort keys %constructor ) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
151 my ($interface, $constructorArgs) = @{$constructor{$impl}};
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
152 print $fd "extern ${interface}* create${impl}($constructorArgs);\n";
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
153 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
154 print $fd "\n";
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
155
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
156 open my $fd,">","$ddir/enumCode.h" or die("can't open $ddir/enumCode.h $!");
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
157 print $fd "enum Code {\n";
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
158 for my $code ( sort keys %codeGear ) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
159 print $fd " C_${code},\n";
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
160 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
161 print $fd "};\n";
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
162
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
163 my $code_init = '';
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
164 for my $code ( sort keys %mCodeGear ) {
52
214d21c891c7 rename to cbc
kono
parents: 47
diff changeset
165 $code_init .= " cbc_context->code[C_${code}] = ${code}_stub;\n";
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
166 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
167
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
168 my $data_num = keys(%dataGear);
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
169 $data_num++;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
170 my $context_c = << "EOFEOF";
47
233a68a261fe ifdef cbcxv6
mir3636
parents: 46
diff changeset
171 #ifndef CBCXV6
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
172 #include <stdlib.h>
47
233a68a261fe ifdef cbcxv6
mir3636
parents: 46
diff changeset
173 #endif
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
174
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
175 #include "../context.h"
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
176
52
214d21c891c7 rename to cbc
kono
parents: 47
diff changeset
177 void initContext(struct Context* cbc_context) {
214d21c891c7 rename to cbc
kono
parents: 47
diff changeset
178 cbc_context->heapLimit = sizeof(union Data)*ALLOCATE_SIZE;
214d21c891c7 rename to cbc
kono
parents: 47
diff changeset
179 cbc_context->code = (__code(**) (struct Context*)) NEWN(ALLOCATE_SIZE, void*);
214d21c891c7 rename to cbc
kono
parents: 47
diff changeset
180 cbc_context->data = NEWN(ALLOCATE_SIZE, union Data*);
214d21c891c7 rename to cbc
kono
parents: 47
diff changeset
181 cbc_context->heapStart = NEWN(cbc_context->heapLimit, char);
214d21c891c7 rename to cbc
kono
parents: 47
diff changeset
182 cbc_context->heap = cbc_context->heapStart;
214d21c891c7 rename to cbc
kono
parents: 47
diff changeset
183 // cbc_context->codeNum = Exit;
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
184
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
185 $code_init
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
186
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
187 #include "dataGearInit.c"
52
214d21c891c7 rename to cbc
kono
parents: 47
diff changeset
188 cbc_context->dataNum = $data_num;
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
189 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
190 EOFEOF
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
191
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
192 open my $fd,">","$ddir/$name-context.c" or die("can't open $ddir/$name-context.c $!");
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
193 print $fd $context_c;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
194
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
195 my $meta_call = <<"EOFEOF";
52
214d21c891c7 rename to cbc
kono
parents: 47
diff changeset
196 __code meta(struct Context* cbc_context, enum Code next) {
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
197 // printf("meta %d\\n",next);
52
214d21c891c7 rename to cbc
kono
parents: 47
diff changeset
198 goto (cbc_context->code[next])(cbc_context);
45
5f19e9554c30 supless warning
k.fukuda
parents:
diff changeset
199 }
5f19e9554c30 supless warning
k.fukuda
parents:
diff changeset
200
52
214d21c891c7 rename to cbc
kono
parents: 47
diff changeset
201 __code parGotoMeta(struct Context* cbc_context, enum Code next) {
214d21c891c7 rename to cbc
kono
parents: 47
diff changeset
202 cbc_context->task = NULL;
214d21c891c7 rename to cbc
kono
parents: 47
diff changeset
203 cbc_context->taskList = NULL;
53
435bfab09924 fix cmakefiles
kono
parents: 52
diff changeset
204 goto (cbc_context->code[Gearef(cbc_context, TaskManager)->taskManager->TaskManager.spawnTasks])(cbc_context);
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
205 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
206
52
214d21c891c7 rename to cbc
kono
parents: 47
diff changeset
207 __code start_code(struct Context* cbc_context) {
53
435bfab09924 fix cmakefiles
kono
parents: 52
diff changeset
208 goto meta(cbc_context, cbc_context->next);
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
209 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
210
52
214d21c891c7 rename to cbc
kono
parents: 47
diff changeset
211 __code start_code_stub(struct Context* cbc_context) {
214d21c891c7 rename to cbc
kono
parents: 47
diff changeset
212 goto start_code(cbc_context);
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
213 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
214
52
214d21c891c7 rename to cbc
kono
parents: 47
diff changeset
215 __code exit_code(struct Context* cbc_context) {
53
435bfab09924 fix cmakefiles
kono
parents: 52
diff changeset
216 // free(cbc_context->code);
435bfab09924 fix cmakefiles
kono
parents: 52
diff changeset
217 // free(cbc_context->data);
435bfab09924 fix cmakefiles
kono
parents: 52
diff changeset
218 // free(cbc_context->heapStart);
435bfab09924 fix cmakefiles
kono
parents: 52
diff changeset
219 goto exit_code(cbc_context);
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
220 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
221
52
214d21c891c7 rename to cbc
kono
parents: 47
diff changeset
222 __code exit_code_stub(struct Context* cbc_context) {
214d21c891c7 rename to cbc
kono
parents: 47
diff changeset
223 goto exit_code(cbc_context);
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
224 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
225
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
226 // end context_c
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
227 EOFEOF
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
228
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
229 print $fd $meta_call;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
230
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
231 open my $fd,">","$ddir/enumData.h" or die("can't open $ddir/enumData.h $!");
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
232 print $fd "enum DataType {\n";
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
233 print $fd " D_Code,\n";
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
234 for my $data ( sort keys %dataGear ) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
235 print $fd " D_${data},\n";
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
236 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
237 print $fd "};\n\n";
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
238
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
239 open my $fd,">","$ddir/typedefData.h" or die("can't open $ddir/typedefData.h $!");
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
240 for my $data ( sort keys %dataGear ) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
241 if ($dataGear{$data} eq 'struct') {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
242 print $fd "typedef struct ${data} ${data};\n";
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
243 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
244 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
245
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
246 open my $fd,">","$ddir/dataGearInit.c" or die("can't open $ddir/dataGearInit.c $!");
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
247 for my $data ( sort keys %dataGear ) {
52
214d21c891c7 rename to cbc
kono
parents: 47
diff changeset
248 print $fd " ALLOC_DATA(cbc_context, ${data});\n";
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
249 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
250 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
251
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
252 # end