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