annotate old-trunk/lwasm/old/insn_gen.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 insn_gen.c, Copyright © 2009 William Astle
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
3
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
4 This file is part of LWASM.
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
5
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
6 LWASM is free software: you can redistribute it and/or modify it under the
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
7 terms of the GNU General Public License as published by the Free Software
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
8 Foundation, either version 3 of the License, or (at your option) any later
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
9 version.
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
10
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
11 This program is distributed in the hope that it will be useful, but WITHOUT
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
14 more details.
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
15
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
16 You should have received a copy of the GNU General Public License along with
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
17 this program. If not, see <http://www.gnu.org/licenses/>.
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
18
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
19 Contains code for parsing general addressing modes (IMM+DIR+EXT+IND)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
20 */
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
21
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
22 #include <config.h>
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
23
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
24 #include <ctype.h>
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
25 #include <stdlib.h>
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
26
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
27 #include "lwasm.h"
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
28 #include "instab.h"
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
29 #include "expr.h"
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
30
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
31 extern void insn_indexed_aux(asmstate_t *as, lwasm_line_t *l, const char **p, int *b1, int *b2, int *b3);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
32
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
33 // "extra" is required due to the way OIM, EIM, TIM, and AIM work
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
34 void insn_gen_aux(asmstate_t *as, lwasm_line_t *l, char **optr, int opnum, int extra)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
35 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
36 int b1 = -1, b2 = -1, b3 = -1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
37
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
38 const char *optr2;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
39 int v1, tv, rval;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
40 lwasm_expr_stack_t *s;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
41 int f8 = 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
42 int f16 = 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
43 int isdp = 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
44
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
45 optr2 = *optr;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
46 while (*optr2 && !isspace(*optr2) && *optr2 != ',') optr2++
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
47 /* do nothing */ ;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
48
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
49 if (*optr2 != ',' && **optr != '[')
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
50 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
51 // not indexed
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
52 if (l -> fsize == 1)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
53 f8 = 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
54 else if (l -> fsize == 2)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
55 f16 = 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
56
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
57 if (**optr == '<')
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
58 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
59 (*optr)++;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
60 f8 = 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
61 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
62 // for compatibility with asxxxx
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
63 // * followed by a digit, alpha, or _, or ., or ?, or another * is "f8"
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
64 else if (**optr == '*')
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
65 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
66 tv = *(*optr + 1);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
67 if (isdigit(tv) || isalpha(tv) || tv == '_' || tv == '.' || tv == '?' || tv == '@' || tv == '*' || tv == '+' || tv == '-')
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
68 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
69 f8 = 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
70 (*optr)++;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
71 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
72 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
73 else if (**optr == '>')
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
74 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
75 (*optr)++;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
76 f16 = 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
77 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
78 rval = lwasm_expr_result2(as, l, optr, 0, &v1, 0);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
79 if (rval != 0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
80 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
81 f16 = 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
82 v1 = 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
83 l -> fsize = 2;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
84 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
85
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
86 if (((v1 >> 8) & 0xff) == (as -> dpval & 0xff))
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
87 isdp = 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
88
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
89 // disallow non-explicit DP in obj target
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
90 if (as -> outformat == OUTPUT_OBJ && !f8)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
91 f16 = 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
92
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
93 if (f8 || (!f16 && isdp))
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
94 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
95 v1 = v1 & 0xffff;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
96 tv = v1 - ((as -> dpval) << 8);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
97 if (tv < 0 || tv > 0xff)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
98 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
99 register_error(as, l, 2, "Byte overflow");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
100 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
101 v1 = v1 & 0xff;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
102 lwasm_emitop(as, l, instab[opnum].ops[0]);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
103 if (extra != -1)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
104 lwasm_emit(as, l, extra);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
105 l -> relocoff = as -> addr - l -> codeaddr;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
106 l -> reloc8bit = 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
107 lwasm_emit(as, l, v1 & 0xff);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
108 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
109 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
110 else
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
111 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
112 // everything else is 16 bit....
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
113 lwasm_emitop(as, l, instab[opnum].ops[2]);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
114 if (extra != -1)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
115 lwasm_emit(as, l, extra);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
116 l -> relocoff = as -> addr - l -> codeaddr;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
117 lwasm_emit(as, l, v1 >> 8);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
118 lwasm_emit(as, l, v1 & 0xff);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
119 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
120 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
121 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
122
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
123 lwasm_emitop(as, l, instab[opnum].ops[1]);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
124 if (extra != -1)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
125 lwasm_emit(as, l, extra);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
126 insn_indexed_aux(as, l, (const char **)optr, &b1, &b2, &b3);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
127 if (b1 != -1)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
128 lwasm_emit(as, l, b1);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
129 if (b2 != -1)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
130 lwasm_emit(as, l, b2);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
131 if (b3 != -1)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
132 lwasm_emit(as, l, b3);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
133 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
134 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
135
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
136 // the various insn_gen? functions have an immediate mode of ? bits
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
137 OPFUNC(insn_gen0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
138 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
139 if (**p == '#')
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
140 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
141 register_error(as, l, 1, "Immediate mode not allowed");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
142 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
143 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
144
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
145 // handle non-immediate
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
146 insn_gen_aux(as, l, p, opnum, -1);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
147 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
148
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
149 OPFUNC(insn_gen8)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
150 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
151 int rval;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
152 int r;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
153
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
154 if (**p == '#')
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
155 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
156 lwasm_emitop(as, l, instab[opnum].ops[3]);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
157 (*p)++;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
158 r = lwasm_expr_result2(as, l, p, 0, &rval, 0);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
159 if (r != 0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
160 rval = 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
161 if (r == 1 && as -> passnum == 2)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
162 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
163 l -> relocoff = as -> addr - l -> codeaddr;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
164 l -> reloc8bit = 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
165 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
166 // register_error(as, l, 2, "Illegal external or intersegment reference");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
167 lwasm_emit(as, l, rval & 0xff);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
168 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
169 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
170
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
171 insn_gen_aux(as, l, p, opnum, -1);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
172 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
173
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
174 OPFUNC(insn_gen16)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
175 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
176 int rval, r;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
177
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
178 if (**p == '#')
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
179 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
180 lwasm_emitop(as, l, instab[opnum].ops[3]);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
181 (*p)++;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
182
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
183 r = lwasm_expr_result2(as, l, p, 0, &rval, 0);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
184 if (r != 0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
185 rval = 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
186 if (r == 1 && as -> passnum == 2)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
187 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
188 l -> relocoff = as -> addr - l -> codeaddr;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
189 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
190 lwasm_emit(as, l, (rval >> 8) & 0xff);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
191 lwasm_emit(as, l, rval & 0xff);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
192 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
193 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
194
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
195 insn_gen_aux(as, l, p, opnum, -1);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
196 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
197
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
198 OPFUNC(insn_gen32)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
199 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
200 int r, rval;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
201
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
202 if (**p == '#')
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
203 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
204 lwasm_emitop(as, l, instab[opnum].ops[3]);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
205 (*p)++;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
206
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
207 r = lwasm_expr_result2(as, l, p, 0, &rval, 0);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
208 if (r != 0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
209 rval = 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
210 if (r == 1 && as -> passnum == 2)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
211 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
212 register_error(as, l, 2, "Illegal external or intersegment reference");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
213 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
214
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
215 lwasm_emit(as, l, (rval >> 24) & 0xff);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
216 lwasm_emit(as, l, (rval >> 16) & 0xff);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
217 lwasm_emit(as, l, (rval >> 8) & 0xff);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
218 lwasm_emit(as, l, rval & 0xff);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
219 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
220 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
221
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
222 insn_gen_aux(as, l, p, opnum, -1);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
223 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
224
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
225 OPFUNC(insn_imm8)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
226 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
227 int r, rval;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
228
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
229 if (**p == '#')
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
230 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
231 lwasm_emitop(as, l, instab[opnum].ops[0]);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
232 (*p)++;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
233
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
234 r = lwasm_expr_result2(as, l, p, 0, &rval, 0);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
235 if (r != 0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
236 rval = 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
237 if (r == 1 && as -> passnum == 2)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
238 register_error(as, l, 2, "Illegal external or intersegment reference");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
239
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
240 if (rval < -128 || rval > 255)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
241 register_error(as, l, 2, "Byte overflow");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
242 lwasm_emit(as, l, rval & 0xff);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
243 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
244 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
245
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
246 register_error(as, l, 1, "Bad operand");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
247 }