Mercurial > hg > Gears > GearsAgda
view src/parallel_execution/generate_stub.pl @ 226:68c03e7057d9
get arg
author | mir3636 |
---|---|
date | Tue, 17 Jan 2017 18:11:39 +0900 |
parents | 90fa6f8246ca |
children | 55260ff44c8c |
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; print STDOUT $1 . "\n"; while (/struct (\w+)/g) { print STDOUT "\t" . $1 . "\n"; } } 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/stub.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"; } print $fd "\n"; } # end