convert.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 <stdlib.h>
  18. #include "system.h"
  19. #include "em_pseu.h"
  20. #include "em_mnem.h"
  21. #include "em_spec.h"
  22. #include "em_flag.h"
  23. #include "em_ptyp.h"
  24. #include "em.h"
  25. #include "em_comp.h"
  26. char *filename; /* Name of input file */
  27. int errors; /* Number of errors */
  28. extern char *C_error;
  29. main(argc,argv)
  30. char **argv;
  31. {
  32. struct e_instr buf;
  33. register struct e_instr *p = &buf;
  34. if (argc >= 2) {
  35. filename = argv[1];
  36. }
  37. else filename = 0;
  38. if (!EM_open(filename)) {
  39. fatal(EM_error);
  40. }
  41. EM_getinstr(p);
  42. C_init((arith) EM_wordsize, (arith) EM_pointersize);
  43. if (argc >= 3) {
  44. if (!C_open(argv[2])) {
  45. fatal("C_open failed");
  46. }
  47. }
  48. else if (!C_open( (char *) 0)) fatal("C_open failed");
  49. C_magic();
  50. while (p->em_type != EM_EOF) {
  51. if (p->em_type == EM_FATAL) {
  52. fatal("%s", EM_error);
  53. }
  54. if (EM_error) {
  55. error("%s", EM_error);
  56. }
  57. if (p->em_type != EM_ERROR && !C_out(p)) {
  58. error("%s", C_error);
  59. }
  60. EM_getinstr(p);
  61. }
  62. C_close();
  63. EM_close();
  64. exit(errors);
  65. }
  66. /* VARARGS */
  67. error(s,a1,a2,a3,a4)
  68. char *s;
  69. {
  70. fprint(STDERR,
  71. "%s, line %d: ",
  72. filename ? filename : "standard input",
  73. EM_lineno);
  74. fprint(STDERR,s,a1,a2,a3,a4);
  75. fprint(STDERR, "\n");
  76. errors++;
  77. }
  78. /* VARARGS */
  79. fatal(s,a1,a2,a3,a4)
  80. char *s;
  81. {
  82. if (C_busy()) C_close();
  83. error(s,a1,a2,a3,a4);
  84. exit(1);
  85. }