12BEGIN {3 nvar=04 printf "#include <scc/mach.h>\n"\5 "#include <scc/scc.h>\n"\6 "#include \"../as.h\"\n"\7 "#include \"proc.h\"\n"89 rules = "opers.dat"10 while (getline < rules > 0) {11 regex[++nregs] = $112 value[nregs] = $213 }14 close(rules)15}16 {sub(/#.*/,"")}1718$7 !~ cpu {next}1920/^$/ {next}2122 {23 if (op[$1] == 0) {24 op[$1] = 125 opstart[$1] = nvar26 opnames[nop++] = $127 }28 opcount[$1]++29 opargs[nvar] = $330 opsize[nvar] = $431 opbytes[nvar] = ($5 == "none") ? "" : $532 opformat[nvar++] = $633 formats[$6] = 134}3536END {37 for (i in formats)38 printf "Format %s;\n", i3940 print "struct ins instab[] = {"41 for (i = 0; i < nop; i++) {42 n = opnames[i]43 start = opstart[n]44 end = start + opcount[n]45 printf "\t{.str = \"%s\", .begin = %d, .end = %d},\n",46 n, start, end47 }48 printf "};\n\n"4950 for (i = 0; i < nop; i++)51 print opnames[i] | "../lexh"52 close("../lexh")5354 print "struct op optab[] = {"55 for (i = 0; i < nvar; i++) {56 printf "\t/* %d */\n", i57 printf "\t{\n" \58 "\t\t.size = %d,\n"\59 "\t\t.format = %s,\n",60 opsize[i], opformat[i]6162 if (opbytes[i] != "")63 printf "\t\t.bytes = (unsigned char [%d]) {%s},\n",64 opsize[i],65 opbytes[i]6667 a = str2args(opargs[i])68 if (a != "")69 printf "\t\t.args = (unsigned char []) {%s}\n", a7071 print "\t},"72 }73 print "};"74}7576function str2args(s, args, i, j, out, n, found)77{78 n = split(s, args, /,/)79 if (n == 0 || args[1] == "none")80 return ""81 for (i = 1; i <= n; i++) {82 a = args[i]83 found = 08485 if (a ~ /\?$/)86 out = out "AOPT ,"87 else if (a ~ /\+$/)88 out = out "AREP ,"8990 for (j = 1; j <= nregs; j++) {91 if (match(a, "^" regex[j])) {92 out = out value[j]93 found = 194 break95 }96 }9798 if (!found) {99 print FILENAME ":" NR ":" \100 $0 ":wrong arg in opcode list", a > "/dev/stderr"101 exit 1102 }103104 a = substr(a, RLENGTH+1)105 sub(/\?$/, "", a)106 sub(/\+$/, "", a)107 if (a != "") {108 print FILENAME ":" NR ":" \109 $0 ": trailing chars: ", a > "/dev/stderr"110 exit 1111 }112 out = out ","113 }114 out = out "0"115116 return out117}