blob: 622259c836864a371e448b8e284964fd3fd2d617 [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 Anvin9c987692007-11-04 21:09:32 -0800439restart_parse:
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400440 first = true;
441 result->forw_ref = false;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000442
H. Peter Anvin76690a12002-04-30 20:52:49 +0000443 stdscan_reset();
Cyrill Gorcunov917117f2009-10-29 23:09:18 +0300444 stdscan_set(buffer);
H. Peter Anvin76690a12002-04-30 20:52:49 +0000445 i = stdscan(NULL, &tokval);
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000446
H. Peter Anvin3e458a82017-05-01 20:28:29 -0700447 nasm_static_assert(P_none == 0);
448 memset(result->prefixes, P_none, sizeof(result->prefixes));
449 result->times = 1; /* No TIMES either yet */
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400450 result->label = NULL; /* Assume no label */
451 result->eops = NULL; /* must do this, whatever happens */
452 result->operands = 0; /* must initialize this */
Jin Kyu Songe3a06b92013-08-28 19:15:23 -0700453 result->evex_rm = 0; /* Ensure EVEX rounding mode is reset */
454 result->evex_brerop = -1; /* Reset EVEX broadcasting/ER op position */
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000455
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400456 /* Ignore blank lines */
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700457 if (i == TOKEN_EOS)
458 goto fail;
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400459
Cyrill Gorcunov5abbe372011-08-28 18:49:00 +0400460 if (i != TOKEN_ID &&
461 i != TOKEN_INSN &&
462 i != TOKEN_PREFIX &&
463 (i != TOKEN_REG || !IS_SREG(tokval.t_integer))) {
464 nasm_error(ERR_NONFATAL,
465 "label or instruction expected at start of line");
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700466 goto fail;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000467 }
468
H. Peter Anvin9c987692007-11-04 21:09:32 -0800469 if (i == TOKEN_ID || (insn_is_label && i == TOKEN_INSN)) {
470 /* there's a label here */
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300471 first = false;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000472 result->label = tokval.t_charptr;
473 i = stdscan(NULL, &tokval);
474 if (i == ':') { /* skip over the optional colon */
475 i = stdscan(NULL, &tokval);
476 } else if (i == 0) {
H. Peter Anvin00444ae2009-07-18 18:49:55 -0700477 nasm_error(ERR_WARNING | ERR_WARN_OL | ERR_PASS1,
H. Peter Anvine2c80182005-01-15 22:15:51 +0000478 "label alone on a line without a colon might be in error");
479 }
480 if (i != TOKEN_INSN || tokval.t_integer != I_EQU) {
481 /*
H. Peter Anvincd7893d2016-02-18 01:25:46 -0800482 * FIXME: location.segment could be NO_SEG, in which case
H. Peter Anvinb20bc732017-03-07 19:23:03 -0800483 * it is possible we should be passing 'absolute.segment'. Look into this.
H. Peter Anvine2c80182005-01-15 22:15:51 +0000484 * Work out whether that is *really* what we should be doing.
485 * Generally fix things. I think this is right as it is, but
486 * am still not certain.
487 */
H. Peter Anvin98578072018-06-01 18:02:54 -0700488 define_label(result->label, location.segment,
489 location.offset, true);
H. Peter Anvine2c80182005-01-15 22:15:51 +0000490 }
H. Peter Anvineba20a72002-04-30 20:53:55 +0000491 }
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000492
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400493 /* Just a label here */
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700494 if (i == TOKEN_EOS)
495 goto fail;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000496
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000497 while (i == TOKEN_PREFIX ||
Cyrill Gorcunov5abbe372011-08-28 18:49:00 +0400498 (i == TOKEN_REG && IS_SREG(tokval.t_integer))) {
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300499 first = false;
H. Peter Anvin9c987692007-11-04 21:09:32 -0800500
H. Peter Anvine2c80182005-01-15 22:15:51 +0000501 /*
502 * Handle special case: the TIMES prefix.
503 */
504 if (i == TOKEN_PREFIX && tokval.t_integer == P_TIMES) {
505 expr *value;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000506
H. Peter Anvine2c80182005-01-15 22:15:51 +0000507 i = stdscan(NULL, &tokval);
H. Peter Anvin130736c2016-02-17 20:27:41 -0800508 value = evaluate(stdscan, NULL, &tokval, NULL, pass0, NULL);
H. Peter Anvine2c80182005-01-15 22:15:51 +0000509 i = tokval.t_type;
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700510 if (!value) /* Error in evaluator */
511 goto fail;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000512 if (!is_simple(value)) {
H. Peter Anvin00444ae2009-07-18 18:49:55 -0700513 nasm_error(ERR_NONFATAL,
H. Peter Anvine2c80182005-01-15 22:15:51 +0000514 "non-constant argument supplied to TIMES");
515 result->times = 1L;
516 } else {
517 result->times = value->value;
H. Peter Anvin94ead272017-09-27 15:22:23 -0700518 if (value->value < 0) {
519 nasm_error(ERR_NONFATAL|ERR_PASS2, "TIMES value %"PRId64" is negative", value->value);
H. Peter Anvine2c80182005-01-15 22:15:51 +0000520 result->times = 0;
521 }
522 }
523 } else {
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300524 int slot = prefix_slot(tokval.t_integer);
525 if (result->prefixes[slot]) {
Charles Crayne052c0bd2007-10-29 18:24:59 -0700526 if (result->prefixes[slot] == tokval.t_integer)
Victor van den Elzend55a1582010-11-07 23:47:13 +0100527 nasm_error(ERR_WARNING | ERR_PASS1,
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300528 "instruction has redundant prefixes");
Charles Crayne052c0bd2007-10-29 18:24:59 -0700529 else
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300530 nasm_error(ERR_NONFATAL,
531 "instruction has conflicting prefixes");
532 }
533 result->prefixes[slot] = tokval.t_integer;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000534 i = stdscan(NULL, &tokval);
535 }
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000536 }
537
538 if (i != TOKEN_INSN) {
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300539 int j;
540 enum prefixes pfx;
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700541
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400542 for (j = 0; j < MAXPREFIX; j++) {
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300543 if ((pfx = result->prefixes[j]) != P_none)
544 break;
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400545 }
H. Peter Anvincb583b92007-10-28 22:04:42 -0700546
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700547 if (i == 0 && pfx != P_none) {
H. Peter Anvine2c80182005-01-15 22:15:51 +0000548 /*
549 * Instruction prefixes are present, but no actual
550 * instruction. This is allowed: at this point we
551 * invent a notional instruction of RESB 0.
552 */
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400553 result->opcode = I_RESB;
554 result->operands = 1;
H. Peter Anvin1980abf2017-03-31 14:52:03 -0700555 nasm_zero(result->oprs);
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400556 result->oprs[0].type = IMMEDIATE;
557 result->oprs[0].offset = 0L;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000558 result->oprs[0].segment = result->oprs[0].wrt = NO_SEG;
559 return result;
560 } else {
H. Peter Anvin00444ae2009-07-18 18:49:55 -0700561 nasm_error(ERR_NONFATAL, "parser: instruction expected");
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700562 goto fail;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000563 }
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000564 }
565
566 result->opcode = tokval.t_integer;
567 result->condition = tokval.t_inttwo;
568
569 /*
Charles Crayne2581c862008-09-10 19:21:52 -0700570 * INCBIN cannot be satisfied with incorrectly
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000571 * evaluated operands, since the correct values _must_ be known
572 * on the first pass. Hence, even in pass one, we set the
573 * `critical' flag on calling evaluate(), so that it will bomb
Charles Crayne2581c862008-09-10 19:21:52 -0700574 * out on undefined symbols.
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000575 */
Charles Crayne2581c862008-09-10 19:21:52 -0700576 if (result->opcode == I_INCBIN) {
Charles Crayne5a7976c2008-03-26 17:20:21 -0700577 critical = (pass0 < 2 ? 1 : 2);
578
H. Peter Anvine2c80182005-01-15 22:15:51 +0000579 } else
580 critical = (pass == 2 ? 2 : 0);
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000581
H. Peter Anvin3e458a82017-05-01 20:28:29 -0700582 if (opcode_is_db(result->opcode) || result->opcode == I_INCBIN) {
H. Peter Anvine2c80182005-01-15 22:15:51 +0000583 extop *eop, **tail = &result->eops, **fixptr;
584 int oper_num = 0;
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300585 int32_t sign;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000586
H. Peter Anvin6867acc2007-10-10 14:58:45 -0700587 result->eops_float = false;
H. Peter Anvineba20a72002-04-30 20:53:55 +0000588
H. Peter Anvine2c80182005-01-15 22:15:51 +0000589 /*
H. Peter Anvin9d546102013-10-02 18:25:19 -0700590 * Begin to read the DB/DW/DD/DQ/DT/DO/DY/DZ/INCBIN operands.
H. Peter Anvine2c80182005-01-15 22:15:51 +0000591 */
592 while (1) {
593 i = stdscan(NULL, &tokval);
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400594 if (i == TOKEN_EOS)
H. Peter Anvine2c80182005-01-15 22:15:51 +0000595 break;
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300596 else if (first && i == ':') {
597 insn_is_label = true;
598 goto restart_parse;
599 }
600 first = false;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000601 fixptr = tail;
602 eop = *tail = nasm_malloc(sizeof(extop));
603 tail = &eop->next;
604 eop->next = NULL;
605 eop->type = EOT_NOTHING;
606 oper_num++;
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300607 sign = +1;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000608
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300609 /*
610 * is_comma_next() here is to distinguish this from
611 * a string used as part of an expression...
612 */
H. Peter Anvin11627042008-06-09 20:45:19 -0700613 if (i == TOKEN_STR && is_comma_next()) {
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400614 eop->type = EOT_DB_STRING;
615 eop->stringval = tokval.t_charptr;
616 eop->stringlen = tokval.t_inttwo;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000617 i = stdscan(NULL, &tokval); /* eat the comma */
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300618 } else if (i == TOKEN_STRFUNC) {
619 bool parens = false;
620 const char *funcname = tokval.t_charptr;
621 enum strfunc func = tokval.t_integer;
622 i = stdscan(NULL, &tokval);
623 if (i == '(') {
624 parens = true;
625 i = stdscan(NULL, &tokval);
626 }
627 if (i != TOKEN_STR) {
628 nasm_error(ERR_NONFATAL,
629 "%s must be followed by a string constant",
630 funcname);
631 eop->type = EOT_NOTHING;
632 } else {
633 eop->type = EOT_DB_STRING_FREE;
634 eop->stringlen =
635 string_transform(tokval.t_charptr, tokval.t_inttwo,
636 &eop->stringval, func);
637 if (eop->stringlen == (size_t)-1) {
638 nasm_error(ERR_NONFATAL, "invalid string for transform");
639 eop->type = EOT_NOTHING;
640 }
641 }
642 if (parens && i && i != ')') {
643 i = stdscan(NULL, &tokval);
644 if (i != ')') {
645 nasm_error(ERR_NONFATAL, "unterminated %s function",
646 funcname);
647 }
648 }
649 if (i && i != ',')
650 i = stdscan(NULL, &tokval);
651 } else if (i == '-' || i == '+') {
652 char *save = stdscan_get();
653 int token = i;
654 sign = (i == '-') ? -1 : 1;
655 i = stdscan(NULL, &tokval);
656 if (i != TOKEN_FLOAT) {
657 stdscan_set(save);
658 i = tokval.t_type = token;
659 goto is_expression;
660 } else {
661 goto is_float;
662 }
H. Peter Anvin518df302008-06-14 16:53:48 -0700663 } else if (i == TOKEN_FLOAT) {
Cyrill Gorcunovbafd8772009-10-31 20:02:14 +0300664is_float:
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300665 eop->type = EOT_DB_STRING;
666 result->eops_float = true;
Cyrill Gorcunovbafd8772009-10-31 20:02:14 +0300667
H. Peter Anvinaf9fe8f2017-05-01 21:44:24 -0700668 eop->stringlen = db_bytes(result->opcode);
Cyrill Gorcunovbafd8772009-10-31 20:02:14 +0300669 if (eop->stringlen > 16) {
670 nasm_error(ERR_NONFATAL, "floating-point constant"
H. Peter Anvin9d546102013-10-02 18:25:19 -0700671 " encountered in DY or DZ instruction");
Cyrill Gorcunovbafd8772009-10-31 20:02:14 +0300672 eop->stringlen = 0;
673 } else if (eop->stringlen < 1) {
674 nasm_error(ERR_NONFATAL, "floating-point constant"
675 " encountered in unknown instruction");
676 /*
677 * fix suggested by Pedro Gimeno... original line was:
678 * eop->type = EOT_NOTHING;
679 */
680 eop->stringlen = 0;
681 }
682
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300683 eop = nasm_realloc(eop, sizeof(extop) + eop->stringlen);
684 tail = &eop->next;
685 *fixptr = eop;
686 eop->stringval = (char *)eop + sizeof(extop);
687 if (!eop->stringlen ||
688 !float_const(tokval.t_charptr, sign,
H. Peter Anvin130736c2016-02-17 20:27:41 -0800689 (uint8_t *)eop->stringval, eop->stringlen))
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300690 eop->type = EOT_NOTHING;
691 i = stdscan(NULL, &tokval); /* eat the comma */
692 } else {
693 /* anything else, assume it is an expression */
H. Peter Anvine2c80182005-01-15 22:15:51 +0000694 expr *value;
H. Peter Anvin518df302008-06-14 16:53:48 -0700695
Cyrill Gorcunovbafd8772009-10-31 20:02:14 +0300696is_expression:
H. Peter Anvine2c80182005-01-15 22:15:51 +0000697 value = evaluate(stdscan, NULL, &tokval, NULL,
H. Peter Anvin130736c2016-02-17 20:27:41 -0800698 critical, NULL);
H. Peter Anvine2c80182005-01-15 22:15:51 +0000699 i = tokval.t_type;
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700700 if (!value) /* Error in evaluator */
701 goto fail;
H. Peter Anvin472a7c12016-10-31 08:44:25 -0700702 if (value_to_extop(value, eop, location.segment)) {
H. Peter Anvin00444ae2009-07-18 18:49:55 -0700703 nasm_error(ERR_NONFATAL,
H. Peter Anvin472a7c12016-10-31 08:44:25 -0700704 "operand %d: expression is not simple or relocatable",
705 oper_num);
H. Peter Anvine2c80182005-01-15 22:15:51 +0000706 }
707 }
H. Peter Anvin6768eb72002-04-30 20:52:26 +0000708
H. Peter Anvine2c80182005-01-15 22:15:51 +0000709 /*
710 * We're about to call stdscan(), which will eat the
711 * comma that we're currently sitting on between
712 * arguments. However, we'd better check first that it
713 * _is_ a comma.
714 */
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400715 if (i == TOKEN_EOS) /* also could be EOL */
H. Peter Anvine2c80182005-01-15 22:15:51 +0000716 break;
717 if (i != ',') {
H. Peter Anvin00444ae2009-07-18 18:49:55 -0700718 nasm_error(ERR_NONFATAL, "comma expected after operand %d",
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400719 oper_num);
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700720 goto fail;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000721 }
722 }
H. Peter Anvind7ed89e2002-04-30 20:52:08 +0000723
H. Peter Anvine2c80182005-01-15 22:15:51 +0000724 if (result->opcode == I_INCBIN) {
725 /*
726 * Correct syntax for INCBIN is that there should be
727 * one string operand, followed by one or two numeric
728 * operands.
729 */
730 if (!result->eops || result->eops->type != EOT_DB_STRING)
H. Peter Anvin00444ae2009-07-18 18:49:55 -0700731 nasm_error(ERR_NONFATAL, "`incbin' expects a file name");
H. Peter Anvine2c80182005-01-15 22:15:51 +0000732 else if (result->eops->next &&
733 result->eops->next->type != EOT_DB_NUMBER)
Victor van den Elzen15bb2332009-08-11 02:10:16 +0200734 nasm_error(ERR_NONFATAL, "`incbin': second parameter is"
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400735 " non-numeric");
H. Peter Anvine2c80182005-01-15 22:15:51 +0000736 else if (result->eops->next && result->eops->next->next &&
737 result->eops->next->next->type != EOT_DB_NUMBER)
Victor van den Elzen15bb2332009-08-11 02:10:16 +0200738 nasm_error(ERR_NONFATAL, "`incbin': third parameter is"
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400739 " non-numeric");
H. Peter Anvine2c80182005-01-15 22:15:51 +0000740 else if (result->eops->next && result->eops->next->next &&
741 result->eops->next->next->next)
H. Peter Anvin00444ae2009-07-18 18:49:55 -0700742 nasm_error(ERR_NONFATAL,
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400743 "`incbin': more than three parameters");
H. Peter Anvineba20a72002-04-30 20:53:55 +0000744 else
H. Peter Anvine2c80182005-01-15 22:15:51 +0000745 return result;
746 /*
747 * If we reach here, one of the above errors happened.
748 * Throw the instruction away.
749 */
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700750 goto fail;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000751 } else /* DB ... */ if (oper_num == 0)
H. Peter Anvin00444ae2009-07-18 18:49:55 -0700752 nasm_error(ERR_WARNING | ERR_PASS1,
H. Peter Anvine2c80182005-01-15 22:15:51 +0000753 "no operand for data declaration");
754 else
755 result->operands = oper_num;
H. Peter Anvind7ed89e2002-04-30 20:52:08 +0000756
H. Peter Anvine2c80182005-01-15 22:15:51 +0000757 return result;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000758 }
759
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400760 /*
761 * Now we begin to parse the operands. There may be up to four
762 * of these, separated by commas, and terminated by a zero token.
763 */
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000764
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700765 for (opnum = 0; opnum < MAX_OPERANDS; opnum++) {
766 operand *op = &result->oprs[opnum];
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300767 expr *value; /* used most of the time */
H. Peter Anvin9148fb52013-09-27 16:39:16 -0700768 bool mref; /* is this going to be a memory ref? */
769 bool bracket; /* is it a [] mref, or a & mref? */
770 bool mib; /* compound (mib) mref? */
H. Peter Anvine2c80182005-01-15 22:15:51 +0000771 int setsize = 0;
Jin Kyu Song72018a22013-08-05 20:46:18 -0700772 decoflags_t brace_flags = 0; /* flags for decorators in braces */
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000773
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700774 op->disp_size = 0; /* have to zero this whatever */
775 op->eaflags = 0; /* and this */
776 op->opflags = 0;
777 op->decoflags = 0;
H. Peter Anvineba20a72002-04-30 20:53:55 +0000778
H. Peter Anvine2c80182005-01-15 22:15:51 +0000779 i = stdscan(NULL, &tokval);
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400780 if (i == TOKEN_EOS)
H. Peter Anvine2c80182005-01-15 22:15:51 +0000781 break; /* end of operands: get out of here */
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300782 else if (first && i == ':') {
783 insn_is_label = true;
784 goto restart_parse;
785 }
786 first = false;
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700787 op->type = 0; /* so far, no override */
H. Peter Anvine2c80182005-01-15 22:15:51 +0000788 while (i == TOKEN_SPECIAL) { /* size specifiers */
H. Peter Anvin09dff8b2017-03-01 01:01:37 -0800789 switch (tokval.t_integer) {
H. Peter Anvine2c80182005-01-15 22:15:51 +0000790 case S_BYTE:
791 if (!setsize) /* we want to use only the first */
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700792 op->type |= BITS8;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000793 setsize = 1;
794 break;
795 case S_WORD:
796 if (!setsize)
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700797 op->type |= BITS16;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000798 setsize = 1;
799 break;
800 case S_DWORD:
801 case S_LONG:
802 if (!setsize)
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700803 op->type |= BITS32;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000804 setsize = 1;
805 break;
806 case S_QWORD:
807 if (!setsize)
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700808 op->type |= BITS64;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000809 setsize = 1;
810 break;
811 case S_TWORD:
812 if (!setsize)
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700813 op->type |= BITS80;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000814 setsize = 1;
815 break;
H. Peter Anvin41c9f6f2007-09-18 13:01:32 -0700816 case S_OWORD:
817 if (!setsize)
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700818 op->type |= BITS128;
H. Peter Anvin41c9f6f2007-09-18 13:01:32 -0700819 setsize = 1;
820 break;
H. Peter Anvindfb91802008-05-20 11:43:53 -0700821 case S_YWORD:
822 if (!setsize)
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700823 op->type |= BITS256;
H. Peter Anvindfb91802008-05-20 11:43:53 -0700824 setsize = 1;
825 break;
Jin Kyu Songd4760c12013-08-21 19:29:11 -0700826 case S_ZWORD:
827 if (!setsize)
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700828 op->type |= BITS512;
Jin Kyu Songd4760c12013-08-21 19:29:11 -0700829 setsize = 1;
830 break;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000831 case S_TO:
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700832 op->type |= TO;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000833 break;
834 case S_STRICT:
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700835 op->type |= STRICT;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000836 break;
837 case S_FAR:
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700838 op->type |= FAR;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000839 break;
840 case S_NEAR:
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700841 op->type |= NEAR;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000842 break;
843 case S_SHORT:
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700844 op->type |= SHORT;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000845 break;
846 default:
H. Peter Anvin00444ae2009-07-18 18:49:55 -0700847 nasm_error(ERR_NONFATAL, "invalid operand size specification");
H. Peter Anvine2c80182005-01-15 22:15:51 +0000848 }
849 i = stdscan(NULL, &tokval);
850 }
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000851
H. Peter Anvine2c80182005-01-15 22:15:51 +0000852 if (i == '[' || i == '&') { /* memory reference */
H. Peter Anvin6867acc2007-10-10 14:58:45 -0700853 mref = true;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000854 bracket = (i == '[');
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700855 i = stdscan(NULL, &tokval); /* then skip the colon */
856 while (i == TOKEN_SPECIAL || i == TOKEN_PREFIX) {
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700857 process_size_override(result, op);
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700858 i = stdscan(NULL, &tokval);
H. Peter Anvine2c80182005-01-15 22:15:51 +0000859 }
Jin Kyu Song164d6072013-10-15 19:10:13 -0700860 /* when a comma follows an opening bracket - [ , eax*4] */
861 if (i == ',') {
862 /* treat as if there is a zero displacement virtually */
863 tokval.t_type = TOKEN_NUM;
864 tokval.t_integer = 0;
865 stdscan_set(stdscan_get() - 1); /* rewind the comma */
866 }
H. Peter Anvine2c80182005-01-15 22:15:51 +0000867 } else { /* immediate operand, or register */
H. Peter Anvin6867acc2007-10-10 14:58:45 -0700868 mref = false;
869 bracket = false; /* placate optimisers */
H. Peter Anvine2c80182005-01-15 22:15:51 +0000870 }
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000871
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700872 if ((op->type & FAR) && !mref &&
H. Peter Anvine2c80182005-01-15 22:15:51 +0000873 result->opcode != I_JMP && result->opcode != I_CALL) {
H. Peter Anvin00444ae2009-07-18 18:49:55 -0700874 nasm_error(ERR_NONFATAL, "invalid use of FAR operand specifier");
H. Peter Anvine2c80182005-01-15 22:15:51 +0000875 }
Debbie Wiles63b53f72002-06-04 19:31:24 +0000876
H. Peter Anvine2c80182005-01-15 22:15:51 +0000877 value = evaluate(stdscan, NULL, &tokval,
H. Peter Anvin130736c2016-02-17 20:27:41 -0800878 &op->opflags, critical, &hints);
H. Peter Anvine2c80182005-01-15 22:15:51 +0000879 i = tokval.t_type;
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700880 if (op->opflags & OPFLAG_FORWARD) {
H. Peter Anvin6867acc2007-10-10 14:58:45 -0700881 result->forw_ref = true;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000882 }
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700883 if (!value) /* Error in evaluator */
884 goto fail;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000885 if (i == ':' && mref) { /* it was seg:offset */
886 /*
887 * Process the segment override.
888 */
Cyrill Gorcunov5abbe372011-08-28 18:49:00 +0400889 if (value[1].type != 0 ||
890 value->value != 1 ||
891 !IS_SREG(value->type))
H. Peter Anvin00444ae2009-07-18 18:49:55 -0700892 nasm_error(ERR_NONFATAL, "invalid segment override");
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700893 else if (result->prefixes[PPS_SEG])
H. Peter Anvin00444ae2009-07-18 18:49:55 -0700894 nasm_error(ERR_NONFATAL,
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700895 "instruction has conflicting segment overrides");
H. Peter Anvin99c4ecd2007-08-28 23:06:00 +0000896 else {
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300897 result->prefixes[PPS_SEG] = value->type;
Cyrill Gorcunov5abbe372011-08-28 18:49:00 +0400898 if (IS_FSGS(value->type))
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700899 op->eaflags |= EAF_FSGS;
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300900 }
H. Peter Anvin76690a12002-04-30 20:52:49 +0000901
H. Peter Anvine2c80182005-01-15 22:15:51 +0000902 i = stdscan(NULL, &tokval); /* then skip the colon */
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700903 while (i == TOKEN_SPECIAL || i == TOKEN_PREFIX) {
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700904 process_size_override(result, op);
H. Peter Anvine2c80182005-01-15 22:15:51 +0000905 i = stdscan(NULL, &tokval);
906 }
907 value = evaluate(stdscan, NULL, &tokval,
H. Peter Anvin130736c2016-02-17 20:27:41 -0800908 &op->opflags, critical, &hints);
H. Peter Anvine2c80182005-01-15 22:15:51 +0000909 i = tokval.t_type;
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700910 if (op->opflags & OPFLAG_FORWARD) {
H. Peter Anvin6867acc2007-10-10 14:58:45 -0700911 result->forw_ref = true;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000912 }
913 /* and get the offset */
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700914 if (!value) /* Error in evaluator */
915 goto fail;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000916 }
Victor van den Elzen02846d32009-06-23 03:47:07 +0200917
H. Peter Anvin9148fb52013-09-27 16:39:16 -0700918 mib = false;
919 if (mref && bracket && i == ',') {
920 /* [seg:base+offset,index*scale] syntax (mib) */
921
922 operand o1, o2; /* Partial operands */
923
924 if (parse_mref(&o1, value))
925 goto fail;
926
927 i = stdscan(NULL, &tokval); /* Eat comma */
928 value = evaluate(stdscan, NULL, &tokval, &op->opflags,
H. Peter Anvin130736c2016-02-17 20:27:41 -0800929 critical, &hints);
H. Peter Anvin9148fb52013-09-27 16:39:16 -0700930 i = tokval.t_type;
Cyrill Gorcunov5c0b0822014-11-22 18:20:29 +0300931 if (!value)
932 goto fail;
H. Peter Anvin9148fb52013-09-27 16:39:16 -0700933
934 if (parse_mref(&o2, value))
935 goto fail;
936
937 if (o2.basereg != -1 && o2.indexreg == -1) {
938 o2.indexreg = o2.basereg;
939 o2.scale = 1;
940 o2.basereg = -1;
941 }
942
943 if (o1.indexreg != -1 || o2.basereg != -1 || o2.offset != 0 ||
944 o2.segment != NO_SEG || o2.wrt != NO_SEG) {
945 nasm_error(ERR_NONFATAL, "invalid mib expression");
946 goto fail;
947 }
948
949 op->basereg = o1.basereg;
950 op->indexreg = o2.indexreg;
951 op->scale = o2.scale;
952 op->offset = o1.offset;
953 op->segment = o1.segment;
954 op->wrt = o1.wrt;
955
956 if (op->basereg != -1) {
957 op->hintbase = op->basereg;
958 op->hinttype = EAH_MAKEBASE;
959 } else if (op->indexreg != -1) {
960 op->hintbase = op->indexreg;
961 op->hinttype = EAH_NOTBASE;
962 } else {
963 op->hintbase = -1;
964 op->hinttype = EAH_NOHINT;
965 }
966
967 mib = true;
968 }
969
H. Peter Anvin552bc2c2009-06-23 11:34:42 -0700970 recover = false;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000971 if (mref && bracket) { /* find ] at the end */
972 if (i != ']') {
H. Peter Anvin00444ae2009-07-18 18:49:55 -0700973 nasm_error(ERR_NONFATAL, "parser: expecting ]");
Victor van den Elzen02846d32009-06-23 03:47:07 +0200974 recover = true;
975 } else { /* we got the required ] */
H. Peter Anvine2c80182005-01-15 22:15:51 +0000976 i = stdscan(NULL, &tokval);
H. Peter Anvinc33d95f2017-03-31 14:37:24 -0700977 if (i == TOKEN_DECORATOR || i == TOKEN_OPMASK) {
978 /* parse opmask (and zeroing) after an operand */
979 recover = parse_braces(&brace_flags);
980 i = tokval.t_type;
Jin Kyu Song72018a22013-08-05 20:46:18 -0700981 }
Victor van den Elzen02846d32009-06-23 03:47:07 +0200982 if (i != 0 && i != ',') {
H. Peter Anvin00444ae2009-07-18 18:49:55 -0700983 nasm_error(ERR_NONFATAL, "comma or end of line expected");
Victor van den Elzen02846d32009-06-23 03:47:07 +0200984 recover = true;
985 }
986 }
H. Peter Anvine2c80182005-01-15 22:15:51 +0000987 } else { /* immediate operand */
Jin Kyu Song72018a22013-08-05 20:46:18 -0700988 if (i != 0 && i != ',' && i != ':' &&
989 i != TOKEN_DECORATOR && i != TOKEN_OPMASK) {
990 nasm_error(ERR_NONFATAL, "comma, colon, decorator or end of "
991 "line expected after operand");
Victor van den Elzen02846d32009-06-23 03:47:07 +0200992 recover = true;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000993 } else if (i == ':') {
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700994 op->type |= COLON;
Jin Kyu Song72018a22013-08-05 20:46:18 -0700995 } else if (i == TOKEN_DECORATOR || i == TOKEN_OPMASK) {
996 /* parse opmask (and zeroing) after an operand */
997 recover = parse_braces(&brace_flags);
H. Peter Anvine2c80182005-01-15 22:15:51 +0000998 }
999 }
Victor van den Elzen02846d32009-06-23 03:47:07 +02001000 if (recover) {
1001 do { /* error recovery */
1002 i = stdscan(NULL, &tokval);
1003 } while (i != 0 && i != ',');
1004 }
H. Peter Anvinea6e34d2002-04-30 20:51:32 +00001005
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +03001006 /*
1007 * now convert the exprs returned from evaluate()
1008 * into operand descriptions...
1009 */
H. Peter Anvin9148fb52013-09-27 16:39:16 -07001010 op->decoflags |= brace_flags;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +00001011
H. Peter Anvine2c80182005-01-15 22:15:51 +00001012 if (mref) { /* it's a memory reference */
H. Peter Anvin9148fb52013-09-27 16:39:16 -07001013 /* A mib reference was fully parsed already */
1014 if (!mib) {
1015 if (parse_mref(op, value))
1016 goto fail;
1017 op->hintbase = hints.base;
1018 op->hinttype = hints.type;
1019 }
1020 mref_set_optype(op);
H. Peter Anvine2c80182005-01-15 22:15:51 +00001021 } else { /* it's not a memory reference */
H. Peter Anvine2c80182005-01-15 22:15:51 +00001022 if (is_just_unknown(value)) { /* it's immediate but unknown */
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001023 op->type |= IMMEDIATE;
1024 op->opflags |= OPFLAG_UNKNOWN;
1025 op->offset = 0; /* don't care */
1026 op->segment = NO_SEG; /* don't care again */
1027 op->wrt = NO_SEG; /* still don't care */
Victor van den Elzen154e5922009-02-25 17:32:00 +01001028
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001029 if(optimizing >= 0 && !(op->type & STRICT)) {
Cyrill Gorcunov210c1012009-11-01 10:24:48 +03001030 /* Be optimistic */
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001031 op->type |=
Ben Rudiak-Gould4e8396b2013-03-01 10:28:32 +04001032 UNITY | SBYTEWORD | SBYTEDWORD | UDWORD | SDWORD;
Cyrill Gorcunov210c1012009-11-01 10:24:48 +03001033 }
H. Peter Anvine2c80182005-01-15 22:15:51 +00001034 } else if (is_reloc(value)) { /* it's immediate */
H. Peter Anvin87646092017-02-28 17:44:24 -08001035 uint64_t n = reloc_value(value);
1036
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001037 op->type |= IMMEDIATE;
H. Peter Anvin87646092017-02-28 17:44:24 -08001038 op->offset = n;
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001039 op->segment = reloc_seg(value);
1040 op->wrt = reloc_wrt(value);
H. Peter Anvin164d2462017-02-20 02:39:56 -08001041 op->opflags |= is_self_relative(value) ? OPFLAG_RELATIVE : 0;
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +04001042
H. Peter Anvine2c80182005-01-15 22:15:51 +00001043 if (is_simple(value)) {
Ben Rudiak-Gould4e8396b2013-03-01 10:28:32 +04001044 if (n == 1)
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001045 op->type |= UNITY;
H. Peter Anvin87646092017-02-28 17:44:24 -08001046 if (optimizing >= 0 && !(op->type & STRICT)) {
Ben Rudiak-Gould4e8396b2013-03-01 10:28:32 +04001047 if ((uint32_t) (n + 128) <= 255)
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001048 op->type |= SBYTEDWORD;
Ben Rudiak-Gould4e8396b2013-03-01 10:28:32 +04001049 if ((uint16_t) (n + 128) <= 255)
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001050 op->type |= SBYTEWORD;
H. Peter Anvin87646092017-02-28 17:44:24 -08001051 if (n <= UINT64_C(0xFFFFFFFF))
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001052 op->type |= UDWORD;
H. Peter Anvin87646092017-02-28 17:44:24 -08001053 if (n + UINT64_C(0x80000000) <= UINT64_C(0xFFFFFFFF))
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001054 op->type |= SDWORD;
H. Peter Anvine2c80182005-01-15 22:15:51 +00001055 }
1056 }
H. Peter Anvin164d2462017-02-20 02:39:56 -08001057 } else if (value->type == EXPR_RDSAE) {
Jin Kyu Song72018a22013-08-05 20:46:18 -07001058 /*
1059 * it's not an operand but a rounding or SAE decorator.
1060 * put the decorator information in the (opflag_t) type field
1061 * of previous operand.
1062 */
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001063 opnum--; op--;
Jin Kyu Song72018a22013-08-05 20:46:18 -07001064 switch (value->value) {
1065 case BRC_RN:
1066 case BRC_RU:
1067 case BRC_RD:
1068 case BRC_RZ:
1069 case BRC_SAE:
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001070 op->decoflags |= (value->value == BRC_SAE ? SAE : ER);
Jin Kyu Song72018a22013-08-05 20:46:18 -07001071 result->evex_rm = value->value;
1072 break;
1073 default:
1074 nasm_error(ERR_NONFATAL, "invalid decorator");
1075 break;
1076 }
H. Peter Anvine2c80182005-01-15 22:15:51 +00001077 } else { /* it's a register */
Cyrill Gorcunov167917a2012-09-10 00:19:12 +04001078 opflags_t rs;
H. Peter Anvineba20a72002-04-30 20:53:55 +00001079
H. Peter Anvine2c80182005-01-15 22:15:51 +00001080 if (value->type >= EXPR_SIMPLE || value->value != 1) {
H. Peter Anvin00444ae2009-07-18 18:49:55 -07001081 nasm_error(ERR_NONFATAL, "invalid operand type");
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001082 goto fail;
H. Peter Anvine2c80182005-01-15 22:15:51 +00001083 }
H. Peter Anvineba20a72002-04-30 20:53:55 +00001084
H. Peter Anvine2c80182005-01-15 22:15:51 +00001085 /*
1086 * check that its only 1 register, not an expression...
1087 */
1088 for (i = 1; value[i].type; i++)
1089 if (value[i].value) {
H. Peter Anvin00444ae2009-07-18 18:49:55 -07001090 nasm_error(ERR_NONFATAL, "invalid operand type");
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001091 goto fail;
H. Peter Anvine2c80182005-01-15 22:15:51 +00001092 }
H. Peter Anvineba20a72002-04-30 20:53:55 +00001093
H. Peter Anvine2c80182005-01-15 22:15:51 +00001094 /* clear overrides, except TO which applies to FPU regs */
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001095 if (op->type & ~TO) {
H. Peter Anvine2c80182005-01-15 22:15:51 +00001096 /*
1097 * we want to produce a warning iff the specified size
1098 * is different from the register size
1099 */
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001100 rs = op->type & SIZE_MASK;
H. Peter Anvine2c80182005-01-15 22:15:51 +00001101 } else
H. Peter Anvin68222142007-11-18 22:18:09 -08001102 rs = 0;
H. Peter Anvine2c80182005-01-15 22:15:51 +00001103
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001104 op->type &= TO;
1105 op->type |= REGISTER;
1106 op->type |= nasm_reg_flags[value->type];
1107 op->decoflags |= brace_flags;
1108 op->basereg = value->type;
H. Peter Anvine2c80182005-01-15 22:15:51 +00001109
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001110 if (rs && (op->type & SIZE_MASK) != rs)
H. Peter Anvin00444ae2009-07-18 18:49:55 -07001111 nasm_error(ERR_WARNING | ERR_PASS1,
H. Peter Anvine2c80182005-01-15 22:15:51 +00001112 "register size specification ignored");
1113 }
1114 }
Jin Kyu Songe3a06b92013-08-28 19:15:23 -07001115
1116 /* remember the position of operand having broadcasting/ER mode */
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001117 if (op->decoflags & (BRDCAST_MASK | ER | SAE))
1118 result->evex_brerop = opnum;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +00001119 }
1120
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001121 result->operands = opnum; /* set operand count */
H. Peter Anvinea6e34d2002-04-30 20:51:32 +00001122
Cyrill Gorcunovc2509502009-10-14 15:36:45 +04001123 /* clear remaining operands */
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001124 while (opnum < MAX_OPERANDS)
1125 result->oprs[opnum++].type = 0;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +00001126
1127 /*
H. Peter Anvin9d546102013-10-02 18:25:19 -07001128 * Transform RESW, RESD, RESQ, REST, RESO, RESY, RESZ into RESB.
H. Peter Anvinea6e34d2002-04-30 20:51:32 +00001129 */
H. Peter Anvin3e458a82017-05-01 20:28:29 -07001130 if (opcode_is_resb(result->opcode)) {
H. Peter Anvinaf9fe8f2017-05-01 21:44:24 -07001131 result->oprs[0].offset *= resb_bytes(result->opcode);
H. Peter Anvin3e458a82017-05-01 20:28:29 -07001132 result->oprs[0].offset *= result->times;
1133 result->times = 1;
H. Peter Anvine2c80182005-01-15 22:15:51 +00001134 result->opcode = I_RESB;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +00001135 }
1136
1137 return result;
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001138
1139fail:
1140 result->opcode = I_none;
1141 return result;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +00001142}
1143
H. Peter Anvine2c80182005-01-15 22:15:51 +00001144static int is_comma_next(void)
H. Peter Anvineba20a72002-04-30 20:53:55 +00001145{
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +04001146 struct tokenval tv;
Keith Kaniosa6dfa782007-04-13 16:47:53 +00001147 char *p;
H. Peter Anvin76690a12002-04-30 20:52:49 +00001148 int i;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +00001149
Cyrill Gorcunov917117f2009-10-29 23:09:18 +03001150 p = stdscan_get();
H. Peter Anvine2c80182005-01-15 22:15:51 +00001151 i = stdscan(NULL, &tv);
Cyrill Gorcunov917117f2009-10-29 23:09:18 +03001152 stdscan_set(p);
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +04001153
H. Peter Anvin76690a12002-04-30 20:52:49 +00001154 return (i == ',' || i == ';' || !i);
H. Peter Anvinea6e34d2002-04-30 20:51:32 +00001155}
1156
H. Peter Anvine2c80182005-01-15 22:15:51 +00001157void cleanup_insn(insn * i)
H. Peter Anvineba20a72002-04-30 20:53:55 +00001158{
H. Peter Anvinea6e34d2002-04-30 20:51:32 +00001159 extop *e;
1160
H. Peter Anvin2aa77392008-06-15 17:39:45 -07001161 while ((e = i->eops)) {
1162 i->eops = e->next;
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +03001163 if (e->type == EOT_DB_STRING_FREE)
1164 nasm_free(e->stringval);
H. Peter Anvine2c80182005-01-15 22:15:51 +00001165 nasm_free(e);
H. Peter Anvinea6e34d2002-04-30 20:51:32 +00001166 }
1167}