blob: 40188410350632c0574c126acdf2d77dc7de0216 [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 Anvin98578072018-06-01 18:02:54 -0700489 define_label(result->label, location.segment,
490 location.offset, true);
H. Peter Anvine2c80182005-01-15 22:15:51 +0000491 }
H. Peter Anvineba20a72002-04-30 20:53:55 +0000492 }
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000493
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400494 /* Just a label here */
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700495 if (i == TOKEN_EOS)
496 goto fail;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000497
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000498 while (i == TOKEN_PREFIX ||
Cyrill Gorcunov5abbe372011-08-28 18:49:00 +0400499 (i == TOKEN_REG && IS_SREG(tokval.t_integer))) {
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300500 first = false;
H. Peter Anvin9c987692007-11-04 21:09:32 -0800501
H. Peter Anvine2c80182005-01-15 22:15:51 +0000502 /*
503 * Handle special case: the TIMES prefix.
504 */
505 if (i == TOKEN_PREFIX && tokval.t_integer == P_TIMES) {
506 expr *value;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000507
H. Peter Anvine2c80182005-01-15 22:15:51 +0000508 i = stdscan(NULL, &tokval);
H. Peter Anvin130736c2016-02-17 20:27:41 -0800509 value = evaluate(stdscan, NULL, &tokval, NULL, pass0, NULL);
H. Peter Anvine2c80182005-01-15 22:15:51 +0000510 i = tokval.t_type;
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700511 if (!value) /* Error in evaluator */
512 goto fail;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000513 if (!is_simple(value)) {
H. Peter Anvin00444ae2009-07-18 18:49:55 -0700514 nasm_error(ERR_NONFATAL,
H. Peter Anvine2c80182005-01-15 22:15:51 +0000515 "non-constant argument supplied to TIMES");
516 result->times = 1L;
517 } else {
518 result->times = value->value;
H. Peter Anvin94ead272017-09-27 15:22:23 -0700519 if (value->value < 0) {
520 nasm_error(ERR_NONFATAL|ERR_PASS2, "TIMES value %"PRId64" is negative", value->value);
H. Peter Anvine2c80182005-01-15 22:15:51 +0000521 result->times = 0;
522 }
523 }
524 } else {
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300525 int slot = prefix_slot(tokval.t_integer);
526 if (result->prefixes[slot]) {
Charles Crayne052c0bd2007-10-29 18:24:59 -0700527 if (result->prefixes[slot] == tokval.t_integer)
Victor van den Elzend55a1582010-11-07 23:47:13 +0100528 nasm_error(ERR_WARNING | ERR_PASS1,
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300529 "instruction has redundant prefixes");
Charles Crayne052c0bd2007-10-29 18:24:59 -0700530 else
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300531 nasm_error(ERR_NONFATAL,
532 "instruction has conflicting prefixes");
533 }
534 result->prefixes[slot] = tokval.t_integer;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000535 i = stdscan(NULL, &tokval);
536 }
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000537 }
538
539 if (i != TOKEN_INSN) {
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300540 int j;
541 enum prefixes pfx;
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700542
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400543 for (j = 0; j < MAXPREFIX; j++) {
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300544 if ((pfx = result->prefixes[j]) != P_none)
545 break;
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400546 }
H. Peter Anvincb583b92007-10-28 22:04:42 -0700547
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700548 if (i == 0 && pfx != P_none) {
H. Peter Anvine2c80182005-01-15 22:15:51 +0000549 /*
550 * Instruction prefixes are present, but no actual
551 * instruction. This is allowed: at this point we
552 * invent a notional instruction of RESB 0.
553 */
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400554 result->opcode = I_RESB;
555 result->operands = 1;
H. Peter Anvin1980abf2017-03-31 14:52:03 -0700556 nasm_zero(result->oprs);
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400557 result->oprs[0].type = IMMEDIATE;
558 result->oprs[0].offset = 0L;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000559 result->oprs[0].segment = result->oprs[0].wrt = NO_SEG;
560 return result;
561 } else {
H. Peter Anvin00444ae2009-07-18 18:49:55 -0700562 nasm_error(ERR_NONFATAL, "parser: instruction expected");
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700563 goto fail;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000564 }
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000565 }
566
567 result->opcode = tokval.t_integer;
568 result->condition = tokval.t_inttwo;
569
570 /*
Charles Crayne2581c862008-09-10 19:21:52 -0700571 * INCBIN cannot be satisfied with incorrectly
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000572 * evaluated operands, since the correct values _must_ be known
573 * on the first pass. Hence, even in pass one, we set the
574 * `critical' flag on calling evaluate(), so that it will bomb
Charles Crayne2581c862008-09-10 19:21:52 -0700575 * out on undefined symbols.
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000576 */
Charles Crayne2581c862008-09-10 19:21:52 -0700577 if (result->opcode == I_INCBIN) {
Charles Crayne5a7976c2008-03-26 17:20:21 -0700578 critical = (pass0 < 2 ? 1 : 2);
579
H. Peter Anvine2c80182005-01-15 22:15:51 +0000580 } else
581 critical = (pass == 2 ? 2 : 0);
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000582
H. Peter Anvin3e458a82017-05-01 20:28:29 -0700583 if (opcode_is_db(result->opcode) || result->opcode == I_INCBIN) {
H. Peter Anvine2c80182005-01-15 22:15:51 +0000584 extop *eop, **tail = &result->eops, **fixptr;
585 int oper_num = 0;
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300586 int32_t sign;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000587
H. Peter Anvin6867acc2007-10-10 14:58:45 -0700588 result->eops_float = false;
H. Peter Anvineba20a72002-04-30 20:53:55 +0000589
H. Peter Anvine2c80182005-01-15 22:15:51 +0000590 /*
H. Peter Anvin9d546102013-10-02 18:25:19 -0700591 * Begin to read the DB/DW/DD/DQ/DT/DO/DY/DZ/INCBIN operands.
H. Peter Anvine2c80182005-01-15 22:15:51 +0000592 */
593 while (1) {
594 i = stdscan(NULL, &tokval);
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400595 if (i == TOKEN_EOS)
H. Peter Anvine2c80182005-01-15 22:15:51 +0000596 break;
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300597 else if (first && i == ':') {
598 insn_is_label = true;
599 goto restart_parse;
600 }
601 first = false;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000602 fixptr = tail;
603 eop = *tail = nasm_malloc(sizeof(extop));
604 tail = &eop->next;
605 eop->next = NULL;
606 eop->type = EOT_NOTHING;
607 oper_num++;
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300608 sign = +1;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000609
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300610 /*
611 * is_comma_next() here is to distinguish this from
612 * a string used as part of an expression...
613 */
H. Peter Anvin11627042008-06-09 20:45:19 -0700614 if (i == TOKEN_STR && is_comma_next()) {
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400615 eop->type = EOT_DB_STRING;
616 eop->stringval = tokval.t_charptr;
617 eop->stringlen = tokval.t_inttwo;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000618 i = stdscan(NULL, &tokval); /* eat the comma */
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300619 } else if (i == TOKEN_STRFUNC) {
620 bool parens = false;
621 const char *funcname = tokval.t_charptr;
622 enum strfunc func = tokval.t_integer;
623 i = stdscan(NULL, &tokval);
624 if (i == '(') {
625 parens = true;
626 i = stdscan(NULL, &tokval);
627 }
628 if (i != TOKEN_STR) {
629 nasm_error(ERR_NONFATAL,
630 "%s must be followed by a string constant",
631 funcname);
632 eop->type = EOT_NOTHING;
633 } else {
634 eop->type = EOT_DB_STRING_FREE;
635 eop->stringlen =
636 string_transform(tokval.t_charptr, tokval.t_inttwo,
637 &eop->stringval, func);
638 if (eop->stringlen == (size_t)-1) {
639 nasm_error(ERR_NONFATAL, "invalid string for transform");
640 eop->type = EOT_NOTHING;
641 }
642 }
643 if (parens && i && i != ')') {
644 i = stdscan(NULL, &tokval);
645 if (i != ')') {
646 nasm_error(ERR_NONFATAL, "unterminated %s function",
647 funcname);
648 }
649 }
650 if (i && i != ',')
651 i = stdscan(NULL, &tokval);
652 } else if (i == '-' || i == '+') {
653 char *save = stdscan_get();
654 int token = i;
655 sign = (i == '-') ? -1 : 1;
656 i = stdscan(NULL, &tokval);
657 if (i != TOKEN_FLOAT) {
658 stdscan_set(save);
659 i = tokval.t_type = token;
660 goto is_expression;
661 } else {
662 goto is_float;
663 }
H. Peter Anvin518df302008-06-14 16:53:48 -0700664 } else if (i == TOKEN_FLOAT) {
Cyrill Gorcunovbafd8772009-10-31 20:02:14 +0300665is_float:
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300666 eop->type = EOT_DB_STRING;
667 result->eops_float = true;
Cyrill Gorcunovbafd8772009-10-31 20:02:14 +0300668
H. Peter Anvinaf9fe8f2017-05-01 21:44:24 -0700669 eop->stringlen = db_bytes(result->opcode);
Cyrill Gorcunovbafd8772009-10-31 20:02:14 +0300670 if (eop->stringlen > 16) {
671 nasm_error(ERR_NONFATAL, "floating-point constant"
H. Peter Anvin9d546102013-10-02 18:25:19 -0700672 " encountered in DY or DZ instruction");
Cyrill Gorcunovbafd8772009-10-31 20:02:14 +0300673 eop->stringlen = 0;
674 } else if (eop->stringlen < 1) {
675 nasm_error(ERR_NONFATAL, "floating-point constant"
676 " encountered in unknown instruction");
677 /*
678 * fix suggested by Pedro Gimeno... original line was:
679 * eop->type = EOT_NOTHING;
680 */
681 eop->stringlen = 0;
682 }
683
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300684 eop = nasm_realloc(eop, sizeof(extop) + eop->stringlen);
685 tail = &eop->next;
686 *fixptr = eop;
687 eop->stringval = (char *)eop + sizeof(extop);
688 if (!eop->stringlen ||
689 !float_const(tokval.t_charptr, sign,
H. Peter Anvin130736c2016-02-17 20:27:41 -0800690 (uint8_t *)eop->stringval, eop->stringlen))
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300691 eop->type = EOT_NOTHING;
692 i = stdscan(NULL, &tokval); /* eat the comma */
693 } else {
694 /* anything else, assume it is an expression */
H. Peter Anvine2c80182005-01-15 22:15:51 +0000695 expr *value;
H. Peter Anvin518df302008-06-14 16:53:48 -0700696
Cyrill Gorcunovbafd8772009-10-31 20:02:14 +0300697is_expression:
H. Peter Anvine2c80182005-01-15 22:15:51 +0000698 value = evaluate(stdscan, NULL, &tokval, NULL,
H. Peter Anvin130736c2016-02-17 20:27:41 -0800699 critical, NULL);
H. Peter Anvine2c80182005-01-15 22:15:51 +0000700 i = tokval.t_type;
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700701 if (!value) /* Error in evaluator */
702 goto fail;
H. Peter Anvin472a7c12016-10-31 08:44:25 -0700703 if (value_to_extop(value, eop, location.segment)) {
H. Peter Anvin00444ae2009-07-18 18:49:55 -0700704 nasm_error(ERR_NONFATAL,
H. Peter Anvin472a7c12016-10-31 08:44:25 -0700705 "operand %d: expression is not simple or relocatable",
706 oper_num);
H. Peter Anvine2c80182005-01-15 22:15:51 +0000707 }
708 }
H. Peter Anvin6768eb72002-04-30 20:52:26 +0000709
H. Peter Anvine2c80182005-01-15 22:15:51 +0000710 /*
711 * We're about to call stdscan(), which will eat the
712 * comma that we're currently sitting on between
713 * arguments. However, we'd better check first that it
714 * _is_ a comma.
715 */
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400716 if (i == TOKEN_EOS) /* also could be EOL */
H. Peter Anvine2c80182005-01-15 22:15:51 +0000717 break;
718 if (i != ',') {
H. Peter Anvin00444ae2009-07-18 18:49:55 -0700719 nasm_error(ERR_NONFATAL, "comma expected after operand %d",
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400720 oper_num);
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700721 goto fail;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000722 }
723 }
H. Peter Anvind7ed89e2002-04-30 20:52:08 +0000724
H. Peter Anvine2c80182005-01-15 22:15:51 +0000725 if (result->opcode == I_INCBIN) {
726 /*
727 * Correct syntax for INCBIN is that there should be
728 * one string operand, followed by one or two numeric
729 * operands.
730 */
731 if (!result->eops || result->eops->type != EOT_DB_STRING)
H. Peter Anvin00444ae2009-07-18 18:49:55 -0700732 nasm_error(ERR_NONFATAL, "`incbin' expects a file name");
H. Peter Anvine2c80182005-01-15 22:15:51 +0000733 else if (result->eops->next &&
734 result->eops->next->type != EOT_DB_NUMBER)
Victor van den Elzen15bb2332009-08-11 02:10:16 +0200735 nasm_error(ERR_NONFATAL, "`incbin': second parameter is"
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400736 " non-numeric");
H. Peter Anvine2c80182005-01-15 22:15:51 +0000737 else if (result->eops->next && result->eops->next->next &&
738 result->eops->next->next->type != EOT_DB_NUMBER)
Victor van den Elzen15bb2332009-08-11 02:10:16 +0200739 nasm_error(ERR_NONFATAL, "`incbin': third parameter is"
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400740 " non-numeric");
H. Peter Anvine2c80182005-01-15 22:15:51 +0000741 else if (result->eops->next && result->eops->next->next &&
742 result->eops->next->next->next)
H. Peter Anvin00444ae2009-07-18 18:49:55 -0700743 nasm_error(ERR_NONFATAL,
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400744 "`incbin': more than three parameters");
H. Peter Anvineba20a72002-04-30 20:53:55 +0000745 else
H. Peter Anvine2c80182005-01-15 22:15:51 +0000746 return result;
747 /*
748 * If we reach here, one of the above errors happened.
749 * Throw the instruction away.
750 */
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700751 goto fail;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000752 } else /* DB ... */ if (oper_num == 0)
H. Peter Anvin00444ae2009-07-18 18:49:55 -0700753 nasm_error(ERR_WARNING | ERR_PASS1,
H. Peter Anvine2c80182005-01-15 22:15:51 +0000754 "no operand for data declaration");
755 else
756 result->operands = oper_num;
H. Peter Anvind7ed89e2002-04-30 20:52:08 +0000757
H. Peter Anvine2c80182005-01-15 22:15:51 +0000758 return result;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000759 }
760
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400761 /*
762 * Now we begin to parse the operands. There may be up to four
763 * of these, separated by commas, and terminated by a zero token.
764 */
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000765
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700766 for (opnum = 0; opnum < MAX_OPERANDS; opnum++) {
767 operand *op = &result->oprs[opnum];
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300768 expr *value; /* used most of the time */
H. Peter Anvin9148fb52013-09-27 16:39:16 -0700769 bool mref; /* is this going to be a memory ref? */
770 bool bracket; /* is it a [] mref, or a & mref? */
771 bool mib; /* compound (mib) mref? */
H. Peter Anvine2c80182005-01-15 22:15:51 +0000772 int setsize = 0;
Jin Kyu Song72018a22013-08-05 20:46:18 -0700773 decoflags_t brace_flags = 0; /* flags for decorators in braces */
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000774
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700775 op->disp_size = 0; /* have to zero this whatever */
776 op->eaflags = 0; /* and this */
777 op->opflags = 0;
778 op->decoflags = 0;
H. Peter Anvineba20a72002-04-30 20:53:55 +0000779
H. Peter Anvine2c80182005-01-15 22:15:51 +0000780 i = stdscan(NULL, &tokval);
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400781 if (i == TOKEN_EOS)
H. Peter Anvine2c80182005-01-15 22:15:51 +0000782 break; /* end of operands: get out of here */
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300783 else if (first && i == ':') {
784 insn_is_label = true;
785 goto restart_parse;
786 }
787 first = false;
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700788 op->type = 0; /* so far, no override */
H. Peter Anvine2c80182005-01-15 22:15:51 +0000789 while (i == TOKEN_SPECIAL) { /* size specifiers */
H. Peter Anvin09dff8b2017-03-01 01:01:37 -0800790 switch (tokval.t_integer) {
H. Peter Anvine2c80182005-01-15 22:15:51 +0000791 case S_BYTE:
792 if (!setsize) /* we want to use only the first */
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700793 op->type |= BITS8;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000794 setsize = 1;
795 break;
796 case S_WORD:
797 if (!setsize)
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700798 op->type |= BITS16;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000799 setsize = 1;
800 break;
801 case S_DWORD:
802 case S_LONG:
803 if (!setsize)
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700804 op->type |= BITS32;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000805 setsize = 1;
806 break;
807 case S_QWORD:
808 if (!setsize)
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700809 op->type |= BITS64;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000810 setsize = 1;
811 break;
812 case S_TWORD:
813 if (!setsize)
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700814 op->type |= BITS80;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000815 setsize = 1;
816 break;
H. Peter Anvin41c9f6f2007-09-18 13:01:32 -0700817 case S_OWORD:
818 if (!setsize)
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700819 op->type |= BITS128;
H. Peter Anvin41c9f6f2007-09-18 13:01:32 -0700820 setsize = 1;
821 break;
H. Peter Anvindfb91802008-05-20 11:43:53 -0700822 case S_YWORD:
823 if (!setsize)
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700824 op->type |= BITS256;
H. Peter Anvindfb91802008-05-20 11:43:53 -0700825 setsize = 1;
826 break;
Jin Kyu Songd4760c12013-08-21 19:29:11 -0700827 case S_ZWORD:
828 if (!setsize)
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700829 op->type |= BITS512;
Jin Kyu Songd4760c12013-08-21 19:29:11 -0700830 setsize = 1;
831 break;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000832 case S_TO:
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700833 op->type |= TO;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000834 break;
835 case S_STRICT:
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700836 op->type |= STRICT;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000837 break;
838 case S_FAR:
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700839 op->type |= FAR;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000840 break;
841 case S_NEAR:
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700842 op->type |= NEAR;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000843 break;
844 case S_SHORT:
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700845 op->type |= SHORT;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000846 break;
847 default:
H. Peter Anvin00444ae2009-07-18 18:49:55 -0700848 nasm_error(ERR_NONFATAL, "invalid operand size specification");
H. Peter Anvine2c80182005-01-15 22:15:51 +0000849 }
850 i = stdscan(NULL, &tokval);
851 }
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000852
H. Peter Anvine2c80182005-01-15 22:15:51 +0000853 if (i == '[' || i == '&') { /* memory reference */
H. Peter Anvin6867acc2007-10-10 14:58:45 -0700854 mref = true;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000855 bracket = (i == '[');
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700856 i = stdscan(NULL, &tokval); /* then skip the colon */
857 while (i == TOKEN_SPECIAL || i == TOKEN_PREFIX) {
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700858 process_size_override(result, op);
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700859 i = stdscan(NULL, &tokval);
H. Peter Anvine2c80182005-01-15 22:15:51 +0000860 }
Jin Kyu Song164d6072013-10-15 19:10:13 -0700861 /* when a comma follows an opening bracket - [ , eax*4] */
862 if (i == ',') {
863 /* treat as if there is a zero displacement virtually */
864 tokval.t_type = TOKEN_NUM;
865 tokval.t_integer = 0;
866 stdscan_set(stdscan_get() - 1); /* rewind the comma */
867 }
H. Peter Anvine2c80182005-01-15 22:15:51 +0000868 } else { /* immediate operand, or register */
H. Peter Anvin6867acc2007-10-10 14:58:45 -0700869 mref = false;
870 bracket = false; /* placate optimisers */
H. Peter Anvine2c80182005-01-15 22:15:51 +0000871 }
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000872
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700873 if ((op->type & FAR) && !mref &&
H. Peter Anvine2c80182005-01-15 22:15:51 +0000874 result->opcode != I_JMP && result->opcode != I_CALL) {
H. Peter Anvin00444ae2009-07-18 18:49:55 -0700875 nasm_error(ERR_NONFATAL, "invalid use of FAR operand specifier");
H. Peter Anvine2c80182005-01-15 22:15:51 +0000876 }
Debbie Wiles63b53f72002-06-04 19:31:24 +0000877
H. Peter Anvine2c80182005-01-15 22:15:51 +0000878 value = evaluate(stdscan, NULL, &tokval,
H. Peter Anvin130736c2016-02-17 20:27:41 -0800879 &op->opflags, critical, &hints);
H. Peter Anvine2c80182005-01-15 22:15:51 +0000880 i = tokval.t_type;
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700881 if (op->opflags & OPFLAG_FORWARD) {
H. Peter Anvin6867acc2007-10-10 14:58:45 -0700882 result->forw_ref = true;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000883 }
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700884 if (!value) /* Error in evaluator */
885 goto fail;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000886 if (i == ':' && mref) { /* it was seg:offset */
887 /*
888 * Process the segment override.
889 */
Cyrill Gorcunov5abbe372011-08-28 18:49:00 +0400890 if (value[1].type != 0 ||
891 value->value != 1 ||
892 !IS_SREG(value->type))
H. Peter Anvin00444ae2009-07-18 18:49:55 -0700893 nasm_error(ERR_NONFATAL, "invalid segment override");
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700894 else if (result->prefixes[PPS_SEG])
H. Peter Anvin00444ae2009-07-18 18:49:55 -0700895 nasm_error(ERR_NONFATAL,
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700896 "instruction has conflicting segment overrides");
H. Peter Anvin99c4ecd2007-08-28 23:06:00 +0000897 else {
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300898 result->prefixes[PPS_SEG] = value->type;
Cyrill Gorcunov5abbe372011-08-28 18:49:00 +0400899 if (IS_FSGS(value->type))
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700900 op->eaflags |= EAF_FSGS;
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300901 }
H. Peter Anvin76690a12002-04-30 20:52:49 +0000902
H. Peter Anvine2c80182005-01-15 22:15:51 +0000903 i = stdscan(NULL, &tokval); /* then skip the colon */
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700904 while (i == TOKEN_SPECIAL || i == TOKEN_PREFIX) {
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700905 process_size_override(result, op);
H. Peter Anvine2c80182005-01-15 22:15:51 +0000906 i = stdscan(NULL, &tokval);
907 }
908 value = evaluate(stdscan, NULL, &tokval,
H. Peter Anvin130736c2016-02-17 20:27:41 -0800909 &op->opflags, critical, &hints);
H. Peter Anvine2c80182005-01-15 22:15:51 +0000910 i = tokval.t_type;
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700911 if (op->opflags & OPFLAG_FORWARD) {
H. Peter Anvin6867acc2007-10-10 14:58:45 -0700912 result->forw_ref = true;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000913 }
914 /* and get the offset */
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700915 if (!value) /* Error in evaluator */
916 goto fail;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000917 }
Victor van den Elzen02846d32009-06-23 03:47:07 +0200918
H. Peter Anvin9148fb52013-09-27 16:39:16 -0700919 mib = false;
920 if (mref && bracket && i == ',') {
921 /* [seg:base+offset,index*scale] syntax (mib) */
922
923 operand o1, o2; /* Partial operands */
924
925 if (parse_mref(&o1, value))
926 goto fail;
927
928 i = stdscan(NULL, &tokval); /* Eat comma */
929 value = evaluate(stdscan, NULL, &tokval, &op->opflags,
H. Peter Anvin130736c2016-02-17 20:27:41 -0800930 critical, &hints);
H. Peter Anvin9148fb52013-09-27 16:39:16 -0700931 i = tokval.t_type;
Cyrill Gorcunov5c0b0822014-11-22 18:20:29 +0300932 if (!value)
933 goto fail;
H. Peter Anvin9148fb52013-09-27 16:39:16 -0700934
935 if (parse_mref(&o2, value))
936 goto fail;
937
938 if (o2.basereg != -1 && o2.indexreg == -1) {
939 o2.indexreg = o2.basereg;
940 o2.scale = 1;
941 o2.basereg = -1;
942 }
943
944 if (o1.indexreg != -1 || o2.basereg != -1 || o2.offset != 0 ||
945 o2.segment != NO_SEG || o2.wrt != NO_SEG) {
946 nasm_error(ERR_NONFATAL, "invalid mib expression");
947 goto fail;
948 }
949
950 op->basereg = o1.basereg;
951 op->indexreg = o2.indexreg;
952 op->scale = o2.scale;
953 op->offset = o1.offset;
954 op->segment = o1.segment;
955 op->wrt = o1.wrt;
956
957 if (op->basereg != -1) {
958 op->hintbase = op->basereg;
959 op->hinttype = EAH_MAKEBASE;
960 } else if (op->indexreg != -1) {
961 op->hintbase = op->indexreg;
962 op->hinttype = EAH_NOTBASE;
963 } else {
964 op->hintbase = -1;
965 op->hinttype = EAH_NOHINT;
966 }
967
968 mib = true;
969 }
970
H. Peter Anvin552bc2c2009-06-23 11:34:42 -0700971 recover = false;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000972 if (mref && bracket) { /* find ] at the end */
973 if (i != ']') {
H. Peter Anvin00444ae2009-07-18 18:49:55 -0700974 nasm_error(ERR_NONFATAL, "parser: expecting ]");
Victor van den Elzen02846d32009-06-23 03:47:07 +0200975 recover = true;
976 } else { /* we got the required ] */
H. Peter Anvine2c80182005-01-15 22:15:51 +0000977 i = stdscan(NULL, &tokval);
H. Peter Anvinc33d95f2017-03-31 14:37:24 -0700978 if (i == TOKEN_DECORATOR || i == TOKEN_OPMASK) {
979 /* parse opmask (and zeroing) after an operand */
980 recover = parse_braces(&brace_flags);
981 i = tokval.t_type;
Jin Kyu Song72018a22013-08-05 20:46:18 -0700982 }
Victor van den Elzen02846d32009-06-23 03:47:07 +0200983 if (i != 0 && i != ',') {
H. Peter Anvin00444ae2009-07-18 18:49:55 -0700984 nasm_error(ERR_NONFATAL, "comma or end of line expected");
Victor van den Elzen02846d32009-06-23 03:47:07 +0200985 recover = true;
986 }
987 }
H. Peter Anvine2c80182005-01-15 22:15:51 +0000988 } else { /* immediate operand */
Jin Kyu Song72018a22013-08-05 20:46:18 -0700989 if (i != 0 && i != ',' && i != ':' &&
990 i != TOKEN_DECORATOR && i != TOKEN_OPMASK) {
991 nasm_error(ERR_NONFATAL, "comma, colon, decorator or end of "
992 "line expected after operand");
Victor van den Elzen02846d32009-06-23 03:47:07 +0200993 recover = true;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000994 } else if (i == ':') {
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700995 op->type |= COLON;
Jin Kyu Song72018a22013-08-05 20:46:18 -0700996 } else if (i == TOKEN_DECORATOR || i == TOKEN_OPMASK) {
997 /* parse opmask (and zeroing) after an operand */
998 recover = parse_braces(&brace_flags);
H. Peter Anvine2c80182005-01-15 22:15:51 +0000999 }
1000 }
Victor van den Elzen02846d32009-06-23 03:47:07 +02001001 if (recover) {
1002 do { /* error recovery */
1003 i = stdscan(NULL, &tokval);
1004 } while (i != 0 && i != ',');
1005 }
H. Peter Anvinea6e34d2002-04-30 20:51:32 +00001006
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +03001007 /*
1008 * now convert the exprs returned from evaluate()
1009 * into operand descriptions...
1010 */
H. Peter Anvin9148fb52013-09-27 16:39:16 -07001011 op->decoflags |= brace_flags;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +00001012
H. Peter Anvine2c80182005-01-15 22:15:51 +00001013 if (mref) { /* it's a memory reference */
H. Peter Anvin9148fb52013-09-27 16:39:16 -07001014 /* A mib reference was fully parsed already */
1015 if (!mib) {
1016 if (parse_mref(op, value))
1017 goto fail;
1018 op->hintbase = hints.base;
1019 op->hinttype = hints.type;
1020 }
1021 mref_set_optype(op);
H. Peter Anvine2c80182005-01-15 22:15:51 +00001022 } else { /* it's not a memory reference */
H. Peter Anvine2c80182005-01-15 22:15:51 +00001023 if (is_just_unknown(value)) { /* it's immediate but unknown */
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001024 op->type |= IMMEDIATE;
1025 op->opflags |= OPFLAG_UNKNOWN;
1026 op->offset = 0; /* don't care */
1027 op->segment = NO_SEG; /* don't care again */
1028 op->wrt = NO_SEG; /* still don't care */
Victor van den Elzen154e5922009-02-25 17:32:00 +01001029
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001030 if(optimizing >= 0 && !(op->type & STRICT)) {
Cyrill Gorcunov210c1012009-11-01 10:24:48 +03001031 /* Be optimistic */
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001032 op->type |=
Ben Rudiak-Gould4e8396b2013-03-01 10:28:32 +04001033 UNITY | SBYTEWORD | SBYTEDWORD | UDWORD | SDWORD;
Cyrill Gorcunov210c1012009-11-01 10:24:48 +03001034 }
H. Peter Anvine2c80182005-01-15 22:15:51 +00001035 } else if (is_reloc(value)) { /* it's immediate */
H. Peter Anvin87646092017-02-28 17:44:24 -08001036 uint64_t n = reloc_value(value);
1037
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001038 op->type |= IMMEDIATE;
H. Peter Anvin87646092017-02-28 17:44:24 -08001039 op->offset = n;
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001040 op->segment = reloc_seg(value);
1041 op->wrt = reloc_wrt(value);
H. Peter Anvin164d2462017-02-20 02:39:56 -08001042 op->opflags |= is_self_relative(value) ? OPFLAG_RELATIVE : 0;
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +04001043
H. Peter Anvine2c80182005-01-15 22:15:51 +00001044 if (is_simple(value)) {
Ben Rudiak-Gould4e8396b2013-03-01 10:28:32 +04001045 if (n == 1)
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001046 op->type |= UNITY;
H. Peter Anvin87646092017-02-28 17:44:24 -08001047 if (optimizing >= 0 && !(op->type & STRICT)) {
Ben Rudiak-Gould4e8396b2013-03-01 10:28:32 +04001048 if ((uint32_t) (n + 128) <= 255)
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001049 op->type |= SBYTEDWORD;
Ben Rudiak-Gould4e8396b2013-03-01 10:28:32 +04001050 if ((uint16_t) (n + 128) <= 255)
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001051 op->type |= SBYTEWORD;
H. Peter Anvin87646092017-02-28 17:44:24 -08001052 if (n <= UINT64_C(0xFFFFFFFF))
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001053 op->type |= UDWORD;
H. Peter Anvin87646092017-02-28 17:44:24 -08001054 if (n + UINT64_C(0x80000000) <= UINT64_C(0xFFFFFFFF))
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001055 op->type |= SDWORD;
H. Peter Anvine2c80182005-01-15 22:15:51 +00001056 }
1057 }
H. Peter Anvin164d2462017-02-20 02:39:56 -08001058 } else if (value->type == EXPR_RDSAE) {
Jin Kyu Song72018a22013-08-05 20:46:18 -07001059 /*
1060 * it's not an operand but a rounding or SAE decorator.
1061 * put the decorator information in the (opflag_t) type field
1062 * of previous operand.
1063 */
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001064 opnum--; op--;
Jin Kyu Song72018a22013-08-05 20:46:18 -07001065 switch (value->value) {
1066 case BRC_RN:
1067 case BRC_RU:
1068 case BRC_RD:
1069 case BRC_RZ:
1070 case BRC_SAE:
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001071 op->decoflags |= (value->value == BRC_SAE ? SAE : ER);
Jin Kyu Song72018a22013-08-05 20:46:18 -07001072 result->evex_rm = value->value;
1073 break;
1074 default:
1075 nasm_error(ERR_NONFATAL, "invalid decorator");
1076 break;
1077 }
H. Peter Anvine2c80182005-01-15 22:15:51 +00001078 } else { /* it's a register */
Cyrill Gorcunov167917a2012-09-10 00:19:12 +04001079 opflags_t rs;
H. Peter Anvineba20a72002-04-30 20:53:55 +00001080
H. Peter Anvine2c80182005-01-15 22:15:51 +00001081 if (value->type >= EXPR_SIMPLE || value->value != 1) {
H. Peter Anvin00444ae2009-07-18 18:49:55 -07001082 nasm_error(ERR_NONFATAL, "invalid operand type");
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001083 goto fail;
H. Peter Anvine2c80182005-01-15 22:15:51 +00001084 }
H. Peter Anvineba20a72002-04-30 20:53:55 +00001085
H. Peter Anvine2c80182005-01-15 22:15:51 +00001086 /*
1087 * check that its only 1 register, not an expression...
1088 */
1089 for (i = 1; value[i].type; i++)
1090 if (value[i].value) {
H. Peter Anvin00444ae2009-07-18 18:49:55 -07001091 nasm_error(ERR_NONFATAL, "invalid operand type");
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001092 goto fail;
H. Peter Anvine2c80182005-01-15 22:15:51 +00001093 }
H. Peter Anvineba20a72002-04-30 20:53:55 +00001094
H. Peter Anvine2c80182005-01-15 22:15:51 +00001095 /* clear overrides, except TO which applies to FPU regs */
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001096 if (op->type & ~TO) {
H. Peter Anvine2c80182005-01-15 22:15:51 +00001097 /*
1098 * we want to produce a warning iff the specified size
1099 * is different from the register size
1100 */
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001101 rs = op->type & SIZE_MASK;
H. Peter Anvine2c80182005-01-15 22:15:51 +00001102 } else
H. Peter Anvin68222142007-11-18 22:18:09 -08001103 rs = 0;
H. Peter Anvine2c80182005-01-15 22:15:51 +00001104
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001105 op->type &= TO;
1106 op->type |= REGISTER;
1107 op->type |= nasm_reg_flags[value->type];
1108 op->decoflags |= brace_flags;
1109 op->basereg = value->type;
H. Peter Anvine2c80182005-01-15 22:15:51 +00001110
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001111 if (rs && (op->type & SIZE_MASK) != rs)
H. Peter Anvin00444ae2009-07-18 18:49:55 -07001112 nasm_error(ERR_WARNING | ERR_PASS1,
H. Peter Anvine2c80182005-01-15 22:15:51 +00001113 "register size specification ignored");
1114 }
1115 }
Jin Kyu Songe3a06b92013-08-28 19:15:23 -07001116
1117 /* remember the position of operand having broadcasting/ER mode */
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001118 if (op->decoflags & (BRDCAST_MASK | ER | SAE))
1119 result->evex_brerop = opnum;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +00001120 }
1121
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001122 result->operands = opnum; /* set operand count */
H. Peter Anvinea6e34d2002-04-30 20:51:32 +00001123
Cyrill Gorcunovc2509502009-10-14 15:36:45 +04001124 /* clear remaining operands */
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001125 while (opnum < MAX_OPERANDS)
1126 result->oprs[opnum++].type = 0;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +00001127
1128 /*
H. Peter Anvin9d546102013-10-02 18:25:19 -07001129 * Transform RESW, RESD, RESQ, REST, RESO, RESY, RESZ into RESB.
H. Peter Anvinea6e34d2002-04-30 20:51:32 +00001130 */
H. Peter Anvin3e458a82017-05-01 20:28:29 -07001131 if (opcode_is_resb(result->opcode)) {
H. Peter Anvinaf9fe8f2017-05-01 21:44:24 -07001132 result->oprs[0].offset *= resb_bytes(result->opcode);
H. Peter Anvin3e458a82017-05-01 20:28:29 -07001133 result->oprs[0].offset *= result->times;
1134 result->times = 1;
H. Peter Anvine2c80182005-01-15 22:15:51 +00001135 result->opcode = I_RESB;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +00001136 }
1137
1138 return result;
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001139
1140fail:
1141 result->opcode = I_none;
1142 return result;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +00001143}
1144
H. Peter Anvine2c80182005-01-15 22:15:51 +00001145static int is_comma_next(void)
H. Peter Anvineba20a72002-04-30 20:53:55 +00001146{
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +04001147 struct tokenval tv;
Keith Kaniosa6dfa782007-04-13 16:47:53 +00001148 char *p;
H. Peter Anvin76690a12002-04-30 20:52:49 +00001149 int i;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +00001150
Cyrill Gorcunov917117f2009-10-29 23:09:18 +03001151 p = stdscan_get();
H. Peter Anvine2c80182005-01-15 22:15:51 +00001152 i = stdscan(NULL, &tv);
Cyrill Gorcunov917117f2009-10-29 23:09:18 +03001153 stdscan_set(p);
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +04001154
H. Peter Anvin76690a12002-04-30 20:52:49 +00001155 return (i == ',' || i == ';' || !i);
H. Peter Anvinea6e34d2002-04-30 20:51:32 +00001156}
1157
H. Peter Anvine2c80182005-01-15 22:15:51 +00001158void cleanup_insn(insn * i)
H. Peter Anvineba20a72002-04-30 20:53:55 +00001159{
H. Peter Anvinea6e34d2002-04-30 20:51:32 +00001160 extop *e;
1161
H. Peter Anvin2aa77392008-06-15 17:39:45 -07001162 while ((e = i->eops)) {
1163 i->eops = e->next;
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +03001164 if (e->type == EOT_DB_STRING_FREE)
1165 nasm_free(e->stringval);
H. Peter Anvine2c80182005-01-15 22:15:51 +00001166 nasm_free(e);
H. Peter Anvinea6e34d2002-04-30 20:51:32 +00001167 }
1168}