tokens.dat: Data file containing alphanumeric tokens not in other .dats
[nasm.git] / parser.c
blobe90f35d5be65be63324d606d995d749599fe9915
1 /* parser.c source line parser for the Netwide Assembler
3 * The Netwide Assembler is copyright (C) 1996 Simon Tatham and
4 * Julian Hall. All rights reserved. The software is
5 * redistributable under the licence given in the file "Licence"
6 * distributed in the NASM archive.
8 * initial version 27/iii/95 by Simon Tatham
9 */
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <stddef.h>
14 #include <string.h>
15 #include <ctype.h>
16 #include <inttypes.h>
18 #include "nasm.h"
19 #include "insns.h"
20 #include "nasmlib.h"
21 #include "parser.h"
22 #include "float.h"
24 extern int in_abs_seg; /* ABSOLUTE segment flag */
25 extern int32_t abs_seg; /* ABSOLUTE segment */
26 extern int32_t abs_offset; /* ABSOLUTE segment offset */
28 #include "regflags.c" /* List of register flags */
30 static int is_comma_next(void);
32 static int i;
33 static struct tokenval tokval;
34 static efunc error;
35 static struct ofmt *outfmt; /* Structure of addresses of output routines */
36 static loc_t *location; /* Pointer to current line's segment,offset */
38 void parser_global_info(struct ofmt *output, loc_t * locp)
40 outfmt = output;
41 location = locp;
44 insn *parse_line(int pass, char *buffer, insn * result,
45 efunc errfunc, evalfunc evaluate, ldfunc ldef)
47 int operand;
48 int critical;
49 struct eval_hints hints;
51 result->forw_ref = FALSE;
52 error = errfunc;
54 stdscan_reset();
55 stdscan_bufptr = buffer;
56 i = stdscan(NULL, &tokval);
58 result->label = NULL; /* Assume no label */
59 result->eops = NULL; /* must do this, whatever happens */
60 result->operands = 0; /* must initialize this */
62 if (i == 0) { /* blank line - ignore */
63 result->opcode = -1; /* and no instruction either */
64 return result;
66 if (i != TOKEN_ID && i != TOKEN_INSN && i != TOKEN_PREFIX &&
67 (i != TOKEN_REG || (REG_SREG & ~reg_flags[tokval.t_integer]))) {
68 error(ERR_NONFATAL, "label or instruction expected"
69 " at start of line");
70 result->opcode = -1;
71 return result;
74 if (i == TOKEN_ID) { /* there's a label here */
75 result->label = tokval.t_charptr;
76 i = stdscan(NULL, &tokval);
77 if (i == ':') { /* skip over the optional colon */
78 i = stdscan(NULL, &tokval);
79 } else if (i == 0) {
80 error(ERR_WARNING | ERR_WARN_OL | ERR_PASS1,
81 "label alone on a line without a colon might be in error");
83 if (i != TOKEN_INSN || tokval.t_integer != I_EQU) {
85 * FIXME: location->segment could be NO_SEG, in which case
86 * it is possible we should be passing 'abs_seg'. Look into this.
87 * Work out whether that is *really* what we should be doing.
88 * Generally fix things. I think this is right as it is, but
89 * am still not certain.
91 ldef(result->label, in_abs_seg ? abs_seg : location->segment,
92 location->offset, NULL, TRUE, FALSE, outfmt, errfunc);
96 if (i == 0) {
97 result->opcode = -1; /* this line contains just a label */
98 return result;
101 result->nprefix = 0;
102 result->times = 1L;
104 while (i == TOKEN_PREFIX ||
105 (i == TOKEN_REG && !(REG_SREG & ~reg_flags[tokval.t_integer])))
108 * Handle special case: the TIMES prefix.
110 if (i == TOKEN_PREFIX && tokval.t_integer == P_TIMES) {
111 expr *value;
113 i = stdscan(NULL, &tokval);
114 value =
115 evaluate(stdscan, NULL, &tokval, NULL, pass0, error, NULL);
116 i = tokval.t_type;
117 if (!value) { /* but, error in evaluator */
118 result->opcode = -1; /* unrecoverable parse error: */
119 return result; /* ignore this instruction */
121 if (!is_simple(value)) {
122 error(ERR_NONFATAL,
123 "non-constant argument supplied to TIMES");
124 result->times = 1L;
125 } else {
126 result->times = value->value;
127 if (value->value < 0) {
128 error(ERR_NONFATAL, "TIMES value %d is negative",
129 value->value);
130 result->times = 0;
133 } else {
134 if (result->nprefix == MAXPREFIX)
135 error(ERR_NONFATAL,
136 "instruction has more than %d prefixes", MAXPREFIX);
137 else
138 result->prefixes[result->nprefix++] = tokval.t_integer;
139 i = stdscan(NULL, &tokval);
143 if (i != TOKEN_INSN) {
144 if (result->nprefix > 0 && i == 0) {
146 * Instruction prefixes are present, but no actual
147 * instruction. This is allowed: at this point we
148 * invent a notional instruction of RESB 0.
150 result->opcode = I_RESB;
151 result->operands = 1;
152 result->oprs[0].type = IMMEDIATE;
153 result->oprs[0].offset = 0L;
154 result->oprs[0].segment = result->oprs[0].wrt = NO_SEG;
155 return result;
156 } else {
157 error(ERR_NONFATAL, "parser: instruction expected");
158 result->opcode = -1;
159 return result;
163 result->opcode = tokval.t_integer;
164 result->condition = tokval.t_inttwo;
167 * RESB, RESW and RESD cannot be satisfied with incorrectly
168 * evaluated operands, since the correct values _must_ be known
169 * on the first pass. Hence, even in pass one, we set the
170 * `critical' flag on calling evaluate(), so that it will bomb
171 * out on undefined symbols. Nasty, but there's nothing we can
172 * do about it.
174 * For the moment, EQU has the same difficulty, so we'll
175 * include that.
177 if (result->opcode == I_RESB || result->opcode == I_RESW || result->opcode == I_RESD || result->opcode == I_RESQ || result->opcode == I_REST || result->opcode == I_EQU || result->opcode == I_INCBIN) { /* fbk */
178 critical = pass0;
179 } else
180 critical = (pass == 2 ? 2 : 0);
182 if (result->opcode == I_DB ||
183 result->opcode == I_DW ||
184 result->opcode == I_DD ||
185 result->opcode == I_DQ ||
186 result->opcode == I_DT || result->opcode == I_INCBIN) {
187 extop *eop, **tail = &result->eops, **fixptr;
188 int oper_num = 0;
190 result->eops_float = FALSE;
193 * Begin to read the DB/DW/DD/DQ/DT/INCBIN operands.
195 while (1) {
196 i = stdscan(NULL, &tokval);
197 if (i == 0)
198 break;
199 fixptr = tail;
200 eop = *tail = nasm_malloc(sizeof(extop));
201 tail = &eop->next;
202 eop->next = NULL;
203 eop->type = EOT_NOTHING;
204 oper_num++;
206 if (i == TOKEN_NUM && tokval.t_charptr && is_comma_next()) {
207 eop->type = EOT_DB_STRING;
208 eop->stringval = tokval.t_charptr;
209 eop->stringlen = tokval.t_inttwo;
210 i = stdscan(NULL, &tokval); /* eat the comma */
211 continue;
214 if ((i == TOKEN_FLOAT && is_comma_next()) || i == '-') {
215 int32_t sign = +1L;
217 if (i == '-') {
218 char *save = stdscan_bufptr;
219 i = stdscan(NULL, &tokval);
220 sign = -1L;
221 if (i != TOKEN_FLOAT || !is_comma_next()) {
222 stdscan_bufptr = save;
223 i = tokval.t_type = '-';
227 if (i == TOKEN_FLOAT) {
228 eop->type = EOT_DB_STRING;
229 result->eops_float = TRUE;
230 if (result->opcode == I_DD)
231 eop->stringlen = 4;
232 else if (result->opcode == I_DQ)
233 eop->stringlen = 8;
234 else if (result->opcode == I_DT)
235 eop->stringlen = 10;
236 else {
237 error(ERR_NONFATAL, "floating-point constant"
238 " encountered in `D%c' instruction",
239 result->opcode == I_DW ? 'W' : 'B');
241 * fix suggested by Pedro Gimeno... original line
242 * was:
243 * eop->type = EOT_NOTHING;
245 eop->stringlen = 0;
247 eop =
248 nasm_realloc(eop, sizeof(extop) + eop->stringlen);
249 tail = &eop->next;
250 *fixptr = eop;
251 eop->stringval = (char *)eop + sizeof(extop);
252 if (eop->stringlen < 4 ||
253 !float_const(tokval.t_charptr, sign,
254 (uint8_t *)eop->stringval,
255 eop->stringlen, error))
256 eop->type = EOT_NOTHING;
257 i = stdscan(NULL, &tokval); /* eat the comma */
258 continue;
262 /* anything else */
264 expr *value;
265 value = evaluate(stdscan, NULL, &tokval, NULL,
266 critical, error, NULL);
267 i = tokval.t_type;
268 if (!value) { /* error in evaluator */
269 result->opcode = -1; /* unrecoverable parse error: */
270 return result; /* ignore this instruction */
272 if (is_unknown(value)) {
273 eop->type = EOT_DB_NUMBER;
274 eop->offset = 0; /* doesn't matter what we put */
275 eop->segment = eop->wrt = NO_SEG; /* likewise */
276 } else if (is_reloc(value)) {
277 eop->type = EOT_DB_NUMBER;
278 eop->offset = reloc_value(value);
279 eop->segment = reloc_seg(value);
280 eop->wrt = reloc_wrt(value);
281 } else {
282 error(ERR_NONFATAL,
283 "operand %d: expression is not simple"
284 " or relocatable", oper_num);
289 * We're about to call stdscan(), which will eat the
290 * comma that we're currently sitting on between
291 * arguments. However, we'd better check first that it
292 * _is_ a comma.
294 if (i == 0) /* also could be EOL */
295 break;
296 if (i != ',') {
297 error(ERR_NONFATAL, "comma expected after operand %d",
298 oper_num);
299 result->opcode = -1; /* unrecoverable parse error: */
300 return result; /* ignore this instruction */
304 if (result->opcode == I_INCBIN) {
306 * Correct syntax for INCBIN is that there should be
307 * one string operand, followed by one or two numeric
308 * operands.
310 if (!result->eops || result->eops->type != EOT_DB_STRING)
311 error(ERR_NONFATAL, "`incbin' expects a file name");
312 else if (result->eops->next &&
313 result->eops->next->type != EOT_DB_NUMBER)
314 error(ERR_NONFATAL, "`incbin': second parameter is",
315 " non-numeric");
316 else if (result->eops->next && result->eops->next->next &&
317 result->eops->next->next->type != EOT_DB_NUMBER)
318 error(ERR_NONFATAL, "`incbin': third parameter is",
319 " non-numeric");
320 else if (result->eops->next && result->eops->next->next &&
321 result->eops->next->next->next)
322 error(ERR_NONFATAL,
323 "`incbin': more than three parameters");
324 else
325 return result;
327 * If we reach here, one of the above errors happened.
328 * Throw the instruction away.
330 result->opcode = -1;
331 return result;
332 } else /* DB ... */ if (oper_num == 0)
333 error(ERR_WARNING | ERR_PASS1,
334 "no operand for data declaration");
335 else
336 result->operands = oper_num;
338 return result;
341 /* right. Now we begin to parse the operands. There may be up to three
342 * of these, separated by commas, and terminated by a zero token. */
344 for (operand = 0; operand < 3; operand++) {
345 expr *value; /* used most of the time */
346 int mref; /* is this going to be a memory ref? */
347 int bracket; /* is it a [] mref, or a & mref? */
348 int setsize = 0;
350 result->oprs[operand].addr_size = 0; /* have to zero this whatever */
351 result->oprs[operand].eaflags = 0; /* and this */
352 result->oprs[operand].opflags = 0;
354 i = stdscan(NULL, &tokval);
355 if (i == 0)
356 break; /* end of operands: get out of here */
357 result->oprs[operand].type = 0; /* so far, no override */
358 while (i == TOKEN_SPECIAL) { /* size specifiers */
359 switch ((int)tokval.t_integer) {
360 case S_BYTE:
361 if (!setsize) /* we want to use only the first */
362 result->oprs[operand].type |= BITS8;
363 setsize = 1;
364 break;
365 case S_WORD:
366 if (!setsize)
367 result->oprs[operand].type |= BITS16;
368 setsize = 1;
369 break;
370 case S_DWORD:
371 case S_LONG:
372 if (!setsize)
373 result->oprs[operand].type |= BITS32;
374 setsize = 1;
375 break;
376 case S_QWORD:
377 if (!setsize)
378 result->oprs[operand].type |= BITS64;
379 setsize = 1;
380 break;
381 case S_TWORD:
382 if (!setsize)
383 result->oprs[operand].type |= BITS80;
384 setsize = 1;
385 break;
386 case S_TO:
387 result->oprs[operand].type |= TO;
388 break;
389 case S_STRICT:
390 result->oprs[operand].type |= STRICT;
391 break;
392 case S_FAR:
393 result->oprs[operand].type |= FAR;
394 break;
395 case S_NEAR:
396 result->oprs[operand].type |= NEAR;
397 break;
398 case S_SHORT:
399 result->oprs[operand].type |= SHORT;
400 break;
401 default:
402 error(ERR_NONFATAL, "invalid operand size specification");
404 i = stdscan(NULL, &tokval);
407 if (i == '[' || i == '&') { /* memory reference */
408 mref = TRUE;
409 bracket = (i == '[');
410 while ((i = stdscan(NULL, &tokval)) == TOKEN_SPECIAL) {
411 /* check for address directives */
412 if (tasm_compatible_mode) {
413 switch ((int)tokval.t_integer) {
414 /* For TASM compatibility a size override inside the
415 * brackets changes the size of the operand, not the
416 * address type of the operand as it does in standard
417 * NASM syntax. Hence:
419 * mov eax,[DWORD val]
421 * is valid syntax in TASM compatibility mode. Note that
422 * you lose the ability to override the default address
423 * type for the instruction, but we never use anything
424 * but 32-bit flat model addressing in our code.
426 case S_BYTE:
427 result->oprs[operand].type |= BITS8;
428 break;
429 case S_WORD:
430 result->oprs[operand].type |= BITS16;
431 break;
432 case S_DWORD:
433 case S_LONG:
434 result->oprs[operand].type |= BITS32;
435 break;
436 case S_QWORD:
437 result->oprs[operand].type |= BITS64;
438 break;
439 case S_TWORD:
440 result->oprs[operand].type |= BITS80;
441 break;
442 default:
443 error(ERR_NONFATAL,
444 "invalid operand size specification");
446 } else {
447 /* Standard NASM compatible syntax */
448 switch ((int)tokval.t_integer) {
449 case S_NOSPLIT:
450 result->oprs[operand].eaflags |= EAF_TIMESTWO;
451 break;
452 case S_REL:
453 result->oprs[operand].eaflags |= EAF_REL;
454 break;
455 case S_ABS:
456 result->oprs[operand].eaflags |= EAF_ABS;
457 break;
458 case S_BYTE:
459 result->oprs[operand].eaflags |= EAF_BYTEOFFS;
460 break;
461 case S_WORD:
462 result->oprs[operand].addr_size = 16;
463 result->oprs[operand].eaflags |= EAF_WORDOFFS;
464 break;
465 case S_DWORD:
466 case S_LONG:
467 result->oprs[operand].addr_size = 32;
468 result->oprs[operand].eaflags |= EAF_WORDOFFS;
469 break;
470 case S_QWORD:
471 result->oprs[operand].addr_size = 64;
472 result->oprs[operand].eaflags |= EAF_WORDOFFS;
473 break;
474 default:
475 error(ERR_NONFATAL, "invalid size specification in"
476 " effective address");
480 } else { /* immediate operand, or register */
481 mref = FALSE;
482 bracket = FALSE; /* placate optimisers */
485 if ((result->oprs[operand].type & FAR) && !mref &&
486 result->opcode != I_JMP && result->opcode != I_CALL) {
487 error(ERR_NONFATAL, "invalid use of FAR operand specifier");
490 value = evaluate(stdscan, NULL, &tokval,
491 &result->oprs[operand].opflags,
492 critical, error, &hints);
493 i = tokval.t_type;
494 if (result->oprs[operand].opflags & OPFLAG_FORWARD) {
495 result->forw_ref = TRUE;
497 if (!value) { /* error in evaluator */
498 result->opcode = -1; /* unrecoverable parse error: */
499 return result; /* ignore this instruction */
501 if (i == ':' && mref) { /* it was seg:offset */
503 * Process the segment override.
505 if (value[1].type != 0 || value->value != 1 ||
506 REG_SREG & ~reg_flags[value->type])
507 error(ERR_NONFATAL, "invalid segment override");
508 else if (result->nprefix == MAXPREFIX)
509 error(ERR_NONFATAL,
510 "instruction has more than %d prefixes", MAXPREFIX);
511 else {
512 result->prefixes[result->nprefix++] = value->type;
513 if (!(REG_FSGS & ~reg_flags[value->type]))
514 result->oprs[operand].eaflags |= EAF_FSGS;
517 i = stdscan(NULL, &tokval); /* then skip the colon */
518 if (i == TOKEN_SPECIAL) { /* another check for size override */
519 switch ((int)tokval.t_integer) {
520 case S_WORD:
521 result->oprs[operand].addr_size = 16;
522 break;
523 case S_DWORD:
524 case S_LONG:
525 result->oprs[operand].addr_size = 32;
526 break;
527 case S_QWORD:
528 result->oprs[operand].addr_size = 64;
529 break;
530 default:
531 error(ERR_NONFATAL, "invalid size specification in"
532 " effective address");
534 i = stdscan(NULL, &tokval);
536 value = evaluate(stdscan, NULL, &tokval,
537 &result->oprs[operand].opflags,
538 critical, error, &hints);
539 i = tokval.t_type;
540 if (result->oprs[operand].opflags & OPFLAG_FORWARD) {
541 result->forw_ref = TRUE;
543 /* and get the offset */
544 if (!value) { /* but, error in evaluator */
545 result->opcode = -1; /* unrecoverable parse error: */
546 return result; /* ignore this instruction */
549 if (mref && bracket) { /* find ] at the end */
550 if (i != ']') {
551 error(ERR_NONFATAL, "parser: expecting ]");
552 do { /* error recovery again */
553 i = stdscan(NULL, &tokval);
554 } while (i != 0 && i != ',');
555 } else /* we got the required ] */
556 i = stdscan(NULL, &tokval);
557 } else { /* immediate operand */
558 if (i != 0 && i != ',' && i != ':') {
559 error(ERR_NONFATAL, "comma or end of line expected");
560 do { /* error recovery */
561 i = stdscan(NULL, &tokval);
562 } while (i != 0 && i != ',');
563 } else if (i == ':') {
564 result->oprs[operand].type |= COLON;
568 /* now convert the exprs returned from evaluate() into operand
569 * descriptions... */
571 if (mref) { /* it's a memory reference */
572 expr *e = value;
573 int b, i, s; /* basereg, indexreg, scale */
574 int64_t o; /* offset */
576 b = i = -1, o = s = 0;
577 result->oprs[operand].hintbase = hints.base;
578 result->oprs[operand].hinttype = hints.type;
580 if (e->type && e->type <= EXPR_REG_END) { /* this bit's a register */
581 if (e->value == 1) /* in fact it can be basereg */
582 b = e->type;
583 else /* no, it has to be indexreg */
584 i = e->type, s = e->value;
585 e++;
587 if (e->type && e->type <= EXPR_REG_END) { /* it's a 2nd register */
588 if (b != -1) /* If the first was the base, ... */
589 i = e->type, s = e->value; /* second has to be indexreg */
591 else if (e->value != 1) { /* If both want to be index */
592 error(ERR_NONFATAL,
593 "beroset-p-592-invalid effective address");
594 result->opcode = -1;
595 return result;
596 } else
597 b = e->type;
598 e++;
600 if (e->type != 0) { /* is there an offset? */
601 if (e->type <= EXPR_REG_END) { /* in fact, is there an error? */
602 error(ERR_NONFATAL,
603 "beroset-p-603-invalid effective address");
604 result->opcode = -1;
605 return result;
606 } else {
607 if (e->type == EXPR_UNKNOWN) {
608 o = 0; /* doesn't matter what */
609 result->oprs[operand].wrt = NO_SEG; /* nor this */
610 result->oprs[operand].segment = NO_SEG; /* or this */
611 while (e->type)
612 e++; /* go to the end of the line */
613 } else {
614 if (e->type == EXPR_SIMPLE) {
615 o = e->value;
616 e++;
618 if (e->type == EXPR_WRT) {
619 result->oprs[operand].wrt = e->value;
620 e++;
621 } else
622 result->oprs[operand].wrt = NO_SEG;
624 * Look for a segment base type.
626 if (e->type && e->type < EXPR_SEGBASE) {
627 error(ERR_NONFATAL,
628 "beroset-p-630-invalid effective address");
629 result->opcode = -1;
630 return result;
632 while (e->type && e->value == 0)
633 e++;
634 if (e->type && e->value != 1) {
635 error(ERR_NONFATAL,
636 "beroset-p-637-invalid effective address");
637 result->opcode = -1;
638 return result;
640 if (e->type) {
641 result->oprs[operand].segment =
642 e->type - EXPR_SEGBASE;
643 e++;
644 } else
645 result->oprs[operand].segment = NO_SEG;
646 while (e->type && e->value == 0)
647 e++;
648 if (e->type) {
649 error(ERR_NONFATAL,
650 "beroset-p-650-invalid effective address");
651 result->opcode = -1;
652 return result;
656 } else {
657 o = 0;
658 result->oprs[operand].wrt = NO_SEG;
659 result->oprs[operand].segment = NO_SEG;
662 if (e->type != 0) { /* there'd better be nothing left! */
663 error(ERR_NONFATAL,
664 "beroset-p-663-invalid effective address");
665 result->opcode = -1;
666 return result;
669 result->oprs[operand].type |= MEMORY;
671 if (b == -1 && (i == -1 || s == 0)) {
672 int is_rel = globalbits == 64 &&
673 !(result->oprs[operand].eaflags & EAF_ABS) &&
674 ((globalrel &&
675 !(result->oprs[operand].eaflags & EAF_FSGS)) ||
676 (result->oprs[operand].eaflags & EAF_REL));
678 result->oprs[operand].type |= is_rel ? IP_REL : MEM_OFFS;
680 result->oprs[operand].basereg = b;
681 result->oprs[operand].indexreg = i;
682 result->oprs[operand].scale = s;
683 result->oprs[operand].offset = o;
684 } else { /* it's not a memory reference */
686 if (is_just_unknown(value)) { /* it's immediate but unknown */
687 result->oprs[operand].type |= IMMEDIATE;
688 result->oprs[operand].offset = 0; /* don't care */
689 result->oprs[operand].segment = NO_SEG; /* don't care again */
690 result->oprs[operand].wrt = NO_SEG; /* still don't care */
691 } else if (is_reloc(value)) { /* it's immediate */
692 result->oprs[operand].type |= IMMEDIATE;
693 result->oprs[operand].offset = reloc_value(value);
694 result->oprs[operand].segment = reloc_seg(value);
695 result->oprs[operand].wrt = reloc_wrt(value);
696 if (is_simple(value)) {
697 if (reloc_value(value) == 1)
698 result->oprs[operand].type |= UNITY;
699 if (optimizing >= 0 &&
700 !(result->oprs[operand].type & STRICT)) {
701 if (reloc_value(value) >= -128 &&
702 reloc_value(value) <= 127)
703 result->oprs[operand].type |= SBYTE;
706 } else { /* it's a register */
708 if (value->type >= EXPR_SIMPLE || value->value != 1) {
709 error(ERR_NONFATAL, "invalid operand type");
710 result->opcode = -1;
711 return result;
715 * check that its only 1 register, not an expression...
717 for (i = 1; value[i].type; i++)
718 if (value[i].value) {
719 error(ERR_NONFATAL, "invalid operand type");
720 result->opcode = -1;
721 return result;
724 /* clear overrides, except TO which applies to FPU regs */
725 if (result->oprs[operand].type & ~TO) {
727 * we want to produce a warning iff the specified size
728 * is different from the register size
730 i = result->oprs[operand].type & SIZE_MASK;
731 } else
732 i = 0;
734 result->oprs[operand].type &= TO;
735 result->oprs[operand].type |= REGISTER;
736 result->oprs[operand].type |= reg_flags[value->type];
737 result->oprs[operand].basereg = value->type;
739 if (i && (result->oprs[operand].type & SIZE_MASK) != i)
740 error(ERR_WARNING | ERR_PASS1,
741 "register size specification ignored");
746 result->operands = operand; /* set operand count */
748 while (operand < 3) /* clear remaining operands */
749 result->oprs[operand++].type = 0;
752 * Transform RESW, RESD, RESQ, REST into RESB.
754 switch (result->opcode) {
755 case I_RESW:
756 result->opcode = I_RESB;
757 result->oprs[0].offset *= 2;
758 break;
759 case I_RESD:
760 result->opcode = I_RESB;
761 result->oprs[0].offset *= 4;
762 break;
763 case I_RESQ:
764 result->opcode = I_RESB;
765 result->oprs[0].offset *= 8;
766 break;
767 case I_REST:
768 result->opcode = I_RESB;
769 result->oprs[0].offset *= 10;
770 break;
773 return result;
776 static int is_comma_next(void)
778 char *p;
779 int i;
780 struct tokenval tv;
782 p = stdscan_bufptr;
783 i = stdscan(NULL, &tv);
784 stdscan_bufptr = p;
785 return (i == ',' || i == ';' || !i);
788 void cleanup_insn(insn * i)
790 extop *e;
792 while (i->eops) {
793 e = i->eops;
794 i->eops = i->eops->next;
795 nasm_free(e);