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