annotate src/pseudo.c @ 78:121bf4a588ea

Checkpointing deployment of non-constant expression handling
author lost
date Sat, 10 Jan 2009 05:00:42 +0000
parents c8c772ef5df9
children d0ce3f5f6797
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
78
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
128 if (as -> passnum == 1)
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 }
78
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
133
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
134 r = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v, 0);
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
135 if (r != 0)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
136 return;
78
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
137 l -> nocodelen = v;
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
138 as -> addr += v;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
139 }
53
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
140
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
141 OPFUNC(pseudo_rmd)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
142 {
78
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
143 int r, v;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
144
78
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
145 if (as -> passnum == 1)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
146 {
78
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
147 as -> addr += l -> nocodelen;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
148 return;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
149 }
78
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
150 r = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v, 0);
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
151 if (r != 0)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
152 return;
78
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
153 v *= 2;
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
154 l -> nocodelen = v;
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
155 as -> addr += v;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
156 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
157
53
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
158 OPFUNC(pseudo_rmq)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
159 {
78
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
160 int r, v;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
161
78
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
162 if (as -> passnum == 1)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
163 {
78
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
164 as -> addr += l -> nocodelen;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
165 return;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
166 }
78
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
167 r = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v, 0);
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
168 if (r != 0)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
169 return;
78
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
170 v *= 4;
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
171 l -> nocodelen = v;
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
172 as -> addr += v;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
173 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
174
53
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
175 OPFUNC(pseudo_zmb)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
176 {
78
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
177 int r, v;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
178
78
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
179 r = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v, 0);
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
180 if (r != 0)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
181 return;
78
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
182 while (v--)
53
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
183 lwasm_emit(as, l, 0);
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
184 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
185
53
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
186 OPFUNC(pseudo_zmd)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
187 {
78
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
188 int r, v;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
189
78
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
190 r = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v, 0);
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
191 if (r != 0)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
192 return;
78
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
193 v *= 2;
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
194 while (v--)
53
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
195 lwasm_emit(as, l, 0);
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
196 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
197
53
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
198 OPFUNC(pseudo_zmq)
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
199 {
78
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
200 int r, v;
53
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
201
78
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
202 r = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v, 0);
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
203 if (r != 0)
53
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
204 return;
78
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
205 v *= 4;
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
206 while (v--)
53
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
207 lwasm_emit(as, l, 0);
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
208 }
493cb8ea50a0 Added rm[dq], zm[bdq]
lost
parents: 52
diff changeset
209
54
360d53062bb9 Fixed typo in instruction table and added END directive
lost
parents: 53
diff changeset
210 OPFUNC(pseudo_end)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
211 {
78
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
212 int r, v;
54
360d53062bb9 Fixed typo in instruction table and added END directive
lost
parents: 53
diff changeset
213 lwasm_expr_stack_t *s;
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
360d53062bb9 Fixed typo in instruction table and added END directive
lost
parents: 53
diff changeset
216 as -> endseen = 1;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
217
54
360d53062bb9 Fixed typo in instruction table and added END directive
lost
parents: 53
diff changeset
218 // address only matters for DECB output
360d53062bb9 Fixed typo in instruction table and added END directive
lost
parents: 53
diff changeset
219 if (as -> outformat != OUTPUT_DECB)
360d53062bb9 Fixed typo in instruction table and added END directive
lost
parents: 53
diff changeset
220 return;
360d53062bb9 Fixed typo in instruction table and added END directive
lost
parents: 53
diff changeset
221
78
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
222 r = lwasm_expr_result2(as, l, p, 0, &v, 0);
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
223 if (r != 0)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
224 {
78
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
225 register_error(as, l, 2, "Bad operand");
54
360d53062bb9 Fixed typo in instruction table and added END directive
lost
parents: 53
diff changeset
226 }
360d53062bb9 Fixed typo in instruction table and added END directive
lost
parents: 53
diff changeset
227
78
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
228 v = v & 0xffff;
54
360d53062bb9 Fixed typo in instruction table and added END directive
lost
parents: 53
diff changeset
229 if (as -> passnum == 2)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
230 {
78
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
231 as -> execaddr = v;
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
232 l -> symaddr = v;
54
360d53062bb9 Fixed typo in instruction table and added END directive
lost
parents: 53
diff changeset
233 l -> addrset = 2;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
234 }
54
360d53062bb9 Fixed typo in instruction table and added END directive
lost
parents: 53
diff changeset
235 }
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
236
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
237
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
238 OPFUNC(pseudo_align)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
239 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
240 int cn;
78
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
241 int r, v;
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
242
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
243 if (as -> passnum == 2)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
244 {
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
245 while (as -> addr < l -> symaddr)
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
246 lwasm_emit(as, l, 0);
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
247 return;
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
248 }
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
249
78
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
250 r = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v, 0);
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
251 if (r != 0)
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
252 {
78
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
253 l -> symaddr = as -> addr;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
254 return;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
255 }
78
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
256
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
257 if (v < 1)
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
258 {
78
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
259 register_error(as, l, 1, "Illegal alignment %d", v);
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
260 return;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
261 }
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
262
78
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
263 cn = l -> codeaddr % v;
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
264 if (cn)
78
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
265 cn = v - cn;
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
266
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
267 while (cn--)
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
268 {
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
269 lwasm_emit(as, l, 0);
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
270 }
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
271 l -> symaddr = as -> addr;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
272 }
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
273
50
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
274 OPFUNC(pseudo_equ)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
275 {
78
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
276 int r, v;
52
b9856da2674a Added file inclusion
lost
parents: 50
diff changeset
277
50
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
278 if (l -> sym == NULL)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
279 {
50
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
280 register_error(as, l, 1, "No symbol specified");
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
281 return;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
282 }
50
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
283
78
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
284 r = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v, 0);
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
285 if (r < 0)
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
286 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
287
78
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
288 l -> symaddr = v & 0xFFFF;
50
e672232caffe Added rmb pseudo op
lost
parents: 49
diff changeset
289 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
290
78
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
291 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
292 }
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
293
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 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
295 {
64
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
296 int rval;
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
297
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
298 // set MUST run on both passes as the symbol value changes!
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
299
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
300 if (l -> sym == NULL)
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
301 {
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
302 register_error(as, l, 1, "No symbol specified");
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
303 return;
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
304 }
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
305
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
306 if (lwasm_expr_result(as, l, p, EXPR_PASS1CONST | EXPR_PASS2CONST, &rval) < 0)
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
307 rval = 0;
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
308
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
309 l -> symaddr = rval & 0xFFFF;
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
310 l -> addrset = 2;
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
311
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
312 lwasm_register_symbol(as, l, l -> sym, rval, 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
313 }
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
314
65
31d8e85706e7 Implemented setdp and corrected handling of direct page detection in insn_gen_aux()
lost
parents: 64
diff changeset
315 OPFUNC(pseudo_setdp)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
316 {
65
31d8e85706e7 Implemented setdp and corrected handling of direct page detection in insn_gen_aux()
lost
parents: 64
diff changeset
317 int rval;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
318
65
31d8e85706e7 Implemented setdp and corrected handling of direct page detection in insn_gen_aux()
lost
parents: 64
diff changeset
319 // setdp is needed on both passes
31d8e85706e7 Implemented setdp and corrected handling of direct page detection in insn_gen_aux()
lost
parents: 64
diff changeset
320 if (lwasm_expr_result(as, l, p, EXPR_PASS1CONST | EXPR_PASS2CONST | EXPR_BYTE, &rval) < 0)
31d8e85706e7 Implemented setdp and corrected handling of direct page detection in insn_gen_aux()
lost
parents: 64
diff changeset
321 rval = 0;
31d8e85706e7 Implemented setdp and corrected handling of direct page detection in insn_gen_aux()
lost
parents: 64
diff changeset
322
31d8e85706e7 Implemented setdp and corrected handling of direct page detection in insn_gen_aux()
lost
parents: 64
diff changeset
323 l -> symaddr = rval & 0xFF;
31d8e85706e7 Implemented setdp and corrected handling of direct page detection in insn_gen_aux()
lost
parents: 64
diff changeset
324 l -> addrset = 2;
31d8e85706e7 Implemented setdp and corrected handling of direct page detection in insn_gen_aux()
lost
parents: 64
diff changeset
325
31d8e85706e7 Implemented setdp and corrected handling of direct page detection in insn_gen_aux()
lost
parents: 64
diff changeset
326 as -> dpval = rval & 0xFF;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
327 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
328
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
329 OPFUNC(pseudo_fcc)
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
330 {
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
331 int delim = 0;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
332
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
333 delim = **p;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
334 if (!delim)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
335 {
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
336 register_error(as, l, 1, "Bad operand");
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
337 return;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
338 }
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
339 *p += 1;
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
340 while (**p && **p != delim)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
341 {
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
342 lwasm_emit(as, l, **p);
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
343 (*p)++;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
344 }
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
345 if (**p)
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
346 (*p)++;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
347 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
348
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
349
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
350 OPFUNC(pseudo_fcs)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
351 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
352 int delim = 0;
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
353
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
354 delim = **p;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
355 if (!delim)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
356 {
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
357 register_error(as, l, 1, "Bad operand");
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
358 return;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
359 }
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
360 *p += 1;
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
361 while (**p && **p != delim)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
362 {
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
363 if (!*((*p) + 1) || *((*p) + 1) == delim)
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
364 lwasm_emit(as, l, **p | 0x80);
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
365 else
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
366 lwasm_emit(as, l, **p);
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
367 (*p)++;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
368 }
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
369 if (**p)
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
370 (*p)++;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
371 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
372
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
373 OPFUNC(pseudo_fcn)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
374 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
375 int delim = 0;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
376
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
377 delim = **p;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
378 if (!delim)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
379 {
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
380 register_error(as, l, 1, "Bad operand");
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
381 return;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
382 }
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
383 *p += 1;
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
384 while (**p && **p != delim)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
385 {
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
386 lwasm_emit(as, l, **p);
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
387 (*p)++;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
388 }
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
389 if (**p)
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
390 (*p)++;
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
391 lwasm_emit(as, l, 0);
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
392 }
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
393
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
394 OPFUNC(pseudo_fcb)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
395 {
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
396 int v1;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
397
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
398 fcb_again:
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
399 if (lwasm_expr_result(as, l, p, EXPR_PASS2CONST | EXPR_BYTE, &v1) < 0)
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
400 return;
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
401
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
402 lwasm_emit(as, l, v1);
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
403 if (**p == ',')
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
404 {
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
405 (*p)++;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
406 goto fcb_again;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
407 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
408 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
409
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
410 OPFUNC(pseudo_fdb)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
411 {
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
412 int v1;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
413
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
414 fdb_again:
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
415 if (lwasm_expr_result(as, l, p, EXPR_PASS2CONST, &v1) < 0)
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
416 return;
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
417
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
418 lwasm_emit(as, l, v1 >> 8);
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
419 lwasm_emit(as, l, v1 & 0xff);
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
420 if (**p == ',')
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
421 {
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
422 (*p)++;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
423 goto fdb_again;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
424 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
425 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
426
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
427 OPFUNC(pseudo_fqb)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
428 {
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
429 int v1;
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
430
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
431 fqb_again:
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
432 if (lwasm_expr_result(as, l, p, EXPR_PASS2CONST, &v1) < 0)
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
433 return;
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
434
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
435 lwasm_emit(as, l, v1 >> 24);
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
436 lwasm_emit(as, l, v1 >> 16);
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
437 lwasm_emit(as, l, v1 >> 8);
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
438 lwasm_emit(as, l, v1 & 0xff);
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
439 if (**p == ',')
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
440 {
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
441 (*p)++;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
442 goto fqb_again;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
443 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
444 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
445
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
446 // 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
447 OPFUNC(pseudo_endc)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
448 {
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
449 if (as -> skipcond && !(as -> skipmacro))
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
450 {
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
451 as -> skipcount -= 1;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
452 if (as -> skipcount <= 0)
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
453 {
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
454 as -> skipcond = 0;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
455 }
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
456 }
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
457 return;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
458 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
459
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
460 // if "else" executes, we must be going into an "ignore" state
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
461 OPFUNC(pseudo_else)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
462 {
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
463 if (as -> skipmacro)
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
464 return;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
465
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
466 if (as -> skipcond)
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
467 {
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
468 if (as -> skipcount == 1)
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
469 {
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
470 as -> skipcount = 0;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
471 as -> skipcond = 0;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
472 }
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
473 return;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
474 }
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
475
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
476 as -> skipcond = 1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
477 as -> skipcount = 1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
478 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
479
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
480 OPFUNC(pseudo_ifne)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
481 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
482 int v1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
483 int rval;
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
484
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
485 if (as -> skipcond && !(as -> skipmacro))
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
486 {
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
487 as -> skipcount++;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
488 return;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
489 }
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
490
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
491 rval = lwasm_expr_result(as, l, p, EXPR_PASS1CONST, &v1);
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
492 if (rval < 0)
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
493 return;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
494 if (!v1)
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
495 {
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
496 as -> skipcond = 1;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
497 as -> skipcount = 1;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
498 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
499 }
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
500
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
501 OPFUNC(pseudo_ifeq)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
502 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
503 int v1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
504 int rval;
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
505
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
506 if (as -> skipcond && !(as -> skipmacro))
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
507 {
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
508 as -> skipcount++;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
509 return;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
510 }
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
511
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
512 rval = lwasm_expr_result(as, l, p, EXPR_PASS1CONST, &v1);
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
513 if (rval < 0)
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
514 return;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
515 if (v1)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
516 {
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
517 as -> skipcond = 1;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
518 as -> skipcount = 1;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
519 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
520 }
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
521
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
522 OPFUNC(pseudo_iflt)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
523 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
524 int v1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
525 int rval;
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
526
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
527 if (as -> skipcond && !(as -> skipmacro))
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
528 {
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
529 as -> skipcount++;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
530 return;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
531 }
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
532
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
533 rval = lwasm_expr_result(as, l, p, EXPR_PASS1CONST, &v1);
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
534 if (rval < 0)
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
535 return;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
536 if (v1 >= 0)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
537 {
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
538 as -> skipcond = 1;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
539 as -> skipcount = 1;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
540 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
541 }
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
542
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
543 OPFUNC(pseudo_ifle)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
544 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
545 int v1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
546 int rval;
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
547
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
548 if (as -> skipcond && !(as -> skipmacro))
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
549 {
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
550 as -> skipcount++;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
551 return;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
552 }
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
553
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
554 rval = lwasm_expr_result(as, l, p, EXPR_PASS1CONST, &v1);
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
555 if (rval < 0)
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
556 return;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
557 if (v1 > 0)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
558 {
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
559 as -> skipcond = 1;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
560 as -> skipcount = 1;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
561 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
562 }
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
563
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
564 OPFUNC(pseudo_ifgt)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
565 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
566 int v1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
567 int rval;
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
568
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
569 if (as -> skipcond && !(as -> skipmacro))
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
570 {
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
571 as -> skipcount++;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
572 return;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
573 }
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
574
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
575 rval = lwasm_expr_result(as, l, p, EXPR_PASS1CONST, &v1);
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
576 if (rval < 0)
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
577 return;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
578 if (v1 <= 0)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
579 {
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
580 as -> skipcond = 1;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
581 as -> skipcount = 1;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
582 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
583 }
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
584
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
585 OPFUNC(pseudo_ifge)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
586 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
587 int v1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
588 int rval;
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
589
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
590 if (as -> skipcond && !(as -> skipmacro))
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
591 {
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
592 as -> skipcount++;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
593 return;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
594 }
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
595
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
596 rval = lwasm_expr_result(as, l, p, EXPR_PASS1CONST, &v1);
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
597 if (rval < 0)
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
598 return;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
599 if (v1 < 0)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
600 {
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
601 as -> skipcond = 1;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
602 as -> skipcount = 1;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
603 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
604 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
605
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
606 OPFUNC(pseudo_error)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
607 {
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
608 register_error(as, l, 1, "User error: %s", *p);
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
609 }
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
610
74
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
611
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
612 OPFUNC(pseudo_section)
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
613 {
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
614 sectiontab_t *s;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
615 char *p2;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
616 char *sn;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
617 char *opts;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
618
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
619
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
620 if (as -> outformat != OUTPUT_OBJ)
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
621 {
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
622 register_error(as, l, 1, "Sections only supported for obj target");
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
623 return;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
624 }
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
625
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
626 if (as -> csect)
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
627 {
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
628 as -> csect -> offset = as -> addr;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
629 as -> csect = NULL;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
630 }
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
631
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
632 if (!**p)
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
633 {
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
634 register_error(as, l, 1, "Need section name");
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
635 return;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
636 }
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
637
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
638 for (p2 = *p; *p2 && !isspace(*p2); p2++)
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
639 /* do nothing */ ;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
640
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
641 sn = lwasm_alloc(p2 - *p + 1);
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
642 memcpy(sn, *p, p2 - *p);
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
643 sn[p2 - *p] = '\0';
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
644
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
645 *p = p2;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
646
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
647 opts = strchr(sn, ',');
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
648 if (opts)
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
649 {
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
650 *opts++ = '\0';
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
651 }
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
652
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
653 // have we seen the section name already?
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
654 for (s = as -> sections; s; s = s -> next)
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
655 {
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
656 if (!strcmp(s -> name, sn))
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
657 break;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
658 }
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
659
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
660 if (s)
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
661 {
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
662 lwasm_free(sn);
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
663 if (opts)
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
664 {
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
665 register_error(as, l, 1, "Section options can only be specified the first time");
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
666 return;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
667 }
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
668 }
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
669 else if (!s)
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
670 {
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
671 s = lwasm_alloc(sizeof(sectiontab_t));
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
672 s -> name = sn;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
673 s -> offset = 0;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
674 s -> flags = 0;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
675
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
676 // parse options; only one "bss"
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
677 if (opts && as -> passnum == 1)
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
678 {
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
679 if (!strcasecmp(opts, "bss"))
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
680 {
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
681 s -> flags = SECTION_BSS;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
682 }
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
683 else
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
684 {
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
685 register_error(as, l, 1, "Unrecognized section option '%s'", opts);
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
686 lwasm_free(s -> name);
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
687 lwasm_free(s);
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
688 return;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
689 }
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
690 }
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
691
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
692 s -> next = as -> sections;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
693 as -> sections = s;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
694 }
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
695 as -> addr = s -> offset;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
696 as -> csect = s;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
697 as -> context = lwasm_next_context(as);
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
698 }
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
699
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
700 OPFUNC(pseudo_endsection)
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
701 {
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
702 if (as -> outformat != OUTPUT_OBJ)
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
703 {
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
704 register_error(as, l, 1, "Sections only supported for obj target");
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
705 return;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
706 }
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
707
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
708 if (!(as -> csect))
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
709 {
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
710 register_error(as, l, 1, "ENDSECTION when not in a section");
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
711 return;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
712 }
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
713
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
714 as -> csect -> offset = as -> addr;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
715 as -> addr = 0;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
716 as -> csect = 0;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
717 as -> context = lwasm_next_context(as);
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
718 }