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