gentmap.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /* Generate targ-vals.h and targ-map.c. */
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. struct tdefs {
  6. char *symbol;
  7. int value;
  8. };
  9. static struct tdefs sys_tdefs[] = {
  10. #define sys_defs
  11. #include "targ-vals.def"
  12. #undef sys_defs
  13. { 0, 0 }
  14. };
  15. static struct tdefs errno_tdefs[] = {
  16. #define errno_defs
  17. #include "targ-vals.def"
  18. #undef errno_defs
  19. { 0, 0 }
  20. };
  21. static struct tdefs open_tdefs[] = {
  22. #define open_defs
  23. #include "targ-vals.def"
  24. #undef open_defs
  25. { 0, 0 }
  26. };
  27. static void
  28. gen_targ_vals_h (void)
  29. {
  30. struct tdefs *t;
  31. printf ("/* Target header values needed by the simulator and gdb. */\n");
  32. printf ("/* This file is machine generated by gentmap.c. */\n\n");
  33. printf ("#ifndef TARG_VALS_H\n");
  34. printf ("#define TARG_VALS_H\n\n");
  35. printf ("/* syscall values */\n");
  36. for (t = &sys_tdefs[0]; t->symbol; ++t)
  37. printf ("#define TARGET_%s %d\n", t->symbol, t->value);
  38. printf ("\n");
  39. printf ("/* errno values */\n");
  40. for (t = &errno_tdefs[0]; t->symbol; ++t)
  41. printf ("#define TARGET_%s %d\n", t->symbol, t->value);
  42. printf ("\n");
  43. printf ("/* open flag values */\n");
  44. for (t = &open_tdefs[0]; t->symbol; ++t)
  45. printf ("#define TARGET_%s 0x%x\n", t->symbol, t->value);
  46. printf ("\n");
  47. printf ("#endif /* TARG_VALS_H */\n");
  48. }
  49. static void
  50. gen_targ_map_c (void)
  51. {
  52. struct tdefs *t;
  53. printf ("/* Target value mapping utilities needed by the simulator and gdb. */\n");
  54. printf ("/* This file is machine generated by gentmap.c. */\n\n");
  55. printf ("#include \"config.h\"\n");
  56. printf ("#include <errno.h>\n");
  57. printf ("#include <fcntl.h>\n");
  58. printf ("#include \"ansidecl.h\"\n");
  59. printf ("#include \"gdb/callback.h\"\n");
  60. printf ("#include \"targ-vals.h\"\n");
  61. printf ("\n");
  62. printf ("/* syscall mapping table */\n");
  63. printf ("CB_TARGET_DEFS_MAP cb_init_syscall_map[] = {\n");
  64. for (t = &sys_tdefs[0]; t->symbol; ++t)
  65. {
  66. printf ("#ifdef CB_%s\n", t->symbol);
  67. /* Skip the "SYS_" prefix for the name. */
  68. printf (" { \"%s\", CB_%s, TARGET_%s },\n", t->symbol + 4, t->symbol, t->symbol);
  69. printf ("#endif\n");
  70. }
  71. printf (" { 0, -1, -1 }\n");
  72. printf ("};\n\n");
  73. printf ("/* errno mapping table */\n");
  74. printf ("CB_TARGET_DEFS_MAP cb_init_errno_map[] = {\n");
  75. for (t = &errno_tdefs[0]; t->symbol; ++t)
  76. {
  77. printf ("#ifdef %s\n", t->symbol);
  78. printf (" { \"%s\", %s, TARGET_%s },\n", t->symbol, t->symbol, t->symbol);
  79. printf ("#endif\n");
  80. }
  81. printf (" { 0, 0, 0 }\n");
  82. printf ("};\n\n");
  83. printf ("/* open flags mapping table */\n");
  84. printf ("CB_TARGET_DEFS_MAP cb_init_open_map[] = {\n");
  85. for (t = &open_tdefs[0]; t->symbol; ++t)
  86. {
  87. printf ("#ifdef %s\n", t->symbol);
  88. printf (" { \"%s\", %s, TARGET_%s },\n", t->symbol, t->symbol, t->symbol);
  89. printf ("#endif\n");
  90. }
  91. printf (" { 0, -1, -1 }\n");
  92. printf ("};\n\n");
  93. }
  94. int
  95. main (int argc, char *argv[])
  96. {
  97. if (argc != 2)
  98. abort ();
  99. if (strcmp (argv[1], "-h") == 0)
  100. gen_targ_vals_h ();
  101. else if (strcmp (argv[1], "-c") == 0)
  102. gen_targ_map_c ();
  103. else
  104. abort ();
  105. exit (0);
  106. }