blob: 64d7a024c2319a4d2b2513399acd6db9e1f7e7e4 [file] [log] [blame]
H. Peter Anvin9e6747c2009-06-28 17:13:04 -07001/* ----------------------------------------------------------------------- *
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +03002 *
H. Peter Anvin98578072018-06-01 18:02:54 -07003 * Copyright 1996-2018 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/*
H. Peter Anvin8e37ff42017-04-02 18:38:58 -0700194 * Brace decorators are are parsed here. opmask and zeroing
195 * decorators can be placed in any order. e.g. zmm1 {k2}{z} or zmm2
196 * {z}{k3} decorator(s) are placed at the end of an operand.
Jin Kyu Song72018a22013-08-05 20:46:18 -0700197 */
198static bool parse_braces(decoflags_t *decoflags)
199{
H. Peter Anvin8e37ff42017-04-02 18:38:58 -0700200 int i, j;
Jin Kyu Song72018a22013-08-05 20:46:18 -0700201
202 i = tokval.t_type;
H. Peter Anvin8e37ff42017-04-02 18:38:58 -0700203
204 while (true) {
205 switch (i) {
206 case TOKEN_OPMASK:
Jin Kyu Song72018a22013-08-05 20:46:18 -0700207 if (*decoflags & OPMASK_MASK) {
H. Peter Anvin8e37ff42017-04-02 18:38:58 -0700208 nasm_error(ERR_NONFATAL,
209 "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]);
H. Peter Anvin8e37ff42017-04-02 18:38:58 -0700214 break;
215 case TOKEN_DECORATOR:
216 j = tokval.t_integer;
217 switch (j) {
Jin Kyu Song72018a22013-08-05 20:46:18 -0700218 case BRC_Z:
H. Peter Anvin8e37ff42017-04-02 18:38:58 -0700219 *decoflags |= Z_MASK;
220 break;
221 case BRC_1TO2:
222 case BRC_1TO4:
223 case BRC_1TO8:
224 case BRC_1TO16:
225 *decoflags |= BRDCAST_MASK | VAL_BRNUM(j - BRC_1TO2);
Jin Kyu Song72018a22013-08-05 20:46:18 -0700226 break;
Jin Kyu Songcc1dc9d2013-08-15 19:01:25 -0700227 default:
H. Peter Anvin8e37ff42017-04-02 18:38:58 -0700228 nasm_error(ERR_NONFATAL,
229 "{%s} is not an expected decorator",
230 tokval.t_charptr);
Jin Kyu Songcc1dc9d2013-08-15 19:01:25 -0700231 break;
Jin Kyu Song72018a22013-08-05 20:46:18 -0700232 }
Jin Kyu Song72018a22013-08-05 20:46:18 -0700233 break;
H. Peter Anvin8e37ff42017-04-02 18:38:58 -0700234 case ',':
235 case TOKEN_EOS:
236 return false;
237 default:
238 nasm_error(ERR_NONFATAL,
239 "only a series of valid decorators expected");
240 return true;
Jin Kyu Song72018a22013-08-05 20:46:18 -0700241 }
242 i = stdscan(NULL, &tokval);
H. Peter Anvin8e37ff42017-04-02 18:38:58 -0700243 }
Jin Kyu Song72018a22013-08-05 20:46:18 -0700244}
245
H. Peter Anvin9148fb52013-09-27 16:39:16 -0700246static int parse_mref(operand *op, const expr *e)
H. Peter Anvin9f4706f2013-09-26 17:28:39 -0700247{
248 int b, i, s; /* basereg, indexreg, scale */
249 int64_t o; /* offset */
250
H. Peter Anvin9148fb52013-09-27 16:39:16 -0700251 b = i = -1;
252 o = s = 0;
H. Peter Anvin164d2462017-02-20 02:39:56 -0800253 op->segment = op->wrt = NO_SEG;
H. Peter Anvin9f4706f2013-09-26 17:28:39 -0700254
255 if (e->type && e->type <= EXPR_REG_END) { /* this bit's a register */
256 bool is_gpr = is_class(REG_GPR,nasm_reg_flags[e->type]);
257
258 if (is_gpr && e->value == 1)
259 b = e->type; /* It can be basereg */
H. Peter Anvin472a7c12016-10-31 08:44:25 -0700260 else /* No, it has to be indexreg */
H. Peter Anvin9f4706f2013-09-26 17:28:39 -0700261 i = e->type, s = e->value;
262 e++;
263 }
264 if (e->type && e->type <= EXPR_REG_END) { /* it's a 2nd register */
265 bool is_gpr = is_class(REG_GPR,nasm_reg_flags[e->type]);
266
267 if (b != -1) /* If the first was the base, ... */
268 i = e->type, s = e->value; /* second has to be indexreg */
269
270 else if (!is_gpr || e->value != 1) {
271 /* If both want to be index */
272 nasm_error(ERR_NONFATAL,
273 "invalid effective address: two index registers");
274 return -1;
275 } else
276 b = e->type;
277 e++;
278 }
H. Peter Anvin164d2462017-02-20 02:39:56 -0800279
280 if (e->type) { /* is there an offset? */
H. Peter Anvin9f4706f2013-09-26 17:28:39 -0700281 if (e->type <= EXPR_REG_END) { /* in fact, is there an error? */
282 nasm_error(ERR_NONFATAL,
H. Peter Anvin164d2462017-02-20 02:39:56 -0800283 "invalid effective address: impossible register");
H. Peter Anvin9f4706f2013-09-26 17:28:39 -0700284 return -1;
285 } else {
286 if (e->type == EXPR_UNKNOWN) {
287 op->opflags |= OPFLAG_UNKNOWN;
288 o = 0; /* doesn't matter what */
H. Peter Anvin9f4706f2013-09-26 17:28:39 -0700289 while (e->type)
290 e++; /* go to the end of the line */
291 } else {
292 if (e->type == EXPR_SIMPLE) {
293 o = e->value;
294 e++;
295 }
296 if (e->type == EXPR_WRT) {
297 op->wrt = e->value;
298 e++;
H. Peter Anvin164d2462017-02-20 02:39:56 -0800299 }
H. Peter Anvin9f4706f2013-09-26 17:28:39 -0700300 /*
301 * Look for a segment base type.
302 */
H. Peter Anvin164d2462017-02-20 02:39:56 -0800303 for (; e->type; e++) {
304 if (!e->value)
305 continue;
306
307 if (e->type <= EXPR_REG_END) {
308 nasm_error(ERR_NONFATAL,
309 "invalid effective address: too many registers");
310 return -1;
311 } else if (e->type < EXPR_SEGBASE) {
312 nasm_error(ERR_NONFATAL,
313 "invalid effective address: bad subexpression type");
314 return -1;
315 } else if (e->value == 1) {
316 if (op->segment != NO_SEG) {
317 nasm_error(ERR_NONFATAL,
318 "invalid effective address: multiple base segments");
319 return -1;
320 }
321 op->segment = e->type - EXPR_SEGBASE;
322 } else if (e->value == -1 &&
323 e->type == location.segment + EXPR_SEGBASE &&
324 !(op->opflags & OPFLAG_RELATIVE)) {
325 op->opflags |= OPFLAG_RELATIVE;
326 } else {
327 nasm_error(ERR_NONFATAL,
328 "invalid effective address: impossible segment base multiplier");
329 return -1;
330 }
H. Peter Anvin9f4706f2013-09-26 17:28:39 -0700331 }
332 }
333 }
H. Peter Anvin9f4706f2013-09-26 17:28:39 -0700334 }
335
H. Peter Anvin164d2462017-02-20 02:39:56 -0800336 nasm_assert(!e->type); /* We should be at the end */
H. Peter Anvin9f4706f2013-09-26 17:28:39 -0700337
H. Peter Anvin9148fb52013-09-27 16:39:16 -0700338 op->basereg = b;
339 op->indexreg = i;
340 op->scale = s;
341 op->offset = o;
342 return 0;
343}
344
345static void mref_set_optype(operand *op)
346{
347 int b = op->basereg;
348 int i = op->indexreg;
349 int s = op->scale;
350
H. Peter Anvin9f4706f2013-09-26 17:28:39 -0700351 /* It is memory, but it can match any r/m operand */
352 op->type |= MEMORY_ANY;
353
354 if (b == -1 && (i == -1 || s == 0)) {
355 int is_rel = globalbits == 64 &&
356 !(op->eaflags & EAF_ABS) &&
357 ((globalrel &&
358 !(op->eaflags & EAF_FSGS)) ||
359 (op->eaflags & EAF_REL));
360
361 op->type |= is_rel ? IP_REL : MEM_OFFS;
362 }
363
364 if (i != -1) {
365 opflags_t iclass = nasm_reg_flags[i];
366
367 if (is_class(XMMREG,iclass))
368 op->type |= XMEM;
369 else if (is_class(YMMREG,iclass))
370 op->type |= YMEM;
371 else if (is_class(ZMMREG,iclass))
372 op->type |= ZMEM;
373 }
H. Peter Anvin9f4706f2013-09-26 17:28:39 -0700374}
375
H. Peter Anvin472a7c12016-10-31 08:44:25 -0700376/*
377 * Convert an expression vector returned from evaluate() into an
378 * extop structure. Return zero on success.
379 */
380static int value_to_extop(expr * vect, extop *eop, int32_t myseg)
381{
382 eop->type = EOT_DB_NUMBER;
383 eop->offset = 0;
384 eop->segment = eop->wrt = NO_SEG;
385 eop->relative = false;
386
387 for (; vect->type; vect++) {
388 if (!vect->value) /* zero term, safe to ignore */
389 continue;
390
Cyrill Gorcunovfd610f22016-11-28 23:57:08 +0300391 if (vect->type <= EXPR_REG_END) /* false if a register is present */
H. Peter Anvin472a7c12016-10-31 08:44:25 -0700392 return -1;
393
394 if (vect->type == EXPR_UNKNOWN) /* something we can't resolve yet */
395 return 0;
396
397 if (vect->type == EXPR_SIMPLE) {
398 /* Simple number expression */
399 eop->offset += vect->value;
400 continue;
401 }
402 if (eop->wrt == NO_SEG && !eop->relative && vect->type == EXPR_WRT) {
403 /* WRT term */
404 eop->wrt = vect->value;
405 continue;
406 }
407
H. Peter Anvind97ccee2017-02-21 11:31:35 -0800408 if (!eop->relative &&
H. Peter Anvin472a7c12016-10-31 08:44:25 -0700409 vect->type == EXPR_SEGBASE + myseg && vect->value == -1) {
410 /* Expression of the form: foo - $ */
411 eop->relative = true;
412 continue;
413 }
414
415 if (eop->segment == NO_SEG && vect->type >= EXPR_SEGBASE &&
416 vect->value == 1) {
417 eop->segment = vect->type - EXPR_SEGBASE;
418 continue;
419 }
420
421 /* Otherwise, badness */
422 return -1;
423 }
424
425 /* We got to the end and it was all okay */
426 return 0;
427}
428
H. Peter Anvin98578072018-06-01 18:02:54 -0700429insn *parse_line(int pass, char *buffer, insn *result)
H. Peter Anvineba20a72002-04-30 20:53:55 +0000430{
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400431 bool insn_is_label = false;
432 struct eval_hints hints;
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700433 int opnum;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000434 int critical;
H. Peter Anvin9c987692007-11-04 21:09:32 -0800435 bool first;
H. Peter Anvin552bc2c2009-06-23 11:34:42 -0700436 bool recover;
Martin Lindhe58f37c12016-11-16 16:43:16 +0100437 int i;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000438
H. Peter Anvin7daa26f2018-06-02 23:48:16 -0700439 nasm_static_assert(P_none == 0);
440
H. Peter Anvin9c987692007-11-04 21:09:32 -0800441restart_parse:
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400442 first = true;
443 result->forw_ref = false;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000444
H. Peter Anvin76690a12002-04-30 20:52:49 +0000445 stdscan_reset();
Cyrill Gorcunov917117f2009-10-29 23:09:18 +0300446 stdscan_set(buffer);
H. Peter Anvin76690a12002-04-30 20:52:49 +0000447 i = stdscan(NULL, &tokval);
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000448
H. Peter Anvin3e458a82017-05-01 20:28:29 -0700449 memset(result->prefixes, P_none, sizeof(result->prefixes));
450 result->times = 1; /* No TIMES either yet */
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400451 result->label = NULL; /* Assume no label */
452 result->eops = NULL; /* must do this, whatever happens */
453 result->operands = 0; /* must initialize this */
Jin Kyu Songe3a06b92013-08-28 19:15:23 -0700454 result->evex_rm = 0; /* Ensure EVEX rounding mode is reset */
455 result->evex_brerop = -1; /* Reset EVEX broadcasting/ER op position */
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000456
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400457 /* Ignore blank lines */
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700458 if (i == TOKEN_EOS)
459 goto fail;
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400460
Cyrill Gorcunov5abbe372011-08-28 18:49:00 +0400461 if (i != TOKEN_ID &&
462 i != TOKEN_INSN &&
463 i != TOKEN_PREFIX &&
464 (i != TOKEN_REG || !IS_SREG(tokval.t_integer))) {
465 nasm_error(ERR_NONFATAL,
466 "label or instruction expected at start of line");
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700467 goto fail;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000468 }
469
H. Peter Anvin9c987692007-11-04 21:09:32 -0800470 if (i == TOKEN_ID || (insn_is_label && i == TOKEN_INSN)) {
471 /* there's a label here */
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300472 first = false;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000473 result->label = tokval.t_charptr;
474 i = stdscan(NULL, &tokval);
475 if (i == ':') { /* skip over the optional colon */
476 i = stdscan(NULL, &tokval);
477 } else if (i == 0) {
H. Peter Anvin00444ae2009-07-18 18:49:55 -0700478 nasm_error(ERR_WARNING | ERR_WARN_OL | ERR_PASS1,
H. Peter Anvine2c80182005-01-15 22:15:51 +0000479 "label alone on a line without a colon might be in error");
480 }
481 if (i != TOKEN_INSN || tokval.t_integer != I_EQU) {
482 /*
H. Peter Anvincd7893d2016-02-18 01:25:46 -0800483 * FIXME: location.segment could be NO_SEG, in which case
H. Peter Anvinb20bc732017-03-07 19:23:03 -0800484 * it is possible we should be passing 'absolute.segment'. Look into this.
H. Peter Anvine2c80182005-01-15 22:15:51 +0000485 * Work out whether that is *really* what we should be doing.
486 * Generally fix things. I think this is right as it is, but
487 * am still not certain.
488 */
H. Peter Anvin (Intel)415b6b32018-06-25 14:09:52 -0700489 define_label(result->label,
490 in_absolute ? absolute.segment : location.segment,
H. Peter Anvin98578072018-06-01 18:02:54 -0700491 location.offset, true);
H. Peter Anvine2c80182005-01-15 22:15:51 +0000492 }
H. Peter Anvineba20a72002-04-30 20:53:55 +0000493 }
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000494
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400495 /* Just a label here */
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700496 if (i == TOKEN_EOS)
497 goto fail;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000498
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000499 while (i == TOKEN_PREFIX ||
Cyrill Gorcunov5abbe372011-08-28 18:49:00 +0400500 (i == TOKEN_REG && IS_SREG(tokval.t_integer))) {
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300501 first = false;
H. Peter Anvin9c987692007-11-04 21:09:32 -0800502
H. Peter Anvine2c80182005-01-15 22:15:51 +0000503 /*
504 * Handle special case: the TIMES prefix.
505 */
506 if (i == TOKEN_PREFIX && tokval.t_integer == P_TIMES) {
507 expr *value;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000508
H. Peter Anvine2c80182005-01-15 22:15:51 +0000509 i = stdscan(NULL, &tokval);
H. Peter Anvin130736c2016-02-17 20:27:41 -0800510 value = evaluate(stdscan, NULL, &tokval, NULL, pass0, NULL);
H. Peter Anvine2c80182005-01-15 22:15:51 +0000511 i = tokval.t_type;
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700512 if (!value) /* Error in evaluator */
513 goto fail;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000514 if (!is_simple(value)) {
H. Peter Anvin00444ae2009-07-18 18:49:55 -0700515 nasm_error(ERR_NONFATAL,
H. Peter Anvine2c80182005-01-15 22:15:51 +0000516 "non-constant argument supplied to TIMES");
517 result->times = 1L;
518 } else {
519 result->times = value->value;
H. Peter Anvin94ead272017-09-27 15:22:23 -0700520 if (value->value < 0) {
521 nasm_error(ERR_NONFATAL|ERR_PASS2, "TIMES value %"PRId64" is negative", value->value);
H. Peter Anvine2c80182005-01-15 22:15:51 +0000522 result->times = 0;
523 }
524 }
525 } else {
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300526 int slot = prefix_slot(tokval.t_integer);
527 if (result->prefixes[slot]) {
Charles Crayne052c0bd2007-10-29 18:24:59 -0700528 if (result->prefixes[slot] == tokval.t_integer)
Victor van den Elzend55a1582010-11-07 23:47:13 +0100529 nasm_error(ERR_WARNING | ERR_PASS1,
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300530 "instruction has redundant prefixes");
Charles Crayne052c0bd2007-10-29 18:24:59 -0700531 else
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300532 nasm_error(ERR_NONFATAL,
533 "instruction has conflicting prefixes");
534 }
535 result->prefixes[slot] = tokval.t_integer;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000536 i = stdscan(NULL, &tokval);
537 }
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000538 }
539
540 if (i != TOKEN_INSN) {
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300541 int j;
542 enum prefixes pfx;
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700543
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400544 for (j = 0; j < MAXPREFIX; j++) {
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300545 if ((pfx = result->prefixes[j]) != P_none)
546 break;
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400547 }
H. Peter Anvincb583b92007-10-28 22:04:42 -0700548
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700549 if (i == 0 && pfx != P_none) {
H. Peter Anvine2c80182005-01-15 22:15:51 +0000550 /*
551 * Instruction prefixes are present, but no actual
552 * instruction. This is allowed: at this point we
553 * invent a notional instruction of RESB 0.
554 */
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400555 result->opcode = I_RESB;
556 result->operands = 1;
H. Peter Anvin1980abf2017-03-31 14:52:03 -0700557 nasm_zero(result->oprs);
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400558 result->oprs[0].type = IMMEDIATE;
559 result->oprs[0].offset = 0L;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000560 result->oprs[0].segment = result->oprs[0].wrt = NO_SEG;
561 return result;
562 } else {
H. Peter Anvin00444ae2009-07-18 18:49:55 -0700563 nasm_error(ERR_NONFATAL, "parser: instruction expected");
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700564 goto fail;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000565 }
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000566 }
567
568 result->opcode = tokval.t_integer;
569 result->condition = tokval.t_inttwo;
570
571 /*
Charles Crayne2581c862008-09-10 19:21:52 -0700572 * INCBIN cannot be satisfied with incorrectly
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000573 * evaluated operands, since the correct values _must_ be known
574 * on the first pass. Hence, even in pass one, we set the
575 * `critical' flag on calling evaluate(), so that it will bomb
Charles Crayne2581c862008-09-10 19:21:52 -0700576 * out on undefined symbols.
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000577 */
Charles Crayne2581c862008-09-10 19:21:52 -0700578 if (result->opcode == I_INCBIN) {
Charles Crayne5a7976c2008-03-26 17:20:21 -0700579 critical = (pass0 < 2 ? 1 : 2);
580
H. Peter Anvine2c80182005-01-15 22:15:51 +0000581 } else
582 critical = (pass == 2 ? 2 : 0);
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000583
H. Peter Anvin3e458a82017-05-01 20:28:29 -0700584 if (opcode_is_db(result->opcode) || 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
H. Peter Anvinaf9fe8f2017-05-01 21:44:24 -0700670 eop->stringlen = db_bytes(result->opcode);
Cyrill Gorcunovbafd8772009-10-31 20:02:14 +0300671 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 */
H. Peter Anvin3e458a82017-05-01 20:28:29 -07001132 if (opcode_is_resb(result->opcode)) {
H. Peter Anvinaf9fe8f2017-05-01 21:44:24 -07001133 result->oprs[0].offset *= resb_bytes(result->opcode);
H. Peter Anvin3e458a82017-05-01 20:28:29 -07001134 result->oprs[0].offset *= result->times;
1135 result->times = 1;
H. Peter Anvine2c80182005-01-15 22:15:51 +00001136 result->opcode = I_RESB;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +00001137 }
1138
1139 return result;
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001140
1141fail:
1142 result->opcode = I_none;
1143 return result;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +00001144}
1145
H. Peter Anvine2c80182005-01-15 22:15:51 +00001146static int is_comma_next(void)
H. Peter Anvineba20a72002-04-30 20:53:55 +00001147{
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +04001148 struct tokenval tv;
Keith Kaniosa6dfa782007-04-13 16:47:53 +00001149 char *p;
H. Peter Anvin76690a12002-04-30 20:52:49 +00001150 int i;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +00001151
Cyrill Gorcunov917117f2009-10-29 23:09:18 +03001152 p = stdscan_get();
H. Peter Anvine2c80182005-01-15 22:15:51 +00001153 i = stdscan(NULL, &tv);
Cyrill Gorcunov917117f2009-10-29 23:09:18 +03001154 stdscan_set(p);
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +04001155
H. Peter Anvin76690a12002-04-30 20:52:49 +00001156 return (i == ',' || i == ';' || !i);
H. Peter Anvinea6e34d2002-04-30 20:51:32 +00001157}
1158
H. Peter Anvine2c80182005-01-15 22:15:51 +00001159void cleanup_insn(insn * i)
H. Peter Anvineba20a72002-04-30 20:53:55 +00001160{
H. Peter Anvinea6e34d2002-04-30 20:51:32 +00001161 extop *e;
1162
H. Peter Anvin2aa77392008-06-15 17:39:45 -07001163 while ((e = i->eops)) {
1164 i->eops = e->next;
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +03001165 if (e->type == EOT_DB_STRING_FREE)
1166 nasm_free(e->stringval);
H. Peter Anvine2c80182005-01-15 22:15:51 +00001167 nasm_free(e);
H. Peter Anvinea6e34d2002-04-30 20:51:32 +00001168 }
1169}