annotate src/pseudo.c @ 79:d0ce3f5f6797

Checkpointing deployment of non-constant expression handling
author lost
date Sat, 10 Jan 2009 07:09:14 +0000
parents 121bf4a588ea
children 03be43ae19cf
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
79
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
291 // 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
292 // to a constant!
78
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 74
diff changeset
293 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
294 }
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
295
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 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
297 {
79
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
298 int r, v;
64
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
299
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
300 // set MUST run on both passes as the symbol value changes!
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
301
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
302 if (l -> sym == NULL)
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
303 {
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
304 register_error(as, l, 1, "No symbol specified");
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
305 return;
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
306 }
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
307
79
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
308 r = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v, 0);
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
309 if (r < 0)
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
310 v = 0;
64
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
311
79
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
312 l -> symaddr = v & 0xFFFF;
64
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
313 l -> addrset = 2;
aaddd47219b4 Added the 'set' directive
lost
parents: 63
diff changeset
314
79
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
315 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
316 }
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
317
65
31d8e85706e7 Implemented setdp and corrected handling of direct page detection in insn_gen_aux()
lost
parents: 64
diff changeset
318 OPFUNC(pseudo_setdp)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
319 {
79
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
320 int r, v;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
321
79
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
322 if (as -> outformat == OUTPUT_OBJ)
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
323 {
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
324 register_error(as, l, 1, "SETDP not permitted with OBJ target");
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
325 return;
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
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
328 // setdp is needed on both passes; must resolve to a constant on pass 1
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
329 r = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v, 0);
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
330 if (r != 0)
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
331 return;
65
31d8e85706e7 Implemented setdp and corrected handling of direct page detection in insn_gen_aux()
lost
parents: 64
diff changeset
332
79
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
333 if (v < -127 || v > 255)
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
334 {
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
335 register_error(as, l, 1, "Byte overflow");
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
336 return;
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
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
339 l -> symaddr = v & 0xFF;
65
31d8e85706e7 Implemented setdp and corrected handling of direct page detection in insn_gen_aux()
lost
parents: 64
diff changeset
340 l -> addrset = 2;
31d8e85706e7 Implemented setdp and corrected handling of direct page detection in insn_gen_aux()
lost
parents: 64
diff changeset
341
79
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
342 as -> dpval = v & 0xFF;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
343 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
344
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
345 OPFUNC(pseudo_fcc)
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
346 {
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
347 int delim = 0;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
348
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
349 delim = **p;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
350 if (!delim)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
351 {
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
352 register_error(as, l, 1, "Bad operand");
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
353 return;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
354 }
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
355 *p += 1;
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
356 while (**p && **p != delim)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
357 {
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
358 lwasm_emit(as, l, **p);
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
359 (*p)++;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
360 }
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
361 if (**p)
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
362 (*p)++;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
363 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
364
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
365
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
366 OPFUNC(pseudo_fcs)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
367 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
368 int delim = 0;
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
369
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
370 delim = **p;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
371 if (!delim)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
372 {
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
373 register_error(as, l, 1, "Bad operand");
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
374 return;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
375 }
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
376 *p += 1;
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
377 while (**p && **p != delim)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
378 {
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
379 if (!*((*p) + 1) || *((*p) + 1) == delim)
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
380 lwasm_emit(as, l, **p | 0x80);
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
381 else
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
382 lwasm_emit(as, l, **p);
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
383 (*p)++;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
384 }
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
385 if (**p)
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
386 (*p)++;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
387 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
388
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
389 OPFUNC(pseudo_fcn)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
390 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
391 int delim = 0;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
392
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
393 delim = **p;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
394 if (!delim)
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
395 {
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
396 register_error(as, l, 1, "Bad operand");
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
397 return;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
398 }
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
399 *p += 1;
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
400 while (**p && **p != delim)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
401 {
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
402 lwasm_emit(as, l, **p);
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
403 (*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 if (**p)
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
406 (*p)++;
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
407 lwasm_emit(as, l, 0);
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
408 }
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
409
79
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
410 // FIXME: handle external, etc., references in a useful manner
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
411 OPFUNC(pseudo_fcb)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
412 {
79
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
413 int r, v;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
414
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
415 fcb_again:
79
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
416 r = lwasm_expr_result2(as, l, p, 0, &v, -1);
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
417 if (r < 0)
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
418 return;
79
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
419
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
420 if (r > 0)
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
421 {
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
422 register_error(as, l, 2, "Illegal external or inter-segment reference");
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
423 v = 0;
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
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
426 if (v < -127 || v > 255)
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
427 {
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
428 register_error(as, l, 1, "Byte overflow");
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
429 }
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
430
79
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
431 lwasm_emit(as, l, v);
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
432 if (**p == ',')
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
433 {
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
434 (*p)++;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
435 goto fcb_again;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
436 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
437 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
438
79
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
439 // FIXME: handle external references in an intelligent way
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
440 OPFUNC(pseudo_fdb)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
441 {
79
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
442 int r, v;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
443
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
444 fdb_again:
79
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
445 r = lwasm_expr_result2(as, l, p, 0, &v, -1);
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
446 if (r < 0)
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
447 return;
79
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
448
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
449 if (r > 0)
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
450 {
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
451 register_error(as, l, 2, "Illegal external or inter-segment reference");
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
452 v = 0;
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
453 }
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
454
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
455 lwasm_emit(as, l, v >> 8);
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
456 lwasm_emit(as, l, v & 0xff);
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
457 if (**p == ',')
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
458 {
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
459 (*p)++;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
460 goto fdb_again;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
461 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
462 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
463
79
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
464 // FIXME: handle external references in a sensible way
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
465 OPFUNC(pseudo_fqb)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
466 {
79
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
467 int r, v;
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
468
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
469 fqb_again:
79
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
470 r = lwasm_expr_result2(as, l, p, 0, &v, -1);
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
471 if (r < 0)
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
472 return;
79
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
473
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
474 if (r > 0)
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
475 {
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
476 register_error(as, l, 2, "Illegal external or inter-segment reference");
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
477 v = 0;
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
478 }
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
479
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
480 lwasm_emit(as, l, v >> 24);
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
481 lwasm_emit(as, l, v >> 16);
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
482 lwasm_emit(as, l, v >> 8);
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
483 lwasm_emit(as, l, v & 0xff);
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
484 if (**p == ',')
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
485 {
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
486 (*p)++;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
487 goto fqb_again;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
488 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
489 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
490
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
491 // 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
492 OPFUNC(pseudo_endc)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
493 {
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
494 if (as -> skipcond && !(as -> skipmacro))
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 -> skipcount -= 1;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
497 if (as -> skipcount <= 0)
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
498 {
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
499 as -> skipcond = 0;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
500 }
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
501 }
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
502 return;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
503 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
504
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
505 // if "else" executes, we must be going into an "ignore" state
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
506 OPFUNC(pseudo_else)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
507 {
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
508 if (as -> skipmacro)
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
509 return;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
510
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
511 if (as -> skipcond)
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
512 {
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
513 if (as -> skipcount == 1)
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
514 {
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
515 as -> skipcount = 0;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
516 as -> skipcond = 0;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
517 }
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
518 return;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
519 }
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
520
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
521 as -> skipcond = 1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
522 as -> skipcount = 1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
523 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
524
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
525 OPFUNC(pseudo_ifne)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
526 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
527 int v1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
528 int rval;
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
529
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
530 if (as -> skipcond && !(as -> skipmacro))
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
531 {
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
532 as -> skipcount++;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
533 return;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
534 }
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
535
79
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
536 rval = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v1, 0);
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
537 if (rval != 0)
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
538 return;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
539 if (!v1)
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
540 {
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
541 as -> skipcond = 1;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
542 as -> skipcount = 1;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
543 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
544 }
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
545
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
546 OPFUNC(pseudo_ifeq)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
547 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
548 int v1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
549 int rval;
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
550
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
551 if (as -> skipcond && !(as -> skipmacro))
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
552 {
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
553 as -> skipcount++;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
554 return;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
555 }
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
556
79
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
557 rval = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v1, 0);
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
558 if (rval != 0)
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
559 return;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
560 if (v1)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
561 {
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
562 as -> skipcond = 1;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
563 as -> skipcount = 1;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
564 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
565 }
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
566
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
567 OPFUNC(pseudo_iflt)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
568 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
569 int v1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
570 int rval;
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
571
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
572 if (as -> skipcond && !(as -> skipmacro))
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
573 {
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
574 as -> skipcount++;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
575 return;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
576 }
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
577
79
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
578 rval = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v1, 0);
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
579 if (rval != 0)
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
580 return;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
581 if (v1 >= 0)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
582 {
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
583 as -> skipcond = 1;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
584 as -> skipcount = 1;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
585 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
586 }
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
587
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
588 OPFUNC(pseudo_ifle)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
589 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
590 int v1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
591 int rval;
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
592
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
593 if (as -> skipcond && !(as -> skipmacro))
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
594 {
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
595 as -> skipcount++;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
596 return;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
597 }
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
598
79
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
599 rval = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v1, 0);
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
600 if (rval != 0)
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
601 return;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
602 if (v1 > 0)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
603 {
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
604 as -> skipcond = 1;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
605 as -> skipcount = 1;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
606 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
607 }
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
608
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
609 OPFUNC(pseudo_ifgt)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
610 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
611 int v1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
612 int rval;
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
613
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
614 if (as -> skipcond && !(as -> skipmacro))
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
615 {
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
616 as -> skipcount++;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
617 return;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
618 }
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
619
79
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
620 rval = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v1, 0);
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
621 if (rval != 0)
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
622 return;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
623 if (v1 <= 0)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
624 {
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
625 as -> skipcond = 1;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
626 as -> skipcount = 1;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
627 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
628 }
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
629
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
630 OPFUNC(pseudo_ifge)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
631 {
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
632 int v1;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
633 int rval;
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
634
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
635 if (as -> skipcond && !(as -> skipmacro))
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
636 {
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
637 as -> skipcount++;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
638 return;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
639 }
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
640
79
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
641 rval = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v1, 0);
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
642 if (rval != 0)
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
643 return;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
644 if (v1 < 0)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
645 {
57
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
646 as -> skipcond = 1;
035b95a3690f Added conditional assembly and macros
lost
parents: 56
diff changeset
647 as -> skipcount = 1;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
648 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
649 }
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
650
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
651 OPFUNC(pseudo_error)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
652 {
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
653 register_error(as, l, 1, "User error: %s", *p);
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
654 }
56
55260a178667 Added from f* pseudo ops
lost
parents: 54
diff changeset
655
74
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
656
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
657 OPFUNC(pseudo_section)
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
658 {
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
659 sectiontab_t *s;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
660 char *p2;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
661 char *sn;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
662 char *opts;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
663
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
664
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
665 if (as -> outformat != OUTPUT_OBJ)
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
666 {
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
667 register_error(as, l, 1, "Sections only supported for obj target");
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
668 return;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
669 }
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
670
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
671 if (as -> csect)
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
672 {
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
673 as -> csect -> offset = as -> addr;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
674 as -> csect = NULL;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
675 }
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
676
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
677 if (!**p)
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
678 {
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
679 register_error(as, l, 1, "Need section name");
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
680 return;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
681 }
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
682
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
683 for (p2 = *p; *p2 && !isspace(*p2); p2++)
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
684 /* do nothing */ ;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
685
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
686 sn = lwasm_alloc(p2 - *p + 1);
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
687 memcpy(sn, *p, p2 - *p);
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
688 sn[p2 - *p] = '\0';
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
689
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
690 *p = p2;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
691
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
692 opts = strchr(sn, ',');
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
693 if (opts)
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
694 {
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
695 *opts++ = '\0';
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
696 }
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
697
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
698 // have we seen the section name already?
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
699 for (s = as -> sections; s; s = s -> next)
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
700 {
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
701 if (!strcmp(s -> name, sn))
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
702 break;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
703 }
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
704
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
705 if (s)
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
706 {
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
707 lwasm_free(sn);
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
708 if (opts)
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, "Section options can only be specified the first time");
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 else if (!s)
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
715 {
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
716 s = lwasm_alloc(sizeof(sectiontab_t));
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
717 s -> name = sn;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
718 s -> offset = 0;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
719 s -> flags = 0;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
720
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
721 // parse options; only one "bss"
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
722 if (opts && as -> passnum == 1)
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
723 {
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
724 if (!strcasecmp(opts, "bss"))
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
725 {
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
726 s -> flags = SECTION_BSS;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
727 }
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
728 else
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
729 {
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
730 register_error(as, l, 1, "Unrecognized section option '%s'", opts);
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
731 lwasm_free(s -> name);
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
732 lwasm_free(s);
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
733 return;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
734 }
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
735 }
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
736
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
737 s -> next = as -> sections;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
738 as -> sections = s;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
739 }
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
740 as -> addr = s -> offset;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
741 as -> csect = s;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
742 as -> context = lwasm_next_context(as);
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
743 }
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
744
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
745 OPFUNC(pseudo_endsection)
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
746 {
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
747 if (as -> outformat != OUTPUT_OBJ)
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
748 {
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
749 register_error(as, l, 1, "Sections only supported for obj target");
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
750 return;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
751 }
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
752
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
753 if (!(as -> csect))
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
754 {
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
755 register_error(as, l, 1, "ENDSECTION when not in a section");
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
756 return;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
757 }
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
758
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
759 as -> csect -> offset = as -> addr;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
760 as -> addr = 0;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
761 as -> csect = 0;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
762 as -> context = lwasm_next_context(as);
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 65
diff changeset
763 }