From 543eeca43f34221665d1edd4726b20ede59a9c21 Mon Sep 17 00:00:00 2001 From: ian Date: Fri, 3 Jun 2005 23:20:31 +0000 Subject: [PATCH] nice new proto-parse stuff --- hostside/.cvsignore | 3 +- hostside/Makefile | 7 ++- hostside/parse-proto-spec | 62 +++++++++++++++++++---- hostside/pic-proto.c | 61 ---------------------- hostside/skelproto-pic.c | 19 +++++++ hostside/{pic-proto.h => skelproto-pic.h} | 20 +++----- 6 files changed, 85 insertions(+), 87 deletions(-) delete mode 100644 hostside/pic-proto.c create mode 100644 hostside/skelproto-pic.c rename hostside/{pic-proto.h => skelproto-pic.h} (51%) diff --git a/hostside/.cvsignore b/hostside/.cvsignore index 753b816..a45bb35 100644 --- a/hostside/.cvsignore +++ b/hostside/.cvsignore @@ -4,4 +4,5 @@ safety t layoutinfo.h *.d -proto-spec.h +proto-expanded +auproto-* diff --git a/hostside/Makefile b/hostside/Makefile index 7fbe9dc..90470e3 100644 --- a/hostside/Makefile +++ b/hostside/Makefile @@ -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 diff --git a/hostside/parse-proto-spec b/hostside/parse-proto-spec index 5ee9501..8d34ce3 100755 --- a/hostside/parse-proto-spec +++ b/hostside/parse-proto-spec @@ -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= ; 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 () { + 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 index 0548662..0000000 --- a/hostside/pic-proto.c +++ /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 index 0000000..9619a3a --- /dev/null +++ b/hostside/skelproto-pic.c @@ -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 +}; diff --git a/hostside/pic-proto.h b/hostside/skelproto-pic.h similarity index 51% rename from hostside/pic-proto.h rename to hostside/skelproto-pic.h index 4774257..c6804e6 100644 --- a/hostside/pic-proto.h +++ b/hostside/skelproto-pic.h @@ -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*/ -- 2.30.2