C_out.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. #include <stdlib.h>
  2. #include "em_arith.h"
  3. #include "em_label.h"
  4. #include "../read_em/em_comp.h"
  5. #include "em_pseu.h"
  6. #include "em_flag.h"
  7. #include "em_ptyp.h"
  8. #include "em_private.h"
  9. /* $Id$ */
  10. static arg();
  11. static pseudo();
  12. extern char em_flag[];
  13. char *C_error;
  14. #define flags(pp) (em_flag[(pp)->em_opcode - sp_fmnem] & EM_PAR)
  15. struct e_instr *
  16. C_alloc()
  17. {
  18. static struct e_instr b;
  19. return &b;
  20. }
  21. int
  22. C_out(p)
  23. register struct e_instr *p;
  24. {
  25. /* Generate EM-code from the e_instr structure "p"
  26. */
  27. switch(p->em_type) {
  28. case EM_MNEM:
  29. OP(p->em_opcode);
  30. if (flags(p) == PAR_B && p->em_argtype == cst_ptyp) {
  31. p->em_ilb = p->em_cst;
  32. p->em_argtype = ilb_ptyp;
  33. }
  34. if (flags(p) != PAR_NO) arg(p, 0);
  35. NL();
  36. break;
  37. case EM_PSEU:
  38. pseudo(p);
  39. break;
  40. case EM_STARTMES:
  41. PS(ps_mes);
  42. CST(p->em_cst);
  43. break;
  44. case EM_MESARG:
  45. arg(p, 1);
  46. break;
  47. case EM_ENDMES:
  48. CEND();
  49. NL();
  50. break;
  51. case EM_DEFILB:
  52. DFILB(p->em_ilb);
  53. NL();
  54. break;
  55. case EM_DEFDLB:
  56. DFDLB(p->em_dlb);
  57. NL();
  58. break;
  59. case EM_DEFDNAM:
  60. DFDNAM(p->em_dnam);
  61. NL();
  62. break;
  63. default:
  64. C_error = "Illegal EM line";
  65. return 0;
  66. }
  67. return 1;
  68. }
  69. static
  70. arg(p, comma)
  71. register struct e_instr *p;
  72. {
  73. /* Output the argument of "p".
  74. */
  75. if (comma) COMMA();
  76. switch(p->em_argtype) {
  77. case 0:
  78. if (p->em_type == EM_MNEM && flags(p) != PAR_W) {
  79. abort();
  80. }
  81. CCEND();
  82. break;
  83. case ilb_ptyp:
  84. if (p->em_type == EM_MNEM) {
  85. CILB(p->em_ilb);
  86. }
  87. else {
  88. ILB(p->em_ilb);
  89. }
  90. break;
  91. case nof_ptyp:
  92. DOFF(p->em_dlb, p->em_off);
  93. break;
  94. case sof_ptyp:
  95. NOFF(p->em_dnam, p->em_off);
  96. break;
  97. case cst_ptyp:
  98. CST(p->em_cst);
  99. break;
  100. case pro_ptyp:
  101. PNAM(p->em_pnam);
  102. break;
  103. case str_ptyp:
  104. SCON(p->em_string, p->em_size);
  105. break;
  106. case ico_ptyp:
  107. WCON(sp_icon, p->em_string, p->em_size);
  108. break;
  109. case uco_ptyp:
  110. WCON(sp_ucon, p->em_string, p->em_size);
  111. break;
  112. case fco_ptyp:
  113. WCON(sp_fcon, p->em_string, p->em_size);
  114. break;
  115. default:
  116. abort();
  117. }
  118. }
  119. static
  120. pseudo(p)
  121. register struct e_instr *p;
  122. {
  123. PS(p->em_opcode);
  124. switch(p->em_opcode) {
  125. case ps_exc:
  126. CST(p->em_exc1);
  127. COMMA();
  128. CST(p->em_exc2);
  129. break;
  130. case ps_rom:
  131. case ps_con:
  132. arg(p, 0);
  133. CEND();
  134. break;
  135. case ps_bss:
  136. CST(EM_bsssize);
  137. arg(p, 1);
  138. COMMA();
  139. CST((arith) EM_bssinit);
  140. break;
  141. case ps_hol:
  142. CST(EM_holsize);
  143. arg(p, 1);
  144. COMMA();
  145. CST((arith) EM_holinit);
  146. break;
  147. case ps_pro:
  148. arg(p, 0);
  149. COMMA();
  150. if (p->em_nlocals != -1) CST(p->em_nlocals);
  151. else CCEND();
  152. break;
  153. case ps_end:
  154. if (p->em_argtype == 0) CCEND();
  155. else CST(p->em_cst);
  156. break;
  157. default:
  158. arg(p, 0);
  159. break;
  160. }
  161. NL();
  162. }