annotate lwasm/pseudo.c @ 182:833d392fec82

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