chiark / gitweb /
nice new proto-parse stuff
authorian <ian>
Fri, 3 Jun 2005 23:20:31 +0000 (23:20 +0000)
committerian <ian>
Fri, 3 Jun 2005 23:20:31 +0000 (23:20 +0000)
hostside/.cvsignore
hostside/Makefile
hostside/parse-proto-spec
hostside/pic-proto.c [deleted file]
hostside/skelproto-pic.c [new file with mode: 0644]
hostside/skelproto-pic.h [moved from hostside/pic-proto.h with 51% similarity]

index 753b8168e94b02c101e2918fddb6563834f8eefa..a45bb3545008b86ecddcfcd4116566ff9a949f30 100644 (file)
@@ -4,4 +4,5 @@ safety
 t
 layoutinfo.h
 *.d
-proto-spec.h
+proto-expanded
+auproto-*
index 7fbe9dcad9bd0ff5d6817246aab6d97651eebf60..90470e3a677972fcfd3678c8165394637f909649 100644 (file)
@@ -14,8 +14,11 @@ hostside:    hostside.o serialio.o client.o obc.o commands.o \
                 nmra.o encode.o retransmit.o output.o -loop
                $(LINK)
 
-proto-spec.h:  ../cebpic/README.protocol ./parse-proto-spec
-               expand <$< | ./parse-proto-spec $o
+proto-expanded:        ../cebpic/README.protocol
+               expand <$< $o
+
+auproto-%:     parse-proto-spec proto-expanded skelproto-%
+               ./$+ $o
 
 layoutinfo.h:  ../layout/ours.layout-data.c Makefile
                sed -e '/^#include/,$$d' $< $o
index 5ee9501a56c5e3909b2e3b214ecaa2dc9c4457fd..8d34ce33d3bbba8daaf56e7e823ac23c782e902a 100755 (executable)
@@ -1,17 +1,22 @@
 #!/usr/bin/perl
 
-print("/* autogenerated - do not edit */\n");
+use IO::Handle;
+
+@ARGV==2 or die;
 
 sub begin ($) {
     $dname= $_[0];
 }
 
