t
layoutinfo.h
*.d
-proto-spec.h
+proto-expanded
+auproto-*
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
#!/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;
}
$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 $!;
+++ /dev/null
-/*
- * 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*/
--- /dev/null
+/*
+ * 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
+};
* 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);
extern const PicInsnInfo pic_command_infos[], pic_reply_infos[];
-#endif /*PIC_PROTO_H*/
+#endif /*AUPROTO_PIC_H*/