opc2c.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809
  1. /* opc2c.c --- generate C opcode decoder code from from .opc file
  2. Copyright (C) 2005-2022 Free Software Foundation, Inc.
  3. Contributed by Red Hat, Inc.
  4. This file is part of the GNU opcode library.
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  15. #include <stdio.h>
  16. #include <string.h>
  17. #include <ctype.h>
  18. #include <stdlib.h>
  19. #include <errno.h>
  20. #include "libiberty.h"
  21. static char * line_buf = NULL;
  22. static int line_buf_size = 0;
  23. #define LBUFINCR 100
  24. char *
  25. safe_fgets (FILE * f)
  26. {
  27. char * line_ptr;
  28. if (line_buf == NULL)
  29. {
  30. line_buf = (char *) malloc (LBUFINCR);
  31. line_buf_size = LBUFINCR;
  32. }
  33. /* Points to last byte. */
  34. line_ptr = line_buf + line_buf_size - 1;
  35. /* So we can see if fgets put a 0 there. */
  36. *line_ptr = 1;
  37. if (fgets (line_buf, line_buf_size, f) == 0)
  38. return NULL;
  39. /* We filled the buffer? */
  40. while (line_ptr[0] == 0 && line_ptr[-1] != '\n')
  41. {
  42. /* Make the buffer bigger and read more of the line. */
  43. line_buf_size += LBUFINCR;
  44. line_buf = (char *) realloc (line_buf, line_buf_size);
  45. /* Points to last byte again. */
  46. line_ptr = line_buf + line_buf_size - 1;
  47. /* So we can see if fgets put a 0 there. */
  48. *line_ptr = 1;
  49. if (fgets (line_buf + line_buf_size - LBUFINCR - 1, LBUFINCR + 1, f) == 0)
  50. return NULL;
  51. }
  52. return line_buf;
  53. }
  54. static int errors = 0;
  55. #define MAX_BYTES 10
  56. typedef struct
  57. {
  58. int varyno:16;
  59. int byte:8;
  60. int shift:8;
  61. } VaryRef;
  62. typedef struct
  63. {
  64. char nbytes;
  65. char dbytes;
  66. char id[MAX_BYTES * 8 + 1];
  67. unsigned char var_start[MAX_BYTES * 8 + 1];
  68. struct
  69. {
  70. unsigned char decodable_mask;
  71. unsigned char decodable_bits;
  72. } b[MAX_BYTES];
  73. char * comment;
  74. char * syntax;
  75. int lineno;
  76. int nlines;
  77. char ** lines;
  78. struct Indirect * last_ind;
  79. int semantics_label;
  80. int nvaries;
  81. VaryRef * vary;
  82. } opcode;
  83. int n_opcodes;
  84. opcode ** opcodes;
  85. opcode * op;
  86. typedef struct
  87. {
  88. char * name;
  89. int nlen;
  90. unsigned char mask;
  91. int n_patterns;
  92. unsigned char * patterns;
  93. } Vary;
  94. Vary ** vary = 0;
  95. int n_varies = 0;
  96. unsigned char cur_bits[MAX_BYTES + 1];
  97. const char * orig_filename;
  98. FILE * sim_log = NULL;
  99. #define lprintf if (sim_log) fprintf
  100. opcode prefix_text, suffix_text;
  101. typedef enum
  102. {
  103. T_unused,
  104. T_op,
  105. T_indirect,
  106. T_done
  107. } OpType;
  108. typedef struct Indirect
  109. {
  110. OpType type;
  111. union
  112. {
  113. struct Indirect * ind;
  114. opcode * op;
  115. } u;
  116. } Indirect;
  117. Indirect indirect[256];
  118. static int
  119. next_varybits (int bits, opcode * op, int byte)
  120. {
  121. int mask = op->b[byte].decodable_mask;
  122. int i;
  123. for (i = 0; i < 8; i++)
  124. if (!(mask & (1 << i)))
  125. {
  126. if (bits & (1 << i))
  127. {
  128. bits &= ~(1 << i);
  129. }
  130. else
  131. {
  132. bits |= (1 << i);
  133. return bits;
  134. }
  135. }
  136. return 0;
  137. }
  138. static int
  139. valid_varybits (int bits, opcode * op, int byte)
  140. {
  141. if (op->nvaries)
  142. {
  143. int vn;
  144. for (vn = 0; vn < op->nvaries; vn++)
  145. {
  146. Vary * v;
  147. int found = 0;
  148. int i;
  149. int ob;
  150. if (byte != op->vary[vn].byte)
  151. continue;
  152. v = vary[op->vary[vn].varyno];
  153. ob = (bits >> op->vary[vn].shift) & v->mask;
  154. lprintf (sim_log, "varybits: vary %s ob %x\n", v->name, ob);
  155. for (i = 0; i < v->n_patterns; i++)
  156. if (ob == v->patterns[i])
  157. {
  158. lprintf (sim_log, " found at %d\n", i);
  159. found = 1;
  160. break;
  161. }
  162. if (!found)
  163. return 0;
  164. }
  165. }
  166. return 1;
  167. }
  168. char *
  169. prmb (int mask, int bits)
  170. {
  171. static char buf[8][30];
  172. static int bn = 0;
  173. char * bp;
  174. bn = (bn + 1) % 8;
  175. bp = buf[bn];
  176. int i;
  177. for (i = 0; i < 8; i++)
  178. {
  179. int bit = 0x80 >> i;
  180. if (!(mask & bit))
  181. *bp++ = '-';
  182. else if (bits & bit)
  183. *bp++ = '1';
  184. else
  185. *bp++ = '0';
  186. if (i % 4 == 3)
  187. *bp++ = ' ';
  188. }
  189. *--bp = 0;
  190. return buf[bn];
  191. }
  192. static int
  193. op_cmp (const void *va, const void *vb)
  194. {
  195. const opcode * a = *(const opcode **) va;
  196. const opcode * b = *(const opcode **) vb;
  197. if (a->nbytes != b->nbytes)
  198. return a->nbytes - b->nbytes;
  199. return strcmp (a->id, b->id);
  200. }
  201. void
  202. dump_lines (opcode * op, int level, Indirect * ind)
  203. {
  204. char * varnames[40];
  205. int i, vn = 0;
  206. if (op->semantics_label)
  207. {
  208. printf ("%*sgoto op_semantics_%d;\n", level, "", op->semantics_label);
  209. return;
  210. }
  211. if (ind != op->last_ind)
  212. {
  213. static int labelno = 0;
  214. labelno++;
  215. printf ("%*sop_semantics_%d:\n", level, "", labelno);
  216. op->semantics_label = labelno;
  217. }
  218. if (op->comment)
  219. {
  220. level += 2;
  221. printf ("%*s{\n", level, "");
  222. printf ("%*s %s\n", level, "", op->comment);
  223. }
  224. for (i = 0; i < op->nbytes * 8;)
  225. {
  226. if (isalpha (op->id[i]))
  227. {
  228. int byte = i >> 3;
  229. int mask = 0;
  230. int shift = 0;
  231. char name[33];
  232. char * np = name;
  233. while (op->id[i] && isalpha (op->id[i]))
  234. {
  235. mask = (mask << 1) | 1;
  236. shift = 7 - (i & 7);
  237. *np++ = op->id[i++];
  238. if (op->var_start[i])
  239. break;
  240. }
  241. *np = 0;
  242. varnames[vn++] = strdup (name);
  243. printf ("#line %d \"%s\"\n", op->lineno + 1, orig_filename);
  244. if (mask & ~0xff)
  245. {
  246. fprintf (stderr, "Error: variable %s spans bytes: %s\n",
  247. name, op->comment);
  248. errors++;
  249. }
  250. else if (shift && (mask != 0xff))
  251. printf ("%*s int %s AU = (op[%d] >> %d) & 0x%02x;\n",
  252. level, "", name, byte, shift, mask);
  253. else if (mask != 0xff)
  254. printf ("%*s int %s AU = op[%d] & 0x%02x;\n",
  255. level, "", name, byte, mask);
  256. else
  257. printf ("%*s int %s AU = op[%d];\n", level, "", name, byte);
  258. }
  259. else
  260. i++;
  261. }
  262. if (op->comment)
  263. {
  264. printf ("%*s if (trace)\n", level, "");
  265. printf ("%*s {\n", level, "");
  266. printf ("%*s printf (\"\\033[33m%%s\\033[0m ", level, "");
  267. for (i = 0; i < op->nbytes; i++)
  268. printf (" %%02x");
  269. printf ("\\n\"");
  270. printf (",\n%*s \"%s\"", level, "", op->comment);
  271. for (i = 0; i < op->nbytes; i++)
  272. {
  273. if (i == 0)
  274. printf (",\n%*s op[%d]", level, "", i);
  275. else
  276. printf (", op[%d]", i);
  277. }
  278. printf (");\n");
  279. for (i = 0; i < vn; i++)
  280. printf ("%*s printf (\" %s = 0x%%x%s\", %s);\n", level, "",
  281. varnames[i], (i < vn - 1) ? "," : "\\n", varnames[i]);
  282. printf ("%*s }\n", level, "");
  283. }
  284. if (op->syntax)
  285. printf ("%*s SYNTAX(\"%s\");\n", level, "", op->syntax);
  286. printf ("#line %d \"%s\"\n", op->lineno + 1, orig_filename);
  287. for (i = 0; i < op->nlines; i++)
  288. if (op->lines[i][0] == '\n')
  289. printf ("%s", op->lines[i]);
  290. else
  291. printf ("%*s%s", level, "", op->lines[i]);
  292. if (op->comment)
  293. printf ("%*s}\n", level, "");
  294. }
  295. void
  296. store_opcode_bits (opcode * op, int byte, Indirect * ind)
  297. {
  298. int bits = op->b[byte].decodable_bits;
  299. do
  300. {
  301. if (!valid_varybits (bits, op, byte))
  302. continue;
  303. switch (ind[bits].type)
  304. {
  305. case T_unused:
  306. if (byte == op->dbytes - 1)
  307. {
  308. ind[bits].type = T_op;
  309. ind[bits].u.op = op;
  310. op->last_ind = ind;
  311. break;
  312. }
  313. else
  314. {
  315. int i2;
  316. ind[bits].type = T_indirect;
  317. ind[bits].u.ind = (Indirect *) malloc (256 * sizeof (Indirect));
  318. for (i2 = 0; i2 < 256; i2++)
  319. ind[bits].u.ind[i2].type = T_unused;
  320. store_opcode_bits (op, byte + 1, ind[bits].u.ind);
  321. }
  322. break;
  323. case T_indirect:
  324. if (byte < op->dbytes - 1)
  325. store_opcode_bits (op, byte + 1, ind[bits].u.ind);
  326. break;
  327. case T_op:
  328. break;
  329. case T_done:
  330. break;
  331. }
  332. }
  333. while ((bits = next_varybits (bits, op, byte)) != 0);
  334. }
  335. void
  336. emit_indirect (Indirect * ind, int byte)
  337. {
  338. int unsup = 0;
  339. int j, n, mask;
  340. mask = 0;
  341. for (j = 0; j < 256; j++)
  342. {
  343. switch (ind[j].type)
  344. {
  345. case T_indirect:
  346. mask = 0xff;
  347. break;
  348. case T_op:
  349. mask |= ind[j].u.op->b[byte].decodable_mask;
  350. break;
  351. case T_done:
  352. case T_unused:
  353. break;
  354. }
  355. }
  356. printf ("%*s GETBYTE ();\n", byte * 6, "");
  357. printf ("%*s switch (op[%d] & 0x%02x)\n", byte * 6, "", byte, mask);
  358. printf ("%*s {\n", byte * 6, "");
  359. for (j = 0; j < 256; j++)
  360. if ((j & ~mask) == 0)
  361. {
  362. switch (ind[j].type)
  363. {
  364. case T_done:
  365. break;
  366. case T_unused:
  367. unsup = 1;
  368. break;
  369. case T_op:
  370. for (n = j; n < 256; n++)
  371. if ((n & ~mask) == 0
  372. && ind[n].type == T_op && ind[n].u.op == ind[j].u.op)
  373. {
  374. ind[n].type = T_done;
  375. printf ("%*s case 0x%02x:\n", byte * 6, "", n);
  376. }
  377. for (n = byte; n < ind[j].u.op->nbytes - 1; n++)
  378. printf ("%*s GETBYTE();\n", byte * 6, "");
  379. dump_lines (ind[j].u.op, byte * 6 + 6, ind);
  380. printf ("%*s break;\n", byte * 6, "");
  381. break;
  382. case T_indirect:
  383. printf ("%*s case 0x%02x:\n", byte * 6, "", j);
  384. emit_indirect (ind[j].u.ind, byte + 1);
  385. printf ("%*s break;\n", byte * 6, "");
  386. break;
  387. }
  388. }
  389. if (unsup)
  390. printf ("%*s default: UNSUPPORTED(); break;\n", byte * 6, "");
  391. printf ("%*s }\n", byte * 6, "");
  392. }
  393. static char *
  394. pv_dup (char * p, char * ep)
  395. {
  396. int n = ep - p;
  397. char *rv = (char *) malloc (n + 1);
  398. memcpy (rv, p, n);
  399. rv[n] = 0;
  400. return rv;
  401. }
  402. static unsigned char
  403. str2mask (char * str, char * ep)
  404. {
  405. unsigned char rv = 0;
  406. while (str < ep)
  407. {
  408. rv *= 2;
  409. if (*str == '1')
  410. rv += 1;
  411. str++;
  412. }
  413. return rv;
  414. }
  415. static void
  416. process_vary (char * line)
  417. {
  418. char * cp;
  419. char * ep;
  420. Vary * v = (Vary *) malloc (sizeof (Vary));
  421. n_varies++;
  422. if (vary)
  423. vary = (Vary **) realloc (vary, n_varies * sizeof (Vary *));
  424. else
  425. vary = (Vary **) malloc (n_varies * sizeof (Vary *));
  426. vary[n_varies - 1] = v;
  427. cp = line;
  428. for (cp = line; isspace (*cp); cp++);
  429. for (ep = cp; *ep && !isspace (*ep); ep++);
  430. v->name = pv_dup (cp, ep);
  431. v->nlen = strlen (v->name);
  432. v->mask = (1 << v->nlen) - 1;
  433. v->n_patterns = 0;
  434. v->patterns = (unsigned char *) malloc (1);
  435. while (1)
  436. {
  437. for (cp = ep; isspace (*cp); cp++);
  438. if (!isdigit (*cp))
  439. break;
  440. for (ep = cp; *ep && !isspace (*ep); ep++);
  441. v->n_patterns++;
  442. v->patterns = (unsigned char *) realloc (v->patterns, v->n_patterns);
  443. v->patterns[v->n_patterns - 1] = str2mask (cp, ep);
  444. }
  445. }
  446. static int
  447. fieldcmp (opcode * op, int bit, char *name)
  448. {
  449. int n = strlen (name);
  450. if (memcmp (op->id + bit, name, n) == 0
  451. && (!isalpha (op->id[bit + n]) || op->var_start[bit + n]))
  452. return 1;
  453. return 0;
  454. }
  455. static void
  456. log_indirect (Indirect * ind, int byte)
  457. {
  458. int i, j;
  459. char * last_c = 0;
  460. for (i = 0; i < 256; i++)
  461. {
  462. for (j = 0; j < byte; j++)
  463. fprintf (sim_log, "%s ", prmb (255, cur_bits[j]));
  464. fprintf (sim_log, "%s ", prmb (255, i));
  465. switch (ind[i].type)
  466. {
  467. case T_op:
  468. case T_done:
  469. if (last_c && (ind[i].u.op->comment == last_c))
  470. fprintf (sim_log, "''\n");
  471. else
  472. fprintf (sim_log, "%s\n", ind[i].u.op->comment);
  473. last_c = ind[i].u.op->comment;
  474. break;
  475. case T_unused:
  476. fprintf (sim_log, "unused\n");
  477. break;
  478. case T_indirect:
  479. fprintf (sim_log, "indirect\n");
  480. cur_bits[byte] = i;
  481. log_indirect (ind[i].u.ind, byte + 1);
  482. last_c = 0;
  483. break;
  484. }
  485. }
  486. }
  487. int
  488. main (int argc, char ** argv)
  489. {
  490. char * line;
  491. FILE * in;
  492. int lineno = 0;
  493. int i;
  494. VaryRef * vlist;
  495. int skipping_section = 0;
  496. if (argc < 2)
  497. {
  498. fprintf (stderr, "usage: opc2c infile.opc > outfile.opc\n");
  499. exit (1);
  500. }
  501. orig_filename = lbasename (argv[1]);
  502. in = fopen (argv[1], "r");
  503. if (!in)
  504. {
  505. fprintf (stderr, "Unable to open file %s for reading: %s\n", argv[1],
  506. xstrerror (errno));
  507. exit (1);
  508. }
  509. n_opcodes = 0;
  510. opcodes = (opcode **) malloc (sizeof (opcode *));
  511. op = &prefix_text;
  512. op->lineno = 0;
  513. while ((line = safe_fgets (in)) != 0)
  514. {
  515. lineno++;
  516. if (strncmp (line, "/*?* ", 5) == 0)
  517. {
  518. skipping_section = 1;
  519. continue;
  520. }
  521. if (strncmp (line, " /** ", 6) == 0
  522. && (isdigit (line[6]) || memcmp (line + 6, "VARY", 4) == 0))
  523. line += 2;
  524. if (line[0] == '/' && line[1] == '*' && line[2] == '*')
  525. {
  526. skipping_section = 0;
  527. if (strncmp (line, "/** */", 6) == 0)
  528. {
  529. op = &suffix_text;
  530. op->lineno = lineno;
  531. }
  532. else if (strncmp (line, "/** VARY ", 9) == 0)
  533. process_vary (line + 9);
  534. else
  535. {
  536. char * lp;
  537. int i, bit, byte;
  538. int var_start = 1;
  539. n_opcodes++;
  540. opcodes =
  541. (opcode **) realloc (opcodes, n_opcodes * sizeof (opcode *));
  542. op = (opcode *) malloc (sizeof (opcode));
  543. opcodes[n_opcodes - 1] = op;
  544. op->nbytes = op->dbytes = 0;
  545. memset (op->id, 0, sizeof (op->id));
  546. memset (op->var_start, 0, sizeof (op->var_start));
  547. for (i = 0; i < MAX_BYTES; i++)
  548. {
  549. op->b[i].decodable_mask = 0;
  550. op->b[i].decodable_bits = 0;
  551. }
  552. op->comment = strdup (line);
  553. op->comment[strlen (op->comment) - 1] = 0;
  554. while (op->comment[0] && isspace (op->comment[0]))
  555. op->comment++;
  556. op->lineno = lineno;
  557. op->nlines = 0;
  558. op->lines = 0;
  559. op->last_ind = 0;
  560. op->semantics_label = 0;
  561. op->nvaries = 0;
  562. op->vary = 0;
  563. i = 0;
  564. for (lp = line + 4; *lp; lp++)
  565. {
  566. bit = 7 - (i & 7);
  567. byte = i >> 3;
  568. if (strncmp (lp, "*/", 2) == 0)
  569. break;
  570. else if ((lp[0] == ' ' && lp[1] == ' ') || (lp[0] == '\t'))
  571. {
  572. while (*lp == ' ' || *lp == '\t')
  573. lp ++;
  574. op->syntax = strdup (lp);
  575. lp = strstr (op->syntax, "*/");
  576. if (lp)
  577. {
  578. *lp-- = 0;
  579. while ((*lp == ' ' || *lp == '\t')
  580. && lp > op->syntax)
  581. *lp-- = 0;
  582. }
  583. break;
  584. }
  585. else if (*lp == ' ')
  586. var_start = 1;
  587. else
  588. {
  589. if (*lp == '0' || *lp == '1')
  590. {
  591. op->b[byte].decodable_mask |= 1 << bit;
  592. var_start = 1;
  593. if (op->dbytes < byte + 1)
  594. op->dbytes = byte + 1;
  595. }
  596. else if (var_start)
  597. {
  598. op->var_start[i] = 1;
  599. var_start = 0;
  600. if (op->dbytes < byte + 1)
  601. op->dbytes = byte + 1;
  602. }
  603. if (*lp == '1')
  604. op->b[byte].decodable_bits |= 1 << bit;
  605. op->nbytes = byte + 1;
  606. op->id[i++] = *lp;
  607. }
  608. }
  609. }
  610. }
  611. else if (!skipping_section)
  612. {
  613. op->nlines++;
  614. if (op->lines)
  615. op->lines =
  616. (char **) realloc (op->lines, op->nlines * sizeof (char *));
  617. else
  618. op->lines = (char **) malloc (op->nlines * sizeof (char *));
  619. op->lines[op->nlines - 1] = strdup (line);
  620. }
  621. }
  622. {
  623. int i, j;
  624. for (i = 0; i < n_varies; i++)
  625. {
  626. Vary *v = vary[i];
  627. lprintf (sim_log, "V[%s] %d\n", v->name, v->nlen);
  628. for (j = 0; j < v->n_patterns; j++)
  629. lprintf (sim_log, " P %02x\n", v->patterns[j]);
  630. }
  631. }
  632. for (i = n_opcodes - 2; i >= 0; i--)
  633. {
  634. if (opcodes[i]->nlines == 0)
  635. {
  636. opcodes[i]->nlines = opcodes[i + 1]->nlines;
  637. opcodes[i]->lines = opcodes[i + 1]->lines;
  638. }
  639. }
  640. for (i = 0; i < 256; i++)
  641. indirect[i].type = T_unused;
  642. qsort (opcodes, n_opcodes, sizeof (opcodes[0]), op_cmp);
  643. vlist = (VaryRef *) malloc (n_varies * sizeof (VaryRef));
  644. for (i = 0; i < n_opcodes; i++)
  645. {
  646. int j, b, v;
  647. for (j = 0; j < opcodes[i]->nbytes; j++)
  648. lprintf (sim_log, "%s ",
  649. prmb (opcodes[i]->b[j].decodable_mask,
  650. opcodes[i]->b[j].decodable_bits));
  651. lprintf (sim_log, " %s\n", opcodes[i]->comment);
  652. for (j = 0; j < opcodes[i]->nbytes; j++)
  653. {
  654. for (b = 0; b < 8; b++)
  655. if (isalpha (opcodes[i]->id[j * 8 + b]))
  656. for (v = 0; v < n_varies; v++)
  657. if (fieldcmp (opcodes[i], j * 8 + b, vary[v]->name))
  658. {
  659. int nv = opcodes[i]->nvaries++;
  660. if (nv)
  661. opcodes[i]->vary =
  662. (VaryRef *) realloc (opcodes[i]->vary,
  663. (nv + 1) * sizeof (VaryRef));
  664. else
  665. opcodes[i]->vary =
  666. (VaryRef *) malloc ((nv + 1) * sizeof (VaryRef));
  667. opcodes[i]->vary[nv].varyno = v;
  668. opcodes[i]->vary[nv].byte = j;
  669. opcodes[i]->vary[nv].shift = 8 - b - vary[v]->nlen;
  670. lprintf (sim_log, "[vary %s shift %d]\n",
  671. vary[v]->name, opcodes[i]->vary[nv].shift);
  672. }
  673. }
  674. }
  675. for (i = 0; i < n_opcodes; i++)
  676. {
  677. int i2;
  678. int bytes = opcodes[i]->dbytes;
  679. lprintf (sim_log, "\nmask:");
  680. for (i2 = 0; i2 < opcodes[i]->nbytes; i2++)
  681. lprintf (sim_log, " %02x", opcodes[i]->b[i2].decodable_mask);
  682. lprintf (sim_log, "%*s%s\n", 13 - 3 * opcodes[i]->nbytes, "",
  683. opcodes[i]->comment);
  684. lprintf (sim_log, "bits:");
  685. for (i2 = 0; i2 < opcodes[i]->nbytes; i2++)
  686. lprintf (sim_log, " %02x", opcodes[i]->b[i2].decodable_bits);
  687. lprintf (sim_log, "%*s(%s) %d byte%s\n", 13 - 3 * opcodes[i]->nbytes,
  688. "", opcodes[i]->id, bytes, bytes == 1 ? "" : "s");
  689. store_opcode_bits (opcodes[i], 0, indirect);
  690. }
  691. printf ("/* DO NOT EDIT! -*- buffer-read-only: t -*- vi:set ro: */\n");
  692. dump_lines (&prefix_text, 0, 0);
  693. emit_indirect (indirect, 0);
  694. dump_lines (&suffix_text, 0, 0);
  695. if (sim_log)
  696. log_indirect (indirect, 0);
  697. return errors;
  698. }