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