view src/parallel_execution/generate_stub.pl @ 200:207aff30ed34

fix generate_stub.pl
author mir3636
date Mon, 19 Dec 2016 19:00:38 +0900
parents bd96dffaa76a
children 90fa6f8246ca
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} = $_;
            }
            next;
        }
        $dataGear{$name} .= $_;
	if (/(\w+);$/ and !/^} (\w+)/) {
	    $tmp = $1 . "\n";
	    if (/{/) {
	            $tmp = "{" . $';
	    }
	    $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