changeset 3:8f05bcf2f4ef

add proto.h
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Wed, 14 Oct 2020 23:44:23 +0900
parents 8fa50012cad9
children e66321b51bb5
files tl1trans/tl1trans.pl
diffstat 1 files changed, 23 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/tl1trans/tl1trans.pl	Wed Oct 14 20:33:17 2020 +0900
+++ b/tl1trans/tl1trans.pl	Wed Oct 14 23:44:23 2020 +0900
@@ -51,12 +51,14 @@
 
 &getDecl;
 &procs;
-&proto;
 my $nest = 0;
 
 # get line without comment
 sub getline {
-    exit 1 if (eof) ;
+    if (eof) {
+        &proto;
+        exit 1;
+    }
     $_ = <>;
     s/^\%.*//;
 }
@@ -123,6 +125,11 @@
     }
 }
 
+#
+# assumption
+#     an expression has no space in it
+#     space means a statement separation
+
 our $cnest = 0;
 sub statement {
     my ($skip) = @_;
@@ -133,6 +140,9 @@
             &getline; chop;
         }
         while($_ ne "") {
+            if (s/^\s+//)  {
+                print $&;
+            }
             if (s/^WRITE\((\d+)://)  {
                 my $d = $1;
                 while($_ ne "") {
@@ -234,7 +244,7 @@
             my $args = "";
             my $lvar = "";
             for my $var (@lvar) {
-                $lvar .= "unsigned char $var;\n";
+                $lvar .= "   unsigned char $var;\n";
             }
             print <<"EOFEOF";
 $type$proc($args) {
@@ -244,7 +254,7 @@
             $nest = 1;
             &statement(0);
             print <<"EOFEOF";
-} // end $proc
+\n} // end $proc
 EOFEOF
         } elsif (/^(\w+)\([\w,]+\)/) {
             $proc = $1;
@@ -257,12 +267,16 @@
 
 sub proto {
     open my $fd, ">","proto.h";
-    foreach my $key ( keys %args ) {
-        if (&isfunc($key)) {
-           print $fd "int ";
-        } else {
-           print $fd "void ";
+    foreach my $key ( @procs ) {
+        print $fd "void ";
+        print $fd $key,"(";
+        if ($args{$key}) {
+           print $fd "unsigned char ",join(",unsigned char ",split(/,/,$args{$key}));
         }
+        print $fd ");\n";
+    }
+    foreach my $key ( @funcs ) {
+        print $fd "int ";
         print $fd $key,"(";
         if ($args{$key}) {
            print $fd "unsigned char ",join(",unsigned char ",split(/,/,$args{$key}));