blob: 9b9e89ac0c5b351c8cf69966ed90adad21c18b61 [file] [log] [blame]
H. Peter Anvin9e6747c2009-06-28 17:13:04 -07001/* ----------------------------------------------------------------------- *
2 *
3 * Copyright 1996-2009 The NASM Authors - All Rights Reserved
4 * 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.
17 *
18 * 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>
Keith Kaniosb7a89542007-04-12 02:40:54 +000045#include <inttypes.h>
H. Peter Anvinea6e34d2002-04-30 20:51:32 +000046
47#include "nasm.h"
H. Peter Anvin24cfef42002-09-12 16:34:06 +000048#include "insns.h"
H. Peter Anvinea6e34d2002-04-30 20:51:32 +000049#include "nasmlib.h"
H. Peter Anvin74cc5e52007-08-30 22:35:34 +000050#include "stdscan.h"
H. Peter Anvinea6e34d2002-04-30 20:51:32 +000051#include "parser.h"
52#include "float.h"
H. Peter Anvina4835d42008-05-20 14:21:29 -070053#include "tables.h"
H. Peter Anvinea6e34d2002-04-30 20:51:32 +000054
H. Peter Anvine2c80182005-01-15 22:15:51 +000055extern int in_abs_seg; /* ABSOLUTE segment flag */
Keith Kaniosb7a89542007-04-12 02:40:54 +000056extern int32_t abs_seg; /* ABSOLUTE segment */
57extern int32_t abs_offset; /* ABSOLUTE segment offset */
H. Peter Anvind0e365d2002-05-26 18:19:19 +000058
H. Peter Anvine2c80182005-01-15 22:15:51 +000059static int is_comma_next(void);
H. Peter Anvinea6e34d2002-04-30 20:51:32 +000060
H. Peter Anvinea6e34d2002-04-30 20:51:32 +000061static int i;
62static struct tokenval tokval;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +000063static efunc error;
H. Peter Anvin12e46512007-10-03 21:30:57 -070064static struct location *location; /* Pointer to current line's segment,offset */
H. Peter Anvineba20a72002-04-30 20:53:55 +000065
H. Peter Anvin605f5152009-07-18 18:31:41 -070066void parser_global_info(struct location * locp)
H. Peter Anvineba20a72002-04-30 20:53:55 +000067{
H. Peter Anvineba20a72002-04-30 20:53:55 +000068 location = locp;
69}
H. Peter Anvinea6e34d2002-04-30 20:51:32 +000070
H. Peter Anvinde4b89b2007-10-01 15:41:25 -070071static int prefix_slot(enum prefixes prefix)
72{
73 switch (prefix) {
H. Peter Anvinc2acf7b2009-02-21 18:22:56 -080074 case P_WAIT:
75 return PPS_WAIT;
H. Peter Anvinde4b89b2007-10-01 15:41:25 -070076 case R_CS:
77 case R_DS:
78 case R_SS:
79 case R_ES:
80 case R_FS:
81 case R_GS:
82 return PPS_SEG;
83 case P_LOCK:
84 case P_REP:
85 case P_REPE:
86 case P_REPZ:
87 case P_REPNE:
88 case P_REPNZ:
89 return PPS_LREP;
90 case P_O16:
91 case P_O32:
92 case P_O64:
93 case P_OSP:
94 return PPS_OSIZE;
95 case P_A16:
96 case P_A32:
97 case P_A64:
98 case P_ASP:
99 return PPS_ASIZE;
100 default:
101 error(ERR_PANIC, "Invalid value %d passed to prefix_slot()", prefix);
102 return -1;
103 }
104}
105
106static void process_size_override(insn * result, int operand)
107{
108 if (tasm_compatible_mode) {
109 switch ((int)tokval.t_integer) {
110 /* 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:
123 result->oprs[operand].type |= BITS8;
124 break;
125 case S_WORD:
126 result->oprs[operand].type |= BITS16;
127 break;
128 case S_DWORD:
129 case S_LONG:
130 result->oprs[operand].type |= BITS32;
131 break;
132 case S_QWORD:
133 result->oprs[operand].type |= BITS64;
134 break;
135 case S_TWORD:
136 result->oprs[operand].type |= BITS80;
137 break;
138 case S_OWORD:
139 result->oprs[operand].type |= BITS128;
140 break;
141 default:
142 error(ERR_NONFATAL,
143 "invalid operand size specification");
144 break;
145 }
146 } else {
147 /* Standard NASM compatible syntax */
148 switch ((int)tokval.t_integer) {
149 case S_NOSPLIT:
150 result->oprs[operand].eaflags |= EAF_TIMESTWO;
151 break;
152 case S_REL:
153 result->oprs[operand].eaflags |= EAF_REL;
154 break;
155 case S_ABS:
156 result->oprs[operand].eaflags |= EAF_ABS;
157 break;
158 case S_BYTE:
159 result->oprs[operand].disp_size = 8;
160 result->oprs[operand].eaflags |= EAF_BYTEOFFS;
161 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 error(ERR_NONFATAL,
168 "conflicting address size specifications");
169 else
170 result->prefixes[PPS_ASIZE] = tokval.t_integer;
171 break;
172 case S_WORD:
173 result->oprs[operand].disp_size = 16;
174 result->oprs[operand].eaflags |= EAF_WORDOFFS;
175 break;
176 case S_DWORD:
177 case S_LONG:
178 result->oprs[operand].disp_size = 32;
179 result->oprs[operand].eaflags |= EAF_WORDOFFS;
180 break;
181 case S_QWORD:
182 result->oprs[operand].disp_size = 64;
183 result->oprs[operand].eaflags |= EAF_WORDOFFS;
184 break;
185 default:
186 error(ERR_NONFATAL, "invalid size specification in"
187 " effective address");
188 break;
189 }
190 }
191}
192
Keith Kaniosa6dfa782007-04-13 16:47:53 +0000193insn *parse_line(int pass, char *buffer, insn * result,
H. Peter Anvine2c80182005-01-15 22:15:51 +0000194 efunc errfunc, evalfunc evaluate, ldfunc ldef)
H. Peter Anvineba20a72002-04-30 20:53:55 +0000195{
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000196 int operand;
197 int critical;
H. Peter Anvin76690a12002-04-30 20:52:49 +0000198 struct eval_hints hints;
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700199 int j;
H. Peter Anvin9c987692007-11-04 21:09:32 -0800200 bool first;
201 bool insn_is_label = false;
H. Peter Anvin552bc2c2009-06-23 11:34:42 -0700202 bool recover;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000203
H. Peter Anvin9c987692007-11-04 21:09:32 -0800204restart_parse:
205 first = true;
H. Peter Anvin6867acc2007-10-10 14:58:45 -0700206 result->forw_ref = false;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000207 error = errfunc;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000208
H. Peter Anvin76690a12002-04-30 20:52:49 +0000209 stdscan_reset();
210 stdscan_bufptr = buffer;
211 i = stdscan(NULL, &tokval);
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000212
H. Peter Anvine2c80182005-01-15 22:15:51 +0000213 result->label = NULL; /* Assume no label */
214 result->eops = NULL; /* must do this, whatever happens */
Keith Kaniosb7a89542007-04-12 02:40:54 +0000215 result->operands = 0; /* must initialize this */
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000216
H. Peter Anvine2c80182005-01-15 22:15:51 +0000217 if (i == 0) { /* blank line - ignore */
218 result->opcode = -1; /* and no instruction either */
219 return result;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000220 }
221 if (i != TOKEN_ID && i != TOKEN_INSN && i != TOKEN_PREFIX &&
H. Peter Anvina4835d42008-05-20 14:21:29 -0700222 (i != TOKEN_REG || (REG_SREG & ~nasm_reg_flags[tokval.t_integer]))) {
H. Peter Anvine2c80182005-01-15 22:15:51 +0000223 error(ERR_NONFATAL, "label or instruction expected"
224 " at start of line");
225 result->opcode = -1;
226 return result;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000227 }
228
H. Peter Anvin9c987692007-11-04 21:09:32 -0800229 if (i == TOKEN_ID || (insn_is_label && i == TOKEN_INSN)) {
230 /* there's a label here */
231 first = false;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000232 result->label = tokval.t_charptr;
233 i = stdscan(NULL, &tokval);
234 if (i == ':') { /* skip over the optional colon */
235 i = stdscan(NULL, &tokval);
236 } else if (i == 0) {
237 error(ERR_WARNING | ERR_WARN_OL | ERR_PASS1,
238 "label alone on a line without a colon might be in error");
239 }
240 if (i != TOKEN_INSN || tokval.t_integer != I_EQU) {
241 /*
242 * FIXME: location->segment could be NO_SEG, in which case
243 * it is possible we should be passing 'abs_seg'. Look into this.
244 * Work out whether that is *really* what we should be doing.
245 * Generally fix things. I think this is right as it is, but
246 * am still not certain.
247 */
248 ldef(result->label, in_abs_seg ? abs_seg : location->segment,
H. Peter Anvin605f5152009-07-18 18:31:41 -0700249 location->offset, NULL, true, false);
H. Peter Anvine2c80182005-01-15 22:15:51 +0000250 }
H. Peter Anvineba20a72002-04-30 20:53:55 +0000251 }
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000252
H. Peter Anvine2c80182005-01-15 22:15:51 +0000253 if (i == 0) {
254 result->opcode = -1; /* this line contains just a label */
255 return result;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000256 }
257
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700258 for (j = 0; j < MAXPREFIX; j++)
259 result->prefixes[j] = P_none;
H. Peter Anvind7ed89e2002-04-30 20:52:08 +0000260 result->times = 1L;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000261
262 while (i == TOKEN_PREFIX ||
H. Peter Anvina4835d42008-05-20 14:21:29 -0700263 (i == TOKEN_REG && !(REG_SREG & ~nasm_reg_flags[tokval.t_integer])))
H. Peter Anvineba20a72002-04-30 20:53:55 +0000264 {
H. Peter Anvin9c987692007-11-04 21:09:32 -0800265 first = false;
266
H. Peter Anvine2c80182005-01-15 22:15:51 +0000267 /*
268 * Handle special case: the TIMES prefix.
269 */
270 if (i == TOKEN_PREFIX && tokval.t_integer == P_TIMES) {
271 expr *value;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000272
H. Peter Anvine2c80182005-01-15 22:15:51 +0000273 i = stdscan(NULL, &tokval);
274 value =
275 evaluate(stdscan, NULL, &tokval, NULL, pass0, error, NULL);
276 i = tokval.t_type;
277 if (!value) { /* but, error in evaluator */
278 result->opcode = -1; /* unrecoverable parse error: */
279 return result; /* ignore this instruction */
280 }
281 if (!is_simple(value)) {
282 error(ERR_NONFATAL,
283 "non-constant argument supplied to TIMES");
284 result->times = 1L;
285 } else {
286 result->times = value->value;
Charles Crayne7f596e72008-09-23 21:49:09 -0700287 if (value->value < 0 && pass0 == 2) {
H. Peter Anvine2c80182005-01-15 22:15:51 +0000288 error(ERR_NONFATAL, "TIMES value %d is negative",
289 value->value);
290 result->times = 0;
291 }
292 }
293 } else {
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700294 int slot = prefix_slot(tokval.t_integer);
295 if (result->prefixes[slot]) {
Charles Crayne052c0bd2007-10-29 18:24:59 -0700296 if (result->prefixes[slot] == tokval.t_integer)
H. Peter Anvin9c987692007-11-04 21:09:32 -0800297 error(ERR_WARNING,
Charles Crayne052c0bd2007-10-29 18:24:59 -0700298 "instruction has redundant prefixes");
299 else
300 error(ERR_NONFATAL,
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700301 "instruction has conflicting prefixes");
302 }
303 result->prefixes[slot] = tokval.t_integer;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000304 i = stdscan(NULL, &tokval);
305 }
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000306 }
307
308 if (i != TOKEN_INSN) {
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700309 int j;
310 enum prefixes pfx;
311
312 for (j = 0; j < MAXPREFIX; j++)
313 if ((pfx = result->prefixes[j]) != P_none)
314 break;
H. Peter Anvincb583b92007-10-28 22:04:42 -0700315
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700316 if (i == 0 && pfx != P_none) {
H. Peter Anvine2c80182005-01-15 22:15:51 +0000317 /*
318 * Instruction prefixes are present, but no actual
319 * instruction. This is allowed: at this point we
320 * invent a notional instruction of RESB 0.
321 */
322 result->opcode = I_RESB;
323 result->operands = 1;
324 result->oprs[0].type = IMMEDIATE;
325 result->oprs[0].offset = 0L;
326 result->oprs[0].segment = result->oprs[0].wrt = NO_SEG;
327 return result;
328 } else {
329 error(ERR_NONFATAL, "parser: instruction expected");
330 result->opcode = -1;
331 return result;
332 }
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000333 }
334
335 result->opcode = tokval.t_integer;
336 result->condition = tokval.t_inttwo;
337
338 /*
Charles Crayne2581c862008-09-10 19:21:52 -0700339 * INCBIN cannot be satisfied with incorrectly
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000340 * evaluated operands, since the correct values _must_ be known
341 * on the first pass. Hence, even in pass one, we set the
342 * `critical' flag on calling evaluate(), so that it will bomb
Charles Crayne2581c862008-09-10 19:21:52 -0700343 * out on undefined symbols.
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000344 */
Charles Crayne2581c862008-09-10 19:21:52 -0700345 if (result->opcode == I_INCBIN) {
Charles Crayne5a7976c2008-03-26 17:20:21 -0700346 critical = (pass0 < 2 ? 1 : 2);
347
H. Peter Anvine2c80182005-01-15 22:15:51 +0000348 } else
349 critical = (pass == 2 ? 2 : 0);
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000350
H. Peter Anvin41c9f6f2007-09-18 13:01:32 -0700351 if (result->opcode == I_DB || result->opcode == I_DW ||
352 result->opcode == I_DD || result->opcode == I_DQ ||
353 result->opcode == I_DT || result->opcode == I_DO ||
H. Peter Anvindfb91802008-05-20 11:43:53 -0700354 result->opcode == I_DY || result->opcode == I_INCBIN) {
H. Peter Anvine2c80182005-01-15 22:15:51 +0000355 extop *eop, **tail = &result->eops, **fixptr;
356 int oper_num = 0;
H. Peter Anvin518df302008-06-14 16:53:48 -0700357 int32_t sign;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000358
H. Peter Anvin6867acc2007-10-10 14:58:45 -0700359 result->eops_float = false;
H. Peter Anvineba20a72002-04-30 20:53:55 +0000360
H. Peter Anvine2c80182005-01-15 22:15:51 +0000361 /*
H. Peter Anvin41c9f6f2007-09-18 13:01:32 -0700362 * Begin to read the DB/DW/DD/DQ/DT/DO/INCBIN operands.
H. Peter Anvine2c80182005-01-15 22:15:51 +0000363 */
364 while (1) {
365 i = stdscan(NULL, &tokval);
366 if (i == 0)
367 break;
H. Peter Anvin9c987692007-11-04 21:09:32 -0800368 else if (first && i == ':') {
369 insn_is_label = true;
370 goto restart_parse;
371 }
372 first = false;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000373 fixptr = tail;
374 eop = *tail = nasm_malloc(sizeof(extop));
375 tail = &eop->next;
376 eop->next = NULL;
377 eop->type = EOT_NOTHING;
378 oper_num++;
H. Peter Anvin518df302008-06-14 16:53:48 -0700379 sign = +1;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000380
H. Peter Anvin518df302008-06-14 16:53:48 -0700381 /* is_comma_next() here is to distinguish this from
382 a string used as part of an expression... */
H. Peter Anvin11627042008-06-09 20:45:19 -0700383 if (i == TOKEN_STR && is_comma_next()) {
H. Peter Anvine2c80182005-01-15 22:15:51 +0000384 eop->type = EOT_DB_STRING;
385 eop->stringval = tokval.t_charptr;
386 eop->stringlen = tokval.t_inttwo;
387 i = stdscan(NULL, &tokval); /* eat the comma */
H. Peter Anvin518df302008-06-14 16:53:48 -0700388 } else if (i == TOKEN_STRFUNC) {
389 bool parens = false;
390 const char *funcname = tokval.t_charptr;
391 enum strfunc func = tokval.t_integer;
392 i = stdscan(NULL, &tokval);
393 if (i == '(') {
394 parens = true;
395 i = stdscan(NULL, &tokval);
396 }
397 if (i != TOKEN_STR) {
398 error(ERR_NONFATAL,
399 "%s must be followed by a string constant",
400 funcname);
401 eop->type = EOT_NOTHING;
402 } else {
403 eop->type = EOT_DB_STRING_FREE;
404 eop->stringlen =
405 string_transform(tokval.t_charptr, tokval.t_inttwo,
406 &eop->stringval, func);
407 if (eop->stringlen == (size_t)-1) {
408 error(ERR_NONFATAL, "invalid string for transform");
409 eop->type = EOT_NOTHING;
410 }
411 }
412 if (parens && i && i != ')') {
413 i = stdscan(NULL, &tokval);
414 if (i != ')') {
415 error(ERR_NONFATAL, "unterminated %s function",
416 funcname);
417 }
418 }
419 if (i && i != ',')
420 i = stdscan(NULL, &tokval);
421 } else if (i == '-' || i == '+') {
422 char *save = stdscan_bufptr;
423 int token = i;
424 sign = (i == '-') ? -1 : 1;
425 i = stdscan(NULL, &tokval);
426 if (i != TOKEN_FLOAT) {
427 stdscan_bufptr = save;
428 i = tokval.t_type = token;
429 goto is_expression;
430 } else {
431 goto is_float;
432 }
433 } else if (i == TOKEN_FLOAT) {
434 is_float:
435 eop->type = EOT_DB_STRING;
436 result->eops_float = true;
437 switch (result->opcode) {
438 case I_DB:
439 eop->stringlen = 1;
440 break;
441 case I_DW:
442 eop->stringlen = 2;
443 break;
444 case I_DD:
445 eop->stringlen = 4;
446 break;
447 case I_DQ:
448 eop->stringlen = 8;
449 break;
450 case I_DT:
451 eop->stringlen = 10;
452 break;
453 case I_DO:
454 eop->stringlen = 16;
455 break;
456 case I_DY:
457 error(ERR_NONFATAL, "floating-point constant"
458 " encountered in DY instruction");
459 eop->stringlen = 0;
460 break;
461 default:
462 error(ERR_NONFATAL, "floating-point constant"
463 " encountered in unknown instruction");
464 /*
465 * fix suggested by Pedro Gimeno... original line
466 * was:
467 * eop->type = EOT_NOTHING;
468 */
469 eop->stringlen = 0;
470 break;
471 }
472 eop = nasm_realloc(eop, sizeof(extop) + eop->stringlen);
473 tail = &eop->next;
474 *fixptr = eop;
475 eop->stringval = (char *)eop + sizeof(extop);
476 if (!eop->stringlen ||
477 !float_const(tokval.t_charptr, sign,
478 (uint8_t *)eop->stringval,
479 eop->stringlen, error))
480 eop->type = EOT_NOTHING;
481 i = stdscan(NULL, &tokval); /* eat the comma */
482 } else {
483 /* anything else, assume it is an expression */
H. Peter Anvine2c80182005-01-15 22:15:51 +0000484 expr *value;
H. Peter Anvin518df302008-06-14 16:53:48 -0700485
486 is_expression:
H. Peter Anvine2c80182005-01-15 22:15:51 +0000487 value = evaluate(stdscan, NULL, &tokval, NULL,
488 critical, error, NULL);
489 i = tokval.t_type;
490 if (!value) { /* error in evaluator */
491 result->opcode = -1; /* unrecoverable parse error: */
492 return result; /* ignore this instruction */
493 }
494 if (is_unknown(value)) {
495 eop->type = EOT_DB_NUMBER;
496 eop->offset = 0; /* doesn't matter what we put */
497 eop->segment = eop->wrt = NO_SEG; /* likewise */
498 } else if (is_reloc(value)) {
499 eop->type = EOT_DB_NUMBER;
500 eop->offset = reloc_value(value);
501 eop->segment = reloc_seg(value);
502 eop->wrt = reloc_wrt(value);
503 } else {
504 error(ERR_NONFATAL,
505 "operand %d: expression is not simple"
506 " or relocatable", oper_num);
507 }
508 }
H. Peter Anvin6768eb72002-04-30 20:52:26 +0000509
H. Peter Anvine2c80182005-01-15 22:15:51 +0000510 /*
511 * We're about to call stdscan(), which will eat the
512 * comma that we're currently sitting on between
513 * arguments. However, we'd better check first that it
514 * _is_ a comma.
515 */
516 if (i == 0) /* also could be EOL */
517 break;
518 if (i != ',') {
519 error(ERR_NONFATAL, "comma expected after operand %d",
520 oper_num);
521 result->opcode = -1; /* unrecoverable parse error: */
522 return result; /* ignore this instruction */
523 }
524 }
H. Peter Anvind7ed89e2002-04-30 20:52:08 +0000525
H. Peter Anvine2c80182005-01-15 22:15:51 +0000526 if (result->opcode == I_INCBIN) {
527 /*
528 * Correct syntax for INCBIN is that there should be
529 * one string operand, followed by one or two numeric
530 * operands.
531 */
532 if (!result->eops || result->eops->type != EOT_DB_STRING)
533 error(ERR_NONFATAL, "`incbin' expects a file name");
534 else if (result->eops->next &&
535 result->eops->next->type != EOT_DB_NUMBER)
536 error(ERR_NONFATAL, "`incbin': second parameter is",
537 " non-numeric");
538 else if (result->eops->next && result->eops->next->next &&
539 result->eops->next->next->type != EOT_DB_NUMBER)
540 error(ERR_NONFATAL, "`incbin': third parameter is",
541 " non-numeric");
542 else if (result->eops->next && result->eops->next->next &&
543 result->eops->next->next->next)
544 error(ERR_NONFATAL,
545 "`incbin': more than three parameters");
H. Peter Anvineba20a72002-04-30 20:53:55 +0000546 else
H. Peter Anvine2c80182005-01-15 22:15:51 +0000547 return result;
548 /*
549 * If we reach here, one of the above errors happened.
550 * Throw the instruction away.
551 */
552 result->opcode = -1;
553 return result;
554 } else /* DB ... */ if (oper_num == 0)
555 error(ERR_WARNING | ERR_PASS1,
556 "no operand for data declaration");
557 else
558 result->operands = oper_num;
H. Peter Anvind7ed89e2002-04-30 20:52:08 +0000559
H. Peter Anvine2c80182005-01-15 22:15:51 +0000560 return result;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000561 }
562
H. Peter Anvin8f94f982007-09-17 16:31:33 -0700563 /* right. Now we begin to parse the operands. There may be up to four
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000564 * of these, separated by commas, and terminated by a zero token. */
565
H. Peter Anvin8f94f982007-09-17 16:31:33 -0700566 for (operand = 0; operand < MAX_OPERANDS; operand++) {
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700567 expr *value; /* used most of the time */
H. Peter Anvine2c80182005-01-15 22:15:51 +0000568 int mref; /* is this going to be a memory ref? */
569 int bracket; /* is it a [] mref, or a & mref? */
570 int setsize = 0;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000571
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700572 result->oprs[operand].disp_size = 0; /* have to zero this whatever */
H. Peter Anvine2c80182005-01-15 22:15:51 +0000573 result->oprs[operand].eaflags = 0; /* and this */
574 result->oprs[operand].opflags = 0;
H. Peter Anvineba20a72002-04-30 20:53:55 +0000575
H. Peter Anvine2c80182005-01-15 22:15:51 +0000576 i = stdscan(NULL, &tokval);
577 if (i == 0)
578 break; /* end of operands: get out of here */
H. Peter Anvin9c987692007-11-04 21:09:32 -0800579 else if (first && i == ':') {
580 insn_is_label = true;
581 goto restart_parse;
582 }
583 first = false;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000584 result->oprs[operand].type = 0; /* so far, no override */
585 while (i == TOKEN_SPECIAL) { /* size specifiers */
586 switch ((int)tokval.t_integer) {
587 case S_BYTE:
588 if (!setsize) /* we want to use only the first */
589 result->oprs[operand].type |= BITS8;
590 setsize = 1;
591 break;
592 case S_WORD:
593 if (!setsize)
594 result->oprs[operand].type |= BITS16;
595 setsize = 1;
596 break;
597 case S_DWORD:
598 case S_LONG:
599 if (!setsize)
600 result->oprs[operand].type |= BITS32;
601 setsize = 1;
602 break;
603 case S_QWORD:
604 if (!setsize)
605 result->oprs[operand].type |= BITS64;
606 setsize = 1;
607 break;
608 case S_TWORD:
609 if (!setsize)
610 result->oprs[operand].type |= BITS80;
611 setsize = 1;
612 break;
H. Peter Anvin41c9f6f2007-09-18 13:01:32 -0700613 case S_OWORD:
614 if (!setsize)
615 result->oprs[operand].type |= BITS128;
616 setsize = 1;
617 break;
H. Peter Anvindfb91802008-05-20 11:43:53 -0700618 case S_YWORD:
619 if (!setsize)
620 result->oprs[operand].type |= BITS256;
621 setsize = 1;
622 break;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000623 case S_TO:
624 result->oprs[operand].type |= TO;
625 break;
626 case S_STRICT:
627 result->oprs[operand].type |= STRICT;
628 break;
629 case S_FAR:
630 result->oprs[operand].type |= FAR;
631 break;
632 case S_NEAR:
633 result->oprs[operand].type |= NEAR;
634 break;
635 case S_SHORT:
636 result->oprs[operand].type |= SHORT;
637 break;
638 default:
639 error(ERR_NONFATAL, "invalid operand size specification");
640 }
641 i = stdscan(NULL, &tokval);
642 }
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000643
H. Peter Anvine2c80182005-01-15 22:15:51 +0000644 if (i == '[' || i == '&') { /* memory reference */
H. Peter Anvin6867acc2007-10-10 14:58:45 -0700645 mref = true;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000646 bracket = (i == '[');
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700647 i = stdscan(NULL, &tokval); /* then skip the colon */
648 while (i == TOKEN_SPECIAL || i == TOKEN_PREFIX) {
649 process_size_override(result, operand);
650 i = stdscan(NULL, &tokval);
H. Peter Anvine2c80182005-01-15 22:15:51 +0000651 }
652 } else { /* immediate operand, or register */
H. Peter Anvin6867acc2007-10-10 14:58:45 -0700653 mref = false;
654 bracket = false; /* placate optimisers */
H. Peter Anvine2c80182005-01-15 22:15:51 +0000655 }
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000656
H. Peter Anvine2c80182005-01-15 22:15:51 +0000657 if ((result->oprs[operand].type & FAR) && !mref &&
658 result->opcode != I_JMP && result->opcode != I_CALL) {
659 error(ERR_NONFATAL, "invalid use of FAR operand specifier");
660 }
Debbie Wiles63b53f72002-06-04 19:31:24 +0000661
H. Peter Anvine2c80182005-01-15 22:15:51 +0000662 value = evaluate(stdscan, NULL, &tokval,
663 &result->oprs[operand].opflags,
664 critical, error, &hints);
665 i = tokval.t_type;
666 if (result->oprs[operand].opflags & OPFLAG_FORWARD) {
H. Peter Anvin6867acc2007-10-10 14:58:45 -0700667 result->forw_ref = true;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000668 }
669 if (!value) { /* error in evaluator */
670 result->opcode = -1; /* unrecoverable parse error: */
671 return result; /* ignore this instruction */
672 }
673 if (i == ':' && mref) { /* it was seg:offset */
674 /*
675 * Process the segment override.
676 */
677 if (value[1].type != 0 || value->value != 1 ||
H. Peter Anvina4835d42008-05-20 14:21:29 -0700678 REG_SREG & ~nasm_reg_flags[value->type])
H. Peter Anvine2c80182005-01-15 22:15:51 +0000679 error(ERR_NONFATAL, "invalid segment override");
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700680 else if (result->prefixes[PPS_SEG])
H. Peter Anvine2c80182005-01-15 22:15:51 +0000681 error(ERR_NONFATAL,
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700682 "instruction has conflicting segment overrides");
H. Peter Anvin99c4ecd2007-08-28 23:06:00 +0000683 else {
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700684 result->prefixes[PPS_SEG] = value->type;
H. Peter Anvina4835d42008-05-20 14:21:29 -0700685 if (!(REG_FSGS & ~nasm_reg_flags[value->type]))
H. Peter Anvin150e20d2007-08-29 15:19:19 +0000686 result->oprs[operand].eaflags |= EAF_FSGS;
H. Peter Anvin99c4ecd2007-08-28 23:06:00 +0000687 }
H. Peter Anvin76690a12002-04-30 20:52:49 +0000688
H. Peter Anvine2c80182005-01-15 22:15:51 +0000689 i = stdscan(NULL, &tokval); /* then skip the colon */
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700690 while (i == TOKEN_SPECIAL || i == TOKEN_PREFIX) {
691 process_size_override(result, operand);
H. Peter Anvine2c80182005-01-15 22:15:51 +0000692 i = stdscan(NULL, &tokval);
693 }
694 value = evaluate(stdscan, NULL, &tokval,
695 &result->oprs[operand].opflags,
696 critical, error, &hints);
697 i = tokval.t_type;
698 if (result->oprs[operand].opflags & OPFLAG_FORWARD) {
H. Peter Anvin6867acc2007-10-10 14:58:45 -0700699 result->forw_ref = true;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000700 }
701 /* and get the offset */
702 if (!value) { /* but, error in evaluator */
703 result->opcode = -1; /* unrecoverable parse error: */
704 return result; /* ignore this instruction */
705 }
706 }
Victor van den Elzen02846d32009-06-23 03:47:07 +0200707
H. Peter Anvin552bc2c2009-06-23 11:34:42 -0700708 recover = false;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000709 if (mref && bracket) { /* find ] at the end */
710 if (i != ']') {
711 error(ERR_NONFATAL, "parser: expecting ]");
Victor van den Elzen02846d32009-06-23 03:47:07 +0200712 recover = true;
713 } else { /* we got the required ] */
H. Peter Anvine2c80182005-01-15 22:15:51 +0000714 i = stdscan(NULL, &tokval);
Victor van den Elzen02846d32009-06-23 03:47:07 +0200715 if (i != 0 && i != ',') {
716 error(ERR_NONFATAL, "comma or end of line expected");
717 recover = true;
718 }
719 }
H. Peter Anvine2c80182005-01-15 22:15:51 +0000720 } else { /* immediate operand */
721 if (i != 0 && i != ',' && i != ':') {
Victor van den Elzen02846d32009-06-23 03:47:07 +0200722 error(ERR_NONFATAL, "comma, colon or end of line expected");
723 recover = true;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000724 } else if (i == ':') {
725 result->oprs[operand].type |= COLON;
726 }
727 }
Victor van den Elzen02846d32009-06-23 03:47:07 +0200728 if (recover) {
729 do { /* error recovery */
730 i = stdscan(NULL, &tokval);
731 } while (i != 0 && i != ',');
732 }
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000733
H. Peter Anvine2c80182005-01-15 22:15:51 +0000734 /* now convert the exprs returned from evaluate() into operand
735 * descriptions... */
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000736
H. Peter Anvine2c80182005-01-15 22:15:51 +0000737 if (mref) { /* it's a memory reference */
738 expr *e = value;
739 int b, i, s; /* basereg, indexreg, scale */
Keith Kanios7a68f302007-04-16 04:56:06 +0000740 int64_t o; /* offset */
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000741
H. Peter Anvine2c80182005-01-15 22:15:51 +0000742 b = i = -1, o = s = 0;
743 result->oprs[operand].hintbase = hints.base;
744 result->oprs[operand].hinttype = hints.type;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000745
H. Peter Anvine2c80182005-01-15 22:15:51 +0000746 if (e->type && e->type <= EXPR_REG_END) { /* this bit's a register */
747 if (e->value == 1) /* in fact it can be basereg */
748 b = e->type;
749 else /* no, it has to be indexreg */
750 i = e->type, s = e->value;
751 e++;
752 }
753 if (e->type && e->type <= EXPR_REG_END) { /* it's a 2nd register */
754 if (b != -1) /* If the first was the base, ... */
755 i = e->type, s = e->value; /* second has to be indexreg */
H. Peter Anvineba20a72002-04-30 20:53:55 +0000756
H. Peter Anvine2c80182005-01-15 22:15:51 +0000757 else if (e->value != 1) { /* If both want to be index */
758 error(ERR_NONFATAL,
759 "beroset-p-592-invalid effective address");
760 result->opcode = -1;
761 return result;
762 } else
763 b = e->type;
764 e++;
765 }
766 if (e->type != 0) { /* is there an offset? */
767 if (e->type <= EXPR_REG_END) { /* in fact, is there an error? */
768 error(ERR_NONFATAL,
769 "beroset-p-603-invalid effective address");
770 result->opcode = -1;
771 return result;
772 } else {
773 if (e->type == EXPR_UNKNOWN) {
Victor van den Elzen154e5922009-02-25 17:32:00 +0100774 result->oprs[operand].opflags |= OPFLAG_UNKNOWN;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000775 o = 0; /* doesn't matter what */
776 result->oprs[operand].wrt = NO_SEG; /* nor this */
777 result->oprs[operand].segment = NO_SEG; /* or this */
778 while (e->type)
779 e++; /* go to the end of the line */
780 } else {
781 if (e->type == EXPR_SIMPLE) {
782 o = e->value;
783 e++;
784 }
785 if (e->type == EXPR_WRT) {
786 result->oprs[operand].wrt = e->value;
787 e++;
788 } else
789 result->oprs[operand].wrt = NO_SEG;
790 /*
791 * Look for a segment base type.
792 */
793 if (e->type && e->type < EXPR_SEGBASE) {
794 error(ERR_NONFATAL,
795 "beroset-p-630-invalid effective address");
796 result->opcode = -1;
797 return result;
798 }
799 while (e->type && e->value == 0)
800 e++;
801 if (e->type && e->value != 1) {
802 error(ERR_NONFATAL,
803 "beroset-p-637-invalid effective address");
804 result->opcode = -1;
805 return result;
806 }
807 if (e->type) {
808 result->oprs[operand].segment =
809 e->type - EXPR_SEGBASE;
810 e++;
811 } else
812 result->oprs[operand].segment = NO_SEG;
813 while (e->type && e->value == 0)
814 e++;
815 if (e->type) {
816 error(ERR_NONFATAL,
817 "beroset-p-650-invalid effective address");
818 result->opcode = -1;
819 return result;
820 }
821 }
822 }
823 } else {
824 o = 0;
825 result->oprs[operand].wrt = NO_SEG;
826 result->oprs[operand].segment = NO_SEG;
827 }
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000828
H. Peter Anvine2c80182005-01-15 22:15:51 +0000829 if (e->type != 0) { /* there'd better be nothing left! */
830 error(ERR_NONFATAL,
831 "beroset-p-663-invalid effective address");
832 result->opcode = -1;
833 return result;
834 }
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000835
H. Peter Anvin0da6b582007-09-12 20:32:39 -0700836 /* It is memory, but it can match any r/m operand */
837 result->oprs[operand].type |= MEMORY_ANY;
H. Peter Anvin99c4ecd2007-08-28 23:06:00 +0000838
839 if (b == -1 && (i == -1 || s == 0)) {
840 int is_rel = globalbits == 64 &&
841 !(result->oprs[operand].eaflags & EAF_ABS) &&
842 ((globalrel &&
H. Peter Anvin150e20d2007-08-29 15:19:19 +0000843 !(result->oprs[operand].eaflags & EAF_FSGS)) ||
H. Peter Anvin99c4ecd2007-08-28 23:06:00 +0000844 (result->oprs[operand].eaflags & EAF_REL));
845
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700846 result->oprs[operand].type |= is_rel ? IP_REL : MEM_OFFS;
H. Peter Anvin99c4ecd2007-08-28 23:06:00 +0000847 }
H. Peter Anvine2c80182005-01-15 22:15:51 +0000848 result->oprs[operand].basereg = b;
849 result->oprs[operand].indexreg = i;
850 result->oprs[operand].scale = s;
851 result->oprs[operand].offset = o;
852 } else { /* it's not a memory reference */
H. Peter Anvine2c80182005-01-15 22:15:51 +0000853 if (is_just_unknown(value)) { /* it's immediate but unknown */
854 result->oprs[operand].type |= IMMEDIATE;
Victor van den Elzen154e5922009-02-25 17:32:00 +0100855 result->oprs[operand].opflags |= OPFLAG_UNKNOWN;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000856 result->oprs[operand].offset = 0; /* don't care */
857 result->oprs[operand].segment = NO_SEG; /* don't care again */
858 result->oprs[operand].wrt = NO_SEG; /* still don't care */
Victor van den Elzen154e5922009-02-25 17:32:00 +0100859
860 if(optimizing >= 0 && !(result->oprs[operand].type & STRICT))
861 {
862 /* Be optimistic */
863 result->oprs[operand].type |= SBYTE16 | SBYTE32 | SBYTE64;
864 }
H. Peter Anvine2c80182005-01-15 22:15:51 +0000865 } else if (is_reloc(value)) { /* it's immediate */
866 result->oprs[operand].type |= IMMEDIATE;
867 result->oprs[operand].offset = reloc_value(value);
868 result->oprs[operand].segment = reloc_seg(value);
869 result->oprs[operand].wrt = reloc_wrt(value);
870 if (is_simple(value)) {
871 if (reloc_value(value) == 1)
872 result->oprs[operand].type |= UNITY;
873 if (optimizing >= 0 &&
874 !(result->oprs[operand].type & STRICT)) {
H. Peter Anvin32cd4c22008-04-04 13:34:53 -0700875 int64_t v64 = reloc_value(value);
876 int32_t v32 = (int32_t)v64;
877 int16_t v16 = (int16_t)v32;
878
879 if (v64 >= -128 && v64 <= 127)
880 result->oprs[operand].type |= SBYTE64;
881 if (v32 >= -128 && v32 <= 127)
882 result->oprs[operand].type |= SBYTE32;
883 if (v16 >= -128 && v16 <= 127)
884 result->oprs[operand].type |= SBYTE16;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000885 }
886 }
887 } else { /* it's a register */
H. Peter Anvin68222142007-11-18 22:18:09 -0800888 unsigned int rs;
H. Peter Anvineba20a72002-04-30 20:53:55 +0000889
H. Peter Anvine2c80182005-01-15 22:15:51 +0000890 if (value->type >= EXPR_SIMPLE || value->value != 1) {
891 error(ERR_NONFATAL, "invalid operand type");
892 result->opcode = -1;
893 return result;
894 }
H. Peter Anvineba20a72002-04-30 20:53:55 +0000895
H. Peter Anvine2c80182005-01-15 22:15:51 +0000896 /*
897 * check that its only 1 register, not an expression...
898 */
899 for (i = 1; value[i].type; i++)
900 if (value[i].value) {
901 error(ERR_NONFATAL, "invalid operand type");
902 result->opcode = -1;
903 return result;
904 }
H. Peter Anvineba20a72002-04-30 20:53:55 +0000905
H. Peter Anvine2c80182005-01-15 22:15:51 +0000906 /* clear overrides, except TO which applies to FPU regs */
907 if (result->oprs[operand].type & ~TO) {
908 /*
909 * we want to produce a warning iff the specified size
910 * is different from the register size
911 */
H. Peter Anvin68222142007-11-18 22:18:09 -0800912 rs = result->oprs[operand].type & SIZE_MASK;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000913 } else
H. Peter Anvin68222142007-11-18 22:18:09 -0800914 rs = 0;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000915
916 result->oprs[operand].type &= TO;
917 result->oprs[operand].type |= REGISTER;
H. Peter Anvina4835d42008-05-20 14:21:29 -0700918 result->oprs[operand].type |= nasm_reg_flags[value->type];
H. Peter Anvine2c80182005-01-15 22:15:51 +0000919 result->oprs[operand].basereg = value->type;
920
H. Peter Anvin68222142007-11-18 22:18:09 -0800921 if (rs && (result->oprs[operand].type & SIZE_MASK) != rs)
H. Peter Anvine2c80182005-01-15 22:15:51 +0000922 error(ERR_WARNING | ERR_PASS1,
923 "register size specification ignored");
924 }
925 }
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000926 }
927
H. Peter Anvine2c80182005-01-15 22:15:51 +0000928 result->operands = operand; /* set operand count */
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000929
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700930/* clear remaining operands */
931while (operand < MAX_OPERANDS)
932 result->oprs[operand++].type = 0;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000933
934 /*
H. Peter Anvindfb91802008-05-20 11:43:53 -0700935 * Transform RESW, RESD, RESQ, REST, RESO, RESY into RESB.
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000936 */
937 switch (result->opcode) {
H. Peter Anvine2c80182005-01-15 22:15:51 +0000938 case I_RESW:
939 result->opcode = I_RESB;
940 result->oprs[0].offset *= 2;
941 break;
942 case I_RESD:
943 result->opcode = I_RESB;
944 result->oprs[0].offset *= 4;
945 break;
946 case I_RESQ:
947 result->opcode = I_RESB;
948 result->oprs[0].offset *= 8;
949 break;
950 case I_REST:
951 result->opcode = I_RESB;
952 result->oprs[0].offset *= 10;
953 break;
H. Peter Anvin41c9f6f2007-09-18 13:01:32 -0700954 case I_RESO:
955 result->opcode = I_RESB;
956 result->oprs[0].offset *= 16;
957 break;
H. Peter Anvindfb91802008-05-20 11:43:53 -0700958 case I_RESY:
959 result->opcode = I_RESB;
960 result->oprs[0].offset *= 32;
961 break;
H. Peter Anvin16b0a332007-09-12 20:27:41 -0700962 default:
963 break;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000964 }
965
966 return result;
967}
968
H. Peter Anvine2c80182005-01-15 22:15:51 +0000969static int is_comma_next(void)
H. Peter Anvineba20a72002-04-30 20:53:55 +0000970{
Keith Kaniosa6dfa782007-04-13 16:47:53 +0000971 char *p;
H. Peter Anvin76690a12002-04-30 20:52:49 +0000972 int i;
973 struct tokenval tv;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000974
H. Peter Anvin76690a12002-04-30 20:52:49 +0000975 p = stdscan_bufptr;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000976 i = stdscan(NULL, &tv);
H. Peter Anvin76690a12002-04-30 20:52:49 +0000977 stdscan_bufptr = p;
978 return (i == ',' || i == ';' || !i);
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000979}
980
H. Peter Anvine2c80182005-01-15 22:15:51 +0000981void cleanup_insn(insn * i)
H. Peter Anvineba20a72002-04-30 20:53:55 +0000982{
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000983 extop *e;
984
H. Peter Anvin2aa77392008-06-15 17:39:45 -0700985 while ((e = i->eops)) {
986 i->eops = e->next;
987 if (e->type == EOT_DB_STRING_FREE)
988 nasm_free(e->stringval);
H. Peter Anvine2c80182005-01-15 22:15:51 +0000989 nasm_free(e);
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000990 }
991}