blob: 79da372931b92de28a8efe30e31d6744a1ab694b [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 Anvine2c80182005-01-15 22:15:51 +000064static struct ofmt *outfmt; /* Structure of addresses of output routines */
H. Peter Anvin12e46512007-10-03 21:30:57 -070065static struct location *location; /* Pointer to current line's segment,offset */
H. Peter Anvineba20a72002-04-30 20:53:55 +000066
H. Peter Anvin12e46512007-10-03 21:30:57 -070067void parser_global_info(struct ofmt *output, struct location * locp)
H. Peter Anvineba20a72002-04-30 20:53:55 +000068{
69 outfmt = output;
70 location = locp;
71}
H. Peter Anvinea6e34d2002-04-30 20:51:32 +000072
H. Peter Anvinde4b89b2007-10-01 15:41:25 -070073static int prefix_slot(enum prefixes prefix)
74{
75 switch (prefix) {
H. Peter Anvinc2acf7b2009-02-21 18:22:56 -080076 case P_WAIT:
77 return PPS_WAIT;
H. Peter Anvinde4b89b2007-10-01 15:41:25 -070078 case R_CS:
79 case R_DS:
80 case R_SS:
81 case R_ES:
82 case R_FS:
83 case R_GS:
84 return PPS_SEG;
85 case P_LOCK:
86 case P_REP:
87 case P_REPE:
88 case P_REPZ:
89 case P_REPNE:
90 case P_REPNZ:
91 return PPS_LREP;
92 case P_O16:
93 case P_O32:
94 case P_O64:
95 case P_OSP:
96 return PPS_OSIZE;
97 case P_A16:
98 case P_A32:
99 case P_A64:
100 case P_ASP:
101 return PPS_ASIZE;
102 default:
103 error(ERR_PANIC, "Invalid value %d passed to prefix_slot()", prefix);
104 return -1;
105 }
106}
107
108static void process_size_override(insn * result, int operand)
109{
110 if (tasm_compatible_mode) {
111 switch ((int)tokval.t_integer) {
112 /* For TASM compatibility a size override inside the
113 * brackets changes the size of the operand, not the
114 * address type of the operand as it does in standard
115 * NASM syntax. Hence:
116 *
117 * mov eax,[DWORD val]
118 *
119 * is valid syntax in TASM compatibility mode. Note that
120 * you lose the ability to override the default address
121 * type for the instruction, but we never use anything
122 * but 32-bit flat model addressing in our code.
123 */
124 case S_BYTE:
125 result->oprs[operand].type |= BITS8;
126 break;
127 case S_WORD:
128 result->oprs[operand].type |= BITS16;
129 break;
130 case S_DWORD:
131 case S_LONG:
132 result->oprs[operand].type |= BITS32;
133 break;
134 case S_QWORD:
135 result->oprs[operand].type |= BITS64;
136 break;
137 case S_TWORD:
138 result->oprs[operand].type |= BITS80;
139 break;
140 case S_OWORD:
141 result->oprs[operand].type |= BITS128;
142 break;
143 default:
144 error(ERR_NONFATAL,
145 "invalid operand size specification");
146 break;
147 }
148 } else {
149 /* Standard NASM compatible syntax */
150 switch ((int)tokval.t_integer) {
151 case S_NOSPLIT:
152 result->oprs[operand].eaflags |= EAF_TIMESTWO;
153 break;
154 case S_REL:
155 result->oprs[operand].eaflags |= EAF_REL;
156 break;
157 case S_ABS:
158 result->oprs[operand].eaflags |= EAF_ABS;
159 break;
160 case S_BYTE:
161 result->oprs[operand].disp_size = 8;
162 result->oprs[operand].eaflags |= EAF_BYTEOFFS;
163 break;
164 case P_A16:
165 case P_A32:
166 case P_A64:
167 if (result->prefixes[PPS_ASIZE] &&
168 result->prefixes[PPS_ASIZE] != tokval.t_integer)
169 error(ERR_NONFATAL,
170 "conflicting address size specifications");
171 else
172 result->prefixes[PPS_ASIZE] = tokval.t_integer;
173 break;
174 case S_WORD:
175 result->oprs[operand].disp_size = 16;
176 result->oprs[operand].eaflags |= EAF_WORDOFFS;
177 break;
178 case S_DWORD:
179 case S_LONG:
180 result->oprs[operand].disp_size = 32;
181 result->oprs[operand].eaflags |= EAF_WORDOFFS;
182 break;
183 case S_QWORD:
184 result->oprs[operand].disp_size = 64;
185 result->oprs[operand].eaflags |= EAF_WORDOFFS;
186 break;
187 default:
188 error(ERR_NONFATAL, "invalid size specification in"
189 " effective address");
190 break;
191 }
192 }
193}
194
Keith Kaniosa6dfa782007-04-13 16:47:53 +0000195insn *parse_line(int pass, char *buffer, insn * result,
H. Peter Anvine2c80182005-01-15 22:15:51 +0000196 efunc errfunc, evalfunc evaluate, ldfunc ldef)
H. Peter Anvineba20a72002-04-30 20:53:55 +0000197{
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000198 int operand;
199 int critical;
H. Peter Anvin76690a12002-04-30 20:52:49 +0000200 struct eval_hints hints;
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700201 int j;
H. Peter Anvin9c987692007-11-04 21:09:32 -0800202 bool first;
203 bool insn_is_label = false;
H. Peter Anvin552bc2c2009-06-23 11:34:42 -0700204 bool recover;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000205
H. Peter Anvin9c987692007-11-04 21:09:32 -0800206restart_parse:
207 first = true;
H. Peter Anvin6867acc2007-10-10 14:58:45 -0700208 result->forw_ref = false;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000209 error = errfunc;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000210
H. Peter Anvin76690a12002-04-30 20:52:49 +0000211 stdscan_reset();
212 stdscan_bufptr = buffer;
213 i = stdscan(NULL, &tokval);
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000214
H. Peter Anvine2c80182005-01-15 22:15:51 +0000215 result->label = NULL; /* Assume no label */
216 result->eops = NULL; /* must do this, whatever happens */
Keith Kaniosb7a89542007-04-12 02:40:54 +0000217 result->operands = 0; /* must initialize this */
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000218
H. Peter Anvine2c80182005-01-15 22:15:51 +0000219 if (i == 0) { /* blank line - ignore */
220 result->opcode = -1; /* and no instruction either */
221 return result;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000222 }
223 if (i != TOKEN_ID && i != TOKEN_INSN && i != TOKEN_PREFIX &&
H. Peter Anvina4835d42008-05-20 14:21:29 -0700224 (i != TOKEN_REG || (REG_SREG & ~nasm_reg_flags[tokval.t_integer]))) {
H. Peter Anvine2c80182005-01-15 22:15:51 +0000225 error(ERR_NONFATAL, "label or instruction expected"
226 " at start of line");
227 result->opcode = -1;
228 return result;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000229 }
230
H. Peter Anvin9c987692007-11-04 21:09:32 -0800231 if (i == TOKEN_ID || (insn_is_label && i == TOKEN_INSN)) {
232 /* there's a label here */
233 first = false;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000234 result->label = tokval.t_charptr;
235 i = stdscan(NULL, &tokval);
236 if (i == ':') { /* skip over the optional colon */
237 i = stdscan(NULL, &tokval);
238 } else if (i == 0) {
239 error(ERR_WARNING | ERR_WARN_OL | ERR_PASS1,
240 "label alone on a line without a colon might be in error");
241 }
242 if (i != TOKEN_INSN || tokval.t_integer != I_EQU) {
243 /*
244 * FIXME: location->segment could be NO_SEG, in which case
245 * it is possible we should be passing 'abs_seg'. Look into this.
246 * Work out whether that is *really* what we should be doing.
247 * Generally fix things. I think this is right as it is, but
248 * am still not certain.
249 */
250 ldef(result->label, in_abs_seg ? abs_seg : location->segment,
H. Peter Anvin6867acc2007-10-10 14:58:45 -0700251 location->offset, NULL, true, false, outfmt, errfunc);
H. Peter Anvine2c80182005-01-15 22:15:51 +0000252 }
H. Peter Anvineba20a72002-04-30 20:53:55 +0000253 }
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000254
H. Peter Anvine2c80182005-01-15 22:15:51 +0000255 if (i == 0) {
256 result->opcode = -1; /* this line contains just a label */
257 return result;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000258 }
259
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700260 for (j = 0; j < MAXPREFIX; j++)
261 result->prefixes[j] = P_none;
H. Peter Anvind7ed89e2002-04-30 20:52:08 +0000262 result->times = 1L;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000263
264 while (i == TOKEN_PREFIX ||
H. Peter Anvina4835d42008-05-20 14:21:29 -0700265 (i == TOKEN_REG && !(REG_SREG & ~nasm_reg_flags[tokval.t_integer])))
H. Peter Anvineba20a72002-04-30 20:53:55 +0000266 {
H. Peter Anvin9c987692007-11-04 21:09:32 -0800267 first = false;
268
H. Peter Anvine2c80182005-01-15 22:15:51 +0000269 /*
270 * Handle special case: the TIMES prefix.
271 */
272 if (i == TOKEN_PREFIX && tokval.t_integer == P_TIMES) {
273 expr *value;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000274
H. Peter Anvine2c80182005-01-15 22:15:51 +0000275 i = stdscan(NULL, &tokval);
276 value =
277 evaluate(stdscan, NULL, &tokval, NULL, pass0, error, NULL);
278 i = tokval.t_type;
279 if (!value) { /* but, error in evaluator */
280 result->opcode = -1; /* unrecoverable parse error: */
281 return result; /* ignore this instruction */
282 }
283 if (!is_simple(value)) {
284 error(ERR_NONFATAL,
285 "non-constant argument supplied to TIMES");
286 result->times = 1L;
287 } else {
288 result->times = value->value;
Charles Crayne7f596e72008-09-23 21:49:09 -0700289 if (value->value < 0 && pass0 == 2) {
H. Peter Anvine2c80182005-01-15 22:15:51 +0000290 error(ERR_NONFATAL, "TIMES value %d is negative",
291 value->value);
292 result->times = 0;
293 }
294 }
295 } else {
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700296 int slot = prefix_slot(tokval.t_integer);
297 if (result->prefixes[slot]) {
Charles Crayne052c0bd2007-10-29 18:24:59 -0700298 if (result->prefixes[slot] == tokval.t_integer)
H. Peter Anvin9c987692007-11-04 21:09:32 -0800299 error(ERR_WARNING,
Charles Crayne052c0bd2007-10-29 18:24:59 -0700300 "instruction has redundant prefixes");
301 else
302 error(ERR_NONFATAL,
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700303 "instruction has conflicting prefixes");
304 }
305 result->prefixes[slot] = tokval.t_integer;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000306 i = stdscan(NULL, &tokval);
307 }
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000308 }
309
310 if (i != TOKEN_INSN) {
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700311 int j;
312 enum prefixes pfx;
313
314 for (j = 0; j < MAXPREFIX; j++)
315 if ((pfx = result->prefixes[j]) != P_none)
316 break;
H. Peter Anvincb583b92007-10-28 22:04:42 -0700317
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700318 if (i == 0 && pfx != P_none) {
H. Peter Anvine2c80182005-01-15 22:15:51 +0000319 /*
320 * Instruction prefixes are present, but no actual
321 * instruction. This is allowed: at this point we
322 * invent a notional instruction of RESB 0.
323 */
324 result->opcode = I_RESB;
325 result->operands = 1;
326 result->oprs[0].type = IMMEDIATE;
327 result->oprs[0].offset = 0L;
328 result->oprs[0].segment = result->oprs[0].wrt = NO_SEG;
329 return result;
330 } else {
331 error(ERR_NONFATAL, "parser: instruction expected");
332 result->opcode = -1;
333 return result;
334 }
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000335 }
336
337 result->opcode = tokval.t_integer;
338 result->condition = tokval.t_inttwo;
339
340 /*
Charles Crayne2581c862008-09-10 19:21:52 -0700341 * INCBIN cannot be satisfied with incorrectly
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000342 * evaluated operands, since the correct values _must_ be known
343 * on the first pass. Hence, even in pass one, we set the
344 * `critical' flag on calling evaluate(), so that it will bomb
Charles Crayne2581c862008-09-10 19:21:52 -0700345 * out on undefined symbols.
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000346 */
Charles Crayne2581c862008-09-10 19:21:52 -0700347 if (result->opcode == I_INCBIN) {
Charles Crayne5a7976c2008-03-26 17:20:21 -0700348 critical = (pass0 < 2 ? 1 : 2);
349
H. Peter Anvine2c80182005-01-15 22:15:51 +0000350 } else
351 critical = (pass == 2 ? 2 : 0);
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000352
H. Peter Anvin41c9f6f2007-09-18 13:01:32 -0700353 if (result->opcode == I_DB || result->opcode == I_DW ||
354 result->opcode == I_DD || result->opcode == I_DQ ||
355 result->opcode == I_DT || result->opcode == I_DO ||
H. Peter Anvindfb91802008-05-20 11:43:53 -0700356 result->opcode == I_DY || result->opcode == I_INCBIN) {
H. Peter Anvine2c80182005-01-15 22:15:51 +0000357 extop *eop, **tail = &result->eops, **fixptr;
358 int oper_num = 0;
H. Peter Anvin518df302008-06-14 16:53:48 -0700359 int32_t sign;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000360
H. Peter Anvin6867acc2007-10-10 14:58:45 -0700361 result->eops_float = false;
H. Peter Anvineba20a72002-04-30 20:53:55 +0000362
H. Peter Anvine2c80182005-01-15 22:15:51 +0000363 /*
H. Peter Anvin41c9f6f2007-09-18 13:01:32 -0700364 * Begin to read the DB/DW/DD/DQ/DT/DO/INCBIN operands.
H. Peter Anvine2c80182005-01-15 22:15:51 +0000365 */
366 while (1) {
367 i = stdscan(NULL, &tokval);
368 if (i == 0)
369 break;
H. Peter Anvin9c987692007-11-04 21:09:32 -0800370 else if (first && i == ':') {
371 insn_is_label = true;
372 goto restart_parse;
373 }
374 first = false;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000375 fixptr = tail;
376 eop = *tail = nasm_malloc(sizeof(extop));
377 tail = &eop->next;
378 eop->next = NULL;
379 eop->type = EOT_NOTHING;
380 oper_num++;
H. Peter Anvin518df302008-06-14 16:53:48 -0700381 sign = +1;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000382
H. Peter Anvin518df302008-06-14 16:53:48 -0700383 /* is_comma_next() here is to distinguish this from
384 a string used as part of an expression... */
H. Peter Anvin11627042008-06-09 20:45:19 -0700385 if (i == TOKEN_STR && is_comma_next()) {
H. Peter Anvine2c80182005-01-15 22:15:51 +0000386 eop->type = EOT_DB_STRING;
387 eop->stringval = tokval.t_charptr;
388 eop->stringlen = tokval.t_inttwo;
389 i = stdscan(NULL, &tokval); /* eat the comma */
H. Peter Anvin518df302008-06-14 16:53:48 -0700390 } else if (i == TOKEN_STRFUNC) {
391 bool parens = false;
392 const char *funcname = tokval.t_charptr;
393 enum strfunc func = tokval.t_integer;
394 i = stdscan(NULL, &tokval);
395 if (i == '(') {
396 parens = true;
397 i = stdscan(NULL, &tokval);
398 }
399 if (i != TOKEN_STR) {
400 error(ERR_NONFATAL,
401 "%s must be followed by a string constant",
402 funcname);
403 eop->type = EOT_NOTHING;
404 } else {
405 eop->type = EOT_DB_STRING_FREE;
406 eop->stringlen =
407 string_transform(tokval.t_charptr, tokval.t_inttwo,
408 &eop->stringval, func);
409 if (eop->stringlen == (size_t)-1) {
410 error(ERR_NONFATAL, "invalid string for transform");
411 eop->type = EOT_NOTHING;
412 }
413 }
414 if (parens && i && i != ')') {
415 i = stdscan(NULL, &tokval);
416 if (i != ')') {
417 error(ERR_NONFATAL, "unterminated %s function",
418 funcname);
419 }
420 }
421 if (i && i != ',')
422 i = stdscan(NULL, &tokval);
423 } else if (i == '-' || i == '+') {
424 char *save = stdscan_bufptr;
425 int token = i;
426 sign = (i == '-') ? -1 : 1;
427 i = stdscan(NULL, &tokval);
428 if (i != TOKEN_FLOAT) {
429 stdscan_bufptr = save;
430 i = tokval.t_type = token;
431 goto is_expression;
432 } else {
433 goto is_float;
434 }
435 } else if (i == TOKEN_FLOAT) {
436 is_float:
437 eop->type = EOT_DB_STRING;
438 result->eops_float = true;
439 switch (result->opcode) {
440 case I_DB:
441 eop->stringlen = 1;
442 break;
443 case I_DW:
444 eop->stringlen = 2;
445 break;
446 case I_DD:
447 eop->stringlen = 4;
448 break;
449 case I_DQ:
450 eop->stringlen = 8;
451 break;
452 case I_DT:
453 eop->stringlen = 10;
454 break;
455 case I_DO:
456 eop->stringlen = 16;
457 break;
458 case I_DY:
459 error(ERR_NONFATAL, "floating-point constant"
460 " encountered in DY instruction");
461 eop->stringlen = 0;
462 break;
463 default:
464 error(ERR_NONFATAL, "floating-point constant"
465 " encountered in unknown instruction");
466 /*
467 * fix suggested by Pedro Gimeno... original line
468 * was:
469 * eop->type = EOT_NOTHING;
470 */
471 eop->stringlen = 0;
472 break;
473 }
474 eop = nasm_realloc(eop, sizeof(extop) + eop->stringlen);
475 tail = &eop->next;
476 *fixptr = eop;
477 eop->stringval = (char *)eop + sizeof(extop);
478 if (!eop->stringlen ||
479 !float_const(tokval.t_charptr, sign,
480 (uint8_t *)eop->stringval,
481 eop->stringlen, error))
482 eop->type = EOT_NOTHING;
483 i = stdscan(NULL, &tokval); /* eat the comma */
484 } else {
485 /* anything else, assume it is an expression */
H. Peter Anvine2c80182005-01-15 22:15:51 +0000486 expr *value;
H. Peter Anvin518df302008-06-14 16:53:48 -0700487
488 is_expression:
H. Peter Anvine2c80182005-01-15 22:15:51 +0000489 value = evaluate(stdscan, NULL, &tokval, NULL,
490 critical, error, NULL);
491 i = tokval.t_type;
492 if (!value) { /* error in evaluator */
493 result->opcode = -1; /* unrecoverable parse error: */
494 return result; /* ignore this instruction */
495 }
496 if (is_unknown(value)) {
497 eop->type = EOT_DB_NUMBER;
498 eop->offset = 0; /* doesn't matter what we put */
499 eop->segment = eop->wrt = NO_SEG; /* likewise */
500 } else if (is_reloc(value)) {
501 eop->type = EOT_DB_NUMBER;
502 eop->offset = reloc_value(value);
503 eop->segment = reloc_seg(value);
504 eop->wrt = reloc_wrt(value);
505 } else {
506 error(ERR_NONFATAL,
507 "operand %d: expression is not simple"
508 " or relocatable", oper_num);
509 }
510 }
H. Peter Anvin6768eb72002-04-30 20:52:26 +0000511
H. Peter Anvine2c80182005-01-15 22:15:51 +0000512 /*
513 * We're about to call stdscan(), which will eat the
514 * comma that we're currently sitting on between
515 * arguments. However, we'd better check first that it
516 * _is_ a comma.
517 */
518 if (i == 0) /* also could be EOL */
519 break;
520 if (i != ',') {
521 error(ERR_NONFATAL, "comma expected after operand %d",
522 oper_num);
523 result->opcode = -1; /* unrecoverable parse error: */
524 return result; /* ignore this instruction */
525 }
526 }
H. Peter Anvind7ed89e2002-04-30 20:52:08 +0000527
H. Peter Anvine2c80182005-01-15 22:15:51 +0000528 if (result->opcode == I_INCBIN) {
529 /*
530 * Correct syntax for INCBIN is that there should be
531 * one string operand, followed by one or two numeric
532 * operands.
533 */
534 if (!result->eops || result->eops->type != EOT_DB_STRING)
535 error(ERR_NONFATAL, "`incbin' expects a file name");
536 else if (result->eops->next &&
537 result->eops->next->type != EOT_DB_NUMBER)
538 error(ERR_NONFATAL, "`incbin': second parameter is",
539 " non-numeric");
540 else if (result->eops->next && result->eops->next->next &&
541 result->eops->next->next->type != EOT_DB_NUMBER)
542 error(ERR_NONFATAL, "`incbin': third parameter is",
543 " non-numeric");
544 else if (result->eops->next && result->eops->next->next &&
545 result->eops->next->next->next)
546 error(ERR_NONFATAL,
547 "`incbin': more than three parameters");
H. Peter Anvineba20a72002-04-30 20:53:55 +0000548 else
H. Peter Anvine2c80182005-01-15 22:15:51 +0000549 return result;
550 /*
551 * If we reach here, one of the above errors happened.
552 * Throw the instruction away.
553 */
554 result->opcode = -1;
555 return result;
556 } else /* DB ... */ if (oper_num == 0)
557 error(ERR_WARNING | ERR_PASS1,
558 "no operand for data declaration");
559 else
560 result->operands = oper_num;
H. Peter Anvind7ed89e2002-04-30 20:52:08 +0000561
H. Peter Anvine2c80182005-01-15 22:15:51 +0000562 return result;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000563 }
564
H. Peter Anvin8f94f982007-09-17 16:31:33 -0700565 /* right. Now we begin to parse the operands. There may be up to four
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000566 * of these, separated by commas, and terminated by a zero token. */
567
H. Peter Anvin8f94f982007-09-17 16:31:33 -0700568 for (operand = 0; operand < MAX_OPERANDS; operand++) {
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700569 expr *value; /* used most of the time */
H. Peter Anvine2c80182005-01-15 22:15:51 +0000570 int mref; /* is this going to be a memory ref? */
571 int bracket; /* is it a [] mref, or a & mref? */
572 int setsize = 0;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000573
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700574 result->oprs[operand].disp_size = 0; /* have to zero this whatever */
H. Peter Anvine2c80182005-01-15 22:15:51 +0000575 result->oprs[operand].eaflags = 0; /* and this */
576 result->oprs[operand].opflags = 0;
H. Peter Anvineba20a72002-04-30 20:53:55 +0000577
H. Peter Anvine2c80182005-01-15 22:15:51 +0000578 i = stdscan(NULL, &tokval);
579 if (i == 0)
580 break; /* end of operands: get out of here */
H. Peter Anvin9c987692007-11-04 21:09:32 -0800581 else if (first && i == ':') {
582 insn_is_label = true;
583 goto restart_parse;
584 }
585 first = false;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000586 result->oprs[operand].type = 0; /* so far, no override */
587 while (i == TOKEN_SPECIAL) { /* size specifiers */
588 switch ((int)tokval.t_integer) {
589 case S_BYTE:
590 if (!setsize) /* we want to use only the first */
591 result->oprs[operand].type |= BITS8;
592 setsize = 1;
593 break;
594 case S_WORD:
595 if (!setsize)
596 result->oprs[operand].type |= BITS16;
597 setsize = 1;
598 break;
599 case S_DWORD:
600 case S_LONG:
601 if (!setsize)
602 result->oprs[operand].type |= BITS32;
603 setsize = 1;
604 break;
605 case S_QWORD:
606 if (!setsize)
607 result->oprs[operand].type |= BITS64;
608 setsize = 1;
609 break;
610 case S_TWORD:
611 if (!setsize)
612 result->oprs[operand].type |= BITS80;
613 setsize = 1;
614 break;
H. Peter Anvin41c9f6f2007-09-18 13:01:32 -0700615 case S_OWORD:
616 if (!setsize)
617 result->oprs[operand].type |= BITS128;
618 setsize = 1;
619 break;
H. Peter Anvindfb91802008-05-20 11:43:53 -0700620 case S_YWORD:
621 if (!setsize)
622 result->oprs[operand].type |= BITS256;
623 setsize = 1;
624 break;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000625 case S_TO:
626 result->oprs[operand].type |= TO;
627 break;
628 case S_STRICT:
629 result->oprs[operand].type |= STRICT;
630 break;
631 case S_FAR:
632 result->oprs[operand].type |= FAR;
633 break;
634 case S_NEAR:
635 result->oprs[operand].type |= NEAR;
636 break;
637 case S_SHORT:
638 result->oprs[operand].type |= SHORT;
639 break;
640 default:
641 error(ERR_NONFATAL, "invalid operand size specification");
642 }
643 i = stdscan(NULL, &tokval);
644 }
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000645
H. Peter Anvine2c80182005-01-15 22:15:51 +0000646 if (i == '[' || i == '&') { /* memory reference */
H. Peter Anvin6867acc2007-10-10 14:58:45 -0700647 mref = true;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000648 bracket = (i == '[');
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700649 i = stdscan(NULL, &tokval); /* then skip the colon */
650 while (i == TOKEN_SPECIAL || i == TOKEN_PREFIX) {
651 process_size_override(result, operand);
652 i = stdscan(NULL, &tokval);
H. Peter Anvine2c80182005-01-15 22:15:51 +0000653 }
654 } else { /* immediate operand, or register */
H. Peter Anvin6867acc2007-10-10 14:58:45 -0700655 mref = false;
656 bracket = false; /* placate optimisers */
H. Peter Anvine2c80182005-01-15 22:15:51 +0000657 }
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000658
H. Peter Anvine2c80182005-01-15 22:15:51 +0000659 if ((result->oprs[operand].type & FAR) && !mref &&
660 result->opcode != I_JMP && result->opcode != I_CALL) {
661 error(ERR_NONFATAL, "invalid use of FAR operand specifier");
662 }
Debbie Wiles63b53f72002-06-04 19:31:24 +0000663
H. Peter Anvine2c80182005-01-15 22:15:51 +0000664 value = evaluate(stdscan, NULL, &tokval,
665 &result->oprs[operand].opflags,
666 critical, error, &hints);
667 i = tokval.t_type;
668 if (result->oprs[operand].opflags & OPFLAG_FORWARD) {
H. Peter Anvin6867acc2007-10-10 14:58:45 -0700669 result->forw_ref = true;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000670 }
671 if (!value) { /* error in evaluator */
672 result->opcode = -1; /* unrecoverable parse error: */
673 return result; /* ignore this instruction */
674 }
675 if (i == ':' && mref) { /* it was seg:offset */
676 /*
677 * Process the segment override.
678 */
679 if (value[1].type != 0 || value->value != 1 ||
H. Peter Anvina4835d42008-05-20 14:21:29 -0700680 REG_SREG & ~nasm_reg_flags[value->type])
H. Peter Anvine2c80182005-01-15 22:15:51 +0000681 error(ERR_NONFATAL, "invalid segment override");
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700682 else if (result->prefixes[PPS_SEG])
H. Peter Anvine2c80182005-01-15 22:15:51 +0000683 error(ERR_NONFATAL,
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700684 "instruction has conflicting segment overrides");
H. Peter Anvin99c4ecd2007-08-28 23:06:00 +0000685 else {
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700686 result->prefixes[PPS_SEG] = value->type;
H. Peter Anvina4835d42008-05-20 14:21:29 -0700687 if (!(REG_FSGS & ~nasm_reg_flags[value->type]))
H. Peter Anvin150e20d2007-08-29 15:19:19 +0000688 result->oprs[operand].eaflags |= EAF_FSGS;
H. Peter Anvin99c4ecd2007-08-28 23:06:00 +0000689 }
H. Peter Anvin76690a12002-04-30 20:52:49 +0000690
H. Peter Anvine2c80182005-01-15 22:15:51 +0000691 i = stdscan(NULL, &tokval); /* then skip the colon */
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700692 while (i == TOKEN_SPECIAL || i == TOKEN_PREFIX) {
693 process_size_override(result, operand);
H. Peter Anvine2c80182005-01-15 22:15:51 +0000694 i = stdscan(NULL, &tokval);
695 }
696 value = evaluate(stdscan, NULL, &tokval,
697 &result->oprs[operand].opflags,
698 critical, error, &hints);
699 i = tokval.t_type;
700 if (result->oprs[operand].opflags & OPFLAG_FORWARD) {
H. Peter Anvin6867acc2007-10-10 14:58:45 -0700701 result->forw_ref = true;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000702 }
703 /* and get the offset */
704 if (!value) { /* but, error in evaluator */
705 result->opcode = -1; /* unrecoverable parse error: */
706 return result; /* ignore this instruction */
707 }
708 }
Victor van den Elzen02846d32009-06-23 03:47:07 +0200709
H. Peter Anvin552bc2c2009-06-23 11:34:42 -0700710 recover = false;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000711 if (mref && bracket) { /* find ] at the end */
712 if (i != ']') {
713 error(ERR_NONFATAL, "parser: expecting ]");
Victor van den Elzen02846d32009-06-23 03:47:07 +0200714 recover = true;
715 } else { /* we got the required ] */
H. Peter Anvine2c80182005-01-15 22:15:51 +0000716 i = stdscan(NULL, &tokval);
Victor van den Elzen02846d32009-06-23 03:47:07 +0200717 if (i != 0 && i != ',') {
718 error(ERR_NONFATAL, "comma or end of line expected");
719 recover = true;
720 }
721 }
H. Peter Anvine2c80182005-01-15 22:15:51 +0000722 } else { /* immediate operand */
723 if (i != 0 && i != ',' && i != ':') {
Victor van den Elzen02846d32009-06-23 03:47:07 +0200724 error(ERR_NONFATAL, "comma, colon or end of line expected");
725 recover = true;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000726 } else if (i == ':') {
727 result->oprs[operand].type |= COLON;
728 }
729 }
Victor van den Elzen02846d32009-06-23 03:47:07 +0200730 if (recover) {
731 do { /* error recovery */
732 i = stdscan(NULL, &tokval);
733 } while (i != 0 && i != ',');
734 }
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000735
H. Peter Anvine2c80182005-01-15 22:15:51 +0000736 /* now convert the exprs returned from evaluate() into operand
737 * descriptions... */
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000738
H. Peter Anvine2c80182005-01-15 22:15:51 +0000739 if (mref) { /* it's a memory reference */
740 expr *e = value;
741 int b, i, s; /* basereg, indexreg, scale */
Keith Kanios7a68f302007-04-16 04:56:06 +0000742 int64_t o; /* offset */
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000743
H. Peter Anvine2c80182005-01-15 22:15:51 +0000744 b = i = -1, o = s = 0;
745 result->oprs[operand].hintbase = hints.base;
746 result->oprs[operand].hinttype = hints.type;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000747
H. Peter Anvine2c80182005-01-15 22:15:51 +0000748 if (e->type && e->type <= EXPR_REG_END) { /* this bit's a register */
749 if (e->value == 1) /* in fact it can be basereg */
750 b = e->type;
751 else /* no, it has to be indexreg */
752 i = e->type, s = e->value;
753 e++;
754 }
755 if (e->type && e->type <= EXPR_REG_END) { /* it's a 2nd register */
756 if (b != -1) /* If the first was the base, ... */
757 i = e->type, s = e->value; /* second has to be indexreg */
H. Peter Anvineba20a72002-04-30 20:53:55 +0000758
H. Peter Anvine2c80182005-01-15 22:15:51 +0000759 else if (e->value != 1) { /* If both want to be index */
760 error(ERR_NONFATAL,
761 "beroset-p-592-invalid effective address");
762 result->opcode = -1;
763 return result;
764 } else
765 b = e->type;
766 e++;
767 }
768 if (e->type != 0) { /* is there an offset? */
769 if (e->type <= EXPR_REG_END) { /* in fact, is there an error? */
770 error(ERR_NONFATAL,
771 "beroset-p-603-invalid effective address");
772 result->opcode = -1;
773 return result;
774 } else {
775 if (e->type == EXPR_UNKNOWN) {
Victor van den Elzen154e5922009-02-25 17:32:00 +0100776 result->oprs[operand].opflags |= OPFLAG_UNKNOWN;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000777 o = 0; /* doesn't matter what */
778 result->oprs[operand].wrt = NO_SEG; /* nor this */
779 result->oprs[operand].segment = NO_SEG; /* or this */
780 while (e->type)
781 e++; /* go to the end of the line */
782 } else {
783 if (e->type == EXPR_SIMPLE) {
784 o = e->value;
785 e++;
786 }
787 if (e->type == EXPR_WRT) {
788 result->oprs[operand].wrt = e->value;
789 e++;
790 } else
791 result->oprs[operand].wrt = NO_SEG;
792 /*
793 * Look for a segment base type.
794 */
795 if (e->type && e->type < EXPR_SEGBASE) {
796 error(ERR_NONFATAL,
797 "beroset-p-630-invalid effective address");
798 result->opcode = -1;
799 return result;
800 }
801 while (e->type && e->value == 0)
802 e++;
803 if (e->type && e->value != 1) {
804 error(ERR_NONFATAL,
805 "beroset-p-637-invalid effective address");
806 result->opcode = -1;
807 return result;
808 }
809 if (e->type) {
810 result->oprs[operand].segment =
811 e->type - EXPR_SEGBASE;
812 e++;
813 } else
814 result->oprs[operand].segment = NO_SEG;
815 while (e->type && e->value == 0)
816 e++;
817 if (e->type) {
818 error(ERR_NONFATAL,
819 "beroset-p-650-invalid effective address");
820 result->opcode = -1;
821 return result;
822 }
823 }
824 }
825 } else {
826 o = 0;
827 result->oprs[operand].wrt = NO_SEG;
828 result->oprs[operand].segment = NO_SEG;
829 }
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000830
H. Peter Anvine2c80182005-01-15 22:15:51 +0000831 if (e->type != 0) { /* there'd better be nothing left! */
832 error(ERR_NONFATAL,
833 "beroset-p-663-invalid effective address");
834 result->opcode = -1;
835 return result;
836 }
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000837
H. Peter Anvin0da6b582007-09-12 20:32:39 -0700838 /* It is memory, but it can match any r/m operand */
839 result->oprs[operand].type |= MEMORY_ANY;
H. Peter Anvin99c4ecd2007-08-28 23:06:00 +0000840
841 if (b == -1 && (i == -1 || s == 0)) {
842 int is_rel = globalbits == 64 &&
843 !(result->oprs[operand].eaflags & EAF_ABS) &&
844 ((globalrel &&
H. Peter Anvin150e20d2007-08-29 15:19:19 +0000845 !(result->oprs[operand].eaflags & EAF_FSGS)) ||
H. Peter Anvin99c4ecd2007-08-28 23:06:00 +0000846 (result->oprs[operand].eaflags & EAF_REL));
847
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700848 result->oprs[operand].type |= is_rel ? IP_REL : MEM_OFFS;
H. Peter Anvin99c4ecd2007-08-28 23:06:00 +0000849 }
H. Peter Anvine2c80182005-01-15 22:15:51 +0000850 result->oprs[operand].basereg = b;
851 result->oprs[operand].indexreg = i;
852 result->oprs[operand].scale = s;
853 result->oprs[operand].offset = o;
854 } else { /* it's not a memory reference */
H. Peter Anvine2c80182005-01-15 22:15:51 +0000855 if (is_just_unknown(value)) { /* it's immediate but unknown */
856 result->oprs[operand].type |= IMMEDIATE;
Victor van den Elzen154e5922009-02-25 17:32:00 +0100857 result->oprs[operand].opflags |= OPFLAG_UNKNOWN;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000858 result->oprs[operand].offset = 0; /* don't care */
859 result->oprs[operand].segment = NO_SEG; /* don't care again */
860 result->oprs[operand].wrt = NO_SEG; /* still don't care */
Victor van den Elzen154e5922009-02-25 17:32:00 +0100861
862 if(optimizing >= 0 && !(result->oprs[operand].type & STRICT))
863 {
864 /* Be optimistic */
865 result->oprs[operand].type |= SBYTE16 | SBYTE32 | SBYTE64;
866 }
H. Peter Anvine2c80182005-01-15 22:15:51 +0000867 } else if (is_reloc(value)) { /* it's immediate */
868 result->oprs[operand].type |= IMMEDIATE;
869 result->oprs[operand].offset = reloc_value(value);
870 result->oprs[operand].segment = reloc_seg(value);
871 result->oprs[operand].wrt = reloc_wrt(value);
872 if (is_simple(value)) {
873 if (reloc_value(value) == 1)
874 result->oprs[operand].type |= UNITY;
875 if (optimizing >= 0 &&
876 !(result->oprs[operand].type & STRICT)) {
H. Peter Anvin32cd4c22008-04-04 13:34:53 -0700877 int64_t v64 = reloc_value(value);
878 int32_t v32 = (int32_t)v64;
879 int16_t v16 = (int16_t)v32;
880
881 if (v64 >= -128 && v64 <= 127)
882 result->oprs[operand].type |= SBYTE64;
883 if (v32 >= -128 && v32 <= 127)
884 result->oprs[operand].type |= SBYTE32;
885 if (v16 >= -128 && v16 <= 127)
886 result->oprs[operand].type |= SBYTE16;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000887 }
888 }
889 } else { /* it's a register */
H. Peter Anvin68222142007-11-18 22:18:09 -0800890 unsigned int rs;
H. Peter Anvineba20a72002-04-30 20:53:55 +0000891
H. Peter Anvine2c80182005-01-15 22:15:51 +0000892 if (value->type >= EXPR_SIMPLE || value->value != 1) {
893 error(ERR_NONFATAL, "invalid operand type");
894 result->opcode = -1;
895 return result;
896 }
H. Peter Anvineba20a72002-04-30 20:53:55 +0000897
H. Peter Anvine2c80182005-01-15 22:15:51 +0000898 /*
899 * check that its only 1 register, not an expression...
900 */
901 for (i = 1; value[i].type; i++)
902 if (value[i].value) {
903 error(ERR_NONFATAL, "invalid operand type");
904 result->opcode = -1;
905 return result;
906 }
H. Peter Anvineba20a72002-04-30 20:53:55 +0000907
H. Peter Anvine2c80182005-01-15 22:15:51 +0000908 /* clear overrides, except TO which applies to FPU regs */
909 if (result->oprs[operand].type & ~TO) {
910 /*
911 * we want to produce a warning iff the specified size
912 * is different from the register size
913 */
H. Peter Anvin68222142007-11-18 22:18:09 -0800914 rs = result->oprs[operand].type & SIZE_MASK;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000915 } else
H. Peter Anvin68222142007-11-18 22:18:09 -0800916 rs = 0;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000917
918 result->oprs[operand].type &= TO;
919 result->oprs[operand].type |= REGISTER;
H. Peter Anvina4835d42008-05-20 14:21:29 -0700920 result->oprs[operand].type |= nasm_reg_flags[value->type];
H. Peter Anvine2c80182005-01-15 22:15:51 +0000921 result->oprs[operand].basereg = value->type;
922
H. Peter Anvin68222142007-11-18 22:18:09 -0800923 if (rs && (result->oprs[operand].type & SIZE_MASK) != rs)
H. Peter Anvine2c80182005-01-15 22:15:51 +0000924 error(ERR_WARNING | ERR_PASS1,
925 "register size specification ignored");
926 }
927 }
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000928 }
929
H. Peter Anvine2c80182005-01-15 22:15:51 +0000930 result->operands = operand; /* set operand count */
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000931
H. Peter Anvinde4b89b2007-10-01 15:41:25 -0700932/* clear remaining operands */
933while (operand < MAX_OPERANDS)
934 result->oprs[operand++].type = 0;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000935
936 /*
H. Peter Anvindfb91802008-05-20 11:43:53 -0700937 * Transform RESW, RESD, RESQ, REST, RESO, RESY into RESB.
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000938 */
939 switch (result->opcode) {
H. Peter Anvine2c80182005-01-15 22:15:51 +0000940 case I_RESW:
941 result->opcode = I_RESB;
942 result->oprs[0].offset *= 2;
943 break;
944 case I_RESD:
945 result->opcode = I_RESB;
946 result->oprs[0].offset *= 4;
947 break;
948 case I_RESQ:
949 result->opcode = I_RESB;
950 result->oprs[0].offset *= 8;
951 break;
952 case I_REST:
953 result->opcode = I_RESB;
954 result->oprs[0].offset *= 10;
955 break;
H. Peter Anvin41c9f6f2007-09-18 13:01:32 -0700956 case I_RESO:
957 result->opcode = I_RESB;
958 result->oprs[0].offset *= 16;
959 break;
H. Peter Anvindfb91802008-05-20 11:43:53 -0700960 case I_RESY:
961 result->opcode = I_RESB;
962 result->oprs[0].offset *= 32;
963 break;
H. Peter Anvin16b0a332007-09-12 20:27:41 -0700964 default:
965 break;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000966 }
967
968 return result;
969}
970
H. Peter Anvine2c80182005-01-15 22:15:51 +0000971static int is_comma_next(void)
H. Peter Anvineba20a72002-04-30 20:53:55 +0000972{
Keith Kaniosa6dfa782007-04-13 16:47:53 +0000973 char *p;
H. Peter Anvin76690a12002-04-30 20:52:49 +0000974 int i;
975 struct tokenval tv;
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000976
H. Peter Anvin76690a12002-04-30 20:52:49 +0000977 p = stdscan_bufptr;
H. Peter Anvine2c80182005-01-15 22:15:51 +0000978 i = stdscan(NULL, &tv);
H. Peter Anvin76690a12002-04-30 20:52:49 +0000979 stdscan_bufptr = p;
980 return (i == ',' || i == ';' || !i);
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000981}
982
H. Peter Anvine2c80182005-01-15 22:15:51 +0000983void cleanup_insn(insn * i)
H. Peter Anvineba20a72002-04-30 20:53:55 +0000984{
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000985 extop *e;
986
H. Peter Anvin2aa77392008-06-15 17:39:45 -0700987 while ((e = i->eops)) {
988 i->eops = e->next;
989 if (e->type == EOT_DB_STRING_FREE)
990 nasm_free(e->stringval);
H. Peter Anvine2c80182005-01-15 22:15:51 +0000991 nasm_free(e);
H. Peter Anvinea6e34d2002-04-30 20:51:32 +0000992 }
993}