annotate lwasm/pseudo.c @ 151:427e268e876b

renamed src to lwasm to better reflect its purpose
author lost
date Fri, 30 Jan 2009 04:01:55 +0000
parents src/pseudo.c@2ba8f9ef1417
children f0527dc3804d
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 */
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
23
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
24 #include <stdlib.h>
50
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
25 #include <string.h>
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
26 #include "lwasm.h"
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
27 #include "instab.h"
47
804d7465e0f9 Implemented ORG and fixed problems with constants using $, &, or @ to specify base
lost
parents: 4
diff changeset
28 #include "expr.h"
52
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
29 #include "util.h"
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
30
52
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
31 extern int lwasm_read_file(asmstate_t *as, const char *filename);
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
32
47
804d7465e0f9 Implemented ORG and fixed problems with constants using $, &, or @ to specify base
lost
parents: 4
diff changeset
33 OPFUNC(pseudo_org)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
34 {
78
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
35 int v, r;
52
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
36
74
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
37 if (as -> csect)
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
38 {
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
39 register_error(as, l, 1, "ORG not allowed within sections");
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
40 return;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
41 }
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
42
52
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
43 if (as -> passnum != 1)
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
44 {
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
45 // org is not needed to be processed on pass 2
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
46 // this will prevent phasing errors for forward references that
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
47 // resolve on the second pass
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
48 // we saved the org address in l -> codeaddr on pass 1
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
49 as -> addr = l -> codeaddr;
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
50 return;
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
51 }
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
52
47
804d7465e0f9 Implemented ORG and fixed problems with constants using $, &, or @ to specify base
lost
parents: 4
diff changeset
53 if (l -> sym)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
54 {
47
804d7465e0f9 Implemented ORG and fixed problems with constants using $, &, or @ to specify base
lost
parents: 4
diff changeset
55 register_error(as, l, 1, "No symbol allowed with ORG");
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
56 }
78
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
57
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
58 r = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v, 0);
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
59 if (r != 0)
47
804d7465e0f9 Implemented ORG and fixed problems with constants using $, &, or @ to specify base
lost
parents: 4
diff changeset
60 return;
78
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
61 l -> codeaddr = v;
49
21ae0fab469b Added needed infra for useful listing of EQU and ORG type statements
lost
parents: 47
diff changeset
62 l -> addrset = 1;
78
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
63 as -> addr = v;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
64 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
65
47
804d7465e0f9 Implemented ORG and fixed problems with constants using $, &, or @ to specify base
lost
parents: 4
diff changeset
66 /*
52
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
67 The operand for include is a string optionally enclosed in "
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
68 */
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
69 OPFUNC(pseudo_include)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
70 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
71 int v1;
52
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
72 char *fn;
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
73
52
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
74 // only include files on pass 1
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
75 // but make sure local include context is right
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
76 // for the next line...
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
77 if (as -> passnum != 1)
52
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
78 {
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
79 as -> context = lwasm_next_context(as);
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
80 return;
52
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
81 }
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
82
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
83 while (**p && isspace(**p))
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
84 (*p)++;
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
85
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
86 if (!**p)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
87 {
52
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
88 register_error(as, l, 1, "Bad file name");
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
89 return;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
90 }
52
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
91
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
92 if (**p == '"')
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
93 {
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
94 // search for ending "
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
95 (*p)++;
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
96 for (v1 = 0; *((*p)+v1) && *((*p)+v1) != '"'; v1++)
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
97 /* do nothing */ ;
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
98 if (*((*p)+v1) != '"')
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
99 {
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
100 register_error(as, l, 1, "Bad file name");
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
101 return;
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
102 }
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
103 }
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
104 else
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
105 {
52
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
106 // search for a space type character
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
107 for (v1 = 0; *((*p)+v1) && !isspace(*((*p)+v1)); v1++)
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
108 ;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
109 }
52
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
110
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
111 fn = lwasm_alloc(v1 + 1);
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
112 memcpy(fn, *p, v1);
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
113 fn[v1] = '\0';
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
114
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
115 // end local label context on include
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
116 as -> context = lwasm_next_context(as);
52
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
117 if (lwasm_read_file(as, fn) < 0)
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
118 {
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
119 register_error(as, l, 1, "File include error (%s)", fn);
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
120 }
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
121 lwasm_free(fn);
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
122 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
123
50
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
124 OPFUNC(pseudo_rmb)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
125 {
78
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
126 int r, v;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
127
95
f3497072ac44 Fixed think-o in rm* ops (reversed pass number test)
lost
parents: 94
diff changeset
128 if (as -> passnum == 2)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
129 {
78
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
130 as -> addr += l -> nocodelen;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
131 return;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
132 }
103
26c058fa0bc1 Fixed up some issues with pseudo ops and object target
lost
parents: 99
diff changeset
133 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
134 if (r != 0)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
135 return;
78
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
136 l -> nocodelen = v;
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
137 as -> addr += v;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
138 }
53
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
139
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
140 OPFUNC(pseudo_rmd)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
141 {
78
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
142 int r, v;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
143
95
f3497072ac44 Fixed think-o in rm* ops (reversed pass number test)
lost
parents: 94
diff changeset
144 if (as -> passnum == 2)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
145 {
78
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
146 as -> addr += l -> nocodelen;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
147 return;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
148 }
103
26c058fa0bc1 Fixed up some issues with pseudo ops and object target
lost
parents: 99
diff changeset
149 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
150 if (r != 0)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
151 return;
78
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
152 v *= 2;
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
153 l -> nocodelen = v;
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
154 as -> addr += v;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
155 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
156
53
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
157 OPFUNC(pseudo_rmq)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
158 {
78
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
159 int r, v;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
160
95
f3497072ac44 Fixed think-o in rm* ops (reversed pass number test)
lost
parents: 94
diff changeset
161 if (as -> passnum == 2)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
162 {
78
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
163 as -> addr += l -> nocodelen;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
164 return;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
165 }
103
26c058fa0bc1 Fixed up some issues with pseudo ops and object target
lost
parents: 99
diff changeset
166 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
167 if (r != 0)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
168 return;
78
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
169 v *= 4;
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
170 l -> nocodelen = v;
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
171 as -> addr += v;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
172 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
173
53
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
174 OPFUNC(pseudo_zmb)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
175 {
78
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
176 int r, v;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
177
103
26c058fa0bc1 Fixed up some issues with pseudo ops and object target
lost
parents: 99
diff changeset
178 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
179 if (r != 0)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
180 return;
78
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
181 while (v--)
53
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
182 lwasm_emit(as, l, 0);
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
183 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
184
53
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
185 OPFUNC(pseudo_zmd)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
186 {
78
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
187 int r, v;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
188
103
26c058fa0bc1 Fixed up some issues with pseudo ops and object target
lost
parents: 99
diff changeset
189 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
190 if (r != 0)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
191 return;
78
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
192 v *= 2;
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
193 while (v--)
53
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
194 lwasm_emit(as, l, 0);
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
195 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
196
53
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
197 OPFUNC(pseudo_zmq)
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
198 {
78
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
199 int r, v;
53
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
200
103
26c058fa0bc1 Fixed up some issues with pseudo ops and object target
lost
parents: 99
diff changeset
201 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
202 if (r != 0)
53
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
203 return;
78
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
204 v *= 4;
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
205 while (v--)
53
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
206 lwasm_emit(as, l, 0);
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
207 }
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
208
54
360d53062bb9 Fixed typo in instruction table and added END directive
lost
parents: 53
diff changeset
209 OPFUNC(pseudo_end)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
210 {
78
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
211 int r, v;
54
360d53062bb9 Fixed typo in instruction table and added END directive
lost
parents: 53
diff changeset
212 lwasm_expr_stack_t *s;
360d53062bb9 Fixed typo in instruction table and added END directive
lost
parents: 53
diff changeset
213
360d53062bb9 Fixed typo in instruction table and added END directive
lost
parents: 53
diff changeset
214
360d53062bb9 Fixed typo in instruction table and added END directive
lost
parents: 53
diff changeset
215 as -> endseen = 1;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
216
54
360d53062bb9 Fixed typo in instruction table and added END directive
lost
parents: 53
diff changeset
217 // address only matters for DECB output
360d53062bb9 Fixed typo in instruction table and added END directive
lost
parents: 53
diff changeset
218 if (as -> outformat != OUTPUT_DECB)
360d53062bb9 Fixed typo in instruction table and added END directive
lost
parents: 53
diff changeset
219 return;
360d53062bb9 Fixed typo in instruction table and added END directive
lost
parents: 53
diff changeset
220
78
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
221 r = lwasm_expr_result2(as, l, p, 0, &v, 0);
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
222 if (r != 0)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
223 {
78
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
224 register_error(as, l, 2, "Bad operand");
54
360d53062bb9 Fixed typo in instruction table and added END directive
lost
parents: 53
diff changeset
225 }
360d53062bb9 Fixed typo in instruction table and added END directive
lost
parents: 53
diff changeset
226
78
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
227 v = v & 0xffff;
54
360d53062bb9 Fixed typo in instruction table and added END directive
lost
parents: 53
diff changeset
228 if (as -> passnum == 2)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
229 {
78
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
230 as -> execaddr = v;
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
231 l -> symaddr = v;
54
360d53062bb9 Fixed typo in instruction table and added END directive
lost
parents: 53
diff changeset
232 l -> addrset = 2;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
233 }
54
360d53062bb9 Fixed typo in instruction table and added END directive
lost
parents: 53
diff changeset
234 }
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
235
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
236
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
237 OPFUNC(pseudo_align)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
238 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
239 int cn;
78
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
240 int r, v;
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
241
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
242 if (as -> passnum == 2)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
243 {
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
244 while (as -> addr < l -> symaddr)
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
245 lwasm_emit(as, l, 0);
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
246 return;
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
247 }
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
248
103
26c058fa0bc1 Fixed up some issues with pseudo ops and object target
lost
parents: 99
diff changeset
249 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
250 if (r != 0)
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
251 {
78
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
252 l -> symaddr = as -> addr;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
253 return;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
254 }
78
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
255
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
256 if (v < 1)
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
257 {
78
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
258 register_error(as, l, 1, "Illegal alignment %d", v);
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
259 return;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
260 }
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
261
78
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
262 cn = l -> codeaddr % v;
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
263 if (cn)
78
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
264 cn = v - cn;
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
265
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
266 while (cn--)
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
267 {
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
268 lwasm_emit(as, l, 0);
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
269 }
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
270 l -> symaddr = as -> addr;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
271 }
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
272
50
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
273 OPFUNC(pseudo_equ)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
274 {
78
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
275 int r, v;
52
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
276
50
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
277 if (l -> sym == NULL)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
278 {
50
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
279 register_error(as, l, 1, "No symbol specified");
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
280 return;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
281 }
50
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
282
103
26c058fa0bc1 Fixed up some issues with pseudo ops and object target
lost
parents: 99
diff changeset
283 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
284 if (r < 0)
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
285 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
286
78
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
287 l -> symaddr = v & 0xFFFF;
50
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
288 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
289
79
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
290 // 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
291 // to a constant!
78
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
292 lwasm_register_symbol(as, l, l -> sym, v, (r > 0 ? SYMBOL_COMPLEX: SYMBOL_NORM) | SYMBOL_FORCE);
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
293 }
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
294
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
295 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
296 {
79
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
297 int r, v;
64
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
298
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
299 // set MUST run on both passes as the symbol value changes!
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
300
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
301 if (l -> sym == NULL)
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
302 {
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
303 register_error(as, l, 1, "No symbol specified");
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
304 return;
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
305 }
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
306
103
26c058fa0bc1 Fixed up some issues with pseudo ops and object target
lost
parents: 99
diff changeset
307 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
308 if (r < 0)
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
309 v = 0;
64
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
310
79
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
311 l -> symaddr = v & 0xFFFF;
64
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
312 l -> addrset = 2;
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
313
79
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
314 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
315 }
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
316
65
31d8e85706e7 Implemented setdp and corrected handling of direct page detection in insn_gen_aux()
lost
parents: 64
diff changeset
317 OPFUNC(pseudo_setdp)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
318 {
79
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
319 int r, v;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
320
79
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
321 if (as -> outformat == OUTPUT_OBJ)
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
322 {
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
323 register_error(as, l, 1, "SETDP not permitted with OBJ target");
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
324 return;
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
325 }
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
326
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
327 // 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
328 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
329 if (r != 0)
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
330 return;
65
31d8e85706e7 Implemented setdp and corrected handling of direct page detection in insn_gen_aux()
lost
parents: 64
diff changeset
331
79
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
332 if (v < -127 || v > 255)
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
333 {
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
334 register_error(as, l, 1, "Byte overflow");
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
335 return;
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
336 }
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
337
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
338 l -> symaddr = v & 0xFF;
65
31d8e85706e7 Implemented setdp and corrected handling of direct page detection in insn_gen_aux()
lost
parents: 64
diff changeset
339 l -> addrset = 2;
31d8e85706e7 Implemented setdp and corrected handling of direct page detection in insn_gen_aux()
lost
parents: 64
diff changeset
340
79
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
341 as -> dpval = v & 0xFF;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
342 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
343
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
344 OPFUNC(pseudo_fcc)
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
345 {
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
346 int delim = 0;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
347
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
348 delim = **p;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
349 if (!delim)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
350 {
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
351 register_error(as, l, 1, "Bad operand");
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
352 return;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
353 }
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
354 *p += 1;
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
355 while (**p && **p != delim)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
356 {
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
357 lwasm_emit(as, l, **p);
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
358 (*p)++;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
359 }
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
360 if (**p)
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
361 (*p)++;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
362 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
363
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
364
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
365 OPFUNC(pseudo_fcs)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
366 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
367 int delim = 0;
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
368
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
369 delim = **p;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
370 if (!delim)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
371 {
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
372 register_error(as, l, 1, "Bad operand");
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
373 return;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
374 }
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
375 *p += 1;
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
376 while (**p && **p != delim)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
377 {
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
378 if (!*((*p) + 1) || *((*p) + 1) == delim)
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
379 lwasm_emit(as, l, **p | 0x80);
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
380 else
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
381 lwasm_emit(as, l, **p);
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
382 (*p)++;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
383 }
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
384 if (**p)
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
385 (*p)++;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
386 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
387
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
388 OPFUNC(pseudo_fcn)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
389 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
390 int delim = 0;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
391
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
392 delim = **p;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
393 if (!delim)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
394 {
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
395 register_error(as, l, 1, "Bad operand");
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
396 return;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
397 }
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
398 *p += 1;
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
399 while (**p && **p != delim)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
400 {
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
401 lwasm_emit(as, l, **p);
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
402 (*p)++;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
403 }
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
404 if (**p)
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
405 (*p)++;
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
406 lwasm_emit(as, l, 0);
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
407 }
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
408
79
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
409 // FIXME: handle external, etc., references in a useful manner
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
410 OPFUNC(pseudo_fcb)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
411 {
79
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
412 int r, v;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
413
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
414 fcb_again:
79
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
415 r = lwasm_expr_result2(as, l, p, 0, &v, -1);
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
416 if (r < 0)
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
417 return;
79
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
418
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
419 if (r > 0)
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
420 {
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
421 register_error(as, l, 2, "Illegal external or inter-segment reference");
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
422 v = 0;
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
423 }
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
424
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
425 if (v < -127 || v > 255)
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 register_error(as, l, 1, "Byte overflow");
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
428 }
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
429
79
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
430 lwasm_emit(as, l, v);
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
431 if (**p == ',')
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
432 {
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
433 (*p)++;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
434 goto fcb_again;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
435 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
436 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
437
79
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
438 // FIXME: handle external references in an intelligent way
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
439 OPFUNC(pseudo_fdb)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
440 {
79
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
441 int r, v;
103
26c058fa0bc1 Fixed up some issues with pseudo ops and object target
lost
parents: 99
diff changeset
442 int extseen = 0;
26c058fa0bc1 Fixed up some issues with pseudo ops and object target
lost
parents: 99
diff changeset
443 char *p1;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
444
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
445 fdb_again:
103
26c058fa0bc1 Fixed up some issues with pseudo ops and object target
lost
parents: 99
diff changeset
446 p1 = *p;
79
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
447 r = lwasm_expr_result2(as, l, p, 0, &v, -1);
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
448 if (r < 0)
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
449 return;
79
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
450
103
26c058fa0bc1 Fixed up some issues with pseudo ops and object target
lost
parents: 99
diff changeset
451 if (r > 0 && extseen == 1)
79
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
452 {
103
26c058fa0bc1 Fixed up some issues with pseudo ops and object target
lost
parents: 99
diff changeset
453 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
454 v = 0;
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
455 }
103
26c058fa0bc1 Fixed up some issues with pseudo ops and object target
lost
parents: 99
diff changeset
456 else if (r > 0)
26c058fa0bc1 Fixed up some issues with pseudo ops and object target
lost
parents: 99
diff changeset
457 {
26c058fa0bc1 Fixed up some issues with pseudo ops and object target
lost
parents: 99
diff changeset
458 l -> relocoff = as -> addr - l -> codeaddr;
26c058fa0bc1 Fixed up some issues with pseudo ops and object target
lost
parents: 99
diff changeset
459 *p = p1;
26c058fa0bc1 Fixed up some issues with pseudo ops and object target
lost
parents: 99
diff changeset
460 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
461 }
79
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
462
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
463 lwasm_emit(as, l, v >> 8);
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
464 lwasm_emit(as, l, v & 0xff);
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
465 if (**p == ',')
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
466 {
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
467 (*p)++;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
468 goto fdb_again;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
469 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
470 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
471
79
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
472 // FIXME: handle external references in a sensible way
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
473 OPFUNC(pseudo_fqb)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
474 {
79
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
475 int r, v;
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
476
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
477 fqb_again:
79
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
478 r = lwasm_expr_result2(as, l, p, 0, &v, -1);
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
479 if (r < 0)
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
480 return;
79
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
481
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
482 if (r > 0)
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
483 {
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
484 register_error(as, l, 2, "Illegal external or inter-segment reference");
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
485 v = 0;
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
486 }
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
487
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
488 lwasm_emit(as, l, v >> 24);
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
489 lwasm_emit(as, l, v >> 16);
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
490 lwasm_emit(as, l, v >> 8);
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
491 lwasm_emit(as, l, v & 0xff);
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
492 if (**p == ',')
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
493 {
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
494 (*p)++;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
495 goto fqb_again;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
496 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
497 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
498
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
499 // 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
500 OPFUNC(pseudo_endc)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
501 {
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
502 if (as -> skipcond && !(as -> skipmacro))
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
503 {
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
504 as -> skipcount -= 1;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
505 if (as -> skipcount <= 0)
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
506 {
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
507 as -> skipcond = 0;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
508 }
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
509 }
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
510 return;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
511 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
512
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
513 // if "else" executes, we must be going into an "ignore" state
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
514 OPFUNC(pseudo_else)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
515 {
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
516 if (as -> skipmacro)
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
517 return;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
518
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
519 if (as -> skipcond)
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
520 {
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
521 if (as -> skipcount == 1)
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
522 {
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
523 as -> skipcount = 0;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
524 as -> skipcond = 0;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
525 }
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
526 return;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
527 }
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
528
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
529 as -> skipcond = 1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
530 as -> skipcount = 1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
531 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
532
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
533 OPFUNC(pseudo_ifne)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
534 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
535 int v1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
536 int rval;
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
537
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
538 if (as -> skipcond && !(as -> skipmacro))
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
539 {
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
540 as -> skipcount++;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
541 return;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
542 }
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
543
103
26c058fa0bc1 Fixed up some issues with pseudo ops and object target
lost
parents: 99
diff changeset
544 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
545 if (rval != 0)
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
546 return;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
547 if (!v1)
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
548 {
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
549 as -> skipcond = 1;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
550 as -> skipcount = 1;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
551 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
552 }
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
553
104
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
554 OPFUNC(pseudo_ifdef)
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
555 {
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
556 lwasm_symbol_ent_t *se;
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
557 char *sym;
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
558 char *p2;
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
559
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
560 if (as -> skipcond && !(as -> skipmacro))
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
561 {
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
562 as -> skipcount++;
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
563 return;
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
564 }
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
565
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
566 if (as -> passnum != 1)
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
567 {
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
568 if (!(l -> fsize))
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
569 {
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
570 as -> skipcond = 1;
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
571 as -> skipcount = 1;
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
572 }
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
573 return;
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
574 }
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
575
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
576 if (!**p)
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
577 {
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
578 register_error(as, l, 1, "Need symbol name");
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
579 return;
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
580 }
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
581
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
582 for (p2 = *p; *p2 && !isspace(*p2); p2++)
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
583 /* do nothing */ ;
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
584
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
585 sym = lwasm_alloc(p2 - *p + 1);
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
586 memcpy(sym, *p, p2 - *p);
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
587 sym[p2 - *p] = '\0';
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
588
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
589 *p = p2;
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
590
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
591 se = lwasm_find_symbol(as, sym, l -> context);
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
592 if (!se)
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
593 se = lwasm_find_symbol(as, sym, -1);
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
594
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
595 lwasm_free(sym);
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
596
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
597 if (!se)
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
598 {
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
599 as -> skipcond = 1;
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
600 as -> skipcount = 1;
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
601 l -> fsize = 0;
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
602 }
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
603 else
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
604 {
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
605 l -> fsize = 1;
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
606 }
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
607 }
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
608
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
609 OPFUNC(pseudo_ifndef)
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
610 {
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
611 lwasm_symbol_ent_t *se;
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
612 char *sym;
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
613 char *p2;
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
614
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
615 if (as -> skipcond && !(as -> skipmacro))
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
616 {
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
617 as -> skipcount++;
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
618 return;
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
619 }
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
620
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
621 if (as -> passnum != 1)
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
622 {
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
623 if (l -> fsize)
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
624 {
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
625 as -> skipcond = 1;
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
626 as -> skipcount = 1;
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
627 }
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
628 return;
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
629 }
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
630
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
631 if (!**p)
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
632 {
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
633 register_error(as, l, 1, "Need symbol name");
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
634 return;
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
635 }
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
636
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
637 for (p2 = *p; *p2 && !isspace(*p2); p2++)
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
638 /* do nothing */ ;
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
639
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
640 sym = lwasm_alloc(p2 - *p + 1);
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
641 memcpy(sym, *p, p2 - *p);
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
642 sym[p2 - *p] = '\0';
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
643
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
644 *p = p2;
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
645
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
646 se = lwasm_find_symbol(as, sym, l -> context);
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
647 if (!se)
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
648 se = lwasm_find_symbol(as, sym, -1);
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
649
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
650 lwasm_free(sym);
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
651
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
652 if (se)
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
653 {
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
654 as -> skipcond = 1;
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
655 as -> skipcount = 1;
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
656 l -> fsize = 0;
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
657 }
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
658 else
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
659 {
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
660 l -> fsize = 1;
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
661 }
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
662 }
2ba8f9ef1417 Added ifdef/ifndef conditionals
lost
parents: 103
diff changeset
663
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
664 OPFUNC(pseudo_ifeq)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
665 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
666 int v1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
667 int rval;
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
668
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
669 if (as -> skipcond && !(as -> skipmacro))
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
670 {
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
671 as -> skipcount++;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
672 return;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
673 }
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
674
103
26c058fa0bc1 Fixed up some issues with pseudo ops and object target
lost
parents: 99
diff changeset
675 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
676 if (rval != 0)
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
677 return;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
678 if (v1)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
679 {
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
680 as -> skipcond = 1;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
681 as -> skipcount = 1;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
682 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
683 }
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
684
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
685 OPFUNC(pseudo_iflt)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
686 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
687 int v1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
688 int rval;
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
689
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
690 if (as -> skipcond && !(as -> skipmacro))
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
691 {
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
692 as -> skipcount++;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
693 return;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
694 }
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
695
103
26c058fa0bc1 Fixed up some issues with pseudo ops and object target
lost
parents: 99
diff changeset
696 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
697 if (rval != 0)
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
698 return;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
699 if (v1 >= 0)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
700 {
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
701 as -> skipcond = 1;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
702 as -> skipcount = 1;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
703 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
704 }
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
705
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
706 OPFUNC(pseudo_ifle)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
707 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
708 int v1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
709 int rval;
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
710
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
711 if (as -> skipcond && !(as -> skipmacro))
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
712 {
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
713 as -> skipcount++;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
714 return;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
715 }
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
716
103
26c058fa0bc1 Fixed up some issues with pseudo ops and object target
lost
parents: 99
diff changeset
717 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
718 if (rval != 0)
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
719 return;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
720 if (v1 > 0)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
721 {
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
722 as -> skipcond = 1;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
723 as -> skipcount = 1;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
724 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
725 }
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
726
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
727 OPFUNC(pseudo_ifgt)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
728 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
729 int v1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
730 int rval;
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
731
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
732 if (as -> skipcond && !(as -> skipmacro))
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
733 {
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
734 as -> skipcount++;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
735 return;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
736 }
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
737
103
26c058fa0bc1 Fixed up some issues with pseudo ops and object target
lost
parents: 99
diff changeset
738 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
739 if (rval != 0)
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
740 return;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
741 if (v1 <= 0)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
742 {
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
743 as -> skipcond = 1;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
744 as -> skipcount = 1;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
745 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
746 }
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
747
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
748 OPFUNC(pseudo_ifge)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
749 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
750 int v1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
751 int rval;
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
752
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
753 if (as -> skipcond && !(as -> skipmacro))
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
754 {
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
755 as -> skipcount++;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
756 return;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
757 }
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
758
103
26c058fa0bc1 Fixed up some issues with pseudo ops and object target
lost
parents: 99
diff changeset
759 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
760 if (rval != 0)
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
761 return;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
762 if (v1 < 0)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
763 {
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
764 as -> skipcond = 1;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
765 as -> skipcount = 1;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
766 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
767 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
768
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
769 OPFUNC(pseudo_error)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
770 {
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
771 register_error(as, l, 1, "User error: %s", *p);
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
772 }
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
773
74
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
774
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
775 OPFUNC(pseudo_section)
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
776 {
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
777 sectiontab_t *s;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
778 char *p2;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
779 char *sn;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
780 char *opts;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
781
99
3dcb12a6f4ff Fixed problem handling sections with options on pass 2
lost
parents: 95
diff changeset
782
74
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
783 if (as -> outformat != OUTPUT_OBJ)
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
784 {
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
785 register_error(as, l, 1, "Sections only supported for obj target");
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
786 return;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
787 }
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
788
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
789 if (as -> csect)
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
790 {
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
791 as -> csect -> offset = as -> addr;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
792 as -> csect = NULL;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
793 }
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
794
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
795 if (!**p)
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
796 {
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
797 register_error(as, l, 1, "Need section name");
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
798 return;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
799 }
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
800
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
801 for (p2 = *p; *p2 && !isspace(*p2); p2++)
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
802 /* do nothing */ ;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
803
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
804 sn = lwasm_alloc(p2 - *p + 1);
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
805 memcpy(sn, *p, p2 - *p);
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
806 sn[p2 - *p] = '\0';
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
807
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
808 *p = p2;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
809
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
810 opts = strchr(sn, ',');
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
811 if (opts)
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
812 {
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
813 *opts++ = '\0';
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
814 }
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
815
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
816 // have we seen the section name already?
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
817 for (s = as -> sections; s; s = s -> next)
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
818 {
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
819 if (!strcmp(s -> name, sn))
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
820 break;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
821 }
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
822
99
3dcb12a6f4ff Fixed problem handling sections with options on pass 2
lost
parents: 95
diff changeset
823 if (s && as -> passnum == 1)
74
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
824 {
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
825 lwasm_free(sn);
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
826 if (opts)
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
827 {
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
828 register_error(as, l, 1, "Section options can only be specified the first time");
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
829 return;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
830 }
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
831 }
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
832 else if (!s)
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
833 {
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
834 s = lwasm_alloc(sizeof(sectiontab_t));
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
835 s -> name = sn;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
836 s -> offset = 0;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
837 s -> flags = 0;
85
918be0c02239 Started adding object target output
lost
parents: 82
diff changeset
838 s -> obytes = NULL;
918be0c02239 Started adding object target output
lost
parents: 82
diff changeset
839 s -> oblen = 0;
918be0c02239 Started adding object target output
lost
parents: 82
diff changeset
840 s -> obsize = 0;
86
033a328a10ae Checkpoint: object target output
lost
parents: 85
diff changeset
841 s -> rl = NULL;
90
6097cb1486f8 Added EXPORT pseudo op
lost
parents: 86
diff changeset
842 s -> exports = NULL;
74
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
843 // parse options; only one "bss"
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
844 if (opts && as -> passnum == 1)
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
845 {
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
846 if (!strcasecmp(opts, "bss"))
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
847 {
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
848 s -> flags = SECTION_BSS;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
849 }
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
850 else
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
851 {
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
852 register_error(as, l, 1, "Unrecognized section option '%s'", opts);
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
853 lwasm_free(s -> name);
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
854 lwasm_free(s);
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
855 return;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
856 }
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
857 }
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
858
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
859 s -> next = as -> sections;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
860 as -> sections = s;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
861 }
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
862 as -> addr = s -> offset;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
863 as -> csect = s;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
864 as -> context = lwasm_next_context(as);
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
865 }
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
866
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
867 OPFUNC(pseudo_endsection)
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
868 {
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
869 if (as -> outformat != OUTPUT_OBJ)
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
870 {
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
871 register_error(as, l, 1, "Sections only supported for obj target");
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
872 return;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
873 }
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
874
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
875 if (!(as -> csect))
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
876 {
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
877 register_error(as, l, 1, "ENDSECTION when not in a section");
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
878 return;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
879 }
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
880
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
881 as -> csect -> offset = as -> addr;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
882 as -> addr = 0;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
883 as -> csect = 0;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
884 as -> context = lwasm_next_context(as);
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
885 }
82
03be43ae19cf Added EXTERN directive
lost
parents: 79
diff changeset
886
03be43ae19cf Added EXTERN directive
lost
parents: 79
diff changeset
887 OPFUNC(pseudo_extern)
03be43ae19cf Added EXTERN directive
lost
parents: 79
diff changeset
888 {
03be43ae19cf Added EXTERN directive
lost
parents: 79
diff changeset
889 if (as -> passnum != 1)
03be43ae19cf Added EXTERN directive
lost
parents: 79
diff changeset
890 return;
03be43ae19cf Added EXTERN directive
lost
parents: 79
diff changeset
891
03be43ae19cf Added EXTERN directive
lost
parents: 79
diff changeset
892 if (as -> outformat != OUTPUT_OBJ)
03be43ae19cf Added EXTERN directive
lost
parents: 79
diff changeset
893 {
03be43ae19cf Added EXTERN directive
lost
parents: 79
diff changeset
894 register_error(as, l, 1, "External references only supported for obj target");
03be43ae19cf Added EXTERN directive
lost
parents: 79
diff changeset
895 return;
03be43ae19cf Added EXTERN directive
lost
parents: 79
diff changeset
896 }
03be43ae19cf Added EXTERN directive
lost
parents: 79
diff changeset
897
03be43ae19cf Added EXTERN directive
lost
parents: 79
diff changeset
898 if (as -> csect)
03be43ae19cf Added EXTERN directive
lost
parents: 79
diff changeset
899 {
03be43ae19cf Added EXTERN directive
lost
parents: 79
diff changeset
900 register_error(as, l, 1, "Cannot declare external symbols within a section");
03be43ae19cf Added EXTERN directive
lost
parents: 79
diff changeset
901 return;
03be43ae19cf Added EXTERN directive
lost
parents: 79
diff changeset
902 }
03be43ae19cf Added EXTERN directive
lost
parents: 79
diff changeset
903
03be43ae19cf Added EXTERN directive
lost
parents: 79
diff changeset
904 lwasm_register_symbol(as, l, l -> sym, 0, SYMBOL_EXTERN);
03be43ae19cf Added EXTERN directive
lost
parents: 79
diff changeset
905 }
90
6097cb1486f8 Added EXPORT pseudo op
lost
parents: 86
diff changeset
906
6097cb1486f8 Added EXPORT pseudo op
lost
parents: 86
diff changeset
907 OPFUNC(pseudo_export)
6097cb1486f8 Added EXPORT pseudo op
lost
parents: 86
diff changeset
908 {
6097cb1486f8 Added EXPORT pseudo op
lost
parents: 86
diff changeset
909 lwasm_symbol_ent_t *se;
6097cb1486f8 Added EXPORT pseudo op
lost
parents: 86
diff changeset
910 export_list_t *ex;
6097cb1486f8 Added EXPORT pseudo op
lost
parents: 86
diff changeset
911
6097cb1486f8 Added EXPORT pseudo op
lost
parents: 86
diff changeset
912 if (as -> outformat != OUTPUT_OBJ)
6097cb1486f8 Added EXPORT pseudo op
lost
parents: 86
diff changeset
913 {
6097cb1486f8 Added EXPORT pseudo op
lost
parents: 86
diff changeset
914 register_error(as, l, 1, "Symbol exports only supported for obj target");
6097cb1486f8 Added EXPORT pseudo op
lost
parents: 86
diff changeset
915 return;
6097cb1486f8 Added EXPORT pseudo op
lost
parents: 86
diff changeset
916 }
6097cb1486f8 Added EXPORT pseudo op
lost
parents: 86
diff changeset
917
6097cb1486f8 Added EXPORT pseudo op
lost
parents: 86
diff changeset
918 if (as -> passnum == 1)
6097cb1486f8 Added EXPORT pseudo op
lost
parents: 86
diff changeset
919 return;
6097cb1486f8 Added EXPORT pseudo op
lost
parents: 86
diff changeset
920
6097cb1486f8 Added EXPORT pseudo op
lost
parents: 86
diff changeset
921 // the symbol better be defined at this point (pass 2)
6097cb1486f8 Added EXPORT pseudo op
lost
parents: 86
diff changeset
922 // local symbols cannot be exported nor can "global" symbols
6097cb1486f8 Added EXPORT pseudo op
lost
parents: 86
diff changeset
923 se = lwasm_find_symbol(as, l -> sym, -1);
6097cb1486f8 Added EXPORT pseudo op
lost
parents: 86
diff changeset
924 if (!se)
6097cb1486f8 Added EXPORT pseudo op
lost
parents: 86
diff changeset
925 {
6097cb1486f8 Added EXPORT pseudo op
lost
parents: 86
diff changeset
926 register_error(as, l, 2, "Exported symbols must be fully defined within a section");
6097cb1486f8 Added EXPORT pseudo op
lost
parents: 86
diff changeset
927 return;
6097cb1486f8 Added EXPORT pseudo op
lost
parents: 86
diff changeset
928 }
6097cb1486f8 Added EXPORT pseudo op
lost
parents: 86
diff changeset
929 if (se -> sect == NULL)
6097cb1486f8 Added EXPORT pseudo op
lost
parents: 86
diff changeset
930 {
6097cb1486f8 Added EXPORT pseudo op
lost
parents: 86
diff changeset
931 register_error(as, l, 2, "Only non-local symbols within a section can be exported");
6097cb1486f8 Added EXPORT pseudo op
lost
parents: 86
diff changeset
932 return;
6097cb1486f8 Added EXPORT pseudo op
lost
parents: 86
diff changeset
933 }
6097cb1486f8 Added EXPORT pseudo op
lost
parents: 86
diff changeset
934
6097cb1486f8 Added EXPORT pseudo op
lost
parents: 86
diff changeset
935 if (se -> flags & SYMBOL_SET)
6097cb1486f8 Added EXPORT pseudo op
lost
parents: 86
diff changeset
936 {
6097cb1486f8 Added EXPORT pseudo op
lost
parents: 86
diff changeset
937 register_error(as, l, 2, "You cannot export symbols defined with SET");
6097cb1486f8 Added EXPORT pseudo op
lost
parents: 86
diff changeset
938 return;
6097cb1486f8 Added EXPORT pseudo op
lost
parents: 86
diff changeset
939 }
6097cb1486f8 Added EXPORT pseudo op
lost
parents: 86
diff changeset
940
6097cb1486f8 Added EXPORT pseudo op
lost
parents: 86
diff changeset
941 // if the symbol is not already a simple value, re-evaluate it
6097cb1486f8 Added EXPORT pseudo op
lost
parents: 86
diff changeset
942 // and see if it becomes simple
6097cb1486f8 Added EXPORT pseudo op
lost
parents: 86
diff changeset
943
6097cb1486f8 Added EXPORT pseudo op
lost
parents: 86
diff changeset
944
6097cb1486f8 Added EXPORT pseudo op
lost
parents: 86
diff changeset
945 if (se -> flags & SYMBOL_COMPLEX)
6097cb1486f8 Added EXPORT pseudo op
lost
parents: 86
diff changeset
946 {
6097cb1486f8 Added EXPORT pseudo op
lost
parents: 86
diff changeset
947 register_error(as, l, 2, "Exported symbols must be fully resolved on pass 2");
6097cb1486f8 Added EXPORT pseudo op
lost
parents: 86
diff changeset
948 return;
6097cb1486f8 Added EXPORT pseudo op
lost
parents: 86
diff changeset
949 }
6097cb1486f8 Added EXPORT pseudo op
lost
parents: 86
diff changeset
950
6097cb1486f8 Added EXPORT pseudo op
lost
parents: 86
diff changeset
951 // search for existing export
6097cb1486f8 Added EXPORT pseudo op
lost
parents: 86
diff changeset
952 for (ex = se -> sect -> exports; ex; ex = ex -> next)
6097cb1486f8 Added EXPORT pseudo op
lost
parents: 86
diff changeset
953 if (!strcmp(l -> sym, ex -> sym))
6097cb1486f8 Added EXPORT pseudo op
lost
parents: 86
diff changeset
954 break;
6097cb1486f8 Added EXPORT pseudo op
lost
parents: 86
diff changeset
955 if (ex)
6097cb1486f8 Added EXPORT pseudo op
lost
parents: 86
diff changeset
956 {
6097cb1486f8 Added EXPORT pseudo op
lost
parents: 86
diff changeset
957 register_error(as, l, 2, "Symbol %s already exported", l -> sym);
6097cb1486f8 Added EXPORT pseudo op
lost
parents: 86
diff changeset
958 return;
6097cb1486f8 Added EXPORT pseudo op
lost
parents: 86
diff changeset
959 }
6097cb1486f8 Added EXPORT pseudo op
lost
parents: 86
diff changeset
960
6097cb1486f8 Added EXPORT pseudo op
lost
parents: 86
diff changeset
961 // add an external reference
6097cb1486f8 Added EXPORT pseudo op
lost
parents: 86
diff changeset
962 ex = lwasm_alloc(sizeof(export_list_t));
6097cb1486f8 Added EXPORT pseudo op
lost
parents: 86
diff changeset
963 ex -> next = se -> sect -> exports;
6097cb1486f8 Added EXPORT pseudo op
lost
parents: 86
diff changeset
964 se -> sect -> exports = ex;
6097cb1486f8 Added EXPORT pseudo op
lost
parents: 86
diff changeset
965 ex -> offset = se -> value;
6097cb1486f8 Added EXPORT pseudo op
lost
parents: 86
diff changeset
966 ex -> sym = lwasm_strdup(se -> sym);
6097cb1486f8 Added EXPORT pseudo op
lost
parents: 86
diff changeset
967 }