16 if ($dolinno && $linexpect != $templlinno) {
17 print "# $templlinno \"$templ\"\n" or die $!;
19 print $_[0] or die $!;
20 $linexpect= $templlinno+1;
23 sub expand_and_write () {
25 $templl =~ s/\@([a-z]+)\=(\w*)\@/
26 die "$1=$2 in $templl ?" unless exists $v{$1};
27 $v{$1} eq $2 ? '' : '@SKIP@'
29 $templl =~ m/\@SKIP\@/
31 $templl =~ s/\@([a-z]+)\@/
32 die $1 unless exists $v{$1};
40 return sprintf "0x%02x", (oct("0b$bin") | $orin);
46 if (m/^From host to PIC/) {
47 $dirn= '>'; begin("host2pic");
48 } elsif (m/^From PIC to host/) {
49 $dirn= '<'; begin("pic2host");
53 next unless defined $dirn;
54 next unless m/^ ([<>]) / && $1 eq $dirn;
57 m/^ [<>] ([01A-Za-z. ]+?)(?: +|\s+\([+? A-Z0-9a-z]+\)\s+)([^() \t\n].*)$/;
59 next if $rhs =~ m/^\}/;
60 next if $msg =~ m/\.\.\./;
61 $rhs =~ m/^([A-Z]+)\s/ or die "$rhs?";
64 if ($msg =~ m/^0[01]{7}$/) {
66 $opcodemask= '11111111';
70 $ybit= substr($msg,0,8);
71 $ybit =~ y/Y01A-Z/10/;
72 $ybit =~ m/1.*1/ and die "$msg/$ybit?";
74 $msg =~ m/[A-Z]/ or die "$msg?";
77 die "$msg?" if $msg =~ m/[A-Z]/;
78 die "$msg?" unless $msg =~ m/^(1[01][01_]{6})0_{7}$/ or
79 $msg =~ m/^(0[01][01_]{6})$/;
81 die if $opcode =~ m/_[01]/;
83 $opcodemask =~ y/01_/110/;
87 $arglen= length $arglen;
88 $ybit= oct("0b$ybit");
90 for $yval (($ybit && $doyn) ? (0,1) : '') {
95 $v{cnameyn}= $cname.$yval;
96 $v{opcode}= b2xh($opcode, 0);
97 $v{opcodeyn}= b2xh($opcode, $ybit * $yval);
98 $v{opcodemask}= b2xh($opcodemask, 0);
99 $v{opcodemaskyn}= b2xh($opcodemask, $ybit);
101 $v{arglentf}= sprintf "%d", !!$arglen;
106 open T, "$templ" or die "$templ $!";
108 $templlin= <T>; last unless length $templlin;
110 if ($templlin =~ s/\@L\@//) {
113 if ($templlin !~ m/\@\w+\@/) {
115 } elsif ($templlin =~ s/\@1\@//) {
117 $v{skeleton}= 'autogenerated - do not edit';
120 $doyn= $templlin =~ m/\@[a-z]+yn\@/;
121 $templlin =~ s/\@h2p\@/\@dname=host2pic\@/;
122 $templlin =~ s/\@p2h\@/\@dname=pic2host\@/;
123 open S, "$spec" or die "$spec $!";