From 006382fcc77f7dc6339076e7d010741c454f2e97 Mon Sep 17 00:00:00 2001 From: ian Date: Tue, 31 May 2005 22:55:21 +0000 Subject: [PATCH] parse-proto-spec works so far --- hostside/parse-proto-spec | 50 ++++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 16 deletions(-) diff --git a/hostside/parse-proto-spec b/hostside/parse-proto-spec index e49b905..6aa2b74 100755 --- a/hostside/parse-proto-spec +++ b/hostside/parse-proto-spec @@ -1,37 +1,55 @@ #!/usr/bin/perl + +print("/* autogenerated - do not edit */\n"); + while (<>) { - $dirn= '<' if m/^From host to PIC/ ... m/^\S/; - $dirn= '>' if m/^From host to PIC/ ... m/^\S/; - - $dirn= ? '>' : - m/^From PIC to host/ ... m/^\S/ ? '<' : undef; + chomp; + if (m/^From host to PIC/) { + $dirn= '>'; $dname= "HOST2PIC"; + } elsif (m/^From PIC to host/) { + $dirn= '<'; $dname= "PIC2HOST"; + } elsif (m/^\S/) { + $dirn= undef; + } next unless defined $dirn; - next unless m/^ [(<>)] / && $1 eq $dirn; + next unless m/^ ([<>]) / && $1 eq $dirn; die if m/\t/; - die unless m/^ [<>] ([01A-Z. ]+?) +(?:\([A-Z]\))? (\S.*)$/; + die unless m/^ [<>] ([01A-Za-z. ]+?) +(\S.*)$/; $msg= $1; $rhs= $2; + $rhs =~ s/^\([A-Z][0-9A-Z]+\) +//; next if $rhs =~ m/^\}/; - next if $msg =~ m/^\.\.\./; - $rhs =~ m/^([A-Z]+)\s/; + next if $msg =~ m/\.\.\./; + $rhs =~ m/^([A-Z]+)\s/ or die "$rhs?"; $cname= lc $1; $msg =~ s/ //g; if ($msg =~ m/^0[01]{7}$/) { $opcode= $&; $arglen= 0; + $ybit= 0; } else { - $msg =~ m/A-Z/; + $ybit= substr($msg,0,8); + $ybit =~ y/Y01A-Z/10/; + $ybit =~ m/1.*1/ and die "$msg/$ybit?"; + $msg =~ s/Y/0/g; + $msg =~ m/[A-Z]/ or die "$msg?"; $oplet= $&; $msg =~ s/$oplet/_/g; - die if $msg =~ m/A-Z/; - die if $msg =~ m/_[01]/; - die unless $msg =~ m/^(1[01][01_]{6})0_{7}$/ or + die "$msg?" if $msg =~ m/[A-Z]/; + die "$msg?" unless $msg =~ m/^(1[01][01_]{6})0_{7}$/ or $msg =~ m/^(0[01][01_]{6})$/; $opcode= $1; + die if $opcode =~ m/_[01]/; + $opcode =~ s/_/0/g; $arglen= $msg; $arglen =~ s/[01]//g; $arglen= length $arglen; + $ybit= oct("0b$ybit"); + } + for $yval ($ybit ? (0,1) : '') { + printf(" { %-16s 0x%02x, %2d },\n", + sprintf("\"%s%s\",",$cname, $yval), + oct("0b$opcode") | $ybit *$yval, + $arglen) + or die $!; } - printf(" { %-16s, 0x%02x, %2d },", - "\"$cname\",", bin($opcode), $arglen) - or die $!; } -- 2.30.2