annotate lwasm/pseudo.c @ 426:652eee8f0c82

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