Mercurial > hg > GearsTemplate
changeset 254:edb3aff688d0
fix generator CLI
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 27 Jan 2017 10:10:09 +0900 |
parents | ebc13549394c |
children | 79bbe2c63fb0 |
files | src/parallel_execution/context.h src/parallel_execution/generate_context.pl src/parallel_execution/generate_stub.pl |
diffstat | 3 files changed, 68 insertions(+), 40 deletions(-) [+] |
line wrap: on
line diff
--- a/src/parallel_execution/context.h Thu Jan 26 19:52:08 2017 +0900 +++ b/src/parallel_execution/context.h Fri Jan 27 10:10:09 2017 +0900 @@ -251,7 +251,7 @@ struct OutPutDataSegments { union Data **data; } Ods; -}; // union Data end +}; // union Data end this is necessary for context generator #include "c/typedefData.h" #endif
--- a/src/parallel_execution/generate_context.pl Thu Jan 26 19:52:08 2017 +0900 +++ b/src/parallel_execution/generate_context.pl Fri Jan 27 10:10:09 2017 +0900 @@ -1,24 +1,29 @@ #!/usr/bin/perl use Getopt::Std; +use strict; +# +# generrate Gears OS context heaader and initializer from CbC sources +# # CodeGear # -# *.c -# __code taskManager_stub(struct Context* context) { +# get stub information from # *.c +# __code taskManager_stub(struct Context* context) { +# +# generate CodeGear indexn in context.h +# C_taskManager, # -# context.h -# C_taskManager, +# generate CodeGear stub reference in context.h +# extern __code taskManager_stub(struct Context*); # -# context.c -# extern __code taskManager_stub(struct Context*); -# -# context->code[C_taskManager] = taskManager_stub; +# generate CodeGear stub reference in $name-context.h for each module +# context->code[C_taskManager] = taskManager_stub; # # DataGear # -# context.h -# struct Worker { +# get DataGear information from context.h +# struct Worker { # int id; # struct Context* contexts; # enum Code execute; @@ -28,20 +33,37 @@ # struct Queue* tasks; # } Worker; # -# typedef struct Worker Worker; -# D_Worker, +# generate typedefs and DataGear index in context.h +# typedef struct Worker Worker; +# D_Worker, # -# context.c -# ALLOC_DATA(context, Worker); +# generate DataGear allocator in context.h +# ALLOC_DATA(context, Worker); +# -system "rm -rf c"; -system "mkdir c"; +my $ddir = "c"; -our($opt_o); -getopts('o:'); +our($opt_o,$opt_d,$opt_h); +getopts('o:d:h'); my $name = $opt_o; +if ($opt_d) { + $ddir = $opt_d; +} + +if ( ! -d $ddir) { + mkdir $ddir; +} + +if ($opt_h) { + print "$0 [-d distdir] [-h]\n"; + exit; +} + +my %codeGear; +my %dataGear; + for (@ARGV) { next if (/context.c/); &getStubInfo($_); @@ -49,11 +71,6 @@ my (%mCodeGear) = (%codeGear); -while (<*.c>) { - next if (/context.c/); - &getStubInfo($_); -} - &generateContext(); sub getStubInfo { @@ -66,6 +83,7 @@ } open my $cx,"<","context.h" or die("can't open context.h $!"); + my $inUnionData = 0; while (<$cx>) { if (! $inUnionData) { if ( /^union Data/) { @@ -81,13 +99,13 @@ } sub generateContext { - open my $fd,">","c/extern.h" or die("can't open c/extern.h $!"); + open my $fd,">","$ddir/extern.h" or die("can't open $ddir/extern.h $!"); for my $code ( sort keys %codeGear ) { print $fd "extern __code ${code}_stub(struct Context*);\n"; } print $fd "\n"; - open my $fd,">","c/enumCode.h" or die("can't open c/enumCode.h $!"); + open my $fd,">","$ddir/enumCode.h" or die("can't open $ddir/enumCode.h $!"); print $fd "enum Code {\n"; for my $code ( sort keys %codeGear ) { print $fd " C_${code},\n"; @@ -125,23 +143,23 @@ } EOFEOF - open my $fd,">","c/$name-context.c" or die("can't open c/$name-context.c $!"); + open my $fd,">","$ddir/$name-context.c" or die("can't open $ddir/$name-context.c $!"); print $fd $context_c; - open my $fd,">","c/enumData.h" or die("can't open c/enumData.h $!"); + open my $fd,">","$ddir/enumData.h" or die("can't open $ddir/enumData.h $!"); print $fd "enum DataType {\n"; for my $data ( sort keys %dataGear ) { print $fd " D_${data},\n"; } print $fd "};\n\n"; - open my $fd,">","c/typedefData.h" or die("can't open c/typedefData.h $!"); + open my $fd,">","$ddir/typedefData.h" or die("can't open $ddir/typedefData.h $!"); for my $data ( sort keys %dataGear ) { print $fd "typedef struct ${data} ${data};\n"; } - open my $fd,">","c/dataGearInit.c" or die("can't open c/dataGearInit.c $!"); + open my $fd,">","$ddir/dataGearInit.c" or die("can't open $ddir/dataGearInit.c $!"); for my $data ( sort keys %dataGear ) { print $fd " ALLOC_DATA(context, ${data});\n"; }
--- a/src/parallel_execution/generate_stub.pl Thu Jan 26 19:52:08 2017 +0900 +++ b/src/parallel_execution/generate_stub.pl Fri Jan 27 10:10:09 2017 +0900 @@ -1,6 +1,7 @@ #!/usr/bin/perl use strict; +use Getopt::Std; # interface.cbc # typedef struct Worker { @@ -13,9 +14,10 @@ # struct Queue* tasks; # } Worker; -#while (<*.cbc>) { -while (<SingleLinkedStack.cbc>) { - my $fn = $_; +our($opt_o,$opt_h); +getopts('o:h'); + +for my $fn (@ARGV) { &getDataGear($fn); &generateDataGear($fn); } @@ -102,20 +104,28 @@ sub generateDataGear { my ($filename) = @_; - my $fn1 = $filename; - $fn1 =~ s/\.cbc/.c/; open my $in,"<",$filename or die("can't open $filename $!"); - my $i = 1; - my $fn = $fn1; - while ( -f $fn) { - $fn = "$fn1.$i"; - $i++; + + my $fn; + if ($opt_o) { + $fn = $opt_o; + } else { + my $fn1 = $filename; + $fn1 =~ s/\.cbc/.c/; + my $i = 1; + $fn = $fn1; + while ( -f $fn) { + $fn = "$fn1.$i"; + $i++; + } } open my $fd,">",$fn or die("can't write $fn $!"); + my $prevCodeGearName; my $inTypedef = 0; my %stub; my $codeGearName; + while (<$in>) { if (! $inTypedef) { if (/^typedef struct (\w+) {/) {