makeitems.c 1.8 KB

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