C_out.c 2.6 KB

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