-while (<>) {
+($spec,$templ)=@ARGV;
+
+sub process_line () {
     chomp;
+    $origprotoline= $_;
     if (m/^From host to PIC/) {
-       $dirn= '>'; begin("HOST2PIC");
+       $dirn= '>'; begin("host2pic");
     } elsif (m/^From PIC to host/) {
-       $dirn= '<'; begin("PIC2HOST");
+       $dirn= '<'; begin("pic2host");
     } elsif (m/^\S/) {
        $dirn= undef;
     }
@@ -49,12 +54,47 @@ while (<>) {
        $arglen= length $arglen;
        $ybit= oct("0b$ybit");
     }
-    for $yval ($ybit ? (0,1) : '') {
-       printf("%s_%d( %-12s 0x%02x, %2d )\n",
-              $dname, !!$arglen,
-              sprintf("%s%s,",$cname, $yval),
-              oct("0b$opcode") | $ybit *$yval,
-              $arglen)
-           or die $!;
+    for $yval (($ybit && $doyn) ? (0,1) : '') {
+       undef %v;
+       $v{yn}= $yval;
+       $v{dname}= $dname;
+       $v{cname}= $cname;
+       $v{cnameyn}= $cname.$yval;
+       $v{opcode}= sprintf "0x%02x", oct("0b$opcode");
+       $v{opcodeyn}= sprintf "0x%02x", (oct("0b$opcode") | $ybit * $yval);
+       $v{arglen}= $arglen;
+       $v{arglentf}= sprintf "%d", !!$arglen;
+       $templl= $templlin;
+       $templl =~ s/\@h2p\@/\@dname=host2pic\@/;
+       $templl =~ s/\@p2h\@/\@dname=pic2host\@/;
+       $templl =~ s/\@([a-z]+)\=(\w*)\@/
+           die "$1=$2 in $templl ?" unless exists $v{$1};
+           $v{$1} eq $2  ? '' : '@SKIP@'
+       /ge;
+       $templl =~ m/\@SKIP\@/
+           and next;
+       $templl =~ s/\@([a-z]+)\@/
+           die $1 unless exists $v{$1};
+           $v{$1}
+       /ge;
+       print $templl or die $!;
+    }
+}
+
+open T, "$templ" or die "$templ $!";
+for (;;) {
+    $templlin= <T>;  last unless length $templlin;
+    if ($templlin !~ m/\@\w+\@/) {
+       print $templlin or die $!;
+    } else {
+        $doyn= $templlin =~ m/\@[a-z]+yn\@/;
+        open S, "$spec" or die "$spec $!";
+        while (<S>) {
+           process_line();
+       }
+       S->error and die $!;
+       close S or die $!;
     }
 }
+T->error and die $!;
+close T or die $!;
diff --git a/hostside/pic-proto.c b/hostside/pic-proto.c
deleted file mode 100644 (file)
index 0548662..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * arranges for the declarations of
- *  enco_pic_WHATEVER
- *  onrecv_pic_WHATEVER
- * and the tables
- */
-
-#ifndef PROTOCOL_H
-#define PROTOCOL_H
-
-#define HOST2PIC_0(n,o,a) HOST2PIC_1(n,o,a) 
-#define PIC2HOST_0(n,o,a) PIC2HOST_1(n,o,a)
-
-#if 0
-static void pe(PicInsn *out, );
-#define EP(objnum) { ep(out,o,a,objnum); }
-#define HOST2PIC_0(n,o,a) void enco_pic_##n(PicInsn *out)         EP(0)
-#define HOST2PIC_1(n,o,a) void enco_pic_##n(PicInsn *out, int oj) EP(oj)
-#define PIC2HOST_0(n,o,a) /**/
-#define PIC2HOST_1(n,o,a) /**/
-#include "proto-spec.h"
-#undef HOST2PIC_0
-#undef HOST2PIC_1
-#undef PIC2HOST_0
-#undef PIC2HOST_1
-#endif
-
-extern void enco_pic_polarity_begin(PicInsn *out);
-extern void enco_pic_polarity_setbit(PicInsn *out, int objnum);
-extern void on_pic_debug(int ch);
-
-const PicInsnInfo pic_command_infos[]= {
-#define HOST2PIC_1(n,o,a) { #n, o, a },
-#define PIC2HOST_1(n,o,a) /**/
-#undef PIC2HOST_1
-#include "proto-spec.h"
-#undef HOST2PIC_1
-#undef PIC2HOST_1
-};
-
-const PicInsnInfo pic_reply_infos[]= {
-#define HOST2PIC_1(n,o,a) /**/
-#define PIC2HOST_1(n,o,a) { #n, o, a },
-#undef PIC2HOST_1
-#include "proto-spec.h"
-#undef HOST2PIC_1
-#undef PIC2HOST_1
-};
-
-
-#undef HOST2PIC_1
-#undef HOST2PIC_0
-
-static void pe(PicInsn *out, );
-#define EP(objnum) { ep(out,o,a,objnum); }
-#define PIC2HOST_0(n,o,a) /**/
-#define PIC2HOST_1(n,o,a) /**/
-#include "proto-spec.h"
-#undef PIC2HOST_0
-
-#endif /*NMRA_H*/
diff --git a/hostside/skelproto-pic.c b/hostside/skelproto-pic.c
new file mode 100644 (file)
index 0000000..9619a3a
--- /dev/null
@@ -0,0 +1,19 @@
+/*
+ * arranges for the declarations of
+ *  enco_pic_WHATEVER
+ *  onrecv_pic_WHATEVER
+ * and the tables
+ */
+
+#ifndef PROTOCOL_H
+#define PROTOCOL_H
+
+const PicInsnInfo pic_command_infos[]= {
+  { "@cnameyn@", @opcodeyn@, @arglen@ }, @h2p@
+  0
+};
+
+const PicInsnInfo pic_reply_infos[]= {
+  { "@cnameyn@", @opcodeyn@, @arglen@ }, @p2h@
+  0
+};
similarity index 51%
rename from hostside/pic-proto.h
rename to hostside/skelproto-pic.h
index 4774257c06366208e2f3ddf5a82e9c4403cb85f9..c6804e6fb4394d7c96433ab8033a98eb2515fb36 100644 (file)
@@ -5,18 +5,14 @@
  * and the tables
  */
 
-#ifndef PIC_PROTO_H
-#define PIC_PROTO_H
+#ifndef AUPROTO_PIC_H
+#define AUPROTO_PIC_H
 
-#define HOST2PIC_0(n,o,a) extern void enco_pic_##n(PicInsn *out);
-#define HOST2PIC_1(n,o,a) extern void enco_pic_##n(PicInsn *out, int objnum);
-#define PIC2HOST_0(n,o,a) extern void on_pic_##n(void);
-#define PIC2HOST_1(n,o,a) extern void on_pic_##n(int objnum);
-#include "proto-spec.h"
-#undef HOST2PIC_0
-#undef HOST2PIC_1
-#undef PIC2HOST_0
-#undef PIC2HOST_1
+void enco_pic_@cname@(PicInsn *out);            @h2p@ @arglentf=0@
+void enco_pic_@cname@(PicInsn *out, int objum); @h2p@ @arglentf=1@
+
+void on_pic_@cnameyn@(void);       @p2h@ @arglentf=0@
+void on_pic_@cnameyn@(int objnum); @p2h@ @arglentf=1@
 
 extern void enco_pic_polarity_begin(PicInsn *out);
 extern void enco_pic_polarity_setbit(PicInsn *out, int objnum);
@@ -31,4 +27,4 @@ struct PicInsnInfo {
 
 extern const PicInsnInfo pic_command_infos[], pic_reply_infos[];
 
-#endif /*PIC_PROTO_H*/
+#endif /*AUPROTO_PIC_H*/