Mercurial > hg > GearsTemplate
diff src/parallel_execution/generate_context.pl @ 254:edb3aff688d0
fix generator CLI
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 27 Jan 2017 10:10:09 +0900 (2017-01-27) |
parents | 421ea91dd76c |
children | cd3486e4ba70 |
line wrap: on
line diff
--- 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"; }