convert.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
  3. * See the copyright notice in the ACK home directory, in the file "Copyright".
  4. */
  5. #ifndef NORCSID
  6. static char rcsid[] = "$Id$";
  7. #endif
  8. /* This program converts either human-readable or compact EM
  9. assembly code to calls of the procedure-interface.
  10. It must be linked with two libraries:
  11. - a library to read EM code, according to read_em(3)
  12. - a library implementing the em_code(3) interface.
  13. Thus, this program could serve as an EM_encoder, an
  14. EM_decoder, or some code generator, depending on how it is
  15. linked.
  16. */
  17. #include <system.h>
  18. #include <em_pseu.h>
  19. #include <em_mnem.h>
  20. #include <em_spec.h>
  21. #include <em_flag.h>
  22. #include <em_ptyp.h>
  23. #include <em.h>
  24. #include <em_comp.h>
  25. char *filename; /* Name of input file */
  26. int errors; /* Number of errors */
  27. extern char *C_error;
  28. main(argc,argv)
  29. char **argv;
  30. {
  31. struct e_instr buf;
  32. register struct e_instr *p = &buf;
  33. if (argc >= 2) {
  34. filename = argv[1];
  35. }
  36. else filename = 0;
  37. if (!EM_open(filename)) {
  38. fatal(EM_error);
  39. }
  40. EM_getinstr(p);
  41. C_init((arith) EM_wordsize, (arith) EM_pointersize);
  42. if (argc >= 3) {
  43. if (!C_open(argv[2])) {
  44. fatal("C_open failed");
  45. }
  46. }
  47. else if (!C_open( (char *) 0)) fatal("C_open failed");
  48. C_magic();
  49. while (p->em_type != EM_EOF) {
  50. if (p->em_type == EM_FATAL) {
  51. fatal("%s", EM_error);
  52. }
  53. if (EM_error) {
  54. error("%s", EM_error);
  55. }
  56. if (p->em_type != EM_ERROR && !C_out(p)) {
  57. error("%s", C_error);
  58. }
  59. EM_getinstr(p);
  60. }
  61. C_close();
  62. EM_close();
  63. exit(errors);
  64. }
  65. /* VARARGS */
  66. error(s,a1,a2,a3,a4)
  67. char *s;
  68. {
  69. fprint(STDERR,
  70. "%s, line %d: ",
  71. filename ? filename : "standard input",
  72. EM_lineno);
  73. fprint(STDERR,s,a1,a2,a3,a4);
  74. fprint(STDERR, "\n");
  75. errors++;
  76. }
  77. /* VARARGS */
  78. fatal(s,a1,a2,a3,a4)
  79. char *s;
  80. {
  81. if (C_busy()) C_close();
  82. error(s,a1,a2,a3,a4);
  83. exit(1);
  84. }