annotate lwasm/pseudo.c @ 369:898a41f7eb59

check for valid expressions in pass 6
author lost@starbug
date Thu, 15 Apr 2010 22:26:49 -0600
parents d96c30e60ddf
children 6b33faa21a0a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
347
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
1 /*
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
2 pseudo.c
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
3 Copyright © 2010 William Astle
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
4
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
5 This file is part of LWASM.
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
6
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
7 LWASM is free software: you can redistribute it and/or modify it under the
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
8 terms of the GNU General Public License as published by the Free Software
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
9 Foundation, either version 3 of the License, or (at your option) any later
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
10 version.
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
11
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
12 This program is distributed in the hope that it will be useful, but WITHOUT
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
15 more details.
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
16
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
17 You should have received a copy of the GNU General Public License along with
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
18 this program. If not, see <http://www.gnu.org/licenses/>.
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
19
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
20 */
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
21
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
22 #include <config.h>
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
23
356
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
24 #include <stdio.h>
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
25
347
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
26 #include "lwasm.h"
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
27 #include "instab.h"
356
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
28 #include "input.h"
347
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
29
349
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
30 #include "lw_string.h"
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
31
347
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
32 // for "end"
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
33 PARSEFUNC(pseudo_parse_end)
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
34 {
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
35 lw_expr_t addr;
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
36
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
37 as -> endseen = 1;
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
38
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
39 if (as -> output_format != OUTPUT_DECB)
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
40 {
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
41 skip_operand(p);
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
42 return;
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
43 }
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
44
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
45 addr = lwasm_parse_expr(as, p);
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
46 if (!addr)
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
47 {
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
48 lwasm_register_error(as, l, "Bad expression");
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
49 addr = lw_expr_build(lw_expr_type_int, 0);
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
50 }
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
51 lwasm_save_expr(l, 0, addr);
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
52 }
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
53
348
11a95c6414b4 Added third func to instab to split resolve and emit logic
lost@starbug
parents: 347
diff changeset
54 EMITFUNC(pseudo_emit_end)
347
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
55 {
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
56 lw_expr_t addr;
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
57
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
58 addr = lwasm_fetch_expr(l, 0);
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
59
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
60 if (addr)
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
61 {
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
62 if (!lw_expr_istype(addr, lw_expr_type_int))
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
63 lwasm_register_error(as, l, "Exec address not constant!");
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
64 else
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
65 as -> execaddr = lw_expr_intval(addr);
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
66 }
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
67 as -> endseen = 1;
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
68 }
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
69
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
70 PARSEFUNC(pseudo_parse_fcb)
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
71 {
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
72 int i = 0;
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
73 lw_expr_t e;
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
74
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
75 for (;;)
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
76 {
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
77 e = lwasm_parse_expr(as, p);
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
78 if (!e)
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
79 {
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
80 lwasm_register_error(as, l, "Bad expression (#%s)", i);
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
81 break;
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
82 }
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
83 lwasm_save_expr(l, i, e);
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
84 i++;
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
85 }
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
86
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
87 l -> len = i;
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
88 }
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
89
348
11a95c6414b4 Added third func to instab to split resolve and emit logic
lost@starbug
parents: 347
diff changeset
90 EMITFUNC(pseudo_emit_fcb)
347
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
91 {
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
92 int i;
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
93 lw_expr_t e;
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
94 int v;
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
95
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
96 for (i = 0; i < l -> len; i++)
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
97 {
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
98 e = lwasm_fetch_expr(l, i);
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
99 lwasm_emitexpr(l, e, 1);
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
100 }
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
101 }
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
102
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
103 PARSEFUNC(pseudo_parse_fdb)
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
104 {
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
105 int i = 0;
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
106 lw_expr_t e;
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
107
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
108 for (;;)
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
109 {
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
110 e = lwasm_parse_expr(as, p);
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
111 if (!e)
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
112 {
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
113 lwasm_register_error(as, l, "Bad expression (#%s)", i);
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
114 break;
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
115 }
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
116 lwasm_save_expr(l, i, e);
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
117 i++;
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
118 }
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
119
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
120 l -> len = i * 2;
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
121 }
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
122
348
11a95c6414b4 Added third func to instab to split resolve and emit logic
lost@starbug
parents: 347
diff changeset
123 EMITFUNC(pseudo_emit_fdb)
347
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
124 {
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
125 int i;
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
126 lw_expr_t e;
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
127 int v;
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
128
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
129 for (i = 0; i < (l -> len)/2; i++)
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
130 {
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
131 e = lwasm_fetch_expr(l, i);
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
132 lwasm_emitexpr(l, e, 2);
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
133 }
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
134 }
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
135
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
136 PARSEFUNC(pseudo_parse_fqb)
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
137 {
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
138 int i = 0;
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
139 lw_expr_t e;
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
140
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
141 for (;;)
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
142 {
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
143 e = lwasm_parse_expr(as, p);
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
144 if (!e)
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
145 {
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
146 lwasm_register_error(as, l, "Bad expression (#%s)", i);
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
147 break;
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
148 }
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
149 lwasm_save_expr(l, i, e);
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
150 i++;
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
151 }
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
152
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
153 l -> len = i * 4;
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
154 }
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
155
348
11a95c6414b4 Added third func to instab to split resolve and emit logic
lost@starbug
parents: 347
diff changeset
156 EMITFUNC(pseudo_emit_fqb)
347
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
157 {
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
158 int i;
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
159 lw_expr_t e;
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
160 int v;
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
161
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
162 for (i = 0; i < (l -> len)/4; i++)
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
163 {
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
164 e = lwasm_fetch_expr(l, i);
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
165 lwasm_emitexpr(l, e, 4);
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
166 }
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents:
diff changeset
167 }
349
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
168
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
169 PARSEFUNC(pseudo_parse_fcc)
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
170 {
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
171 char delim;
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
172 int i;
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
173
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
174 if (!**p)
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
175 {
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
176 lwasm_register_error(as, l, "Bad operand");
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
177 return;
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
178 }
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
179
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
180 delim = **p;
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
181 (*p)++;
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
182
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
183 for (i = 0; (*p)[i] && (*p)[i] != delim; i++)
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
184 /* do nothing */ ;
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
185
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
186 if ((*p)[i] != delim)
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
187 {
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
188 lwasm_register_error(as, l, "Bad operand");
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
189 return;
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
190 }
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
191
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
192 l -> lstr = lw_strndup(*p, i);
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
193 (*p) += i + 1;
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
194
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
195 l -> len = i;
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
196 }
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
197
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
198 EMITFUNC(pseudo_emit_fcc)
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
199 {
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
200 int i;
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
201
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
202 for (i = 0; i < l -> len; i++)
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
203 lwasm_emit(l, l -> lstr[i]);
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
204 }
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
205
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
206 PARSEFUNC(pseudo_parse_fcs)
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
207 {
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
208 char delim;
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
209 int i;
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
210
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
211 if (!**p)
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
212 {
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
213 lwasm_register_error(as, l, "Bad operand");
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
214 return;
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
215 }
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
216
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
217 delim = **p;
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
218 (*p)++;
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
219
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
220 for (i = 0; (*p)[i] && (*p)[i] != delim; i++)
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
221 /* do nothing */ ;
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
222
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
223 if ((*p)[i] != delim)
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
224 {
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
225 lwasm_register_error(as, l, "Bad operand");
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
226 return;
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
227 }
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
228
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
229 l -> lstr = lw_strndup(*p, i);
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
230 (*p) += i + 1;
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
231
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
232 l -> len = i;
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
233 }
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
234
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
235 EMITFUNC(pseudo_emit_fcs)
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
236 {
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
237 int i;
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
238
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
239 for (i = 0; i < l -> len - 1; i++)
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
240 lwasm_emit(l, l -> lstr[i]);
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
241 lwasm_emit(l, l -> lstr[i] | 0x80);
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
242 }
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
243
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
244 PARSEFUNC(pseudo_parse_fcn)
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
245 {
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
246 char delim;
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
247 int i;
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
248
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
249 if (!**p)
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
250 {
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
251 lwasm_register_error(as, l, "Bad operand");
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
252 return;
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
253 }
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
254
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
255 delim = **p;
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
256 (*p)++;
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
257
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
258 for (i = 0; (*p)[i] && (*p)[i] != delim; i++)
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
259 /* do nothing */ ;
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
260
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
261 if ((*p)[i] != delim)
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
262 {
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
263 lwasm_register_error(as, l, "Bad operand");
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
264 return;
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
265 }
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
266
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
267 l -> lstr = lw_strndup(*p, i);
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
268 (*p) += i + 1;
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
269
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
270 l -> len = i;
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
271 }
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
272
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
273 EMITFUNC(pseudo_emit_fcn)
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
274 {
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
275 int i;
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
276
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
277 for (i = 0; i < l -> len; i++)
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
278 lwasm_emit(l, l -> lstr[i]);
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
279 lwasm_emit(l, 0);
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
280 }
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
281
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
282 PARSEFUNC(pseudo_parse_rmb)
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
283 {
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
284 lw_expr_t expr;
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
285
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
286 expr = lwasm_parse_expr(as, p);
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
287 if (!expr)
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
288 {
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
289 lwasm_register_error(as, l, "Bad expression");
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
290 }
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
291
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
292 lwasm_save_expr(l, 0, expr);
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
293 }
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
294
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
295 RESOLVEFUNC(pseudo_resolve_rmb)
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
296 {
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
297 lw_expr_t expr;
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
298
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
299 if (l -> len >= 0)
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
300 return;
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
301
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
302 expr = lwasm_fetch_expr(l, 0);
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
303
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
304 if (lw_expr_istype(expr, lw_expr_type_int))
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
305 {
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
306 l -> len = lw_expr_intval(expr);
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
307 }
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
308 }
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
309
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
310 EMITFUNC(pseudo_emit_rmb)
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
311 {
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
312 if (l -> len < 0)
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
313 lwasm_register_error(as, l, "Expression not constant");
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
314 }
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
315
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
316 PARSEFUNC(pseudo_parse_rmd)
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
317 {
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
318 lw_expr_t expr;
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
319
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
320 expr = lwasm_parse_expr(as, p);
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
321 if (!expr)
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
322 {
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
323 lwasm_register_error(as, l, "Bad expression");
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
324 }
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
325
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
326 lwasm_save_expr(l, 0, expr);
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
327 }
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
328
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
329 RESOLVEFUNC(pseudo_resolve_rmd)
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
330 {
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
331 lw_expr_t expr;
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
332
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
333 if (l -> len >= 0)
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
334 return;
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
335
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
336 expr = lwasm_fetch_expr(l, 0);
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
337
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
338 if (lw_expr_istype(expr, lw_expr_type_int))
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
339 {
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
340 l -> len = lw_expr_intval(expr) * 2;
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
341 }
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
342 }
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
343
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
344 EMITFUNC(pseudo_emit_rmd)
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
345 {
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
346 if (l -> len < 0)
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
347 lwasm_register_error(as, l, "Expression not constant");
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
348 }
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
349
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
350
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
351 PARSEFUNC(pseudo_parse_rmq)
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
352 {
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
353 lw_expr_t expr;
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
354
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
355 expr = lwasm_parse_expr(as, p);
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
356 if (!expr)
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
357 {
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
358 lwasm_register_error(as, l, "Bad expression");
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
359 }
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
360
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
361 lwasm_save_expr(l, 0, expr);
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
362 }
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
363
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
364 RESOLVEFUNC(pseudo_resolve_rmq)
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
365 {
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
366 lw_expr_t expr;
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
367
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
368 if (l -> len >= 0)
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
369 return;
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
370
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
371 expr = lwasm_fetch_expr(l, 0);
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
372
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
373 if (lw_expr_istype(expr, lw_expr_type_int))
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
374 {
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
375 l -> len = lw_expr_intval(expr) * 4;
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
376 }
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
377 }
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
378
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
379 EMITFUNC(pseudo_emit_rmq)
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
380 {
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
381 if (l -> len < 0)
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
382 lwasm_register_error(as, l, "Expression not constant");
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
383 }
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
384
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
385
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
386 PARSEFUNC(pseudo_parse_zmq)
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
387 {
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
388 lw_expr_t expr;
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
389
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
390 expr = lwasm_parse_expr(as, p);
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
391 if (!expr)
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
392 {
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
393 lwasm_register_error(as, l, "Bad expression");
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
394 }
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
395
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
396 lwasm_save_expr(l, 0, expr);
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
397 }
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
398
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
399 RESOLVEFUNC(pseudo_resolve_zmq)
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
400 {
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
401 lw_expr_t expr;
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
402
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
403 if (l -> len >= 0)
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
404 return;
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
405
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
406 expr = lwasm_fetch_expr(l, 0);
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
407
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
408 if (lw_expr_istype(expr, lw_expr_type_int))
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
409 {
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
410 l -> len = lw_expr_intval(expr) * 4;
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
411 }
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
412 }
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
413
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
414 EMITFUNC(pseudo_emit_zmq)
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
415 {
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
416 int i;
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
417
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
418 if (l -> len < 0)
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
419 {
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
420 lwasm_register_error(as, l, "Expression not constant");
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
421 return;
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
422 }
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
423
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
424 for (i = 0; i < l -> len; i++)
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
425 lwasm_emit(l, 0);
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
426 }
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
427
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
428
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
429 PARSEFUNC(pseudo_parse_zmd)
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
430 {
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
431 lw_expr_t expr;
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
432
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
433 expr = lwasm_parse_expr(as, p);
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
434 if (!expr)
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
435 {
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
436 lwasm_register_error(as, l, "Bad expression");
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
437 }
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
438
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
439 lwasm_save_expr(l, 0, expr);
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
440 }
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
441
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
442 RESOLVEFUNC(pseudo_resolve_zmd)
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
443 {
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
444 lw_expr_t expr;
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
445
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
446 if (l -> len >= 0)
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
447 return;
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
448
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
449 expr = lwasm_fetch_expr(l, 0);
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
450
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
451 if (lw_expr_istype(expr, lw_expr_type_int))
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
452 {
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
453 l -> len = lw_expr_intval(expr) * 2;
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
454 }
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
455 }
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
456
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
457 EMITFUNC(pseudo_emit_zmd)
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
458 {
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
459 int i;
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
460
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
461 if (l -> len < 0)
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
462 {
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
463 lwasm_register_error(as, l, "Expression not constant");
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
464 return;
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
465 }
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
466
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
467 for (i = 0; i < l -> len; i++)
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
468 lwasm_emit(l, 0);
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
469 }
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
470
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
471 PARSEFUNC(pseudo_parse_zmb)
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
472 {
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
473 lw_expr_t expr;
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
474
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
475 expr = lwasm_parse_expr(as, p);
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
476 if (!expr)
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
477 {
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
478 lwasm_register_error(as, l, "Bad expression");
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
479 }
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
480
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
481 lwasm_save_expr(l, 0, expr);
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
482 }
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
483
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
484 RESOLVEFUNC(pseudo_resolve_zmb)
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
485 {
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
486 lw_expr_t expr;
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
487
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
488 if (l -> len >= 0)
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
489 return;
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
490
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
491 expr = lwasm_fetch_expr(l, 0);
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
492
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
493 if (lw_expr_istype(expr, lw_expr_type_int))
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
494 {
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
495 l -> len = lw_expr_intval(expr);
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
496 }
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
497 }
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
498
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
499 EMITFUNC(pseudo_emit_zmb)
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
500 {
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
501 int i;
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
502
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
503 if (l -> len < 0)
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
504 {
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
505 lwasm_register_error(as, l, "Expression not constant");
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
506 return;
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
507 }
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
508
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
509 for (i = 0; i < l -> len; i++)
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
510 lwasm_emit(l, 0);
dcd2978a7d18 More pseudo ops
lost@starbug
parents: 348
diff changeset
511 }
350
f5666775d76f Even more pseudo ops
lost@starbug
parents: 349
diff changeset
512
f5666775d76f Even more pseudo ops
lost@starbug
parents: 349
diff changeset
513 PARSEFUNC(pseudo_parse_org)
f5666775d76f Even more pseudo ops
lost@starbug
parents: 349
diff changeset
514 {
f5666775d76f Even more pseudo ops
lost@starbug
parents: 349
diff changeset
515 lw_expr_t e;
f5666775d76f Even more pseudo ops
lost@starbug
parents: 349
diff changeset
516
351
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
517 l -> len = 0;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
518
350
f5666775d76f Even more pseudo ops
lost@starbug
parents: 349
diff changeset
519 e = lwasm_parse_expr(as, p);
f5666775d76f Even more pseudo ops
lost@starbug
parents: 349
diff changeset
520 if (!e)
f5666775d76f Even more pseudo ops
lost@starbug
parents: 349
diff changeset
521 {
f5666775d76f Even more pseudo ops
lost@starbug
parents: 349
diff changeset
522 lwasm_register_error(as, l, "Bad operand");
f5666775d76f Even more pseudo ops
lost@starbug
parents: 349
diff changeset
523 return;
f5666775d76f Even more pseudo ops
lost@starbug
parents: 349
diff changeset
524 }
f5666775d76f Even more pseudo ops
lost@starbug
parents: 349
diff changeset
525
f5666775d76f Even more pseudo ops
lost@starbug
parents: 349
diff changeset
526 lw_expr_destroy(l -> addr);
f5666775d76f Even more pseudo ops
lost@starbug
parents: 349
diff changeset
527 l -> addr = e;
f5666775d76f Even more pseudo ops
lost@starbug
parents: 349
diff changeset
528 l -> len = 0;
f5666775d76f Even more pseudo ops
lost@starbug
parents: 349
diff changeset
529 }
f5666775d76f Even more pseudo ops
lost@starbug
parents: 349
diff changeset
530
f5666775d76f Even more pseudo ops
lost@starbug
parents: 349
diff changeset
531 PARSEFUNC(pseudo_parse_equ)
f5666775d76f Even more pseudo ops
lost@starbug
parents: 349
diff changeset
532 {
f5666775d76f Even more pseudo ops
lost@starbug
parents: 349
diff changeset
533 lw_expr_t e;
f5666775d76f Even more pseudo ops
lost@starbug
parents: 349
diff changeset
534
351
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
535 l -> len = 0;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
536
350
f5666775d76f Even more pseudo ops
lost@starbug
parents: 349
diff changeset
537 if (!(l -> sym))
f5666775d76f Even more pseudo ops
lost@starbug
parents: 349
diff changeset
538 {
f5666775d76f Even more pseudo ops
lost@starbug
parents: 349
diff changeset
539 lwasm_register_error(as, l, "Missing symbol");
f5666775d76f Even more pseudo ops
lost@starbug
parents: 349
diff changeset
540 return;
f5666775d76f Even more pseudo ops
lost@starbug
parents: 349
diff changeset
541 }
f5666775d76f Even more pseudo ops
lost@starbug
parents: 349
diff changeset
542
f5666775d76f Even more pseudo ops
lost@starbug
parents: 349
diff changeset
543 e = lwasm_parse_expr(as, p);
f5666775d76f Even more pseudo ops
lost@starbug
parents: 349
diff changeset
544 if (!e)
f5666775d76f Even more pseudo ops
lost@starbug
parents: 349
diff changeset
545 {
f5666775d76f Even more pseudo ops
lost@starbug
parents: 349
diff changeset
546 lwasm_register_error(as, l, "Bad operand");
f5666775d76f Even more pseudo ops
lost@starbug
parents: 349
diff changeset
547 return;
f5666775d76f Even more pseudo ops
lost@starbug
parents: 349
diff changeset
548 }
f5666775d76f Even more pseudo ops
lost@starbug
parents: 349
diff changeset
549
f5666775d76f Even more pseudo ops
lost@starbug
parents: 349
diff changeset
550 register_symbol(as, l, l -> sym, e, symbol_flag_none);
f5666775d76f Even more pseudo ops
lost@starbug
parents: 349
diff changeset
551 l -> symset = 1;
f5666775d76f Even more pseudo ops
lost@starbug
parents: 349
diff changeset
552 }
351
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
553
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
554 PARSEFUNC(pseudo_parse_set)
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
555 {
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
556 lw_expr_t e;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
557
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
558 l -> len = 0;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
559
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
560 if (!(l -> sym))
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
561 {
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
562 lwasm_register_error(as, l, "Missing symbol");
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
563 return;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
564 }
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
565
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
566 e = lwasm_parse_expr(as, p);
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
567 if (!e)
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
568 {
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
569 lwasm_register_error(as, l, "Bad operand");
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
570 return;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
571 }
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
572
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
573 register_symbol(as, l, l -> sym, e, symbol_flag_set);
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
574 l -> symset = 1;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
575 }
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
576
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
577 PARSEFUNC(pseudo_parse_setdp)
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
578 {
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
579 lw_expr_t e;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
580
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
581 l -> len = 0;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
582
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
583 if (as -> output_format == OUTPUT_OBJ)
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
584 {
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
585 lwasm_register_error(as, l, "SETDP not permitted for object target");
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
586 return;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
587 }
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
588
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
589 e = lwasm_parse_expr(as, p);
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
590 if (!e)
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
591 {
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
592 lwasm_register_error(as, l, "Bad operand");
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
593 return;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
594 }
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
595
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
596 if (!lw_expr_istype(e, lw_expr_type_int))
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
597 {
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
598 lwasm_register_error(as, l, "SETDP must be constant on pass 1");
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
599 return;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
600 }
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
601 l -> dpval = lw_expr_intval(e) & 0xff;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
602 }
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
603
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
604 PARSEFUNC(pseudo_parse_ifp1)
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
605 {
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
606 l -> len = 0;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
607
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
608 if (as -> skipcond && !(as -> skipmacro))
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
609 {
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
610 as -> skipcount++;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
611 skip_operand(p);
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
612 return;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
613 }
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
614
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
615 lwasm_register_warning(as, l, "IFP1 if is not supported; ignoring");
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
616
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
617 }
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
618
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
619 PARSEFUNC(pseudo_parse_ifp2)
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
620 {
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
621 l -> len = 0;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
622
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
623 if (as -> skipcond && !(as -> skipmacro))
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
624 {
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
625 as -> skipcount++;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
626 skip_operand(p);
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
627 return;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
628 }
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
629
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
630 lwasm_register_warning(as, l, "IFP2 if is not supported; ignoring");
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
631 }
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
632
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
633 PARSEFUNC(pseudo_parse_ifeq)
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
634 {
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
635 lw_expr_t e;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
636
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
637 l -> len = 0;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
638
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
639 if (as -> skipcond && !(as -> skipmacro))
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
640 {
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
641 as -> skipcount++;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
642 skip_operand(p);
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
643 return;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
644 }
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
645
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
646 e = lwasm_parse_expr(as, p);
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
647 if (!e)
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
648 {
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
649 lwasm_register_error(as, l, "Bad expression");
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
650 return;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
651 }
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
652 if (!lw_expr_istype(e, lw_expr_type_int))
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
653 {
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
654 lwasm_register_error(as, l, "Conditions must be constant on pass 1");
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
655 return;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
656 }
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
657 if (lw_expr_intval(e) != 0)
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
658 {
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
659 as -> skipcond = 1;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
660 as -> skipcount = 1;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
661 }
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
662 }
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
663
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
664 PARSEFUNC(pseudo_parse_ifne)
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
665 {
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
666 lw_expr_t e;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
667
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
668 l -> len = 0;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
669
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
670 if (as -> skipcond && !(as -> skipmacro))
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
671 {
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
672 as -> skipcount++;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
673 skip_operand(p);
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
674 return;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
675 }
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
676
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
677 e = lwasm_parse_expr(as, p);
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
678 if (!e)
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
679 {
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
680 lwasm_register_error(as, l, "Bad expression");
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
681 return;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
682 }
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
683 if (!lw_expr_istype(e, lw_expr_type_int))
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
684 {
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
685 lwasm_register_error(as, l, "Conditions must be constant on pass 1");
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
686 return;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
687 }
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
688 if (lw_expr_intval(e) == 0)
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
689 {
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
690 as -> skipcond = 1;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
691 as -> skipcount = 1;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
692 }
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
693 }
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
694
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
695
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
696 PARSEFUNC(pseudo_parse_ifgt)
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
697 {
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
698 lw_expr_t e;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
699
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
700 l -> len = 0;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
701
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
702 if (as -> skipcond && !(as -> skipmacro))
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
703 {
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
704 as -> skipcount++;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
705 skip_operand(p);
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
706 return;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
707 }
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
708
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
709 e = lwasm_parse_expr(as, p);
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
710 if (!e)
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
711 {
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
712 lwasm_register_error(as, l, "Bad expression");
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
713 return;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
714 }
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
715 if (!lw_expr_istype(e, lw_expr_type_int))
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
716 {
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
717 lwasm_register_error(as, l, "Conditions must be constant on pass 1");
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
718 return;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
719 }
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
720 if (lw_expr_intval(e) <= 0)
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
721 {
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
722 as -> skipcond = 1;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
723 as -> skipcount = 1;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
724 }
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
725 }
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
726
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
727 PARSEFUNC(pseudo_parse_ifge)
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
728 {
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
729 lw_expr_t e;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
730
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
731 l -> len = 0;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
732
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
733 if (as -> skipcond && !(as -> skipmacro))
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
734 {
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
735 as -> skipcount++;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
736 skip_operand(p);
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
737 return;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
738 }
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
739
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
740 e = lwasm_parse_expr(as, p);
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
741 if (!e)
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
742 {
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
743 lwasm_register_error(as, l, "Bad expression");
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
744 return;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
745 }
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
746 if (!lw_expr_istype(e, lw_expr_type_int))
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
747 {
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
748 lwasm_register_error(as, l, "Conditions must be constant on pass 1");
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
749 return;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
750 }
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
751 if (lw_expr_intval(e) < 0)
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
752 {
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
753 as -> skipcond = 1;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
754 as -> skipcount = 1;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
755 }
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
756 }
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
757
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
758 PARSEFUNC(pseudo_parse_iflt)
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
759 {
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
760 lw_expr_t e;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
761
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
762 l -> len = 0;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
763
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
764 if (as -> skipcond && !(as -> skipmacro))
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
765 {
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
766 as -> skipcount++;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
767 skip_operand(p);
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
768 return;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
769 }
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
770
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
771 e = lwasm_parse_expr(as, p);
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
772 if (!e)
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
773 {
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
774 lwasm_register_error(as, l, "Bad expression");
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
775 return;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
776 }
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
777 if (!lw_expr_istype(e, lw_expr_type_int))
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
778 {
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
779 lwasm_register_error(as, l, "Conditions must be constant on pass 1");
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
780 return;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
781 }
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
782 if (lw_expr_intval(e) >= 0)
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
783 {
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
784 as -> skipcond = 1;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
785 as -> skipcount = 1;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
786 }
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
787 }
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
788
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
789 PARSEFUNC(pseudo_parse_ifle)
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
790 {
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
791 lw_expr_t e;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
792
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
793 l -> len = 0;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
794
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
795 if (as -> skipcond && !(as -> skipmacro))
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
796 {
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
797 as -> skipcount++;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
798 skip_operand(p);
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
799 return;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
800 }
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
801
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
802 e = lwasm_parse_expr(as, p);
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
803 if (!e)
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
804 {
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
805 lwasm_register_error(as, l, "Bad expression");
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
806 return;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
807 }
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
808 if (!lw_expr_istype(e, lw_expr_type_int))
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
809 {
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
810 lwasm_register_error(as, l, "Conditions must be constant on pass 1");
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
811 return;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
812 }
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
813 if (lw_expr_intval(e) > 0)
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
814 {
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
815 as -> skipcond = 1;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
816 as -> skipcount = 1;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
817 }
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
818 }
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
819
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
820 PARSEFUNC(pseudo_parse_endc)
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
821 {
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
822 l -> len = 0;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
823 if (as -> skipcond && !(as -> skipmacro))
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
824 {
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
825 as -> skipcount--;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
826 if (as -> skipcount < 0)
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
827 as -> skipcond = 0;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
828 }
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
829 }
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
830
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
831 PARSEFUNC(pseudo_parse_else)
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
832 {
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
833 l -> len = 0;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
834
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
835 if (as -> skipmacro)
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
836 return;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
837
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
838 if (as -> skipcond)
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
839 {
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
840 if (as -> skipcount == 1)
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
841 {
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
842 as -> skipcount = 0;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
843 as -> skipcond = 0;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
844 }
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
845 return;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
846 }
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
847 as -> skipcond = 1;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
848 as -> skipcount = 1;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
849 }
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
850
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
851 PARSEFUNC(pseudo_parse_ifdef)
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
852 {
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
853 char *sym;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
854 int i;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
855 struct symtabe *s;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
856
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
857 l -> len = 0;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
858
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
859 if (as -> skipcond && !(as -> skipmacro))
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
860 {
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
861 as -> skipcount++;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
862 skip_operand(p);
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
863 return;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
864 }
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
865
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
866 for (i = 0; (*p)[i] && !isspace((*p)[i]); i++)
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
867 /* do nothing */ ;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
868
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
869 sym = lw_strndup(*p, i);
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
870
363
d96c30e60ddf Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents: 356
diff changeset
871 s = lookup_symbol(as, l, sym);
351
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
872
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
873 lw_free(sym);
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
874
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
875 if (!s)
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
876 {
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
877 as -> skipcond = 1;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
878 as -> skipcount = 1;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
879 }
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
880 }
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
881
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
882 PARSEFUNC(pseudo_parse_ifndef)
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
883 {
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
884 char *sym;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
885 int i;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
886 struct symtabe *s;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
887
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
888 l -> len = 0;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
889
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
890 if (as -> skipcond && !(as -> skipmacro))
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
891 {
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
892 as -> skipcount++;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
893 skip_operand(p);
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
894 return;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
895 }
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
896
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
897 for (i = 0; (*p)[i] && !isspace((*p)[i]); i++)
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
898 /* do nothing */ ;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
899
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
900 sym = lw_strndup(*p, i);
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
901
363
d96c30e60ddf Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents: 356
diff changeset
902 s = lookup_symbol(as, l, sym);
351
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
903
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
904 lw_free(sym);
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
905
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
906 if (s)
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
907 {
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
908 as -> skipcond = 1;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
909 as -> skipcount = 1;
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
910 }
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
911 }
4dba8c7e242c conditional pseudo ops added
lost@starbug
parents: 350
diff changeset
912
354
60568b123281 Added os9 opcodes and ERROR
lost@starbug
parents: 351
diff changeset
913 PARSEFUNC(pseudo_parse_error)
60568b123281 Added os9 opcodes and ERROR
lost@starbug
parents: 351
diff changeset
914 {
60568b123281 Added os9 opcodes and ERROR
lost@starbug
parents: 351
diff changeset
915 lwasm_register_error(as, l, "User error: %s", *p);
60568b123281 Added os9 opcodes and ERROR
lost@starbug
parents: 351
diff changeset
916 skip_operand(p);
60568b123281 Added os9 opcodes and ERROR
lost@starbug
parents: 351
diff changeset
917 }
356
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
918
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
919 PARSEFUNC(pseudo_parse_includebin)
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
920 {
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
921 char *fn, *p2;
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
922 int delim = 0;
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
923 FILE *fp;
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
924 long flen;
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
925
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
926 if (!**p)
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
927 {
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
928 lwasm_register_error(as, l, "Missing filename");
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
929 return;
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
930 }
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
931
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
932 if (**p == '"' || **p == '\'')
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
933 {
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
934 delim = **p;
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
935 (*p)++;
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
936
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
937 for (p2 = *p; *p2 && *p2 != delim; p2++)
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
938 /* do nothing */ ;
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
939 }
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
940 else
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
941 {
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
942 for (p2 = *p; *p2 && !isspace(*p2); p2++)
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
943 /* do nothing */ ;
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
944 }
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
945 fn = lw_strndup(*p, p2 - *p);
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
946
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
947 if (delim && **p)
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
948 (*p)++;
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
949
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
950 fp = input_open_standalone(as, fn);
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
951 if (!fp)
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
952 {
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
953 lwasm_register_error(as, l, "Cannot open file");
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
954 lw_free(fn);
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
955 return;
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
956 }
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
957
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
958 l -> lstr = fn;
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
959
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
960 fseek(fp, 0, SEEK_END);
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
961 flen = ftell(fp);
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
962 fclose(fp);
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
963
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
964 l -> len = flen;
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
965 }
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
966
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
967 EMITFUNC(pseudo_emit_includebin)
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
968 {
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
969 FILE *fp;
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
970 int c;
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
971
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
972 fp = input_open_standalone(as, l -> lstr);
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
973 if (!fp)
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
974 {
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
975 lwasm_register_error(as, l, "Cannot open file (emit)!");
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
976 return;
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
977 }
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
978
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
979 for (;;)
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
980 {
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
981 c = fgetc(fp);
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
982 if (c == EOF)
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
983 {
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
984 fclose(fp);
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
985 return;
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
986 }
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
987 lwasm_emit(l, c);
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
988 }
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
989 }
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
990
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
991 PARSEFUNC(pseudo_parse_include)
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
992 {
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
993 char *fn, *p2;
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
994 int delim = 0;
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
995
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
996 if (!**p)
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
997 {
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
998 lwasm_register_error(as, l, "Missing filename");
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
999 return;
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1000 }
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1001
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1002 if (**p == '"' || **p == '\'')
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1003 {
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1004 delim = **p;
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1005 (*p)++;
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1006
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1007 for (p2 = *p; *p2 && *p2 != delim; p2++)
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1008 /* do nothing */ ;
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1009 }
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1010 else
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1011 {
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1012 for (p2 = *p; *p2 && !isspace(*p2); p2++)
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1013 /* do nothing */ ;
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1014 }
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1015 fn = lw_strndup(*p, p2 - *p);
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1016
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1017 if (delim && **p)
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1018 (*p)++;
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1019
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1020 input_open(as, fn);
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1021
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1022 l -> len = 0;
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1023 }
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1024
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1025 PARSEFUNC(pseudo_parse_align)
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1026 {
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1027 lw_expr_t e;
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1028
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1029 if (!**p)
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1030 {
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1031 lwasm_register_error(as, l, "Bad operand");
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1032 return;
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1033 }
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1034
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1035 e = lwasm_parse_expr(as, p);
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1036 if (!e)
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1037 {
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1038 lwasm_register_error(as, l, "Bad operand");
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1039 return;
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1040 }
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1041
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1042 lwasm_save_expr(l, 0, e);
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1043
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1044 if (**p == ',')
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1045 {
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1046 e = lwasm_parse_expr(as, p);
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1047 }
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1048 else
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1049 {
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1050 e = lw_expr_build(lw_expr_type_int, 0);
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1051 }
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1052 if (!e)
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1053 {
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1054 lwasm_register_error(as, l, "Bad padding");
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1055 return;
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1056 }
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1057
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1058 lwasm_save_expr(l, 1, e);
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1059 }
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1060
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1061 RESOLVEFUNC(pseudo_resolve_align)
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1062 {
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1063 lw_expr_t e;
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1064 int align;
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1065
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1066 e = lwasm_fetch_expr(l, 0);
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1067
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1068 if (lw_expr_istype(e, lw_expr_type_int))
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1069 {
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1070 align = lw_expr_intval(e);
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1071 if (align < 1)
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1072 {
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1073 lwasm_register_error(as, l, "Invalid alignment");
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1074 return;
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1075 }
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1076 }
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1077
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1078 if (lw_expr_istype(l -> addr, lw_expr_type_int))
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1079 {
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1080 int a;
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1081 a = lw_expr_intval(l -> addr);
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1082 if (a % align == 0)
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1083 {
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1084 l -> len = 0;
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1085 return;
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1086 }
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1087 l -> len = align - (a % align);
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1088 return;
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1089 }
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1090 }
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1091
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1092 EMITFUNC(pseudo_emit_align)
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1093 {
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1094 lw_expr_t e;
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1095 int i;
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1096
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1097 e = lwasm_fetch_expr(l, 1);
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1098 for (i = 0; i < l -> len; i++)
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1099 {
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1100 lwasm_emitexpr(l, e, 1);
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1101 }
7166254491ed Finished pseudo ops
lost@starbug
parents: 354
diff changeset
1102 }