Mercurial > hg > Gears > Gears
view src/parallel_execution/tools/static_gen_header.pl @ 661:b6a3e1638f3a
Search headerfile first at generate_stub.pl
author | anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 18 Aug 2020 16:23:22 +0900 |
parents | 0aa2e7cde328 |
children | 9323327f09ae |
line wrap: on
line source
#!/usr/bin/env perl use strict; use warnings; use Getopt::Long qw/:config posix_default no_ignore_case bundling auto_help/; use Pod::Usage qw/pod2usage/; use Cwd qw/getcwd/; use File::Path qw/make_path/; =head1 DESCRIPTION emit Gears header files =head1 SYNOPSIS % sample.pl --interface list % sample.pl --impl single_linked_list --interface list % sample.pl -w --interface list =cut GetOptions( \my %opt, qw/ interface=s impl=s o=s w /) or pod2usage(1); unless ($opt{interface}) { pod2usage(1); } my ($type, $msg); if ($opt{impl}) { $msg = emit_impl_header($opt{interface}, $opt{impl}); $type = $opt{impl}; } else { $msg = emit_interface_header($opt{interface}); $type = $opt{interface}; } $msg .= emit_last($type); unless ($opt{w} || $opt{o}) { print $msg; exit 0; } my $emit_file; if ($opt{o}) { $emit_file = $opt{o}; } else { my $output_dir = $opt{impl} ? "impl" : "interface"; my $cwd = getcwd(); my $output_dir_path = "$cwd/$output_dir"; mkdir_output_dir($output_dir_path); $emit_file = "$output_dir_path/$type.h" } open my $fh, '>', $emit_file; print $fh $msg; close $fh; sub mkdir_output_dir { my $output_dir = shift; if (-d $output_dir) { return; } make_path($output_dir); } sub emit_interface_header { my $interface_name = shift; return "typedef struct $interface_name <Type, Impl> {\n"; } sub emit_impl_header { my ($interface_name, $impl_name) = @_; return "typedef struct $impl_name <Type, Isa> impl $interface_name {\n"; } sub emit_last { my $type = shift; my $msg = " __code next(...);\n"; $msg .= "} $type;\n"; return $msg; }