changeset 343:a9aba14b2b6a

add static_gen_header script
author anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Thu, 27 Feb 2020 16:17:40 +0900
parents 1a63c120f2ba
children 12c7ba704de7
files src/gearsTools/static_gen_header.pl src/types.h
diffstat 2 files changed, 82 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/gearsTools/static_gen_header.pl	Thu Feb 27 16:17:40 2020 +0900
@@ -0,0 +1,81 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+
+=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
+
+use Getopt::Long qw/:config posix_default no_ignore_case bundling auto_help/;
+
+use Pod::Usage qw/pod2usage/;
+
+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 {
+    $emit_file = "$type.h"
+}
+
+
+open my $fh, '>', $emit_file;
+print $fh $msg;
+close $fh;
+
+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 = <<"EOF";
+  __code next(....);
+} $type;
+EOF
+  return $msg;
+}
--- a/src/types.h	Thu Feb 27 15:54:33 2020 +0900
+++ b/src/types.h	Thu Feb 27 16:17:40 2020 +0900
@@ -7,4 +7,4 @@
 
 #ifndef NULL
 #define NULL ((void*)0)
-#endif
\ No newline at end of file
+#endif