blob: 9093cf202d6695699bb0ad10d546b66779841e74 [file] [log] [blame]
H. Peter Anvin9e6747c2009-06-28 17:13:04 -07001/* ----------------------------------------------------------------------- *
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +03002 *
H. Peter Anvin164d2462017-02-20 02:39:56 -08003 * Copyright 1996-2017 The NASM Authors - All Rights Reserved
H. Peter Anvin9e6747c2009-06-28 17:13:04 -07004 * See the file AUTHORS included with the NASM distribution for
5 * the specific copyright holders.
H. Peter Anvinea6e34d2002-04-30 20:51:32 +00006 *
H. Peter Anvin9e6747c2009-06-28 17:13:04 -07007 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following
9 * conditions are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +030017 *
H. Peter Anvin9e6747c2009-06-28 17:13:04 -070018 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
19 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
20 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 * ----------------------------------------------------------------------- */
33
34/*
35 * parser.c source line parser for the Netwide Assembler
H. Peter Anvinea6e34d2002-04-30 20:51:32 +000036 */
37
H. Peter Anvinfe501952007-10-02 21:53:51 -070038#include "compiler.h"
39
H. Peter Anvinea6e34d2002-04-30 20:51:32 +000040#include <stdio.h>
41#include <stdlib.h>
42#include <stddef.h>
43#include <string.h>
44#include <ctype.h>
45
46#include "nasm.h"
H. Peter Anvin24cfef42002-09-12 16:34:06 +000047#include "insns.h"
H. Peter Anvinea6e34d2002-04-30 20:51:32 +000048#include "nasmlib.h"
H. Peter Anvinb20bc732017-03-07 19:23:03 -080049#include "error.h"
H. Peter Anvin74cc5e52007-08-30 22:35:34 +000050#include "stdscan.h"
H. Peter Anvin00444ae2009-07-18 18:49:55 -070051#include "eval.h"
H. Peter Anvinea6e34d2002-04-30 20:51:32 +000052#include "parser.h"
53#include "float.h"
H. Peter Anvinb20bc732017-03-07 19:23:03 -080054#include "assemble.h"
H. Peter Anvina4835d42008-05-20 14:21:29 -070055#include "tables.h"
H. Peter Anvinea6e34d2002-04-30 20:51:32 +000056
H. Peter Anvind0e365d2002-05-26 18:19:19 +000057
H. Peter Anvine2c80182005-01-15 22:15:51 +000058static int is_comma_next(void);
H. Peter Anvinea6e34d2002-04-30 20:51:32 +000059
H. Peter Anvinea6e34d2002-04-30 20:51:32 +000060static struct tokenval tokval;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +000061
Cyrill Gorcunov18914e62011-11-12 11:41:51 +040062static int prefix_slot(int prefix)
H. Peter Anvinde4b89b2007-10-01 15:41:25 -070063{
64 switch (prefix) {
H. Peter Anvinc2acf7b2009-02-21 18:22:56 -080065 case P_WAIT:
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +030066 return PPS_WAIT;
H. Peter Anvinde4b89b2007-10-01 15:41:25 -070067 case R_CS:
68 case R_DS:
69 case R_SS:
70 case R_ES:
71 case R_FS:
72 case R_GS:
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +030073 return PPS_SEG;
H. Peter Anvinde4b89b2007-10-01 15:41:25 -070074 case P_LOCK:
H. Peter Anvin10da41e2012-02-24 20:57:04 -080075 return PPS_LOCK;
H. Peter Anvinde4b89b2007-10-01 15:41:25 -070076 case P_REP:
77 case P_REPE:
78 case P_REPZ:
79 case P_REPNE:
80 case P_REPNZ:
H. Peter Anvin4ecd5d72012-02-24 21:51:46 -080081 case P_XACQUIRE:
82 case P_XRELEASE:
Jin Kyu Song03041092013-10-15 19:38:51 -070083 case P_BND:
Jin Kyu Songb287ff02013-12-04 20:05:55 -080084 case P_NOBND:
H. Peter Anvin10da41e2012-02-24 20:57:04 -080085 return PPS_REP;
H. Peter Anvinde4b89b2007-10-01 15:41:25 -070086 case P_O16:
87 case P_O32:
88 case P_O64:
89 case P_OSP:
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +030090 return PPS_OSIZE;
H. Peter Anvinde4b89b2007-10-01 15:41:25 -070091 case P_A16:
92 case P_A32:
93 case P_A64:
94 case P_ASP:
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +030095 return PPS_ASIZE;
Jin Kyu Song945b1b82013-10-25 19:29:53 -070096 case P_EVEX:
H. Peter Anvin621a69a2013-11-28 12:11:24 -080097 case P_VEX3:
98 case P_VEX2:
99 return PPS_VEX;
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700100 default:
H. Peter Anvin41087062016-03-03 14:27:34 -0800101 nasm_panic(0, "Invalid value %d passed to prefix_slot()", prefix);
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300102 return -1;
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700103 }
104}
105
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700106static void process_size_override(insn *result, operand *op)
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700107{
108 if (tasm_compatible_mode) {
H. Peter Anvin09dff8b2017-03-01 01:01:37 -0800109 switch (tokval.t_integer) {
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300110 /* For TASM compatibility a size override inside the
111 * brackets changes the size of the operand, not the
112 * address type of the operand as it does in standard
113 * NASM syntax. Hence:
114 *
115 * mov eax,[DWORD val]
116 *
117 * is valid syntax in TASM compatibility mode. Note that
118 * you lose the ability to override the default address
119 * type for the instruction, but we never use anything
120 * but 32-bit flat model addressing in our code.
121 */
122 case S_BYTE:
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700123 op->type |= BITS8;
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300124 break;
125 case S_WORD:
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700126 op->type |= BITS16;
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300127 break;
128 case S_DWORD:
129 case S_LONG:
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700130 op->type |= BITS32;
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300131 break;
132 case S_QWORD:
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700133 op->type |= BITS64;
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300134 break;
135 case S_TWORD:
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700136 op->type |= BITS80;
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300137 break;
138 case S_OWORD:
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700139 op->type |= BITS128;
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300140 break;
141 default:
142 nasm_error(ERR_NONFATAL,
143 "invalid operand size specification");
144 break;
145 }
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700146 } else {
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300147 /* Standard NASM compatible syntax */
H. Peter Anvin09dff8b2017-03-01 01:01:37 -0800148 switch (tokval.t_integer) {
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300149 case S_NOSPLIT:
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700150 op->eaflags |= EAF_TIMESTWO;
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300151 break;
152 case S_REL:
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700153 op->eaflags |= EAF_REL;
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300154 break;
155 case S_ABS:
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700156 op->eaflags |= EAF_ABS;
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300157 break;
158 case S_BYTE:
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700159 op->disp_size = 8;
160 op->eaflags |= EAF_BYTEOFFS;
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300161 break;
162 case P_A16:
163 case P_A32:
164 case P_A64:
165 if (result->prefixes[PPS_ASIZE] &&
166 result->prefixes[PPS_ASIZE] != tokval.t_integer)
167 nasm_error(ERR_NONFATAL,
168 "conflicting address size specifications");
169 else
170 result->prefixes[PPS_ASIZE] = tokval.t_integer;
171 break;
172 case S_WORD:
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700173 op->disp_size = 16;
174 op->eaflags |= EAF_WORDOFFS;
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300175 break;
176 case S_DWORD:
177 case S_LONG:
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700178 op->disp_size = 32;
179 op->eaflags |= EAF_WORDOFFS;
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300180 break;
181 case S_QWORD:
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700182 op->disp_size = 64;
183 op->eaflags |= EAF_WORDOFFS;
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300184 break;
185 default:
186 nasm_error(ERR_NONFATAL, "invalid size specification in"
187 " effective address");
188 break;
189 }
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700190 }
191}
192
Jin Kyu Song72018a22013-08-05 20:46:18 -0700193/*
194 * when two or more decorators follow a register operand,
195 * consecutive decorators are parsed here.
Jin Kyu Songf9a71e02013-08-21 19:29:09 -0700196 * opmask and zeroing decorators can be placed in any order.
Jin Kyu Song487f3522013-11-27 14:10:40 -0800197 * e.g. zmm1 {k2}{z} or zmm2 {z}{k3}
Jin Kyu Song72018a22013-08-05 20:46:18 -0700198 * decorator(s) are placed at the end of an operand.
199 */
200static bool parse_braces(decoflags_t *decoflags)
201{
202 int i;
203 bool recover = false;
204
205 i = tokval.t_type;
206 do {
207 if (i == TOKEN_OPMASK) {
208 if (*decoflags & OPMASK_MASK) {
Jin Kyu Songc9486b92013-10-28 17:07:57 -0700209 nasm_error(ERR_NONFATAL, "opmask k%"PRIu64" is already set",
Jin Kyu Song72018a22013-08-05 20:46:18 -0700210 *decoflags & OPMASK_MASK);
211 *decoflags &= ~OPMASK_MASK;
212 }
213 *decoflags |= VAL_OPMASK(nasm_regvals[tokval.t_integer]);
214 } else if (i == TOKEN_DECORATOR) {
215 switch (tokval.t_integer) {
216 case BRC_Z:
217 /*
218 * according to AVX512 spec, only zeroing/merging decorator
219 * is supported with opmask
220 */
221 *decoflags |= GEN_Z(0);
222 break;
Jin Kyu Songcc1dc9d2013-08-15 19:01:25 -0700223 default:
224 nasm_error(ERR_NONFATAL, "{%s} is not an expected decorator",
225 tokval.t_charptr);
226 break;
Jin Kyu Song72018a22013-08-05 20:46:18 -0700227 }
228 } else if (i == ',' || i == TOKEN_EOS){
229 break;
230 } else {
231 nasm_error(ERR_NONFATAL, "only a series of valid decorators"
232 " expected");
233 recover = true;
234 break;
235 }
236 i = stdscan(NULL, &tokval);
237 } while(1);
238
239 return recover;
240}
241
H. Peter Anvin9148fb52013-09-27 16:39:16 -0700242static int parse_mref(operand *op, const expr *e)
H. Peter Anvin9f4706f2013-09-26 17:28:39 -0700243{
244 int b, i, s; /* basereg, indexreg, scale */
245 int64_t o; /* offset */
246
H. Peter Anvin9148fb52013-09-27 16:39:16 -0700247 b = i = -1;
248 o = s = 0;
H. Peter Anvin164d2462017-02-20 02:39:56 -0800249 op->segment = op->wrt = NO_SEG;
H. Peter Anvin9f4706f2013-09-26 17:28:39 -0700250
251 if (e->type && e->type <= EXPR_REG_END) { /* this bit's a register */
252 bool is_gpr = is_class(REG_GPR,nasm_reg_flags[e->type]);
253
254 if (is_gpr && e->value == 1)
255 b = e->type; /* It can be basereg */
H. Peter Anvin472a7c12016-10-31 08:44:25 -0700256 else /* No, it has to be indexreg */
H. Peter Anvin9f4706f2013-09-26 17:28:39 -0700257 i = e->type, s = e->value;
258 e++;
259 }
260 if (e->type && e->type <= EXPR_REG_END) { /* it's a 2nd register */
261 bool is_gpr = is_class(REG_GPR,nasm_reg_flags[e->type]);
262
263 if (b != -1) /* If the first was the base, ... */
264 i = e->type, s = e->value; /* second has to be indexreg */
265
266 else if (!is_gpr || e->value != 1) {
267 /* If both want to be index */
268 nasm_error(ERR_NONFATAL,
269 "invalid effective address: two index registers");
270 return -1;
271 } else
272 b = e->type;
273 e++;
274 }
H. Peter Anvin164d2462017-02-20 02:39:56 -0800275
276 if (e->type) { /* is there an offset? */
H. Peter Anvin9f4706f2013-09-26 17:28:39 -0700277 if (e->type <= EXPR_REG_END) { /* in fact, is there an error? */
278 nasm_error(ERR_NONFATAL,
H. Peter Anvin164d2462017-02-20 02:39:56 -0800279 "invalid effective address: impossible register");
H. Peter Anvin9f4706f2013-09-26 17:28:39 -0700280 return -1;
281 } else {
282 if (e->type == EXPR_UNKNOWN) {
283 op->opflags |= OPFLAG_UNKNOWN;
284 o = 0; /* doesn't matter what */
H. Peter Anvin9f4706f2013-09-26 17:28:39 -0700285 while (e->type)
286 e++; /* go to the end of the line */
287 } else {
288 if (e->type == EXPR_SIMPLE) {
289 o = e->value;
290 e++;
291 }
292 if (e->type == EXPR_WRT) {
293 op->wrt = e->value;
294 e++;
H. Peter Anvin164d2462017-02-20 02:39:56 -0800295 }
H. Peter Anvin9f4706f2013-09-26 17:28:39 -0700296 /*
297 * Look for a segment base type.
298 */
H. Peter Anvin164d2462017-02-20 02:39:56 -0800299 for (; e->type; e++) {
300 if (!e->value)
301 continue;
302
303 if (e->type <= EXPR_REG_END) {
304 nasm_error(ERR_NONFATAL,
305 "invalid effective address: too many registers");
306 return -1;
307 } else if (e->type < EXPR_SEGBASE) {
308 nasm_error(ERR_NONFATAL,
309 "invalid effective address: bad subexpression type");
310 return -1;
311 } else if (e->value == 1) {
312 if (op->segment != NO_SEG) {
313 nasm_error(ERR_NONFATAL,
314 "invalid effective address: multiple base segments");
315 return -1;
316 }
317 op->segment = e->type - EXPR_SEGBASE;
318 } else if (e->value == -1 &&
319 e->type == location.segment + EXPR_SEGBASE &&
320 !(op->opflags & OPFLAG_RELATIVE)) {
321 op->opflags |= OPFLAG_RELATIVE;
322 } else {
323 nasm_error(ERR_NONFATAL,
324 "invalid effective address: impossible segment base multiplier");
325 return -1;
326 }
H. Peter Anvin9f4706f2013-09-26 17:28:39 -0700327 }
328 }
329 }
H. Peter Anvin9f4706f2013-09-26 17:28:39 -0700330 }
331
H. Peter Anvin164d2462017-02-20 02:39:56 -0800332 nasm_assert(!e->type); /* We should be at the end */
H. Peter Anvin9f4706f2013-09-26 17:28:39 -0700333
H. Peter Anvin9148fb52013-09-27 16:39:16 -0700334 op->basereg = b;
335 op->indexreg = i;
336 op->scale = s;
337 op->offset = o;
338 return 0;
339}
340
341static void mref_set_optype(operand *op)
342{
343 int b = op->basereg;
344 int i = op->indexreg;
345 int s = op->scale;
346
H. Peter Anvin9f4706f2013-09-26 17:28:39 -0700347 /* It is memory, but it can match any r/m operand */
348 op->type |= MEMORY_ANY;
349
350 if (b == -1 && (i == -1 || s == 0)) {
351 int is_rel = globalbits == 64 &&
352 !(op->eaflags & EAF_ABS) &&
353 ((globalrel &&
354 !(op->eaflags & EAF_FSGS)) ||
355 (op->eaflags & EAF_REL));
356
357 op->type |= is_rel ? IP_REL : MEM_OFFS;
358 }
359
360 if (i != -1) {
361 opflags_t iclass = nasm_reg_flags[i];
362
363 if (is_class(XMMREG,iclass))
364 op->type |= XMEM;
365 else if (is_class(YMMREG,iclass))
366 op->type |= YMEM;
367 else if (is_class(ZMMREG,iclass))
368 op->type |= ZMEM;
369 }
H. Peter Anvin9f4706f2013-09-26 17:28:39 -0700370}
371
H. Peter Anvin472a7c12016-10-31 08:44:25 -0700372/*
373 * Convert an expression vector returned from evaluate() into an
374 * extop structure. Return zero on success.
375 */
376static int value_to_extop(expr * vect, extop *eop, int32_t myseg)
377{
378 eop->type = EOT_DB_NUMBER;
379 eop->offset = 0;
380 eop->segment = eop->wrt = NO_SEG;
381 eop->relative = false;
382
383 for (; vect->type; vect++) {
384 if (!vect->value) /* zero term, safe to ignore */
385 continue;
386
Cyrill Gorcunovfd610f22016-11-28 23:57:08 +0300387 if (vect->type <= EXPR_REG_END) /* false if a register is present */
H. Peter Anvin472a7c12016-10-31 08:44:25 -0700388 return -1;
389
390 if (vect->type == EXPR_UNKNOWN) /* something we can't resolve yet */
391 return 0;
392
393 if (vect->type == EXPR_SIMPLE) {
394 /* Simple number expression */
395 eop->offset += vect->value;
396 continue;
397 }
398 if (eop->wrt == NO_SEG && !eop->relative && vect->type == EXPR_WRT) {
399 /* WRT term */
400 eop->wrt = vect->value;
401 continue;
402 }
403
H. Peter Anvind97ccee2017-02-21 11:31:35 -0800404 if (!eop->relative &&
H. Peter Anvin472a7c12016-10-31 08:44:25 -0700405 vect->type == EXPR_SEGBASE + myseg && vect->value == -1) {
406 /* Expression of the form: foo - $ */
407 eop->relative = true;
408 continue;
409 }
410
411 if (eop->segment == NO_SEG && vect->type >= EXPR_SEGBASE &&
412 vect->value == 1) {
413 eop->segment = vect->type - EXPR_SEGBASE;
414 continue;
415 }
416
417 /* Otherwise, badness */
418 return -1;
419 }
420
421 /* We got to the end and it was all okay */
422 return 0;
423}
424
H. Peter Anvin00444ae2009-07-18 18:49:55 -0700425insn *parse_line(int pass, char *buffer, insn *result, ldfunc ldef)
H. Peter Anvineba20a72002-04-30 20:53:55 +0000426{
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400427 bool insn_is_label = false;
428 struct eval_hints hints;
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700429 int opnum;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000430 int critical;
H. Peter Anvin9c987692007-11-04 21:09:32 -0800431 bool first;
H. Peter Anvin552bc2c2009-06-23 11:34:42 -0700432 bool recover;
Martin Lindhe58f37c12016-11-16 16:43:16 +0100433 int i;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000434
H. Peter Anvin9c987692007-11-04 21:09:32 -0800435restart_parse:
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400436 first = true;
437 result->forw_ref = false;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000438
H. Peter Anvin76690a12002-04-30 20:52:49 +0000439 stdscan_reset();
Cyrill Gorcunov917117f2009-10-29 23:09:18 +0300440 stdscan_set(buffer);
H. Peter Anvin76690a12002-04-30 20:52:49 +0000441 i = stdscan(NULL, &tokval);
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000442
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400443 result->label = NULL; /* Assume no label */
444 result->eops = NULL; /* must do this, whatever happens */
445 result->operands = 0; /* must initialize this */
Jin Kyu Songe3a06b92013-08-28 19:15:23 -0700446 result->evex_rm = 0; /* Ensure EVEX rounding mode is reset */
447 result->evex_brerop = -1; /* Reset EVEX broadcasting/ER op position */
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000448
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400449 /* Ignore blank lines */
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700450 if (i == TOKEN_EOS)
451 goto fail;
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400452
Cyrill Gorcunov5abbe372011-08-28 18:49:00 +0400453 if (i != TOKEN_ID &&
454 i != TOKEN_INSN &&
455 i != TOKEN_PREFIX &&
456 (i != TOKEN_REG || !IS_SREG(tokval.t_integer))) {
457 nasm_error(ERR_NONFATAL,
458 "label or instruction expected at start of line");
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700459 goto fail;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000460 }
461
H. Peter Anvin9c987692007-11-04 21:09:32 -0800462 if (i == TOKEN_ID || (insn_is_label && i == TOKEN_INSN)) {
463 /* there's a label here */
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300464 first = false;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000465 result->label = tokval.t_charptr;
466 i = stdscan(NULL, &tokval);
467 if (i == ':') { /* skip over the optional colon */
468 i = stdscan(NULL, &tokval);
469 } else if (i == 0) {
H. Peter Anvin00444ae2009-07-18 18:49:55 -0700470 nasm_error(ERR_WARNING | ERR_WARN_OL | ERR_PASS1,
H. Peter Anvine2c80182005-01-15 22:15:51 +0000471 "label alone on a line without a colon might be in error");
472 }
473 if (i != TOKEN_INSN || tokval.t_integer != I_EQU) {
474 /*
H. Peter Anvincd7893d2016-02-18 01:25:46 -0800475 * FIXME: location.segment could be NO_SEG, in which case
H. Peter Anvinb20bc732017-03-07 19:23:03 -0800476 * it is possible we should be passing 'absolute.segment'. Look into this.
H. Peter Anvine2c80182005-01-15 22:15:51 +0000477 * Work out whether that is *really* what we should be doing.
478 * Generally fix things. I think this is right as it is, but
479 * am still not certain.
480 */
H. Peter Anvinb20bc732017-03-07 19:23:03 -0800481 ldef(result->label, in_absolute ? absolute.segment : location.segment,
H. Peter Anvincd7893d2016-02-18 01:25:46 -0800482 location.offset, NULL, true, false);
H. Peter Anvine2c80182005-01-15 22:15:51 +0000483 }
H. Peter Anvineba20a72002-04-30 20:53:55 +0000484 }
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000485
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400486 /* Just a label here */
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700487 if (i == TOKEN_EOS)
488 goto fail;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000489
H. Peter Anvin94e40522017-01-24 12:26:09 -0800490 nasm_static_assert(P_none == 0);
Cyrill Gorcunov836492f2013-07-16 01:33:09 +0400491 memset(result->prefixes, P_none, sizeof(result->prefixes));
H. Peter Anvind7ed89e2002-04-30 20:52:08 +0000492 result->times = 1L;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000493
494 while (i == TOKEN_PREFIX ||
Cyrill Gorcunov5abbe372011-08-28 18:49:00 +0400495 (i == TOKEN_REG && IS_SREG(tokval.t_integer))) {
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300496 first = false;
H. Peter Anvin9c987692007-11-04 21:09:32 -0800497
H. Peter Anvine2c80182005-01-15 22:15:51 +0000498 /*
499 * Handle special case: the TIMES prefix.
500 */
501 if (i == TOKEN_PREFIX && tokval.t_integer == P_TIMES) {
502 expr *value;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000503
H. Peter Anvine2c80182005-01-15 22:15:51 +0000504 i = stdscan(NULL, &tokval);
H. Peter Anvin130736c2016-02-17 20:27:41 -0800505 value = evaluate(stdscan, NULL, &tokval, NULL, pass0, NULL);
H. Peter Anvine2c80182005-01-15 22:15:51 +0000506 i = tokval.t_type;
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700507 if (!value) /* Error in evaluator */
508 goto fail;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000509 if (!is_simple(value)) {
H. Peter Anvin00444ae2009-07-18 18:49:55 -0700510 nasm_error(ERR_NONFATAL,
H. Peter Anvine2c80182005-01-15 22:15:51 +0000511 "non-constant argument supplied to TIMES");
512 result->times = 1L;
513 } else {
514 result->times = value->value;
Charles Crayne7f596e72008-09-23 21:49:09 -0700515 if (value->value < 0 && pass0 == 2) {
Victor van den Elzen15bb2332009-08-11 02:10:16 +0200516 nasm_error(ERR_NONFATAL, "TIMES value %"PRId64" is negative",
H. Peter Anvine2c80182005-01-15 22:15:51 +0000517 value->value);
518 result->times = 0;
519 }
520 }
521 } else {
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300522 int slot = prefix_slot(tokval.t_integer);
523 if (result->prefixes[slot]) {
Charles Crayne052c0bd2007-10-29 18:24:59 -0700524 if (result->prefixes[slot] == tokval.t_integer)
Victor van den Elzend55a1582010-11-07 23:47:13 +0100525 nasm_error(ERR_WARNING | ERR_PASS1,
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300526 "instruction has redundant prefixes");
Charles Crayne052c0bd2007-10-29 18:24:59 -0700527 else
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300528 nasm_error(ERR_NONFATAL,
529 "instruction has conflicting prefixes");
530 }
531 result->prefixes[slot] = tokval.t_integer;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000532 i = stdscan(NULL, &tokval);
533 }
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000534 }
535
536 if (i != TOKEN_INSN) {
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300537 int j;
538 enum prefixes pfx;
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700539
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400540 for (j = 0; j < MAXPREFIX; j++) {
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300541 if ((pfx = result->prefixes[j]) != P_none)
542 break;
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400543 }
H. Peter Anvincb583b92007-10-28 22:04:42 -0700544
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700545 if (i == 0 && pfx != P_none) {
H. Peter Anvine2c80182005-01-15 22:15:51 +0000546 /*
547 * Instruction prefixes are present, but no actual
548 * instruction. This is allowed: at this point we
549 * invent a notional instruction of RESB 0.
550 */
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400551 result->opcode = I_RESB;
552 result->operands = 1;
H. Peter Anvin1980abf2017-03-31 14:52:03 -0700553 nasm_zero(result->oprs);
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400554 result->oprs[0].type = IMMEDIATE;
555 result->oprs[0].offset = 0L;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000556 result->oprs[0].segment = result->oprs[0].wrt = NO_SEG;
557 return result;
558 } else {
H. Peter Anvin00444ae2009-07-18 18:49:55 -0700559 nasm_error(ERR_NONFATAL, "parser: instruction expected");
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700560 goto fail;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000561 }
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000562 }
563
564 result->opcode = tokval.t_integer;
565 result->condition = tokval.t_inttwo;
566
567 /*
Charles Crayne2581c862008-09-10 19:21:52 -0700568 * INCBIN cannot be satisfied with incorrectly
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000569 * evaluated operands, since the correct values _must_ be known
570 * on the first pass. Hence, even in pass one, we set the
571 * `critical' flag on calling evaluate(), so that it will bomb
Charles Crayne2581c862008-09-10 19:21:52 -0700572 * out on undefined symbols.
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000573 */
Charles Crayne2581c862008-09-10 19:21:52 -0700574 if (result->opcode == I_INCBIN) {
Charles Crayne5a7976c2008-03-26 17:20:21 -0700575 critical = (pass0 < 2 ? 1 : 2);
576
H. Peter Anvine2c80182005-01-15 22:15:51 +0000577 } else
578 critical = (pass == 2 ? 2 : 0);
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000579
H. Peter Anvin41c9f6f2007-09-18 13:01:32 -0700580 if (result->opcode == I_DB || result->opcode == I_DW ||
581 result->opcode == I_DD || result->opcode == I_DQ ||
582 result->opcode == I_DT || result->opcode == I_DO ||
H. Peter Anvin9d546102013-10-02 18:25:19 -0700583 result->opcode == I_DY || result->opcode == I_DZ ||
584 result->opcode == I_INCBIN) {
H. Peter Anvine2c80182005-01-15 22:15:51 +0000585 extop *eop, **tail = &result->eops, **fixptr;
586 int oper_num = 0;
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300587 int32_t sign;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000588
H. Peter Anvin6867acc2007-10-10 14:58:45 -0700589 result->eops_float = false;
H. Peter Anvineba20a72002-04-30 20:53:55 +0000590
H. Peter Anvine2c80182005-01-15 22:15:51 +0000591 /*
H. Peter Anvin9d546102013-10-02 18:25:19 -0700592 * Begin to read the DB/DW/DD/DQ/DT/DO/DY/DZ/INCBIN operands.
H. Peter Anvine2c80182005-01-15 22:15:51 +0000593 */
594 while (1) {
595 i = stdscan(NULL, &tokval);
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400596 if (i == TOKEN_EOS)
H. Peter Anvine2c80182005-01-15 22:15:51 +0000597 break;
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300598 else if (first && i == ':') {
599 insn_is_label = true;
600 goto restart_parse;
601 }
602 first = false;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000603 fixptr = tail;
604 eop = *tail = nasm_malloc(sizeof(extop));
605 tail = &eop->next;
606 eop->next = NULL;
607 eop->type = EOT_NOTHING;
608 oper_num++;
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300609 sign = +1;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000610
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300611 /*
612 * is_comma_next() here is to distinguish this from
613 * a string used as part of an expression...
614 */
H. Peter Anvin11627042008-06-09 20:45:19 -0700615 if (i == TOKEN_STR && is_comma_next()) {
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400616 eop->type = EOT_DB_STRING;
617 eop->stringval = tokval.t_charptr;
618 eop->stringlen = tokval.t_inttwo;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000619 i = stdscan(NULL, &tokval); /* eat the comma */
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300620 } else if (i == TOKEN_STRFUNC) {
621 bool parens = false;
622 const char *funcname = tokval.t_charptr;
623 enum strfunc func = tokval.t_integer;
624 i = stdscan(NULL, &tokval);
625 if (i == '(') {
626 parens = true;
627 i = stdscan(NULL, &tokval);
628 }
629 if (i != TOKEN_STR) {
630 nasm_error(ERR_NONFATAL,
631 "%s must be followed by a string constant",
632 funcname);
633 eop->type = EOT_NOTHING;
634 } else {
635 eop->type = EOT_DB_STRING_FREE;
636 eop->stringlen =
637 string_transform(tokval.t_charptr, tokval.t_inttwo,
638 &eop->stringval, func);
639 if (eop->stringlen == (size_t)-1) {
640 nasm_error(ERR_NONFATAL, "invalid string for transform");
641 eop->type = EOT_NOTHING;
642 }
643 }
644 if (parens && i && i != ')') {
645 i = stdscan(NULL, &tokval);
646 if (i != ')') {
647 nasm_error(ERR_NONFATAL, "unterminated %s function",
648 funcname);
649 }
650 }
651 if (i && i != ',')
652 i = stdscan(NULL, &tokval);
653 } else if (i == '-' || i == '+') {
654 char *save = stdscan_get();
655 int token = i;
656 sign = (i == '-') ? -1 : 1;
657 i = stdscan(NULL, &tokval);
658 if (i != TOKEN_FLOAT) {
659 stdscan_set(save);
660 i = tokval.t_type = token;
661 goto is_expression;
662 } else {
663 goto is_float;
664 }
H. Peter Anvin518df302008-06-14 16:53:48 -0700665 } else if (i == TOKEN_FLOAT) {
Cyrill Gorcunovbafd8772009-10-31 20:02:14 +0300666is_float:
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300667 eop->type = EOT_DB_STRING;
668 result->eops_float = true;
Cyrill Gorcunovbafd8772009-10-31 20:02:14 +0300669
670 eop->stringlen = idata_bytes(result->opcode);
671 if (eop->stringlen > 16) {
672 nasm_error(ERR_NONFATAL, "floating-point constant"
H. Peter Anvin9d546102013-10-02 18:25:19 -0700673 " encountered in DY or DZ instruction");
Cyrill Gorcunovbafd8772009-10-31 20:02:14 +0300674 eop->stringlen = 0;
675 } else if (eop->stringlen < 1) {
676 nasm_error(ERR_NONFATAL, "floating-point constant"
677 " encountered in unknown instruction");
678 /*
679 * fix suggested by Pedro Gimeno... original line was:
680 * eop->type = EOT_NOTHING;
681 */
682 eop->stringlen = 0;
683 }
684
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300685 eop = nasm_realloc(eop, sizeof(extop) + eop->stringlen);
686 tail = &eop->next;
687 *fixptr = eop;
688 eop->stringval = (char *)eop + sizeof(extop);
689 if (!eop->stringlen ||
690 !float_const(tokval.t_charptr, sign,
H. Peter Anvin130736c2016-02-17 20:27:41 -0800691 (uint8_t *)eop->stringval, eop->stringlen))
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300692 eop->type = EOT_NOTHING;
693 i = stdscan(NULL, &tokval); /* eat the comma */
694 } else {
695 /* anything else, assume it is an expression */
H. Peter Anvine2c80182005-01-15 22:15:51 +0000696 expr *value;
H. Peter Anvin518df302008-06-14 16:53:48 -0700697
Cyrill Gorcunovbafd8772009-10-31 20:02:14 +0300698is_expression:
H. Peter Anvine2c80182005-01-15 22:15:51 +0000699 value = evaluate(stdscan, NULL, &tokval, NULL,
H. Peter Anvin130736c2016-02-17 20:27:41 -0800700 critical, NULL);
H. Peter Anvine2c80182005-01-15 22:15:51 +0000701 i = tokval.t_type;
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700702 if (!value) /* Error in evaluator */
703 goto fail;
H. Peter Anvin472a7c12016-10-31 08:44:25 -0700704 if (value_to_extop(value, eop, location.segment)) {
H. Peter Anvin00444ae2009-07-18 18:49:55 -0700705 nasm_error(ERR_NONFATAL,
H. Peter Anvin472a7c12016-10-31 08:44:25 -0700706 "operand %d: expression is not simple or relocatable",
707 oper_num);
H. Peter Anvine2c80182005-01-15 22:15:51 +0000708 }
709 }
H. Peter Anvin6768eb72002-04-30 20:52:26 +0000710
H. Peter Anvine2c80182005-01-15 22:15:51 +0000711 /*
712 * We're about to call stdscan(), which will eat the
713 * comma that we're currently sitting on between
714 * arguments. However, we'd better check first that it
715 * _is_ a comma.
716 */
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400717 if (i == TOKEN_EOS) /* also could be EOL */
H. Peter Anvine2c80182005-01-15 22:15:51 +0000718 break;
719 if (i != ',') {
H. Peter Anvin00444ae2009-07-18 18:49:55 -0700720 nasm_error(ERR_NONFATAL, "comma expected after operand %d",
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400721 oper_num);
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700722 goto fail;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000723 }
724 }
H. Peter Anvind7ed89e2002-04-30 20:52:08 +0000725
H. Peter Anvine2c80182005-01-15 22:15:51 +0000726 if (result->opcode == I_INCBIN) {
727 /*
728 * Correct syntax for INCBIN is that there should be
729 * one string operand, followed by one or two numeric
730 * operands.
731 */
732 if (!result->eops || result->eops->type != EOT_DB_STRING)
H. Peter Anvin00444ae2009-07-18 18:49:55 -0700733 nasm_error(ERR_NONFATAL, "`incbin' expects a file name");
H. Peter Anvine2c80182005-01-15 22:15:51 +0000734 else if (result->eops->next &&
735 result->eops->next->type != EOT_DB_NUMBER)
Victor van den Elzen15bb2332009-08-11 02:10:16 +0200736 nasm_error(ERR_NONFATAL, "`incbin': second parameter is"
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400737 " non-numeric");
H. Peter Anvine2c80182005-01-15 22:15:51 +0000738 else if (result->eops->next && result->eops->next->next &&
739 result->eops->next->next->type != EOT_DB_NUMBER)
Victor van den Elzen15bb2332009-08-11 02:10:16 +0200740 nasm_error(ERR_NONFATAL, "`incbin': third parameter is"
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400741 " non-numeric");
H. Peter Anvine2c80182005-01-15 22:15:51 +0000742 else if (result->eops->next && result->eops->next->next &&
743 result->eops->next->next->next)
H. Peter Anvin00444ae2009-07-18 18:49:55 -0700744 nasm_error(ERR_NONFATAL,
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400745 "`incbin': more than three parameters");
H. Peter Anvineba20a72002-04-30 20:53:55 +0000746 else
H. Peter Anvine2c80182005-01-15 22:15:51 +0000747 return result;
748 /*
749 * If we reach here, one of the above errors happened.
750 * Throw the instruction away.
751 */
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700752 goto fail;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000753 } else /* DB ... */ if (oper_num == 0)
H. Peter Anvin00444ae2009-07-18 18:49:55 -0700754 nasm_error(ERR_WARNING | ERR_PASS1,
H. Peter Anvine2c80182005-01-15 22:15:51 +0000755 "no operand for data declaration");
756 else
757 result->operands = oper_num;
H. Peter Anvind7ed89e2002-04-30 20:52:08 +0000758
H. Peter Anvine2c80182005-01-15 22:15:51 +0000759 return result;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000760 }
761
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400762 /*
763 * Now we begin to parse the operands. There may be up to four
764 * of these, separated by commas, and terminated by a zero token.
765 */
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000766
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700767 for (opnum = 0; opnum < MAX_OPERANDS; opnum++) {
768 operand *op = &result->oprs[opnum];
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300769 expr *value; /* used most of the time */
H. Peter Anvin9148fb52013-09-27 16:39:16 -0700770 bool mref; /* is this going to be a memory ref? */
771 bool bracket; /* is it a [] mref, or a & mref? */
772 bool mib; /* compound (mib) mref? */
H. Peter Anvine2c80182005-01-15 22:15:51 +0000773 int setsize = 0;
Jin Kyu Song72018a22013-08-05 20:46:18 -0700774 decoflags_t brace_flags = 0; /* flags for decorators in braces */
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000775
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700776 op->disp_size = 0; /* have to zero this whatever */
777 op->eaflags = 0; /* and this */
778 op->opflags = 0;
779 op->decoflags = 0;
H. Peter Anvineba20a72002-04-30 20:53:55 +0000780
H. Peter Anvine2c80182005-01-15 22:15:51 +0000781 i = stdscan(NULL, &tokval);
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400782 if (i == TOKEN_EOS)
H. Peter Anvine2c80182005-01-15 22:15:51 +0000783 break; /* end of operands: get out of here */
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300784 else if (first && i == ':') {
785 insn_is_label = true;
786 goto restart_parse;
787 }
788 first = false;
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700789 op->type = 0; /* so far, no override */
H. Peter Anvine2c80182005-01-15 22:15:51 +0000790 while (i == TOKEN_SPECIAL) { /* size specifiers */
H. Peter Anvin09dff8b2017-03-01 01:01:37 -0800791 switch (tokval.t_integer) {
H. Peter Anvine2c80182005-01-15 22:15:51 +0000792 case S_BYTE:
793 if (!setsize) /* we want to use only the first */
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700794 op->type |= BITS8;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000795 setsize = 1;
796 break;
797 case S_WORD:
798 if (!setsize)
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700799 op->type |= BITS16;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000800 setsize = 1;
801 break;
802 case S_DWORD:
803 case S_LONG:
804 if (!setsize)
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700805 op->type |= BITS32;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000806 setsize = 1;
807 break;
808 case S_QWORD:
809 if (!setsize)
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700810 op->type |= BITS64;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000811 setsize = 1;
812 break;
813 case S_TWORD:
814 if (!setsize)
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700815 op->type |= BITS80;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000816 setsize = 1;
817 break;
H. Peter Anvin41c9f6f2007-09-18 13:01:32 -0700818 case S_OWORD:
819 if (!setsize)
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700820 op->type |= BITS128;
H. Peter Anvin41c9f6f2007-09-18 13:01:32 -0700821 setsize = 1;
822 break;
H. Peter Anvindfb91802008-05-20 11:43:53 -0700823 case S_YWORD:
824 if (!setsize)
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700825 op->type |= BITS256;
H. Peter Anvindfb91802008-05-20 11:43:53 -0700826 setsize = 1;
827 break;
Jin Kyu Songd4760c12013-08-21 19:29:11 -0700828 case S_ZWORD:
829 if (!setsize)
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700830 op->type |= BITS512;
Jin Kyu Songd4760c12013-08-21 19:29:11 -0700831 setsize = 1;
832 break;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000833 case S_TO:
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700834 op->type |= TO;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000835 break;
836 case S_STRICT:
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700837 op->type |= STRICT;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000838 break;
839 case S_FAR:
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700840 op->type |= FAR;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000841 break;
842 case S_NEAR:
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700843 op->type |= NEAR;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000844 break;
845 case S_SHORT:
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700846 op->type |= SHORT;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000847 break;
848 default:
H. Peter Anvin00444ae2009-07-18 18:49:55 -0700849 nasm_error(ERR_NONFATAL, "invalid operand size specification");
H. Peter Anvine2c80182005-01-15 22:15:51 +0000850 }
851 i = stdscan(NULL, &tokval);
852 }
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000853
H. Peter Anvine2c80182005-01-15 22:15:51 +0000854 if (i == '[' || i == '&') { /* memory reference */
H. Peter Anvin6867acc2007-10-10 14:58:45 -0700855 mref = true;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000856 bracket = (i == '[');
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700857 i = stdscan(NULL, &tokval); /* then skip the colon */
858 while (i == TOKEN_SPECIAL || i == TOKEN_PREFIX) {
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700859 process_size_override(result, op);
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700860 i = stdscan(NULL, &tokval);
H. Peter Anvine2c80182005-01-15 22:15:51 +0000861 }
Jin Kyu Song164d6072013-10-15 19:10:13 -0700862 /* when a comma follows an opening bracket - [ , eax*4] */
863 if (i == ',') {
864 /* treat as if there is a zero displacement virtually */
865 tokval.t_type = TOKEN_NUM;
866 tokval.t_integer = 0;
867 stdscan_set(stdscan_get() - 1); /* rewind the comma */
868 }
H. Peter Anvine2c80182005-01-15 22:15:51 +0000869 } else { /* immediate operand, or register */
H. Peter Anvin6867acc2007-10-10 14:58:45 -0700870 mref = false;
871 bracket = false; /* placate optimisers */
H. Peter Anvine2c80182005-01-15 22:15:51 +0000872 }
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000873
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700874 if ((op->type & FAR) && !mref &&
H. Peter Anvine2c80182005-01-15 22:15:51 +0000875 result->opcode != I_JMP && result->opcode != I_CALL) {
H. Peter Anvin00444ae2009-07-18 18:49:55 -0700876 nasm_error(ERR_NONFATAL, "invalid use of FAR operand specifier");
H. Peter Anvine2c80182005-01-15 22:15:51 +0000877 }
Debbie Wiles63b53f72002-06-04 19:31:24 +0000878
H. Peter Anvine2c80182005-01-15 22:15:51 +0000879 value = evaluate(stdscan, NULL, &tokval,
H. Peter Anvin130736c2016-02-17 20:27:41 -0800880 &op->opflags, critical, &hints);
H. Peter Anvine2c80182005-01-15 22:15:51 +0000881 i = tokval.t_type;
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700882 if (op->opflags & OPFLAG_FORWARD) {
H. Peter Anvin6867acc2007-10-10 14:58:45 -0700883 result->forw_ref = true;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000884 }
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700885 if (!value) /* Error in evaluator */
886 goto fail;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000887 if (i == ':' && mref) { /* it was seg:offset */
888 /*
889 * Process the segment override.
890 */
Cyrill Gorcunov5abbe372011-08-28 18:49:00 +0400891 if (value[1].type != 0 ||
892 value->value != 1 ||
893 !IS_SREG(value->type))
H. Peter Anvin00444ae2009-07-18 18:49:55 -0700894 nasm_error(ERR_NONFATAL, "invalid segment override");
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700895 else if (result->prefixes[PPS_SEG])
H. Peter Anvin00444ae2009-07-18 18:49:55 -0700896 nasm_error(ERR_NONFATAL,
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700897 "instruction has conflicting segment overrides");
H. Peter Anvin99c4ecd2007-08-28 23:06:00 +0000898 else {
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300899 result->prefixes[PPS_SEG] = value->type;
Cyrill Gorcunov5abbe372011-08-28 18:49:00 +0400900 if (IS_FSGS(value->type))
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700901 op->eaflags |= EAF_FSGS;
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300902 }
H. Peter Anvin76690a12002-04-30 20:52:49 +0000903
H. Peter Anvine2c80182005-01-15 22:15:51 +0000904 i = stdscan(NULL, &tokval); /* then skip the colon */
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700905 while (i == TOKEN_SPECIAL || i == TOKEN_PREFIX) {
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700906 process_size_override(result, op);
H. Peter Anvine2c80182005-01-15 22:15:51 +0000907 i = stdscan(NULL, &tokval);
908 }
909 value = evaluate(stdscan, NULL, &tokval,
H. Peter Anvin130736c2016-02-17 20:27:41 -0800910 &op->opflags, critical, &hints);
H. Peter Anvine2c80182005-01-15 22:15:51 +0000911 i = tokval.t_type;
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700912 if (op->opflags & OPFLAG_FORWARD) {
H. Peter Anvin6867acc2007-10-10 14:58:45 -0700913 result->forw_ref = true;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000914 }
915 /* and get the offset */
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700916 if (!value) /* Error in evaluator */
917 goto fail;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000918 }
Victor van den Elzen02846d32009-06-23 03:47:07 +0200919
H. Peter Anvin9148fb52013-09-27 16:39:16 -0700920 mib = false;
921 if (mref && bracket && i == ',') {
922 /* [seg:base+offset,index*scale] syntax (mib) */
923
924 operand o1, o2; /* Partial operands */
925
926 if (parse_mref(&o1, value))
927 goto fail;
928
929 i = stdscan(NULL, &tokval); /* Eat comma */
930 value = evaluate(stdscan, NULL, &tokval, &op->opflags,
H. Peter Anvin130736c2016-02-17 20:27:41 -0800931 critical, &hints);
H. Peter Anvin9148fb52013-09-27 16:39:16 -0700932 i = tokval.t_type;
Cyrill Gorcunov5c0b0822014-11-22 18:20:29 +0300933 if (!value)
934 goto fail;
H. Peter Anvin9148fb52013-09-27 16:39:16 -0700935
936 if (parse_mref(&o2, value))
937 goto fail;
938
939 if (o2.basereg != -1 && o2.indexreg == -1) {
940 o2.indexreg = o2.basereg;
941 o2.scale = 1;
942 o2.basereg = -1;
943 }
944
945 if (o1.indexreg != -1 || o2.basereg != -1 || o2.offset != 0 ||
946 o2.segment != NO_SEG || o2.wrt != NO_SEG) {
947 nasm_error(ERR_NONFATAL, "invalid mib expression");
948 goto fail;
949 }
950
951 op->basereg = o1.basereg;
952 op->indexreg = o2.indexreg;
953 op->scale = o2.scale;
954 op->offset = o1.offset;
955 op->segment = o1.segment;
956 op->wrt = o1.wrt;
957
958 if (op->basereg != -1) {
959 op->hintbase = op->basereg;
960 op->hinttype = EAH_MAKEBASE;
961 } else if (op->indexreg != -1) {
962 op->hintbase = op->indexreg;
963 op->hinttype = EAH_NOTBASE;
964 } else {
965 op->hintbase = -1;
966 op->hinttype = EAH_NOHINT;
967 }
968
969 mib = true;
970 }
971
H. Peter Anvin552bc2c2009-06-23 11:34:42 -0700972 recover = false;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000973 if (mref && bracket) { /* find ] at the end */
974 if (i != ']') {
H. Peter Anvin00444ae2009-07-18 18:49:55 -0700975 nasm_error(ERR_NONFATAL, "parser: expecting ]");
Victor van den Elzen02846d32009-06-23 03:47:07 +0200976 recover = true;
977 } else { /* we got the required ] */
H. Peter Anvine2c80182005-01-15 22:15:51 +0000978 i = stdscan(NULL, &tokval);
H. Peter Anvinc33d95f2017-03-31 14:37:24 -0700979 if (i == TOKEN_DECORATOR || i == TOKEN_OPMASK) {
980 /* parse opmask (and zeroing) after an operand */
981 recover = parse_braces(&brace_flags);
982 i = tokval.t_type;
Jin Kyu Song72018a22013-08-05 20:46:18 -0700983 }
Victor van den Elzen02846d32009-06-23 03:47:07 +0200984 if (i != 0 && i != ',') {
H. Peter Anvin00444ae2009-07-18 18:49:55 -0700985 nasm_error(ERR_NONFATAL, "comma or end of line expected");
Victor van den Elzen02846d32009-06-23 03:47:07 +0200986 recover = true;
987 }
988 }
H. Peter Anvine2c80182005-01-15 22:15:51 +0000989 } else { /* immediate operand */
Jin Kyu Song72018a22013-08-05 20:46:18 -0700990 if (i != 0 && i != ',' && i != ':' &&
991 i != TOKEN_DECORATOR && i != TOKEN_OPMASK) {
992 nasm_error(ERR_NONFATAL, "comma, colon, decorator or end of "
993 "line expected after operand");
Victor van den Elzen02846d32009-06-23 03:47:07 +0200994 recover = true;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000995 } else if (i == ':') {
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700996 op->type |= COLON;
Jin Kyu Song72018a22013-08-05 20:46:18 -0700997 } else if (i == TOKEN_DECORATOR || i == TOKEN_OPMASK) {
998 /* parse opmask (and zeroing) after an operand */
999 recover = parse_braces(&brace_flags);
H. Peter Anvine2c80182005-01-15 22:15:51 +00001000 }
1001 }
Victor van den Elzen02846d32009-06-23 03:47:07 +02001002 if (recover) {
1003 do { /* error recovery */
1004 i = stdscan(NULL, &tokval);
1005 } while (i != 0 && i != ',');
1006 }
H. Peter Anvinea6e34d2002-04-30 20:51:32 +00001007
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +03001008 /*
1009 * now convert the exprs returned from evaluate()
1010 * into operand descriptions...
1011 */
H. Peter Anvin9148fb52013-09-27 16:39:16 -07001012 op->decoflags |= brace_flags;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +00001013
H. Peter Anvine2c80182005-01-15 22:15:51 +00001014 if (mref) { /* it's a memory reference */
H. Peter Anvin9148fb52013-09-27 16:39:16 -07001015 /* A mib reference was fully parsed already */
1016 if (!mib) {
1017 if (parse_mref(op, value))
1018 goto fail;
1019 op->hintbase = hints.base;
1020 op->hinttype = hints.type;
1021 }
1022 mref_set_optype(op);
H. Peter Anvine2c80182005-01-15 22:15:51 +00001023 } else { /* it's not a memory reference */
H. Peter Anvine2c80182005-01-15 22:15:51 +00001024 if (is_just_unknown(value)) { /* it's immediate but unknown */
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001025 op->type |= IMMEDIATE;
1026 op->opflags |= OPFLAG_UNKNOWN;
1027 op->offset = 0; /* don't care */
1028 op->segment = NO_SEG; /* don't care again */
1029 op->wrt = NO_SEG; /* still don't care */
Victor van den Elzen154e5922009-02-25 17:32:00 +01001030
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001031 if(optimizing >= 0 && !(op->type & STRICT)) {
Cyrill Gorcunov210c1012009-11-01 10:24:48 +03001032 /* Be optimistic */
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001033 op->type |=
Ben Rudiak-Gould4e8396b2013-03-01 10:28:32 +04001034 UNITY | SBYTEWORD | SBYTEDWORD | UDWORD | SDWORD;
Cyrill Gorcunov210c1012009-11-01 10:24:48 +03001035 }
H. Peter Anvine2c80182005-01-15 22:15:51 +00001036 } else if (is_reloc(value)) { /* it's immediate */
H. Peter Anvin87646092017-02-28 17:44:24 -08001037 uint64_t n = reloc_value(value);
1038
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001039 op->type |= IMMEDIATE;
H. Peter Anvin87646092017-02-28 17:44:24 -08001040 op->offset = n;
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001041 op->segment = reloc_seg(value);
1042 op->wrt = reloc_wrt(value);
H. Peter Anvin164d2462017-02-20 02:39:56 -08001043 op->opflags |= is_self_relative(value) ? OPFLAG_RELATIVE : 0;
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +04001044
H. Peter Anvine2c80182005-01-15 22:15:51 +00001045 if (is_simple(value)) {
Ben Rudiak-Gould4e8396b2013-03-01 10:28:32 +04001046 if (n == 1)
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001047 op->type |= UNITY;
H. Peter Anvin87646092017-02-28 17:44:24 -08001048 if (optimizing >= 0 && !(op->type & STRICT)) {
Ben Rudiak-Gould4e8396b2013-03-01 10:28:32 +04001049 if ((uint32_t) (n + 128) <= 255)
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001050 op->type |= SBYTEDWORD;
Ben Rudiak-Gould4e8396b2013-03-01 10:28:32 +04001051 if ((uint16_t) (n + 128) <= 255)
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001052 op->type |= SBYTEWORD;
H. Peter Anvin87646092017-02-28 17:44:24 -08001053 if (n <= UINT64_C(0xFFFFFFFF))
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001054 op->type |= UDWORD;
H. Peter Anvin87646092017-02-28 17:44:24 -08001055 if (n + UINT64_C(0x80000000) <= UINT64_C(0xFFFFFFFF))
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001056 op->type |= SDWORD;
H. Peter Anvine2c80182005-01-15 22:15:51 +00001057 }
1058 }
H. Peter Anvin164d2462017-02-20 02:39:56 -08001059 } else if (value->type == EXPR_RDSAE) {
Jin Kyu Song72018a22013-08-05 20:46:18 -07001060 /*
1061 * it's not an operand but a rounding or SAE decorator.
1062 * put the decorator information in the (opflag_t) type field
1063 * of previous operand.
1064 */
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001065 opnum--; op--;
Jin Kyu Song72018a22013-08-05 20:46:18 -07001066 switch (value->value) {
1067 case BRC_RN:
1068 case BRC_RU:
1069 case BRC_RD:
1070 case BRC_RZ:
1071 case BRC_SAE:
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001072 op->decoflags |= (value->value == BRC_SAE ? SAE : ER);
Jin Kyu Song72018a22013-08-05 20:46:18 -07001073 result->evex_rm = value->value;
1074 break;
1075 default:
1076 nasm_error(ERR_NONFATAL, "invalid decorator");
1077 break;
1078 }
H. Peter Anvine2c80182005-01-15 22:15:51 +00001079 } else { /* it's a register */
Cyrill Gorcunov167917a2012-09-10 00:19:12 +04001080 opflags_t rs;
H. Peter Anvineba20a72002-04-30 20:53:55 +00001081
H. Peter Anvine2c80182005-01-15 22:15:51 +00001082 if (value->type >= EXPR_SIMPLE || value->value != 1) {
H. Peter Anvin00444ae2009-07-18 18:49:55 -07001083 nasm_error(ERR_NONFATAL, "invalid operand type");
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001084 goto fail;
H. Peter Anvine2c80182005-01-15 22:15:51 +00001085 }
H. Peter Anvineba20a72002-04-30 20:53:55 +00001086
H. Peter Anvine2c80182005-01-15 22:15:51 +00001087 /*
1088 * check that its only 1 register, not an expression...
1089 */
1090 for (i = 1; value[i].type; i++)
1091 if (value[i].value) {
H. Peter Anvin00444ae2009-07-18 18:49:55 -07001092 nasm_error(ERR_NONFATAL, "invalid operand type");
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001093 goto fail;
H. Peter Anvine2c80182005-01-15 22:15:51 +00001094 }
H. Peter Anvineba20a72002-04-30 20:53:55 +00001095
H. Peter Anvine2c80182005-01-15 22:15:51 +00001096 /* clear overrides, except TO which applies to FPU regs */
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001097 if (op->type & ~TO) {
H. Peter Anvine2c80182005-01-15 22:15:51 +00001098 /*
1099 * we want to produce a warning iff the specified size
1100 * is different from the register size
1101 */
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001102 rs = op->type & SIZE_MASK;
H. Peter Anvine2c80182005-01-15 22:15:51 +00001103 } else
H. Peter Anvin68222142007-11-18 22:18:09 -08001104 rs = 0;
H. Peter Anvine2c80182005-01-15 22:15:51 +00001105
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001106 op->type &= TO;
1107 op->type |= REGISTER;
1108 op->type |= nasm_reg_flags[value->type];
1109 op->decoflags |= brace_flags;
1110 op->basereg = value->type;
H. Peter Anvine2c80182005-01-15 22:15:51 +00001111
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001112 if (rs && (op->type & SIZE_MASK) != rs)
H. Peter Anvin00444ae2009-07-18 18:49:55 -07001113 nasm_error(ERR_WARNING | ERR_PASS1,
H. Peter Anvine2c80182005-01-15 22:15:51 +00001114 "register size specification ignored");
1115 }
1116 }
Jin Kyu Songe3a06b92013-08-28 19:15:23 -07001117
1118 /* remember the position of operand having broadcasting/ER mode */
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001119 if (op->decoflags & (BRDCAST_MASK | ER | SAE))
1120 result->evex_brerop = opnum;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +00001121 }
1122
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001123 result->operands = opnum; /* set operand count */
H. Peter Anvinea6e34d2002-04-30 20:51:32 +00001124
Cyrill Gorcunovc2509502009-10-14 15:36:45 +04001125 /* clear remaining operands */
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001126 while (opnum < MAX_OPERANDS)
1127 result->oprs[opnum++].type = 0;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +00001128
1129 /*
H. Peter Anvin9d546102013-10-02 18:25:19 -07001130 * Transform RESW, RESD, RESQ, REST, RESO, RESY, RESZ into RESB.
H. Peter Anvinea6e34d2002-04-30 20:51:32 +00001131 */
1132 switch (result->opcode) {
H. Peter Anvine2c80182005-01-15 22:15:51 +00001133 case I_RESW:
1134 result->opcode = I_RESB;
1135 result->oprs[0].offset *= 2;
1136 break;
1137 case I_RESD:
1138 result->opcode = I_RESB;
1139 result->oprs[0].offset *= 4;
1140 break;
1141 case I_RESQ:
1142 result->opcode = I_RESB;
1143 result->oprs[0].offset *= 8;
1144 break;
1145 case I_REST:
1146 result->opcode = I_RESB;
1147 result->oprs[0].offset *= 10;
1148 break;
H. Peter Anvin41c9f6f2007-09-18 13:01:32 -07001149 case I_RESO:
1150 result->opcode = I_RESB;
1151 result->oprs[0].offset *= 16;
1152 break;
H. Peter Anvindfb91802008-05-20 11:43:53 -07001153 case I_RESY:
1154 result->opcode = I_RESB;
1155 result->oprs[0].offset *= 32;
1156 break;
H. Peter Anvin9d546102013-10-02 18:25:19 -07001157 case I_RESZ:
1158 result->opcode = I_RESB;
1159 result->oprs[0].offset *= 64;
1160 break;
H. Peter Anvin16b0a332007-09-12 20:27:41 -07001161 default:
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +03001162 break;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +00001163 }
1164
1165 return result;
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001166
1167fail:
1168 result->opcode = I_none;
1169 return result;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +00001170}
1171
H. Peter Anvine2c80182005-01-15 22:15:51 +00001172static int is_comma_next(void)
H. Peter Anvineba20a72002-04-30 20:53:55 +00001173{
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +04001174 struct tokenval tv;
Keith Kaniosa6dfa782007-04-13 16:47:53 +00001175 char *p;
H. Peter Anvin76690a12002-04-30 20:52:49 +00001176 int i;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +00001177
Cyrill Gorcunov917117f2009-10-29 23:09:18 +03001178 p = stdscan_get();
H. Peter Anvine2c80182005-01-15 22:15:51 +00001179 i = stdscan(NULL, &tv);
Cyrill Gorcunov917117f2009-10-29 23:09:18 +03001180 stdscan_set(p);
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +04001181
H. Peter Anvin76690a12002-04-30 20:52:49 +00001182 return (i == ',' || i == ';' || !i);
H. Peter Anvinea6e34d2002-04-30 20:51:32 +00001183}
1184
H. Peter Anvine2c80182005-01-15 22:15:51 +00001185void cleanup_insn(insn * i)
H. Peter Anvineba20a72002-04-30 20:53:55 +00001186{
H. Peter Anvinea6e34d2002-04-30 20:51:32 +00001187 extop *e;
1188
H. Peter Anvin2aa77392008-06-15 17:39:45 -07001189 while ((e = i->eops)) {
1190 i->eops = e->next;
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +03001191 if (e->type == EOT_DB_STRING_FREE)
1192 nasm_free(e->stringval);
H. Peter Anvine2c80182005-01-15 22:15:51 +00001193 nasm_free(e);
H. Peter Anvinea6e34d2002-04-30 20:51:32 +00001194 }
1195}