Mercurial > hg > Gears > GearsAgda
view src/parallel_execution/generate_stub.pl @ 228:55260ff44c8c
generate stub
author | mir3636 |
---|---|
date | Sat, 21 Jan 2017 19:42:39 +0900 |
parents | 68c03e7057d9 |
children | a10ea0cfc929 |
line wrap: on
line source
#!/usr/bin/perl # interface.cbc # typedef struct Worker { # int id; # struct Context* contexts; # enum Code execute; # enum Code taskSend; # enum Code taskRecive; # enum Code shutdown; # struct Queue* tasks; # } Worker; system "rm -rf d"; system "mkdir d"; while (<*.cbc>) { &getDataGear($_); } &generateDataGear(); sub getDataGear { my ($filename) = @_; open my $fd,"<",$filename or die("can't open $filename $!"); while (<$fd>) { if (! $inTypedef) { if (/^typedef struct (\w+) {/) { $inTypedef = 1; $name = $1; $dataGear{$name} = $_; } if (/^\_\_code (\w+)/) { $codeGearName = $1; while (/struct (\w+)/g) { $dataGearName{$codeGearName} .= "\t\tGearef(context, " . $1 . ")." . lc $1; $dataGearName{$codeGearName} .= ",\n"; } next; } next; } $dataGear{$name} .= $_; if (/(\w+);$/ and !/^} (\w+)/) { $tmp = $1 . "\n"; if (/{/) { $tmp = "{" . $'; $tmp =~ s/;$//; } $var{$name} .= $tmp; $tmp = $`; $tmp =~ s/^\s*//; $type{$name} .= $tmp . "\n"; } if (/^}/) { $inTypedef = 0; } } } sub generateDataGear { open my $fd,">","d/extern.h" or die("can't open d/extern.h $!"); for my $name ( sort keys %dataGear ) { print $fd $dataGear{$name},"\n"; } print $fd "\n"; open my $fd,">","d/type.h" or die("can't open d/stub.h $!"); for my $name ( sort keys %dataGear ) { print $fd $var{$name},"\n"; } for my $name ( sort keys %dataGear ) { print $fd $type{$name},"\n"; } open my $fd,">","d/stub.h" or die("can't open d/stub.h $!"); for my $codeGearName ( sort keys %dataGearName ) { print $fd "__code ", $codeGearName ,"_stub (struct Context* context) {\n"; print $fd "\tgoto meta(context, \n"; chomp($dataGearName{$codeGearName}); chop($dataGearName{$codeGearName}); print $fd $dataGearName{$codeGearName},") \n} \n\n"; } print $fd "\n"; } # end