annotate lwasm/pseudo.c @ 232:1009f302ac11

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