blob: 6b52b2572966a2f8522bca5209b7f12456b5acb5 [file] [log] [blame]
H. Peter Anvin9e6747c2009-06-28 17:13:04 -07001/* ----------------------------------------------------------------------- *
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +03002 *
H. Peter Anvin164d2462017-02-20 02:39:56 -08003 * Copyright 1996-2017 The NASM Authors - All Rights Reserved
H. Peter Anvin9e6747c2009-06-28 17:13:04 -07004 * See the file AUTHORS included with the NASM distribution for
5 * the specific copyright holders.
H. Peter Anvinea6e34d2002-04-30 20:51:32 +00006 *
H. Peter Anvin9e6747c2009-06-28 17:13:04 -07007 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following
9 * conditions are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +030017 *
H. Peter Anvin9e6747c2009-06-28 17:13:04 -070018 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
19 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
20 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 * ----------------------------------------------------------------------- */
33
34/*
35 * parser.c source line parser for the Netwide Assembler
H. Peter Anvinea6e34d2002-04-30 20:51:32 +000036 */
37
H. Peter Anvinfe501952007-10-02 21:53:51 -070038#include "compiler.h"
39
H. Peter Anvinea6e34d2002-04-30 20:51:32 +000040#include <stdio.h>
41#include <stdlib.h>
42#include <stddef.h>
43#include <string.h>
44#include <ctype.h>
45
46#include "nasm.h"
H. Peter Anvin24cfef42002-09-12 16:34:06 +000047#include "insns.h"
H. Peter Anvinea6e34d2002-04-30 20:51:32 +000048#include "nasmlib.h"
H. Peter Anvinb20bc732017-03-07 19:23:03 -080049#include "error.h"
H. Peter Anvin74cc5e52007-08-30 22:35:34 +000050#include "stdscan.h"
H. Peter Anvin00444ae2009-07-18 18:49:55 -070051#include "eval.h"
H. Peter Anvinea6e34d2002-04-30 20:51:32 +000052#include "parser.h"
53#include "float.h"
H. Peter Anvinb20bc732017-03-07 19:23:03 -080054#include "assemble.h"
H. Peter Anvina4835d42008-05-20 14:21:29 -070055#include "tables.h"
H. Peter Anvinea6e34d2002-04-30 20:51:32 +000056
H. Peter Anvind0e365d2002-05-26 18:19:19 +000057
H. Peter Anvine2c80182005-01-15 22:15:51 +000058static int is_comma_next(void);
H. Peter Anvinea6e34d2002-04-30 20:51:32 +000059
H. Peter Anvinea6e34d2002-04-30 20:51:32 +000060static struct tokenval tokval;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +000061
Cyrill Gorcunov18914e62011-11-12 11:41:51 +040062static int prefix_slot(int prefix)
H. Peter Anvinde4b89b2007-10-01 15:41:25 -070063{
64 switch (prefix) {
H. Peter Anvinc2acf7b2009-02-21 18:22:56 -080065 case P_WAIT:
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +030066 return PPS_WAIT;
H. Peter Anvinde4b89b2007-10-01 15:41:25 -070067 case R_CS:
68 case R_DS:
69 case R_SS:
70 case R_ES:
71 case R_FS:
72 case R_GS:
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +030073 return PPS_SEG;
H. Peter Anvinde4b89b2007-10-01 15:41:25 -070074 case P_LOCK:
H. Peter Anvin10da41e2012-02-24 20:57:04 -080075 return PPS_LOCK;
H. Peter Anvinde4b89b2007-10-01 15:41:25 -070076 case P_REP:
77 case P_REPE:
78 case P_REPZ:
79 case P_REPNE:
80 case P_REPNZ:
H. Peter Anvin4ecd5d72012-02-24 21:51:46 -080081 case P_XACQUIRE:
82 case P_XRELEASE:
Jin Kyu Song03041092013-10-15 19:38:51 -070083 case P_BND:
Jin Kyu Songb287ff02013-12-04 20:05:55 -080084 case P_NOBND:
H. Peter Anvin10da41e2012-02-24 20:57:04 -080085 return PPS_REP;
H. Peter Anvinde4b89b2007-10-01 15:41:25 -070086 case P_O16:
87 case P_O32:
88 case P_O64:
89 case P_OSP:
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +030090 return PPS_OSIZE;
H. Peter Anvinde4b89b2007-10-01 15:41:25 -070091 case P_A16:
92 case P_A32:
93 case P_A64:
94 case P_ASP:
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +030095 return PPS_ASIZE;
Jin Kyu Song945b1b82013-10-25 19:29:53 -070096 case P_EVEX:
H. Peter Anvin621a69a2013-11-28 12:11:24 -080097 case P_VEX3:
98 case P_VEX2:
99 return PPS_VEX;
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700100 default:
H. Peter Anvin41087062016-03-03 14:27:34 -0800101 nasm_panic(0, "Invalid value %d passed to prefix_slot()", prefix);
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300102 return -1;
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700103 }
104}
105
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700106static void process_size_override(insn *result, operand *op)
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700107{
108 if (tasm_compatible_mode) {
H. Peter Anvin09dff8b2017-03-01 01:01:37 -0800109 switch (tokval.t_integer) {
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300110 /* For TASM compatibility a size override inside the
111 * brackets changes the size of the operand, not the
112 * address type of the operand as it does in standard
113 * NASM syntax. Hence:
114 *
115 * mov eax,[DWORD val]
116 *
117 * is valid syntax in TASM compatibility mode. Note that
118 * you lose the ability to override the default address
119 * type for the instruction, but we never use anything
120 * but 32-bit flat model addressing in our code.
121 */
122 case S_BYTE:
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700123 op->type |= BITS8;
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300124 break;
125 case S_WORD:
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700126 op->type |= BITS16;
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300127 break;
128 case S_DWORD:
129 case S_LONG:
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700130 op->type |= BITS32;
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300131 break;
132 case S_QWORD:
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700133 op->type |= BITS64;
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300134 break;
135 case S_TWORD:
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700136 op->type |= BITS80;
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300137 break;
138 case S_OWORD:
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700139 op->type |= BITS128;
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300140 break;
141 default:
142 nasm_error(ERR_NONFATAL,
143 "invalid operand size specification");
144 break;
145 }
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700146 } else {
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300147 /* Standard NASM compatible syntax */
H. Peter Anvin09dff8b2017-03-01 01:01:37 -0800148 switch (tokval.t_integer) {
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300149 case S_NOSPLIT:
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700150 op->eaflags |= EAF_TIMESTWO;
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300151 break;
152 case S_REL:
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700153 op->eaflags |= EAF_REL;
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300154 break;
155 case S_ABS:
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700156 op->eaflags |= EAF_ABS;
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300157 break;
158 case S_BYTE:
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700159 op->disp_size = 8;
160 op->eaflags |= EAF_BYTEOFFS;
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300161 break;
162 case P_A16:
163 case P_A32:
164 case P_A64:
165 if (result->prefixes[PPS_ASIZE] &&
166 result->prefixes[PPS_ASIZE] != tokval.t_integer)
167 nasm_error(ERR_NONFATAL,
168 "conflicting address size specifications");
169 else
170 result->prefixes[PPS_ASIZE] = tokval.t_integer;
171 break;
172 case S_WORD:
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700173 op->disp_size = 16;
174 op->eaflags |= EAF_WORDOFFS;
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300175 break;
176 case S_DWORD:
177 case S_LONG:
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700178 op->disp_size = 32;
179 op->eaflags |= EAF_WORDOFFS;
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300180 break;
181 case S_QWORD:
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700182 op->disp_size = 64;
183 op->eaflags |= EAF_WORDOFFS;
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300184 break;
185 default:
186 nasm_error(ERR_NONFATAL, "invalid size specification in"
187 " effective address");
188 break;
189 }
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700190 }
191}
192
Jin Kyu Song72018a22013-08-05 20:46:18 -0700193/*
194 * when two or more decorators follow a register operand,
195 * consecutive decorators are parsed here.
Jin Kyu Songf9a71e02013-08-21 19:29:09 -0700196 * opmask and zeroing decorators can be placed in any order.
Jin Kyu Song487f3522013-11-27 14:10:40 -0800197 * e.g. zmm1 {k2}{z} or zmm2 {z}{k3}
Jin Kyu Song72018a22013-08-05 20:46:18 -0700198 * decorator(s) are placed at the end of an operand.
199 */
200static bool parse_braces(decoflags_t *decoflags)
201{
202 int i;
203 bool recover = false;
204
205 i = tokval.t_type;
206 do {
207 if (i == TOKEN_OPMASK) {
208 if (*decoflags & OPMASK_MASK) {
Jin Kyu Songc9486b92013-10-28 17:07:57 -0700209 nasm_error(ERR_NONFATAL, "opmask k%"PRIu64" is already set",
Jin Kyu Song72018a22013-08-05 20:46:18 -0700210 *decoflags & OPMASK_MASK);
211 *decoflags &= ~OPMASK_MASK;
212 }
213 *decoflags |= VAL_OPMASK(nasm_regvals[tokval.t_integer]);
214 } else if (i == TOKEN_DECORATOR) {
215 switch (tokval.t_integer) {
216 case BRC_Z:
217 /*
218 * according to AVX512 spec, only zeroing/merging decorator
219 * is supported with opmask
220 */
221 *decoflags |= GEN_Z(0);
222 break;
Jin Kyu Songcc1dc9d2013-08-15 19:01:25 -0700223 default:
224 nasm_error(ERR_NONFATAL, "{%s} is not an expected decorator",
225 tokval.t_charptr);
226 break;
Jin Kyu Song72018a22013-08-05 20:46:18 -0700227 }
228 } else if (i == ',' || i == TOKEN_EOS){
229 break;
230 } else {
231 nasm_error(ERR_NONFATAL, "only a series of valid decorators"
232 " expected");
233 recover = true;
234 break;
235 }
236 i = stdscan(NULL, &tokval);
237 } while(1);
238
239 return recover;
240}
241
H. Peter Anvin9148fb52013-09-27 16:39:16 -0700242static int parse_mref(operand *op, const expr *e)
H. Peter Anvin9f4706f2013-09-26 17:28:39 -0700243{
244 int b, i, s; /* basereg, indexreg, scale */
245 int64_t o; /* offset */
246
H. Peter Anvin9148fb52013-09-27 16:39:16 -0700247 b = i = -1;
248 o = s = 0;
H. Peter Anvin164d2462017-02-20 02:39:56 -0800249 op->segment = op->wrt = NO_SEG;
H. Peter Anvin9f4706f2013-09-26 17:28:39 -0700250
251 if (e->type && e->type <= EXPR_REG_END) { /* this bit's a register */
252 bool is_gpr = is_class(REG_GPR,nasm_reg_flags[e->type]);
253
254 if (is_gpr && e->value == 1)
255 b = e->type; /* It can be basereg */
H. Peter Anvin472a7c12016-10-31 08:44:25 -0700256 else /* No, it has to be indexreg */
H. Peter Anvin9f4706f2013-09-26 17:28:39 -0700257 i = e->type, s = e->value;
258 e++;
259 }
260 if (e->type && e->type <= EXPR_REG_END) { /* it's a 2nd register */
261 bool is_gpr = is_class(REG_GPR,nasm_reg_flags[e->type]);
262
263 if (b != -1) /* If the first was the base, ... */
264 i = e->type, s = e->value; /* second has to be indexreg */
265
266 else if (!is_gpr || e->value != 1) {
267 /* If both want to be index */
268 nasm_error(ERR_NONFATAL,
269 "invalid effective address: two index registers");
270 return -1;
271 } else
272 b = e->type;
273 e++;
274 }
H. Peter Anvin164d2462017-02-20 02:39:56 -0800275
276 if (e->type) { /* is there an offset? */
H. Peter Anvin9f4706f2013-09-26 17:28:39 -0700277 if (e->type <= EXPR_REG_END) { /* in fact, is there an error? */
278 nasm_error(ERR_NONFATAL,
H. Peter Anvin164d2462017-02-20 02:39:56 -0800279 "invalid effective address: impossible register");
H. Peter Anvin9f4706f2013-09-26 17:28:39 -0700280 return -1;
281 } else {
282 if (e->type == EXPR_UNKNOWN) {
283 op->opflags |= OPFLAG_UNKNOWN;
284 o = 0; /* doesn't matter what */
H. Peter Anvin9f4706f2013-09-26 17:28:39 -0700285 while (e->type)
286 e++; /* go to the end of the line */
287 } else {
288 if (e->type == EXPR_SIMPLE) {
289 o = e->value;
290 e++;
291 }
292 if (e->type == EXPR_WRT) {
293 op->wrt = e->value;
294 e++;
H. Peter Anvin164d2462017-02-20 02:39:56 -0800295 }
H. Peter Anvin9f4706f2013-09-26 17:28:39 -0700296 /*
297 * Look for a segment base type.
298 */
H. Peter Anvin164d2462017-02-20 02:39:56 -0800299 for (; e->type; e++) {
300 if (!e->value)
301 continue;
302
303 if (e->type <= EXPR_REG_END) {
304 nasm_error(ERR_NONFATAL,
305 "invalid effective address: too many registers");
306 return -1;
307 } else if (e->type < EXPR_SEGBASE) {
308 nasm_error(ERR_NONFATAL,
309 "invalid effective address: bad subexpression type");
310 return -1;
311 } else if (e->value == 1) {
312 if (op->segment != NO_SEG) {
313 nasm_error(ERR_NONFATAL,
314 "invalid effective address: multiple base segments");
315 return -1;
316 }
317 op->segment = e->type - EXPR_SEGBASE;
318 } else if (e->value == -1 &&
319 e->type == location.segment + EXPR_SEGBASE &&
320 !(op->opflags & OPFLAG_RELATIVE)) {
321 op->opflags |= OPFLAG_RELATIVE;
322 } else {
323 nasm_error(ERR_NONFATAL,
324 "invalid effective address: impossible segment base multiplier");
325 return -1;
326 }
H. Peter Anvin9f4706f2013-09-26 17:28:39 -0700327 }
328 }
329 }
H. Peter Anvin9f4706f2013-09-26 17:28:39 -0700330 }
331
H. Peter Anvin164d2462017-02-20 02:39:56 -0800332 nasm_assert(!e->type); /* We should be at the end */
H. Peter Anvin9f4706f2013-09-26 17:28:39 -0700333
H. Peter Anvin9148fb52013-09-27 16:39:16 -0700334 op->basereg = b;
335 op->indexreg = i;
336 op->scale = s;
337 op->offset = o;
338 return 0;
339}
340
341static void mref_set_optype(operand *op)
342{
343 int b = op->basereg;
344 int i = op->indexreg;
345 int s = op->scale;
346
H. Peter Anvin9f4706f2013-09-26 17:28:39 -0700347 /* It is memory, but it can match any r/m operand */
348 op->type |= MEMORY_ANY;
349
350 if (b == -1 && (i == -1 || s == 0)) {
351 int is_rel = globalbits == 64 &&
352 !(op->eaflags & EAF_ABS) &&
353 ((globalrel &&
354 !(op->eaflags & EAF_FSGS)) ||
355 (op->eaflags & EAF_REL));
356
357 op->type |= is_rel ? IP_REL : MEM_OFFS;
358 }
359
360 if (i != -1) {
361 opflags_t iclass = nasm_reg_flags[i];
362
363 if (is_class(XMMREG,iclass))
364 op->type |= XMEM;
365 else if (is_class(YMMREG,iclass))
366 op->type |= YMEM;
367 else if (is_class(ZMMREG,iclass))
368 op->type |= ZMEM;
369 }
H. Peter Anvin9f4706f2013-09-26 17:28:39 -0700370}
371
H. Peter Anvin472a7c12016-10-31 08:44:25 -0700372/*
373 * Convert an expression vector returned from evaluate() into an
374 * extop structure. Return zero on success.
375 */
376static int value_to_extop(expr * vect, extop *eop, int32_t myseg)
377{
378 eop->type = EOT_DB_NUMBER;
379 eop->offset = 0;
380 eop->segment = eop->wrt = NO_SEG;
381 eop->relative = false;
382
383 for (; vect->type; vect++) {
384 if (!vect->value) /* zero term, safe to ignore */
385 continue;
386
Cyrill Gorcunovfd610f22016-11-28 23:57:08 +0300387 if (vect->type <= EXPR_REG_END) /* false if a register is present */
H. Peter Anvin472a7c12016-10-31 08:44:25 -0700388 return -1;
389
390 if (vect->type == EXPR_UNKNOWN) /* something we can't resolve yet */
391 return 0;
392
393 if (vect->type == EXPR_SIMPLE) {
394 /* Simple number expression */
395 eop->offset += vect->value;
396 continue;
397 }
398 if (eop->wrt == NO_SEG && !eop->relative && vect->type == EXPR_WRT) {
399 /* WRT term */
400 eop->wrt = vect->value;
401 continue;
402 }
403
H. Peter Anvind97ccee2017-02-21 11:31:35 -0800404 if (!eop->relative &&
H. Peter Anvin472a7c12016-10-31 08:44:25 -0700405 vect->type == EXPR_SEGBASE + myseg && vect->value == -1) {
406 /* Expression of the form: foo - $ */
407 eop->relative = true;
408 continue;
409 }
410
411 if (eop->segment == NO_SEG && vect->type >= EXPR_SEGBASE &&
412 vect->value == 1) {
413 eop->segment = vect->type - EXPR_SEGBASE;
414 continue;
415 }
416
417 /* Otherwise, badness */
418 return -1;
419 }
420
421 /* We got to the end and it was all okay */
422 return 0;
423}
424
H. Peter Anvin00444ae2009-07-18 18:49:55 -0700425insn *parse_line(int pass, char *buffer, insn *result, ldfunc ldef)
H. Peter Anvineba20a72002-04-30 20:53:55 +0000426{
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400427 bool insn_is_label = false;
428 struct eval_hints hints;
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700429 int opnum;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000430 int critical;
H. Peter Anvin9c987692007-11-04 21:09:32 -0800431 bool first;
H. Peter Anvin552bc2c2009-06-23 11:34:42 -0700432 bool recover;
Martin Lindhe58f37c12016-11-16 16:43:16 +0100433 int i;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000434
H. Peter Anvin9c987692007-11-04 21:09:32 -0800435restart_parse:
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400436 first = true;
437 result->forw_ref = false;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000438
H. Peter Anvin76690a12002-04-30 20:52:49 +0000439 stdscan_reset();
Cyrill Gorcunov917117f2009-10-29 23:09:18 +0300440 stdscan_set(buffer);
H. Peter Anvin76690a12002-04-30 20:52:49 +0000441 i = stdscan(NULL, &tokval);
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000442
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400443 result->label = NULL; /* Assume no label */
444 result->eops = NULL; /* must do this, whatever happens */
445 result->operands = 0; /* must initialize this */
Jin Kyu Songe3a06b92013-08-28 19:15:23 -0700446 result->evex_rm = 0; /* Ensure EVEX rounding mode is reset */
447 result->evex_brerop = -1; /* Reset EVEX broadcasting/ER op position */
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000448
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400449 /* Ignore blank lines */
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700450 if (i == TOKEN_EOS)
451 goto fail;
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400452
Cyrill Gorcunov5abbe372011-08-28 18:49:00 +0400453 if (i != TOKEN_ID &&
454 i != TOKEN_INSN &&
455 i != TOKEN_PREFIX &&
456 (i != TOKEN_REG || !IS_SREG(tokval.t_integer))) {
457 nasm_error(ERR_NONFATAL,
458 "label or instruction expected at start of line");
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700459 goto fail;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000460 }
461
H. Peter Anvin9c987692007-11-04 21:09:32 -0800462 if (i == TOKEN_ID || (insn_is_label && i == TOKEN_INSN)) {
463 /* there's a label here */
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300464 first = false;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000465 result->label = tokval.t_charptr;
466 i = stdscan(NULL, &tokval);
467 if (i == ':') { /* skip over the optional colon */
468 i = stdscan(NULL, &tokval);
469 } else if (i == 0) {
H. Peter Anvin00444ae2009-07-18 18:49:55 -0700470 nasm_error(ERR_WARNING | ERR_WARN_OL | ERR_PASS1,
H. Peter Anvine2c80182005-01-15 22:15:51 +0000471 "label alone on a line without a colon might be in error");
472 }
473 if (i != TOKEN_INSN || tokval.t_integer != I_EQU) {
474 /*
H. Peter Anvincd7893d2016-02-18 01:25:46 -0800475 * FIXME: location.segment could be NO_SEG, in which case
H. Peter Anvinb20bc732017-03-07 19:23:03 -0800476 * it is possible we should be passing 'absolute.segment'. Look into this.
H. Peter Anvine2c80182005-01-15 22:15:51 +0000477 * Work out whether that is *really* what we should be doing.
478 * Generally fix things. I think this is right as it is, but
479 * am still not certain.
480 */
H. Peter Anvinb20bc732017-03-07 19:23:03 -0800481 ldef(result->label, in_absolute ? absolute.segment : location.segment,
H. Peter Anvincd7893d2016-02-18 01:25:46 -0800482 location.offset, NULL, true, false);
H. Peter Anvine2c80182005-01-15 22:15:51 +0000483 }
H. Peter Anvineba20a72002-04-30 20:53:55 +0000484 }
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000485
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400486 /* Just a label here */
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700487 if (i == TOKEN_EOS)
488 goto fail;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000489
H. Peter Anvin94e40522017-01-24 12:26:09 -0800490 nasm_static_assert(P_none == 0);
Cyrill Gorcunov836492f2013-07-16 01:33:09 +0400491 memset(result->prefixes, P_none, sizeof(result->prefixes));
H. Peter Anvind7ed89e2002-04-30 20:52:08 +0000492 result->times = 1L;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000493
494 while (i == TOKEN_PREFIX ||
Cyrill Gorcunov5abbe372011-08-28 18:49:00 +0400495 (i == TOKEN_REG && IS_SREG(tokval.t_integer))) {
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300496 first = false;
H. Peter Anvin9c987692007-11-04 21:09:32 -0800497
H. Peter Anvine2c80182005-01-15 22:15:51 +0000498 /*
499 * Handle special case: the TIMES prefix.
500 */
501 if (i == TOKEN_PREFIX && tokval.t_integer == P_TIMES) {
502 expr *value;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000503
H. Peter Anvine2c80182005-01-15 22:15:51 +0000504 i = stdscan(NULL, &tokval);
H. Peter Anvin130736c2016-02-17 20:27:41 -0800505 value = evaluate(stdscan, NULL, &tokval, NULL, pass0, NULL);
H. Peter Anvine2c80182005-01-15 22:15:51 +0000506 i = tokval.t_type;
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700507 if (!value) /* Error in evaluator */
508 goto fail;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000509 if (!is_simple(value)) {
H. Peter Anvin00444ae2009-07-18 18:49:55 -0700510 nasm_error(ERR_NONFATAL,
H. Peter Anvine2c80182005-01-15 22:15:51 +0000511 "non-constant argument supplied to TIMES");
512 result->times = 1L;
513 } else {
514 result->times = value->value;
Charles Crayne7f596e72008-09-23 21:49:09 -0700515 if (value->value < 0 && pass0 == 2) {
Victor van den Elzen15bb2332009-08-11 02:10:16 +0200516 nasm_error(ERR_NONFATAL, "TIMES value %"PRId64" is negative",
H. Peter Anvine2c80182005-01-15 22:15:51 +0000517 value->value);
518 result->times = 0;
519 }
520 }
521 } else {
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300522 int slot = prefix_slot(tokval.t_integer);
523 if (result->prefixes[slot]) {
Charles Crayne052c0bd2007-10-29 18:24:59 -0700524 if (result->prefixes[slot] == tokval.t_integer)
Victor van den Elzend55a1582010-11-07 23:47:13 +0100525 nasm_error(ERR_WARNING | ERR_PASS1,
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300526 "instruction has redundant prefixes");
Charles Crayne052c0bd2007-10-29 18:24:59 -0700527 else
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300528 nasm_error(ERR_NONFATAL,
529 "instruction has conflicting prefixes");
530 }
531 result->prefixes[slot] = tokval.t_integer;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000532 i = stdscan(NULL, &tokval);
533 }
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000534 }
535
536 if (i != TOKEN_INSN) {
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300537 int j;
538 enum prefixes pfx;
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700539
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400540 for (j = 0; j < MAXPREFIX; j++) {
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +0300541 if ((pfx = result->prefixes[j]) != P_none)
542 break;
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400543 }
H. Peter Anvincb583b92007-10-28 22:04:42 -0700544
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700545 if (i == 0 && pfx != P_none) {
H. Peter Anvine2c80182005-01-15 22:15:51 +0000546 /*
547 * Instruction prefixes are present, but no actual
548 * instruction. This is allowed: at this point we
549 * invent a notional instruction of RESB 0.
550 */
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +0400551 result->opcode = I_RESB;
552 result->operands = 1;
553 result->oprs[0].type = IMMEDIATE;
554 result->oprs[0].offset = 0L;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000555 result->oprs[0].segment = result->oprs[0].wrt = NO_SEG;
556 return result;
557 } else {
H. Peter Anvin00444ae2009-07-18 18:49:55 -0700558 nasm_error(ERR_NONFATAL, "parser: instruction expected");
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -0700559 goto fail;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000560 }
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000561 }
562
563 result->opcode = tokval.t_integer;
564 result->condition = tokval.t_inttwo;
565
566 /*
Charles Crayne2581c862008-09-10 19:21:52 -0700567 * INCBIN cannot be satisfied with incorrectly
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000568 * evaluated operands, since the correct values _must_ be known
569 * on the first pass. Hence, even in pass one, we set the
570 * `critical' flag on calling evaluate(), so that it will bomb
Charles Crayne2581c862008-09-10 19:21:52 -0700571 * out on undefined symbols.
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000572 */
Charles Crayne2581c862008-09-10 19:21:52 -0700573 if (result->opcode == I_INCBIN) {
Charles Crayne5a7976c2008-03-26 17:20:21 -0700574 critical = (pass0 < 2 ? 1 : 2);
575
H. Peter Anvine2c80182005-01-15 22:15:51 +0000576 } else
577 critical = (pass == 2 ? 2 : 0);
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000578
H. Peter Anvin41c9f6f2007-09-18 13:01:32 -0700579 if (result->opcode == I_DB || result->opcode == I_DW ||
580 result->opcode == I_DD || result->opcode == I_DQ ||
581 result->opcode == I_DT || result->opcode == I_DO ||
H. Peter Anvin9d546102013-10-02 18:25:19 -0700582 result->opcode == I_DY || result->opcode == I_DZ ||
583 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
669 eop->stringlen = idata_bytes(result->opcode);
670 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);
Jin Kyu Song50ab1522013-08-21 19:29:12 -0700978 if ((i == TOKEN_DECORATOR) || (i == TOKEN_OPMASK)) {
Jin Kyu Song72018a22013-08-05 20:46:18 -0700979 /*
Jin Kyu Song50ab1522013-08-21 19:29:12 -0700980 * according to AVX512 spec, broacast or opmask decorator
981 * is expected for memory reference operands
Jin Kyu Song72018a22013-08-05 20:46:18 -0700982 */
983 if (tokval.t_flag & TFLAG_BRDCAST) {
Jin Kyu Song25c22122013-10-30 03:12:45 -0700984 brace_flags |= GEN_BRDCAST(0) |
Mark Charneydcaef4b2014-10-09 13:45:17 -0400985 VAL_BRNUM(tokval.t_integer - BRC_1TO2);
Jin Kyu Song72018a22013-08-05 20:46:18 -0700986 i = stdscan(NULL, &tokval);
Jin Kyu Song50ab1522013-08-21 19:29:12 -0700987 } else if (i == TOKEN_OPMASK) {
988 brace_flags |= VAL_OPMASK(nasm_regvals[tokval.t_integer]);
989 i = stdscan(NULL, &tokval);
Jin Kyu Song72018a22013-08-05 20:46:18 -0700990 } else {
Jin Kyu Song50ab1522013-08-21 19:29:12 -0700991 nasm_error(ERR_NONFATAL, "broadcast or opmask "
992 "decorator expected inside braces");
Jin Kyu Song72018a22013-08-05 20:46:18 -0700993 recover = true;
994 }
995 }
996
Victor van den Elzen02846d32009-06-23 03:47:07 +0200997 if (i != 0 && i != ',') {
H. Peter Anvin00444ae2009-07-18 18:49:55 -0700998 nasm_error(ERR_NONFATAL, "comma or end of line expected");
Victor van den Elzen02846d32009-06-23 03:47:07 +0200999 recover = true;
1000 }
1001 }
H. Peter Anvine2c80182005-01-15 22:15:51 +00001002 } else { /* immediate operand */
Jin Kyu Song72018a22013-08-05 20:46:18 -07001003 if (i != 0 && i != ',' && i != ':' &&
1004 i != TOKEN_DECORATOR && i != TOKEN_OPMASK) {
1005 nasm_error(ERR_NONFATAL, "comma, colon, decorator or end of "
1006 "line expected after operand");
Victor van den Elzen02846d32009-06-23 03:47:07 +02001007 recover = true;
H. Peter Anvine2c80182005-01-15 22:15:51 +00001008 } else if (i == ':') {
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001009 op->type |= COLON;
Jin Kyu Song72018a22013-08-05 20:46:18 -07001010 } else if (i == TOKEN_DECORATOR || i == TOKEN_OPMASK) {
1011 /* parse opmask (and zeroing) after an operand */
1012 recover = parse_braces(&brace_flags);
H. Peter Anvine2c80182005-01-15 22:15:51 +00001013 }
1014 }
Victor van den Elzen02846d32009-06-23 03:47:07 +02001015 if (recover) {
1016 do { /* error recovery */
1017 i = stdscan(NULL, &tokval);
1018 } while (i != 0 && i != ',');
1019 }
H. Peter Anvinea6e34d2002-04-30 20:51:32 +00001020
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +03001021 /*
1022 * now convert the exprs returned from evaluate()
1023 * into operand descriptions...
1024 */
H. Peter Anvin9148fb52013-09-27 16:39:16 -07001025 op->decoflags |= brace_flags;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +00001026
H. Peter Anvine2c80182005-01-15 22:15:51 +00001027 if (mref) { /* it's a memory reference */
H. Peter Anvin9148fb52013-09-27 16:39:16 -07001028 /* A mib reference was fully parsed already */
1029 if (!mib) {
1030 if (parse_mref(op, value))
1031 goto fail;
1032 op->hintbase = hints.base;
1033 op->hinttype = hints.type;
1034 }
1035 mref_set_optype(op);
H. Peter Anvine2c80182005-01-15 22:15:51 +00001036 } else { /* it's not a memory reference */
H. Peter Anvine2c80182005-01-15 22:15:51 +00001037 if (is_just_unknown(value)) { /* it's immediate but unknown */
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001038 op->type |= IMMEDIATE;
1039 op->opflags |= OPFLAG_UNKNOWN;
1040 op->offset = 0; /* don't care */
1041 op->segment = NO_SEG; /* don't care again */
1042 op->wrt = NO_SEG; /* still don't care */
Victor van den Elzen154e5922009-02-25 17:32:00 +01001043
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001044 if(optimizing >= 0 && !(op->type & STRICT)) {
Cyrill Gorcunov210c1012009-11-01 10:24:48 +03001045 /* Be optimistic */
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001046 op->type |=
Ben Rudiak-Gould4e8396b2013-03-01 10:28:32 +04001047 UNITY | SBYTEWORD | SBYTEDWORD | UDWORD | SDWORD;
Cyrill Gorcunov210c1012009-11-01 10:24:48 +03001048 }
H. Peter Anvine2c80182005-01-15 22:15:51 +00001049 } else if (is_reloc(value)) { /* it's immediate */
H. Peter Anvin87646092017-02-28 17:44:24 -08001050 uint64_t n = reloc_value(value);
1051
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001052 op->type |= IMMEDIATE;
H. Peter Anvin87646092017-02-28 17:44:24 -08001053 op->offset = n;
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001054 op->segment = reloc_seg(value);
1055 op->wrt = reloc_wrt(value);
H. Peter Anvin164d2462017-02-20 02:39:56 -08001056 op->opflags |= is_self_relative(value) ? OPFLAG_RELATIVE : 0;
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +04001057
H. Peter Anvine2c80182005-01-15 22:15:51 +00001058 if (is_simple(value)) {
Ben Rudiak-Gould4e8396b2013-03-01 10:28:32 +04001059 if (n == 1)
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001060 op->type |= UNITY;
H. Peter Anvin87646092017-02-28 17:44:24 -08001061 if (optimizing >= 0 && !(op->type & STRICT)) {
Ben Rudiak-Gould4e8396b2013-03-01 10:28:32 +04001062 if ((uint32_t) (n + 128) <= 255)
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001063 op->type |= SBYTEDWORD;
Ben Rudiak-Gould4e8396b2013-03-01 10:28:32 +04001064 if ((uint16_t) (n + 128) <= 255)
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001065 op->type |= SBYTEWORD;
H. Peter Anvin87646092017-02-28 17:44:24 -08001066 if (n <= UINT64_C(0xFFFFFFFF))
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001067 op->type |= UDWORD;
H. Peter Anvin87646092017-02-28 17:44:24 -08001068 if (n + UINT64_C(0x80000000) <= UINT64_C(0xFFFFFFFF))
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001069 op->type |= SDWORD;
H. Peter Anvine2c80182005-01-15 22:15:51 +00001070 }
1071 }
H. Peter Anvin164d2462017-02-20 02:39:56 -08001072 } else if (value->type == EXPR_RDSAE) {
Jin Kyu Song72018a22013-08-05 20:46:18 -07001073 /*
1074 * it's not an operand but a rounding or SAE decorator.
1075 * put the decorator information in the (opflag_t) type field
1076 * of previous operand.
1077 */
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001078 opnum--; op--;
Jin Kyu Song72018a22013-08-05 20:46:18 -07001079 switch (value->value) {
1080 case BRC_RN:
1081 case BRC_RU:
1082 case BRC_RD:
1083 case BRC_RZ:
1084 case BRC_SAE:
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001085 op->decoflags |= (value->value == BRC_SAE ? SAE : ER);
Jin Kyu Song72018a22013-08-05 20:46:18 -07001086 result->evex_rm = value->value;
1087 break;
1088 default:
1089 nasm_error(ERR_NONFATAL, "invalid decorator");
1090 break;
1091 }
H. Peter Anvine2c80182005-01-15 22:15:51 +00001092 } else { /* it's a register */
Cyrill Gorcunov167917a2012-09-10 00:19:12 +04001093 opflags_t rs;
H. Peter Anvineba20a72002-04-30 20:53:55 +00001094
H. Peter Anvine2c80182005-01-15 22:15:51 +00001095 if (value->type >= EXPR_SIMPLE || value->value != 1) {
H. Peter Anvin00444ae2009-07-18 18:49:55 -07001096 nasm_error(ERR_NONFATAL, "invalid operand type");
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001097 goto fail;
H. Peter Anvine2c80182005-01-15 22:15:51 +00001098 }
H. Peter Anvineba20a72002-04-30 20:53:55 +00001099
H. Peter Anvine2c80182005-01-15 22:15:51 +00001100 /*
1101 * check that its only 1 register, not an expression...
1102 */
1103 for (i = 1; value[i].type; i++)
1104 if (value[i].value) {
H. Peter Anvin00444ae2009-07-18 18:49:55 -07001105 nasm_error(ERR_NONFATAL, "invalid operand type");
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001106 goto fail;
H. Peter Anvine2c80182005-01-15 22:15:51 +00001107 }
H. Peter Anvineba20a72002-04-30 20:53:55 +00001108
H. Peter Anvine2c80182005-01-15 22:15:51 +00001109 /* clear overrides, except TO which applies to FPU regs */
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001110 if (op->type & ~TO) {
H. Peter Anvine2c80182005-01-15 22:15:51 +00001111 /*
1112 * we want to produce a warning iff the specified size
1113 * is different from the register size
1114 */
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001115 rs = op->type & SIZE_MASK;
H. Peter Anvine2c80182005-01-15 22:15:51 +00001116 } else
H. Peter Anvin68222142007-11-18 22:18:09 -08001117 rs = 0;
H. Peter Anvine2c80182005-01-15 22:15:51 +00001118
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001119 op->type &= TO;
1120 op->type |= REGISTER;
1121 op->type |= nasm_reg_flags[value->type];
1122 op->decoflags |= brace_flags;
1123 op->basereg = value->type;
H. Peter Anvine2c80182005-01-15 22:15:51 +00001124
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001125 if (rs && (op->type & SIZE_MASK) != rs)
H. Peter Anvin00444ae2009-07-18 18:49:55 -07001126 nasm_error(ERR_WARNING | ERR_PASS1,
H. Peter Anvine2c80182005-01-15 22:15:51 +00001127 "register size specification ignored");
1128 }
1129 }
Jin Kyu Songe3a06b92013-08-28 19:15:23 -07001130
1131 /* remember the position of operand having broadcasting/ER mode */
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001132 if (op->decoflags & (BRDCAST_MASK | ER | SAE))
1133 result->evex_brerop = opnum;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +00001134 }
1135
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001136 result->operands = opnum; /* set operand count */
H. Peter Anvinea6e34d2002-04-30 20:51:32 +00001137
Cyrill Gorcunovc2509502009-10-14 15:36:45 +04001138 /* clear remaining operands */
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001139 while (opnum < MAX_OPERANDS)
1140 result->oprs[opnum++].type = 0;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +00001141
1142 /*
H. Peter Anvin9d546102013-10-02 18:25:19 -07001143 * Transform RESW, RESD, RESQ, REST, RESO, RESY, RESZ into RESB.
H. Peter Anvinea6e34d2002-04-30 20:51:32 +00001144 */
1145 switch (result->opcode) {
H. Peter Anvine2c80182005-01-15 22:15:51 +00001146 case I_RESW:
1147 result->opcode = I_RESB;
1148 result->oprs[0].offset *= 2;
1149 break;
1150 case I_RESD:
1151 result->opcode = I_RESB;
1152 result->oprs[0].offset *= 4;
1153 break;
1154 case I_RESQ:
1155 result->opcode = I_RESB;
1156 result->oprs[0].offset *= 8;
1157 break;
1158 case I_REST:
1159 result->opcode = I_RESB;
1160 result->oprs[0].offset *= 10;
1161 break;
H. Peter Anvin41c9f6f2007-09-18 13:01:32 -07001162 case I_RESO:
1163 result->opcode = I_RESB;
1164 result->oprs[0].offset *= 16;
1165 break;
H. Peter Anvindfb91802008-05-20 11:43:53 -07001166 case I_RESY:
1167 result->opcode = I_RESB;
1168 result->oprs[0].offset *= 32;
1169 break;
H. Peter Anvin9d546102013-10-02 18:25:19 -07001170 case I_RESZ:
1171 result->opcode = I_RESB;
1172 result->oprs[0].offset *= 64;
1173 break;
H. Peter Anvin16b0a332007-09-12 20:27:41 -07001174 default:
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +03001175 break;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +00001176 }
1177
1178 return result;
H. Peter Anvindf0d1ba2013-09-26 17:23:08 -07001179
1180fail:
1181 result->opcode = I_none;
1182 return result;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +00001183}
1184
H. Peter Anvine2c80182005-01-15 22:15:51 +00001185static int is_comma_next(void)
H. Peter Anvineba20a72002-04-30 20:53:55 +00001186{
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +04001187 struct tokenval tv;
Keith Kaniosa6dfa782007-04-13 16:47:53 +00001188 char *p;
H. Peter Anvin76690a12002-04-30 20:52:49 +00001189 int i;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +00001190
Cyrill Gorcunov917117f2009-10-29 23:09:18 +03001191 p = stdscan_get();
H. Peter Anvine2c80182005-01-15 22:15:51 +00001192 i = stdscan(NULL, &tv);
Cyrill Gorcunov917117f2009-10-29 23:09:18 +03001193 stdscan_set(p);
Cyrill Gorcunov447e20c2011-08-28 18:02:31 +04001194
H. Peter Anvin76690a12002-04-30 20:52:49 +00001195 return (i == ',' || i == ';' || !i);
H. Peter Anvinea6e34d2002-04-30 20:51:32 +00001196}
1197
H. Peter Anvine2c80182005-01-15 22:15:51 +00001198void cleanup_insn(insn * i)
H. Peter Anvineba20a72002-04-30 20:53:55 +00001199{
H. Peter Anvinea6e34d2002-04-30 20:51:32 +00001200 extop *e;
1201
H. Peter Anvin2aa77392008-06-15 17:39:45 -07001202 while ((e = i->eops)) {
1203 i->eops = e->next;
Cyrill Gorcunovcfbcddf2009-10-31 20:05:32 +03001204 if (e->type == EOT_DB_STRING_FREE)
1205 nasm_free(e->stringval);
H. Peter Anvine2c80182005-01-15 22:15:51 +00001206 nasm_free(e);
H. Peter Anvinea6e34d2002-04-30 20:51:32 +00001207 }
1208}