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