C_out.c 2.6 KB

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