convert.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. main(argc,argv)
  28. char **argv;
  29. {
  30. struct e_instr buf;
  31. register struct e_instr *p = &buf;
  32. if (argc >= 2) {
  33. filename = argv[1];
  34. }
  35. else filename = 0;
  36. if (!EM_open(filename)) {
  37. fatal(EM_error);
  38. }
  39. EM_getinstr(p);
  40. C_init((arith) EM_wordsize, (arith) EM_pointersize);
  41. if (argc >= 3) {
  42. if (!C_open(argv[2])) {
  43. fatal("C_open failed");
  44. }
  45. }
  46. else if (!C_open( (char *) 0)) fatal("C_open failed");
  47. C_magic();
  48. while (p->em_type != EM_EOF) {
  49. if (p->em_type == EM_FATAL) {
  50. fatal("%s", EM_error);
  51. }
  52. if (EM_error) {
  53. error("%s", EM_error);
  54. }
  55. if (p->em_type != EM_ERROR) {
  56. EM_mkcalls(p);
  57. }
  58. EM_getinstr(p);
  59. }
  60. C_close();
  61. EM_close();
  62. exit(errors);
  63. }
  64. /* VARARGS */
  65. error(s,a1,a2,a3,a4)
  66. char *s;
  67. {
  68. fprint(STDERR,
  69. "%s, line %d: ",
  70. filename ? filename : "standard input",
  71. EM_lineno);
  72. fprint(STDERR,s,a1,a2,a3,a4);
  73. fprint(STDERR, "\n");
  74. errors++;
  75. }
  76. /* VARARGS */
  77. fatal(s,a1,a2,a3,a4)
  78. char *s;
  79. {
  80. error(s,a1,a2,a3,a4);
  81. exit(1);
  82. }