annotate old-trunk/lwasm/old/pseudo.c @ 377:55ed7d06b136

Fixed intersection internal references in object target
author lost@starbug
date Mon, 26 Apr 2010 18:37:06 -0600
parents eb230fa7d28e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
339
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1 /*
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
2 pseudo.c
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
3 Copyright © 2009 William Astle
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
4
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
5 This file is part of LWASM.
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
6
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
7 LWASM is free software: you can redistribute it and/or modify it under the
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
8 terms of the GNU General Public License as published by the Free Software
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
9 Foundation, either version 3 of the License, or (at your option) any later
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
10 version.
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
11
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
12 This program is distributed in the hope that it will be useful, but WITHOUT
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
15 more details.
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
16
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
17 You should have received a copy of the GNU General Public License along with
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
18 this program. If not, see <http://www.gnu.org/licenses/>.
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
19
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
20
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
21 This file implements the various pseudo operations.
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
22 */
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
23 #include <config.h>
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
24 #include <errno.h>
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
25 #include <stdio.h>
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
26 #include <stdlib.h>
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
27 #include <string.h>
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
28 #include "lwasm.h"
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
29 #include "instab.h"
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
30 #include "expr.h"
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
31 #include "util.h"
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
32
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
33 extern int lwasm_read_file(asmstate_t *as, const char *filename);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
34
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
35 OPFUNC(pseudo_noop)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
36 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
37 skip_operand(p);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
38 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
39
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
40 OPFUNC(pseudo_org)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
41 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
42 int v, r;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
43
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
44 if (as -> csect)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
45 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
46 register_error(as, l, 1, "ORG not allowed within sections");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
47 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
48 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
49 if (as -> inmod)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
50 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
51 register_error(as, l, 1, "ORG not allowed within modules");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
52 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
53 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
54
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
55 if (as -> passnum != 1)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
56 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
57 // org is not needed to be processed on pass 2
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
58 // this will prevent phasing errors for forward references that
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
59 // resolve on the second pass
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
60 // we saved the org address in l -> codeaddr on pass 1
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
61 as -> addr = l -> codeaddr;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
62 skip_operand(p);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
63 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
64 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
65
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
66 if (l -> sym)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
67 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
68 register_error(as, l, 1, "No symbol allowed with ORG");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
69 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
70
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
71 r = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v, 0);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
72 if (r != 0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
73 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
74 l -> codeaddr = v;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
75 l -> addrset = 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
76 as -> addr = v;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
77 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
78
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
79 /*
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
80 The operand for include is a string optionally enclosed in "
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
81 */
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
82 OPFUNC(pseudo_include)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
83 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
84 int v1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
85 char *fn;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
86
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
87 // only include files on pass 1
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
88 // but make sure local include context is right
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
89 // for the next line...
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
90 if (as -> passnum != 1)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
91 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
92 as -> context = lwasm_next_context(as);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
93 skip_operand(p);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
94 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
95 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
96
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
97 while (**p && isspace(**p))
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
98 (*p)++;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
99
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
100 if (!**p)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
101 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
102 register_error(as, l, 1, "Bad file name");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
103 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
104 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
105
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
106 if (**p == '"')
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
107 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
108 // search for ending "
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
109 (*p)++;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
110 for (v1 = 0; *((*p)+v1) && *((*p)+v1) != '"'; v1++)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
111 /* do nothing */ ;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
112 if (*((*p)+v1) != '"')
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
113 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
114 register_error(as, l, 1, "Bad file name");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
115 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
116 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
117 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
118 else
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
119 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
120 // search for a space type character
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
121 for (v1 = 0; *((*p)+v1) && !isspace(*((*p)+v1)); v1++)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
122 ;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
123 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
124
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
125 fn = lwasm_alloc(v1 + 1);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
126 memcpy(fn, *p, v1);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
127 fn[v1] = '\0';
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
128
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
129 (*p) += v1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
130 if (**p == '"')
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
131 (*p)++;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
132
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
133 // end local label context on include
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
134 as -> context = lwasm_next_context(as);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
135 if (lwasm_read_file(as, fn) < 0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
136 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
137 register_error(as, l, 1, "File include error (%s)", fn);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
138 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
139 lwasm_free(fn);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
140 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
141
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
142 /*
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
143 The operand for includebin is a string optionally enclosed in "
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
144 */
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
145 OPFUNC(pseudo_includebin)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
146 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
147 int v1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
148 char *fn;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
149 FILE *f;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
150
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
151 // only include files on pass 1
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
152 while (**p && isspace(**p))
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
153 (*p)++;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
154
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
155 if (!**p)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
156 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
157 register_error(as, l, 1, "Bad file name");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
158 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
159 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
160
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
161 if (**p == '"')
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
162 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
163 // search for ending "
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
164 (*p)++;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
165 for (v1 = 0; *((*p)+v1) && *((*p)+v1) != '"'; v1++)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
166 /* do nothing */ ;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
167 if (*((*p)+v1) != '"')
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
168 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
169 register_error(as, l, 1, "Bad file name");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
170 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
171 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
172 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
173 else
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
174 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
175 // search for a space type character
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
176 for (v1 = 0; *((*p)+v1) && !isspace(*((*p)+v1)); v1++)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
177 ;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
178 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
179
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
180 fn = lwasm_alloc(v1 + 1);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
181 memcpy(fn, *p, v1);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
182 fn[v1] = '\0';
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
183
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
184 (*p) += v1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
185 if (**p == '"')
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
186 (*p)++;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
187
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
188 // open the file
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
189 f = fopen(fn, "rb");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
190 if (!f)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
191 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
192 register_error(as, l, 1, "Cannot open file: %s", strerror(errno));
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
193 register_error(as, l, 2, "Cannot open file: %s", strerror(errno));
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
194 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
195
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
196 // don't need fn any more
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
197 lwasm_free(fn);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
198
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
199 // read the contents of the file and "emit()" it
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
200 while (!feof(f) && !ferror(f))
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
201 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
202 v1 = fgetc(f);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
203 if (v1 == EOF)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
204 break;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
205 lwasm_emit(as, l, v1);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
206 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
207 // close file
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
208 fclose(f);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
209 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
210
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
211 OPFUNC(pseudo_rmb)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
212 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
213 int r, v;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
214
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
215 if (as -> passnum == 2)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
216 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
217 as -> addr += l -> nocodelen;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
218 skip_operand(p);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
219 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
220 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
221 r = lwasm_expr_result2(as, l, p, EXPR_SECTCONST | EXPR_PASS1CONST, &v, -1);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
222 if (r != 0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
223 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
224 l -> nocodelen = v;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
225 as -> addr += v;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
226 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
227
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
228 OPFUNC(pseudo_rmd)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
229 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
230 int r, v;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
231
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
232 if (as -> passnum == 2)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
233 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
234 as -> addr += l -> nocodelen;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
235 skip_operand(p);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
236 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
237 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
238 r = lwasm_expr_result2(as, l, p, EXPR_SECTCONST | EXPR_PASS1CONST, &v, 0);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
239 if (r != 0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
240 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
241 v *= 2;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
242 l -> nocodelen = v;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
243 as -> addr += v;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
244 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
245
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
246 OPFUNC(pseudo_rmq)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
247 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
248 int r, v;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
249
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
250 if (as -> passnum == 2)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
251 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
252 as -> addr += l -> nocodelen;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
253 skip_operand(p);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
254 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
255 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
256 r = lwasm_expr_result2(as, l, p, EXPR_SECTCONST | EXPR_PASS1CONST, &v, 0);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
257 if (r != 0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
258 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
259 v *= 4;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
260 l -> nocodelen = v;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
261 as -> addr += v;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
262 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
263
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
264 OPFUNC(pseudo_zmb)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
265 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
266 int r, v;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
267
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
268 r = lwasm_expr_result2(as, l, p, EXPR_SECTCONST | EXPR_PASS1CONST, &v, 0);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
269 if (r != 0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
270 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
271 while (v--)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
272 lwasm_emit(as, l, 0);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
273 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
274
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
275 OPFUNC(pseudo_zmd)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
276 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
277 int r, v;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
278
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
279 r = lwasm_expr_result2(as, l, p, EXPR_SECTCONST | EXPR_PASS1CONST, &v, 0);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
280 if (r != 0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
281 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
282 v *= 2;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
283 while (v--)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
284 lwasm_emit(as, l, 0);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
285 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
286
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
287 OPFUNC(pseudo_zmq)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
288 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
289 int r, v;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
290
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
291 r = lwasm_expr_result2(as, l, p, EXPR_SECTCONST | EXPR_PASS1CONST, &v, 0);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
292 if (r != 0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
293 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
294 v *= 4;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
295 while (v--)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
296 lwasm_emit(as, l, 0);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
297 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
298
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
299 OPFUNC(pseudo_end)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
300 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
301 int r, v;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
302 lwasm_expr_stack_t *s;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
303
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
304
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
305 as -> endseen = 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
306
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
307 // address only matters for DECB output
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
308 if (as -> outformat != OUTPUT_DECB)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
309 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
310 skip_operand(p);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
311 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
312 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
313
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
314 r = lwasm_expr_result2(as, l, p, 0, &v, 0);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
315 if (r != 0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
316 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
317 register_error(as, l, 2, "Bad operand");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
318 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
319
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
320 v = v & 0xffff;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
321 if (as -> passnum == 2)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
322 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
323 as -> execaddr = v;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
324 l -> symaddr = v;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
325 l -> addrset = 2;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
326 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
327 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
328
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
329
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
330 OPFUNC(pseudo_align)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
331 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
332 int cn;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
333 int r, v;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
334 int pad = 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
335 // we have to parse this on pass 2 so that we get the pad value
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
336 // if (as -> passnum == 2)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
337 // {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
338 // skip_operand(p);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
339 // while (as -> addr < l -> symaddr)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
340 // lwasm_emit(as, l, 0);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
341 // return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
342 // }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
343
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
344 r = lwasm_expr_result2(as, l, p, EXPR_SECTCONST | EXPR_PASS1CONST, &v, 0);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
345 if (r != 0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
346 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
347 l -> symaddr = as -> addr;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
348 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
349 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
350
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
351 if (v < 1)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
352 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
353 register_error(as, l, 1, "Illegal alignment %d", v);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
354 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
355 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
356
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
357 cn = l -> codeaddr % v;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
358 if (cn)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
359 cn = v - cn;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
360
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
361 if (**p == ',')
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
362 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
363 // we have a padding value specified
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
364 (*p)++;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
365 r = lwasm_expr_result2(as, l, p, EXPR_SECTCONST, &pad, 1);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
366 if (r != 0 && as -> passnum == 2)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
367 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
368 register_error(as, l, 2, "Illegal padding value - must be constant on pass 2");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
369 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
370 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
371 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
372
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
373 while (cn--)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
374 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
375 lwasm_emit(as, l, pad);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
376 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
377 l -> symaddr = as -> addr;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
378 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
379
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
380 OPFUNC(pseudo_equ)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
381 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
382 int r, v;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
383
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
384 if (l -> sym == NULL)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
385 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
386 register_error(as, l, 1, "No symbol specified");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
387 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
388 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
389
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
390 r = lwasm_expr_result2(as, l, p, EXPR_SECTCONST | EXPR_PASS1CONST, &v, 0);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
391 if (r < 0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
392 v = 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
393
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
394 l -> symaddr = v & 0xFFFF;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
395 l -> addrset = 2;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
396
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
397 // note: we need to do this because the symbol might have resolved
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
398 // to a constant!
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
399 lwasm_register_symbol(as, l, l -> sym, v, (r > 0 ? SYMBOL_COMPLEX: SYMBOL_NORM) | SYMBOL_FORCE | (l -> forceglobal ? SYMBOL_GLOBAL : SYMBOL_NORM));
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
400 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
401
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
402 OPFUNC(pseudo_set)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
403 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
404 int r, v;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
405
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
406 // set MUST run on both passes as the symbol value changes!
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
407
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
408 if (l -> sym == NULL)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
409 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
410 register_error(as, l, 1, "No symbol specified");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
411 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
412 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
413
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
414 r = lwasm_expr_result2(as, l, p, EXPR_SECTCONST | EXPR_PASS1CONST, &v, 0);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
415 if (r < 0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
416 v = 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
417
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
418 l -> symaddr = v & 0xFFFF;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
419 l -> addrset = 2;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
420
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
421 lwasm_register_symbol(as, l, l -> sym, v, (r > 0 ? SYMBOL_COMPLEX: SYMBOL_NORM) | SYMBOL_SET);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
422 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
423
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
424 OPFUNC(pseudo_setdp)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
425 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
426 int r, v;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
427
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
428 if (as -> outformat == OUTPUT_OBJ)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
429 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
430 register_error(as, l, 1, "SETDP not permitted with OBJ target");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
431 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
432 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
433
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
434 // setdp is needed on both passes; must resolve to a constant on pass 1
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
435 r = lwasm_expr_result2(as, l, p, EXPR_SECTCONST | EXPR_PASS1CONST, &v, 0);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
436 if (r != 0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
437 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
438
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
439 if (v < -127 || v > 255)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
440 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
441 register_error(as, l, 1, "Byte overflow");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
442 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
443 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
444
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
445 l -> symaddr = v & 0xFF;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
446 l -> addrset = 2;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
447
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
448 as -> dpval = v & 0xFF;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
449 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
450
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
451 // used to get a byte from a string
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
452 // -1 is end of line
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
453 int pseudo_fcc_fetchchar(asmstate_t *as, char **p)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
454 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
455 int c;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
456
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
457 // -
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
458 if (!**p)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
459 return -1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
460
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
461 c = (unsigned char)(**p);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
462 (*p)++;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
463
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
464 if (as -> pragmas & PRAGMA_CESCAPES && c == '\\')
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
465 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
466 // decode escapes if needed
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
467 if (!**p)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
468 return c;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
469
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
470 c = **p;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
471 (*p)++;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
472
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
473 switch (c)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
474 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
475 // octal value
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
476 // 1, 2, or 3 digits
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
477 // NOTE: \0 for NUL is included in this...
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
478 case '0':
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
479 case '1':
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
480 case '2':
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
481 case '3':
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
482 case '4':
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
483 case '5':
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
484 case '6':
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
485 case '7':
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
486 c -= '0';
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
487 if (**p < '0' || **p > '9')
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
488 return c;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
489 c = c << 3;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
490 c |= **p - '0';
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
491 (*p)++;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
492 if (**p < '0' || **p > '9')
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
493 return c;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
494 c = c << 3;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
495 c |= **p - '0';
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
496 (*p)++;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
497 return c;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
498
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
499 // LF
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
500 case 'n':
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
501 return 10;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
502
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
503 // CR
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
504 case 'r':
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
505 return 13;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
506
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
507 // TAB
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
508 case 't':
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
509 return 9;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
510
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
511 // VT
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
512 case 'v':
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
513 return 11;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
514
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
515 // BS
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
516 case 'b':
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
517 return 8;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
518
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
519 // FF
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
520 case 'f':
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
521 return 12;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
522
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
523 // BEL
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
524 case 'a':
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
525 return 7;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
526
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
527 // hex char code (2 chars)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
528 case 'x':
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
529 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
530 int c2;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
531 if (!**p)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
532 return 'x';
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
533 c = toupper(**p);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
534 (*p)++;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
535 if (c < '0' || (c > '9' && c < 'A') || c > 'F')
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
536 return 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
537 c -= '0';
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
538 if (c > 9)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
539 c -= 7;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
540 c2 = c << 4;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
541 if (!**p)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
542 return 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
543 c = toupper(**p);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
544 (*p)++;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
545 if (c < '0' || (c > '9' && c < 'A') || c > 'F')
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
546 return 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
547 c -= '0';
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
548 if (c > 9)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
549 c -= 7;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
550 c2 |= c;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
551 return c2;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
552 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
553 // everything else stands for itself as a fall back or legit
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
554 default:
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
555 return c;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
556 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
557 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
558 return c;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
559 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
560
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
561 OPFUNC(pseudo_fcc)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
562 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
563 int delim = 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
564 int c;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
565
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
566 delim = **p;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
567 if (!delim)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
568 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
569 register_error(as, l, 1, "Bad operand");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
570 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
571 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
572 *p += 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
573 for (;;)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
574 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
575 c = pseudo_fcc_fetchchar(as, p);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
576 if (c == delim || c < 0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
577 break;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
578
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
579 lwasm_emit(as, l, c);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
580 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
581 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
582
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
583
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
584 OPFUNC(pseudo_fcs)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
585 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
586 int delim = 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
587 int c, lc = -1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
588
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
589 delim = **p;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
590 if (!delim)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
591 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
592 register_error(as, l, 1, "Bad operand");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
593 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
594 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
595 *p += 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
596 for (;;)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
597 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
598 c = pseudo_fcc_fetchchar(as, p);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
599 if (c == delim || c < 0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
600 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
601 if (lc >= 0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
602 lwasm_emit(as, l, lc | 0x80);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
603 break;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
604 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
605 if (lc >= 0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
606 lwasm_emit(as, l, lc);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
607 lc = c;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
608 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
609 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
610
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
611 OPFUNC(pseudo_fcn)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
612 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
613 int delim = 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
614 int c;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
615
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
616 delim = **p;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
617 if (!delim)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
618 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
619 register_error(as, l, 1, "Bad operand");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
620 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
621 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
622 *p += 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
623 for (;;)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
624 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
625 c = pseudo_fcc_fetchchar(as, p);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
626 if (c == delim || c < 0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
627 break;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
628
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
629 lwasm_emit(as, l, c);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
630 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
631 lwasm_emit(as, l, 0);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
632 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
633
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
634 OPFUNC(pseudo_fcb)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
635 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
636 int r, v;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
637
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
638 fcb_again:
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
639 r = lwasm_expr_result2(as, l, p, 0, &v, -1);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
640 if (r < 0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
641 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
642
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
643 if (r > 0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
644 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
645 register_error(as, l, 2, "Illegal external or inter-segment reference");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
646 v = 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
647 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
648
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
649 if (v < -127 || v > 255)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
650 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
651 register_error(as, l, 1, "Byte overflow");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
652 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
653
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
654 lwasm_emit(as, l, v);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
655 if (**p == ',')
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
656 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
657 (*p)++;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
658 goto fcb_again;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
659 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
660 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
661
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
662 // FIXME: handle external references in an intelligent way
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
663 OPFUNC(pseudo_fdb)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
664 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
665 int r, v;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
666 int extseen = 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
667 char *p1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
668
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
669 fdb_again:
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
670 p1 = *p;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
671 r = lwasm_expr_result2(as, l, p, 0, &v, -1);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
672 if (r < 0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
673 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
674
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
675 if (r > 0 && extseen == 1)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
676 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
677 register_error(as, l, 2, "Illegal external or inter-segment reference (only 1 per FDB line)");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
678 v = 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
679 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
680 else if (r > 0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
681 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
682 l -> relocoff = as -> addr - l -> codeaddr;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
683 *p = p1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
684 r = lwasm_expr_result2(as, l, p, 0, &v, 0);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
685 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
686
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
687 lwasm_emit(as, l, v >> 8);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
688 lwasm_emit(as, l, v & 0xff);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
689 if (**p == ',')
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
690 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
691 (*p)++;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
692 goto fdb_again;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
693 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
694 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
695
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
696 // FIXME: handle external references in a sensible way
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
697 OPFUNC(pseudo_fqb)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
698 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
699 int r, v;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
700
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
701 fqb_again:
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
702 r = lwasm_expr_result2(as, l, p, 0, &v, -1);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
703 if (r < 0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
704 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
705
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
706 if (r > 0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
707 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
708 register_error(as, l, 2, "Illegal external or inter-segment reference");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
709 v = 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
710 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
711
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
712 lwasm_emit(as, l, v >> 24);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
713 lwasm_emit(as, l, v >> 16);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
714 lwasm_emit(as, l, v >> 8);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
715 lwasm_emit(as, l, v & 0xff);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
716 if (**p == ',')
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
717 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
718 (*p)++;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
719 goto fqb_again;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
720 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
721 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
722
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
723 // don't need to do anything if we are executing one of these
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
724 OPFUNC(pseudo_endc)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
725 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
726 if (as -> skipcond && !(as -> skipmacro))
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
727 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
728 as -> skipcount -= 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
729 if (as -> skipcount <= 0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
730 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
731 as -> skipcond = 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
732 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
733 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
734 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
735 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
736
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
737 // if "else" executes, we must be going into an "ignore" state
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
738 OPFUNC(pseudo_else)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
739 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
740 if (as -> skipmacro)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
741 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
742
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
743 if (as -> skipcond)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
744 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
745 if (as -> skipcount == 1)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
746 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
747 as -> skipcount = 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
748 as -> skipcond = 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
749 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
750 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
751 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
752
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
753 as -> skipcond = 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
754 as -> skipcount = 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
755 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
756
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
757 OPFUNC(pseudo_ifne)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
758 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
759 int v1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
760 int rval;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
761
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
762 if (as -> skipcond && !(as -> skipmacro))
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
763 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
764 as -> skipcount++;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
765 skip_operand(p);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
766 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
767 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
768
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
769 rval = lwasm_expr_result2(as, l, p, EXPR_SECTCONST | EXPR_PASS1CONST, &v1, 0);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
770 if (rval != 0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
771 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
772 if (!v1)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
773 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
774 as -> skipcond = 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
775 as -> skipcount = 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
776 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
777 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
778
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
779 OPFUNC(pseudo_ifdef)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
780 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
781 lwasm_symbol_ent_t *se;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
782 char *sym;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
783 char *p2;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
784
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
785 if (as -> skipcond && !(as -> skipmacro))
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
786 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
787 as -> skipcount++;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
788 skip_operand(p);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
789 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
790 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
791
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
792 if (as -> passnum != 1)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
793 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
794 skip_operand(p);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
795 if (!(l -> fsize))
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
796 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
797 as -> skipcond = 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
798 as -> skipcount = 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
799 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
800 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
801 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
802
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
803 if (!**p)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
804 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
805 register_error(as, l, 1, "Need symbol name");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
806 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
807 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
808
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
809 for (p2 = *p; **p && !isspace(**p); (*p)++)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
810 /* do nothing */ ;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
811
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
812 sym = lwasm_alloc(*p - p2 + 1);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
813 memcpy(sym, p2, *p - p2);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
814 sym[*p - p2] = '\0';
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
815
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
816 // fprintf(stderr, "STUFF: %s; '%s'; '%s' (%d)\n", p2, *p, sym, as -> passnum);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
817 se = lwasm_find_symbol(as, sym, l -> context);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
818 if (!se)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
819 se = lwasm_find_symbol(as, sym, -1);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
820
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
821 lwasm_free(sym);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
822
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
823 if (!se)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
824 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
825 as -> skipcond = 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
826 as -> skipcount = 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
827 l -> fsize = 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
828 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
829 else
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
830 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
831 l -> fsize = 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
832 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
833 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
834
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
835 OPFUNC(pseudo_ifndef)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
836 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
837 lwasm_symbol_ent_t *se;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
838 char *sym;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
839 char *p2;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
840
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
841 if (as -> skipcond && !(as -> skipmacro))
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
842 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
843 as -> skipcount++;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
844 skip_operand(p);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
845 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
846 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
847
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
848 if (as -> passnum != 1)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
849 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
850 skip_operand(p);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
851 if (l -> fsize)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
852 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
853 as -> skipcond = 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
854 as -> skipcount = 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
855 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
856 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
857 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
858
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
859 if (!**p)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
860 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
861 register_error(as, l, 1, "Need symbol name");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
862 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
863 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
864
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
865 for (p2 = *p; *p2 && !isspace(*p2); p2++)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
866 /* do nothing */ ;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
867
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
868 sym = lwasm_alloc(p2 - *p + 1);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
869 memcpy(sym, *p, p2 - *p);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
870 sym[p2 - *p] = '\0';
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
871
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
872 *p = p2;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
873
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
874 // fprintf(stderr, "STUFF2: %s; '%s'; '%s' (%d)\n", *p, p2, sym, as -> passnum);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
875 se = lwasm_find_symbol(as, sym, l -> context);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
876 if (!se)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
877 se = lwasm_find_symbol(as, sym, -1);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
878
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
879 lwasm_free(sym);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
880
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
881 if (se)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
882 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
883 as -> skipcond = 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
884 as -> skipcount = 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
885 l -> fsize = 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
886 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
887 else
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
888 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
889 l -> fsize = 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
890 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
891 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
892
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
893 OPFUNC(pseudo_ifp1)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
894 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
895 if (as -> skipcond && !(as -> skipmacro))
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
896 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
897 as -> skipcount++;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
898 skip_operand(p);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
899 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
900 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
901
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
902 if (as -> passnum != 1)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
903 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
904 as -> skipcond = 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
905 as -> skipcount = 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
906 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
907 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
908
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
909 OPFUNC(pseudo_ifp2)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
910 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
911 if (as -> skipcond && !(as -> skipmacro))
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
912 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
913 as -> skipcount++;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
914 skip_operand(p);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
915 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
916 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
917
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
918 if (as -> passnum != 2)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
919 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
920 as -> skipcond = 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
921 as -> skipcount = 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
922 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
923 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
924
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
925 OPFUNC(pseudo_ifeq)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
926 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
927 int v1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
928 int rval;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
929
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
930 if (as -> skipcond && !(as -> skipmacro))
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
931 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
932 as -> skipcount++;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
933 skip_operand(p);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
934 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
935 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
936
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
937 rval = lwasm_expr_result2(as, l, p, EXPR_SECTCONST | EXPR_PASS1CONST, &v1, 0);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
938 if (rval != 0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
939 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
940 if (v1)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
941 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
942 as -> skipcond = 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
943 as -> skipcount = 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
944 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
945 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
946
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
947 OPFUNC(pseudo_iflt)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
948 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
949 int v1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
950 int rval;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
951
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
952 if (as -> skipcond && !(as -> skipmacro))
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
953 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
954 as -> skipcount++;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
955 skip_operand(p);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
956 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
957 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
958
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
959 rval = lwasm_expr_result2(as, l, p, EXPR_SECTCONST | EXPR_PASS1CONST, &v1, 0);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
960 if (rval != 0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
961 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
962 if (v1 >= 0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
963 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
964 as -> skipcond = 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
965 as -> skipcount = 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
966 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
967 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
968
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
969 OPFUNC(pseudo_ifle)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
970 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
971 int v1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
972 int rval;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
973
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
974 if (as -> skipcond && !(as -> skipmacro))
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
975 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
976 as -> skipcount++;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
977 skip_operand(p);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
978 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
979 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
980
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
981 rval = lwasm_expr_result2(as, l, p, EXPR_SECTCONST | EXPR_PASS1CONST, &v1, 0);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
982 if (rval != 0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
983 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
984 if (v1 > 0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
985 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
986 as -> skipcond = 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
987 as -> skipcount = 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
988 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
989 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
990
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
991 OPFUNC(pseudo_ifgt)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
992 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
993 int v1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
994 int rval;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
995
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
996 if (as -> skipcond && !(as -> skipmacro))
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
997 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
998 as -> skipcount++;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
999 skip_operand(p);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1000 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1001 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1002
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1003 rval = lwasm_expr_result2(as, l, p, EXPR_SECTCONST | EXPR_PASS1CONST, &v1, 0);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1004 if (rval != 0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1005 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1006 if (v1 <= 0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1007 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1008 as -> skipcond = 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1009 as -> skipcount = 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1010 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1011 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1012
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1013 OPFUNC(pseudo_ifge)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1014 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1015 int v1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1016 int rval;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1017
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1018 if (as -> skipcond && !(as -> skipmacro))
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1019 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1020 as -> skipcount++;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1021 skip_operand(p);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1022 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1023 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1024
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1025 rval = lwasm_expr_result2(as, l, p, EXPR_SECTCONST | EXPR_PASS1CONST, &v1, 0);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1026 if (rval != 0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1027 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1028 if (v1 < 0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1029 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1030 as -> skipcond = 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1031 as -> skipcount = 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1032 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1033 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1034
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1035 OPFUNC(pseudo_error)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1036 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1037 register_error(as, l, 1, "User error: %s", *p);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1038 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1039
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1040
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1041 OPFUNC(pseudo_section)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1042 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1043 sectiontab_t *s;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1044 char *p2;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1045 char *sn;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1046 char *opts;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1047
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1048
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1049 if (as -> outformat != OUTPUT_OBJ)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1050 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1051 register_error(as, l, 1, "Sections only supported for obj target");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1052 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1053 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1054
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1055 if (as -> csect)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1056 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1057 as -> csect -> offset = as -> addr;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1058 as -> csect = NULL;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1059 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1060
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1061 if (!**p)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1062 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1063 register_error(as, l, 1, "Need section name");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1064 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1065 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1066
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1067 for (p2 = *p; *p2 && !isspace(*p2); p2++)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1068 /* do nothing */ ;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1069
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1070 sn = lwasm_alloc(p2 - *p + 1);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1071 memcpy(sn, *p, p2 - *p);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1072 sn[p2 - *p] = '\0';
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1073
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1074 *p = p2;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1075
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1076 opts = strchr(sn, ',');
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1077 if (opts)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1078 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1079 *opts++ = '\0';
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1080 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1081
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1082 // have we seen the section name already?
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1083 for (s = as -> sections; s; s = s -> next)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1084 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1085 if (!strcmp(s -> name, sn))
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1086 break;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1087 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1088
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1089 if (s && as -> passnum == 1)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1090 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1091 lwasm_free(sn);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1092 if (opts)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1093 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1094 register_error(as, l, 1, "Section options can only be specified the first time");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1095 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1096 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1097 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1098 else if (!s)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1099 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1100 s = lwasm_alloc(sizeof(sectiontab_t));
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1101 s -> name = sn;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1102 s -> offset = 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1103 s -> flags = 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1104 s -> obytes = NULL;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1105 s -> oblen = 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1106 s -> obsize = 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1107 s -> rl = NULL;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1108 s -> exports = NULL;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1109 // if name of section is "bss" or ".bss", assume bss flag
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1110 // which can be overridden with !bss flag
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1111 if (!strcasecmp(sn, "bss") || !strcasecmp(sn, ".bss"))
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1112 s -> flags = SECTION_BSS;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1113 // parse options; only one "bss"
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1114 if (opts && as -> passnum == 1)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1115 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1116 if (!strcasecmp(opts, "bss"))
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1117 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1118 s -> flags |= SECTION_BSS;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1119 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1120 else if (!strcasecmp(opts, "!bss"))
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1121 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1122 s -> flags &= ~SECTION_BSS;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1123 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1124 else
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1125 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1126 register_error(as, l, 1, "Unrecognized section option '%s'", opts);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1127 lwasm_free(s -> name);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1128 lwasm_free(s);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1129 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1130 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1131 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1132
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1133 s -> next = as -> sections;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1134 as -> sections = s;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1135 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1136 as -> addr = s -> offset;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1137 as -> csect = s;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1138 as -> context = lwasm_next_context(as);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1139 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1140
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1141 OPFUNC(pseudo_endsection)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1142 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1143 if (as -> outformat != OUTPUT_OBJ)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1144 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1145 register_error(as, l, 1, "Sections only supported for obj target");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1146 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1147 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1148
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1149 if (!(as -> csect))
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1150 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1151 register_error(as, l, 1, "ENDSECTION when not in a section");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1152 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1153 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1154
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1155 as -> csect -> offset = as -> addr;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1156 as -> addr = 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1157 as -> csect = 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1158 as -> context = lwasm_next_context(as);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1159 skip_operand(p);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1160 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1161
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1162 OPFUNC(pseudo_extern)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1163 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1164 if (as -> passnum != 1)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1165 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1166
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1167 if (as -> outformat != OUTPUT_OBJ)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1168 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1169 register_error(as, l, 1, "External references only supported for obj target");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1170 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1171 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1172
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1173 if (as -> csect)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1174 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1175 register_error(as, l, 1, "Cannot declare external symbols within a section");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1176 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1177 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1178
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1179 if (l -> sym)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1180 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1181 lwasm_register_symbol(as, l, l -> sym, 0, SYMBOL_EXTERN);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1182 for ( ; **p; (*p)++) ;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1183 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1184 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1185
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1186 while (**p)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1187 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1188 char *sym2, *sym3;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1189 for (sym2 = *p; **p && !isspace(**p) && **p != ','; (*p)++)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1190 /* do nothing */ ;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1191
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1192 if (l -> sym)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1193 lwasm_free(l -> sym);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1194
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1195 sym3 = lwasm_alloc(*p - sym2 + 1);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1196 memcpy(sym3, sym2, *p - sym2);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1197 sym3[*p - sym2] = '\0';
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1198
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1199 l -> sym = sym3;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1200 debug_message(2, "import symbol: '%s'", sym3);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1201 lwasm_register_symbol(as, l, l -> sym, 0, SYMBOL_EXTERN);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1202 if (**p && (**p != ','))
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1203 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1204 register_error(as, l, 1, "Bad import list");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1205 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1206 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1207 if (**p == ',')
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1208 (*p)++;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1209 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1210 if (!(l -> sym))
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1211 register_error(as, l, 1, "Bad import list");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1212 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1213
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1214 OPFUNC(pseudo_export)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1215 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1216 lwasm_symbol_ent_t *se;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1217 export_list_t *ex;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1218 char *sym2, *sym3;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1219 int after = 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1220
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1221 if (as -> outformat != OUTPUT_OBJ)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1222 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1223 register_error(as, l, 1, "Symbol exports only supported for obj target");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1224 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1225 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1226
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1227 if (as -> passnum == 1)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1228 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1229 skip_operand(p);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1230 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1231 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1232
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1233 if (l -> sym)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1234 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1235 for ( ; **p; (*p)++) ;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1236 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1237
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1238 again:
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1239 if (!(l -> sym) || after == 1)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1240 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1241
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1242 after = 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1243 // look for symbol after op
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1244 if (**p)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1245 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1246 for (sym2 = *p; **p && !isspace(**p) && **p != ','; (*p)++)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1247 /* do nothing */ ;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1248
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1249 debug_message(2, "export expression: %s", sym2);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1250 if (l -> sym)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1251 lwasm_free(l -> sym);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1252 sym3 = lwasm_alloc(*p - sym2 + 1);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1253 memcpy(sym3, sym2, *p - sym2);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1254 sym3[*p - sym2] = '\0';
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1255
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1256 l -> sym = sym3;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1257 debug_message(2, "export symbol: '%s'", sym3);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1258 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1259 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1260 if (!(l -> sym))
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1261 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1262 register_error(as, l, 2, "No symbol");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1263 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1264 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1265
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1266
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1267 // the symbol better be defined at this point (pass 2)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1268 // local symbols cannot be exported nor can "global" symbols
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1269 se = lwasm_find_symbol(as, l -> sym, -1);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1270 if ((!se || (se -> flags & SYMBOL_EXTERN)) && (as -> pragmas & PRAGMA_IMPORTUNDEFEXPORT))
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1271 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1272 void *p;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1273 p = as -> csect;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1274 as -> csect = NULL;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1275 lwasm_register_symbol(as, l, l -> sym, 0, SYMBOL_EXTERN);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1276 as -> csect = p;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1277 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1278 else
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1279 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1280 if (!se)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1281 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1282 register_error(as, l, 2, "Exported symbols must be fully defined within a section");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1283 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1284 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1285 if (se -> sect == NULL)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1286 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1287 register_error(as, l, 2, "Only non-local symbols within a section can be exported");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1288 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1289 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1290
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1291 if (se -> flags & SYMBOL_SET)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1292 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1293 register_error(as, l, 2, "You cannot export symbols defined with SET");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1294 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1295 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1296
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1297 // if the symbol is not already a simple value, re-evaluate it
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1298 // and see if it becomes simple
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1299
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1300
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1301 if (se -> flags & SYMBOL_COMPLEX)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1302 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1303 register_error(as, l, 2, "Exported symbols must be fully resolved on pass 2");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1304 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1305 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1306
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1307 // search for existing export
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1308 for (ex = se -> sect -> exports; ex; ex = ex -> next)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1309 if (!strcmp(l -> sym, ex -> sym))
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1310 break;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1311 if (ex)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1312 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1313 register_error(as, l, 2, "Symbol %s already exported", l -> sym);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1314 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1315 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1316
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1317 // add an external reference
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1318 ex = lwasm_alloc(sizeof(export_list_t));
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1319 ex -> next = se -> sect -> exports;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1320 se -> sect -> exports = ex;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1321 ex -> offset = se -> value;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1322 ex -> sym = lwasm_strdup(se -> sym);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1323 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1324 next:
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1325 if (after == 1)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1326 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1327 if (**p == ',')
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1328 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1329 debug_message(2, "Export another symbol: %s", *p);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1330 (*p)++;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1331 for ( ; **p && isspace(**p); (*p)++)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1332 /* do nothing */ ;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1333 goto again;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1334 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1335 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1336 }