annotate old-trunk/lwasm/old/lwasm.c @ 344:0215a0fbf61b

Added assembly error system and additional checks for symbol syntax
author lost@starbug
date Thu, 25 Mar 2010 22:06:50 -0600
parents eb230fa7d28e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
339
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1 /*
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
2 lwasm.c
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
3 Copyright © 2009 William Astle
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
4
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
5 This file is part of LWASM.
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
6
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
7 LWASM is free software: you can redistribute it and/or modify it under the
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
8 terms of the GNU General Public License as published by the Free Software
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
9 Foundation, either version 3 of the License, or (at your option) any later
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
10 version.
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
11
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
12 This program is distributed in the hope that it will be useful, but WITHOUT
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
15 more details.
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
16
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
17 You should have received a copy of the GNU General Public License along with
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
18 this program. If not, see <http://www.gnu.org/licenses/>.
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
19
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
20
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
21 Contains random functions used by the assembler
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
22 */
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
23
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
24 #define __lwasm_c_seen__
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
25 #include <config.h>
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
26
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
27 #include <stdarg.h>
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
28 #include <stdlib.h>
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
29 #include <stdio.h>
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
30
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
31 #include "lwasm.h"
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
32 #include "util.h"
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
33 #include "expr.h"
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
34
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
35 int debug_level = 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
36
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
37 int register_error(asmstate_t *as, lwasm_line_t *l, int pass, const char *fmt, ...)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
38 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
39 lwasm_error_t *e;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
40 va_list args;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
41 char errbuff[1024];
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
42 int r;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
43
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
44 if (!l)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
45 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
46
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
47 if (as -> passnum != pass)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
48 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
49
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
50 va_start(args, fmt);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
51
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
52 e = lwasm_alloc(sizeof(lwasm_error_t));
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
53
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
54 e -> next = l -> err;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
55 l -> err = e;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
56
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
57 as -> errorcount++;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
58
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
59 r = vsnprintf(errbuff, 1024, fmt, args);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
60 e -> mess = lwasm_strdup(errbuff);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
61
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
62 va_end(args);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
63
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
64 return r;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
65 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
66
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
67 void lwasm_emit(asmstate_t *as, lwasm_line_t *l, int b)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
68 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
69 as -> addr += 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
70 as -> addr &= 0xffff;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
71
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
72 if (as -> outformat == OUTPUT_OBJ && !(as -> csect))
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
73 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
74 register_error(as, l, 1, "Output not allowed outside sections with obj target");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
75 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
76 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
77 if (as -> outformat == OUTPUT_OBJ && as -> csect -> flags & SECTION_BSS)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
78 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
79 register_error(as, l, 1, "Output not allowed inside BSS sections");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
80 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
81 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
82
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
83 if (as -> outformat == OUTPUT_OS9 && as -> inmod == 0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
84 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
85 register_error(as, l, 1, "Output not allowed outside of module in OS9 mode");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
86 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
87 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
88
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
89 if (as -> passnum == 1)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
90 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
91
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
92
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
93 if (l -> codelen >= l -> codesize)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
94 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
95 l -> bytes = realloc(l -> bytes, l -> codesize + 16);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
96 l -> codesize += 16;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
97 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
98 l -> bytes[l -> codelen] = b & 0xff;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
99 l -> codelen += 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
100
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
101 if (as -> outformat == OUTPUT_OS9 && as -> inmod)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
102 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
103 // calc the CRC
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
104 // this is a direct transliteration from the nitros9 asm source
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
105 // to C; it can, no doubt, be optimized for 32 bit processing
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
106 b &= 0xff;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
107
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
108 b ^= (as -> crc)[0];
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
109 (as -> crc)[0] = (as -> crc)[1];
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
110 (as -> crc)[1] = (as -> crc)[2];
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
111 (as -> crc)[1] ^= (b >> 7);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
112 (as -> crc)[2] = (b << 1);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
113 (as -> crc)[1] ^= (b >> 2);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
114 (as -> crc)[2] ^= (b << 6);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
115 b ^= (b << 1);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
116 b ^= (b << 2);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
117 b ^= (b << 4);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
118 if (b & 0x80)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
119 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
120 (as -> crc)[0] ^= 0x80;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
121 (as -> crc)[2] ^= 0x21;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
122 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
123 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
124 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
125
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
126 void lwasm_emitop(asmstate_t *as, lwasm_line_t *l, int o)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
127 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
128 if (o >= 0x100)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
129 lwasm_emit(as, l, o >> 8);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
130 lwasm_emit(as, l, o & 0xff);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
131 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
132
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
133 int lwasm_lookupreg2(const char *reglist, char **str)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
134 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
135 int rval = 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
136
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
137 while (*reglist)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
138 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
139 if (toupper(**str) == *reglist)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
140 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
141 // first char matches
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
142 if (reglist[1] == ' ' && !isalpha(*(*str + 1)))
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
143 break;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
144 if (toupper(*(*str + 1)) == reglist[1])
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
145 break;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
146 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
147 reglist += 2;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
148 rval++;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
149 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
150 if (!*reglist)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
151 return -1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
152 if (reglist[1] == ' ')
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
153 (*str)++;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
154 else
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
155 (*str) += 2;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
156 return rval;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
157 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
158
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
159 int lwasm_lookupreg3(const char *rlist, const char **str)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
160 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
161 int rval = 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
162 int f = 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
163 const char *reglist = rlist;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
164
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
165 while (*reglist)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
166 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
167 if (toupper(**str) == *reglist)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
168 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
169 // first char matches
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
170 if (reglist[1] == ' ')
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
171 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
172 f = 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
173 break;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
174 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
175 if (toupper(*(*str + 1)) == reglist[1])
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
176 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
177 // second char matches
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
178 if (reglist[2] == ' ')
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
179 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
180 f = 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
181 break;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
182 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
183 if (toupper(*(*str + 2)) == reglist[2])
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
184 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
185 f = 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
186 break;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
187 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
188 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
189 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
190 reglist += 3;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
191 rval++;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
192 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
193 if (f == 0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
194 return -1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
195
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
196
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
197 reglist = rval * 3 + rlist;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
198 if (reglist[1] == ' ')
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
199 (*str) += 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
200 else if (reglist[2] == ' ')
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
201 (*str) += 2;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
202 else
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
203 (*str)+=3;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
204 return rval;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
205 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
206
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
207 struct symstateinfo
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
208 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
209 asmstate_t *as;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
210 lwasm_line_t *l;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
211 int flags;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
212 };
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
213
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
214 lwasm_expr_stack_t *lwasm_expr_lookup_symbol(char *sym, void *state)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
215 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
216 lwasm_symbol_ent_t *se;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
217 struct symstateinfo *st;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
218 lwasm_expr_stack_t *rs;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
219 lwasm_expr_term_t *t;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
220 lwasm_expr_stack_node_t *n;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
221
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
222 int val;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
223
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
224 st = state;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
225 debug_message(3, "lwasm_expr_lookup_symbol(): find '%s' (context=%d)", sym, st -> as -> context);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
226
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
227 // check for special symbols first...
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
228 if (sym[1] == '\0')
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
229 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
230 switch (sym[0])
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
231 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
232 // current line address
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
233 case '*':
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
234 case '.':
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
235 val = st -> l -> codeaddr;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
236 goto retconst;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
237
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
238 case '<':
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
239 // previous branch point
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
240 // not implemented
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
241 break;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
242 case '>':
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
243 // next branch point
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
244 // not implemented
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
245 break;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
246 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
247 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
248
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
249 // look for local symbol first then global symbol
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
250 se = lwasm_find_symbol(st -> as, sym, st -> as -> context);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
251 if (!se)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
252 se = lwasm_find_symbol(st -> as, sym, -1);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
253 debug_message(3, "lwasm_expr_lookup_symbol(): got '%p'", se);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
254 if (!se)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
255 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
256 register_error(st -> as, st -> l, 2, "Undefined symbol '%s'", sym);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
257 return NULL;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
258 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
259 // external reference - can not resolve it
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
260 if (se -> flags & SYMBOL_EXTERN)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
261 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
262 return NULL;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
263 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
264 if (st -> flags & EXPR_SECTCONST)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
265 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
266 if (se -> sect == st -> l -> sect)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
267 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
268 if (se -> expr)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
269 goto retsym;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
270 val = se -> value;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
271 goto retconst;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
272 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
273 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
274 if (st -> as -> outformat == OUTPUT_OBJ && se -> sect != NULL)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
275 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
276 return NULL;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
277 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
278 if (st -> as -> outformat != OUTPUT_OBJ || se -> sect == NULL)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
279 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
280 // global symbol, intrasegment reference, or not an object target
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
281 val = se -> value;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
282 goto retconst;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
283 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
284
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
285 // an intersegment reference will return as NULL (to be resolved at output/link time)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
286 // if se -> expr is NULL, it has to be an intersegment reference here
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
287 if (se -> expr == NULL)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
288 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
289 return NULL;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
290 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
291
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
292 retsym:
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
293 // duplicate the expression for return
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
294 rs = lwasm_expr_stack_create();
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
295 for (n = se -> expr -> head; n; n = n -> next)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
296 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
297 lwasm_expr_stack_push(rs, n -> term);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
298 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
299 return rs;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
300
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
301 retconst:
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
302 rs = lwasm_expr_stack_create();
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
303 t = lwasm_expr_term_create_int(val);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
304 lwasm_expr_stack_push(rs, t);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
305 lwasm_expr_term_free(t);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
306 return rs;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
307 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
308
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
309 lwasm_expr_stack_t *lwasm_evaluate_expr(asmstate_t *as, lwasm_line_t *l, const char *inp, const char **outp, int flags)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
310 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
311 struct symstateinfo st;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
312
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
313 st.as = as;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
314 st.l = l;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
315 st.flags = flags;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
316
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
317 debug_message(2, "Evaluate expression: %s", inp);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
318
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
319 return(lwasm_expr_eval(inp, outp, lwasm_expr_lookup_symbol, &st));
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
320 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
321
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
322
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
323 int lwasm_reevaluate_expr(asmstate_t *as, lwasm_line_t *l, lwasm_expr_stack_t *s, int flags)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
324 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
325 struct symstateinfo st;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
326
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
327 st.as = as;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
328 st.l = l;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
329 st.flags = flags;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
330 return(lwasm_expr_reval(s, lwasm_expr_lookup_symbol, &st));
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
331 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
332
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
333 // return 1 if no undefined symbols (externals and incompletes are okay)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
334 // return 0 if there are undefined symbols
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
335 int lwasm_expr_result_ckconst(asmstate_t *as, lwasm_expr_stack_t *s)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
336 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
337 lwasm_expr_stack_node_t *n;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
338 lwasm_symbol_ent_t *se;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
339
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
340 if (as -> outformat != OUTPUT_OBJ)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
341 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
342 if (lwasm_expr_is_constant(s))
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
343 return 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
344 else
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
345 return 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
346 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
347
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
348 for (n = s -> head; n; n = n -> next)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
349 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
350 if (n -> term -> term_type == LWASM_TERM_SYM)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
351 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
352 se = lwasm_find_symbol(as, n -> term -> symbol, as -> context);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
353 if (!se)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
354 se = lwasm_find_symbol(as, n -> term -> symbol, -1);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
355 if (!se)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
356 return 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
357 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
358 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
359 return 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
360 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
361
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
362 /*
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
363 Evaluate an expression according to the flag value. Return 0 if a constant result was
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
364 obtained, 1 if an incomplete result was obtained, and -1 if an error was flagged.
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
365
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
366 */
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
367 int lwasm_expr_result2(asmstate_t *as, lwasm_line_t *l, char **inp, int flag, int *val, int slot)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
368 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
369 lwasm_expr_stack_t *s = NULL;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
370 const char *ep;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
371 int rval;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
372
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
373 if ((as -> passnum == 1 && !(flag & EXPR_REEVAL)) || slot < 0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
374 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
375 s = lwasm_evaluate_expr(as, l, *inp, &ep, flag);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
376 if (slot >= 0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
377 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
378 l -> exprs[slot] = s;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
379 l -> exprends[slot] = ep;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
380 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
381 if (!s)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
382 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
383 register_error(as, l, 1, "Bad expression");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
384 *val = 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
385 return -1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
386 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
387 *inp = (char *)ep;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
388 if (slot >= 0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
389 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
390 // l -> exprends[slot] = (char *)ep;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
391 l -> exprvals[slot] = lwasm_expr_get_value(s);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
392 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
393 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
394 else if (l -> exprs[slot])
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
395 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
396 s = l -> exprs[slot];
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
397 lwasm_reevaluate_expr(as, l, s, flag);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
398 l -> exprvals[slot] = lwasm_expr_get_value(s);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
399 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
400 if (as -> passnum == 2 && slot >= 0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
401 *inp = l -> exprends[slot];
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
402
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
403 if (s && lwasm_expr_is_constant(s))
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
404 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
405 *val = lwasm_expr_get_value(s);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
406 lwasm_expr_stack_free(s);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
407 l -> exprs[slot] = NULL;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
408 s = NULL;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
409 return 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
410 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
411
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
412 if (!s && slot >= 0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
413 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
414 *val = l -> exprvals[slot];
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
415 return 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
416 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
417 else if (!s)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
418 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
419 *val = 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
420 return 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
421 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
422
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
423 // was a constant result on pass 1 requested?
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
424 // that means we must have a constant on either pass
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
425 if (flag & EXPR_PASS1CONST)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
426 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
427 *val = 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
428 if (slot >= 0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
429 l -> exprvals[slot] = 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
430 register_error(as, l, 1, "Illegal forward, external, or inter-section reference");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
431 lwasm_expr_stack_free(s);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
432 if (slot >= 0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
433 l -> exprs[slot] = NULL;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
434 return -1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
435 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
436
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
437 return 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
438 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
439
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
440 void debug_message(int level, const char *fmt, ...)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
441 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
442 va_list args;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
443
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
444 va_start(args, fmt);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
445 if (debug_level >= level)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
446 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
447 if (level > 0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
448 fprintf(stderr, "DEBUG %d: ", level);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
449 vfprintf(stderr, fmt, args);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
450 fputc('\n', stderr);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
451 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
452 va_end(args);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
453 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
454
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
455 int lwasm_next_context(asmstate_t *as)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
456 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
457 int r;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
458 r = as -> nextcontext;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
459 as -> nextcontext += 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
460 debug_message(3, "lwasm_next_context(): %d (%d) pass %d", r, as -> nextcontext, as -> passnum);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
461 return r;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
462 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
463