makeitems.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /* $Id$ */
  2. /*
  3. * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
  4. * See the copyright notice in the ACK home directory, in the file "Copyright".
  5. */
  6. #include <stdlib.h>
  7. #include <stdio.h>
  8. /* MAKE ITEMS TABLE
  9. *
  10. * This program is used by the register allocation phase of the optimizer
  11. * to make the file itemtab.h. It reads two files:
  12. * - the em_mnem.h file, containing the definitions of the
  13. * EM mnemonics
  14. * - the item-file, containing tuples:
  15. * (mnemonic, item_type)
  16. * The output (standard output) is a C array.
  17. */
  18. #define TRUE 1
  19. #define FALSE 0
  20. convert(mnemfile,itemfile)
  21. FILE *mnemfile, *itemfile;
  22. {
  23. char mnem1[20], mnem2[20],def[20],itemtype[20];
  24. int newcl,opc,index;
  25. newcl = TRUE;
  26. printf("struct item_descr itemtab[] = {\n");
  27. for (;;) {
  28. fscanf(mnemfile,"%s%s%d",def,mnem1,&opc);
  29. /* read a line like "#define op_aar 1" */
  30. if (feof(mnemfile)) break;
  31. if (strcmp(def,"#define") != 0) {
  32. error("bad mnemonic file, #define expected");
  33. }
  34. if (newcl) {
  35. fscanf(itemfile,"%s%s%d",mnem2,itemtype,&index);
  36. /* read a line like "op_loc CONST 4" */
  37. }
  38. if (feof(itemfile) || strcmp(mnem1,mnem2) != 0) {
  39. /* there is no line for this mnemonic, so
  40. * it has no type.
  41. */
  42. printf("{NO_ITEM,0}, /* %s */\n", mnem1);
  43. newcl = FALSE;
  44. } else {
  45. printf("{%s,%d}, /* %s */\n",itemtype,index, mnem1);
  46. newcl = TRUE;
  47. }
  48. }
  49. printf("};\n");
  50. }
  51. error(s)
  52. char *s;
  53. {
  54. fprintf(stderr,"%s\n",s);
  55. exit(-1);
  56. }
  57. main(argc,argv)
  58. int argc;
  59. char *argv[];
  60. {
  61. FILE *f1,*f2;
  62. if (argc != 3) {
  63. error("usage: makeitems mnemfile itemfile");
  64. }
  65. if ((f1 = fopen(argv[1],"r")) == NULL) {
  66. error("cannot open mnemonic file");
  67. }
  68. if ((f2 = fopen(argv[2],"r")) == NULL) {
  69. error("cannot open item file");
  70. }
  71. convert(f1,f2);
  72. exit(0);
  73. }