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