1 /* ----------------------------------------------------------------------- *
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.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation, Inc.,
10 * 51 Franklin St, Fifth Floor, Boston MA 02110-1301, USA; version 2.1,
11 * or, at your option, any later version, incorporated herein by
14 * Patches submitted to this file are required to be dual licensed
15 * under the LGPL 2.1+ and the 2-clause BSD license:
17 * Copyright 1996-2009 the NASM Authors - All rights reserved.
19 * Redistribution and use in source and binary forms, with or without
20 * modification, are permitted provided that the following
23 * * Redistributions of source code must retain the above copyright
24 * notice, this list of conditions and the following disclaimer.
25 * * Redistributions in binary form must reproduce the above
26 * copyright notice, this list of conditions and the following
27 * disclaimer in the documentation and/or other materials provided
28 * with the distribution.
30 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
31 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
32 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
33 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
34 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
35 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
36 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
37 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
38 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
40 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
41 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
42 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44 * ----------------------------------------------------------------------- */
47 * parser.c source line parser for the Netwide Assembler
67 extern int in_abs_seg
; /* ABSOLUTE segment flag */
68 extern int32_t abs_seg
; /* ABSOLUTE segment */
69 extern int32_t abs_offset
; /* ABSOLUTE segment offset */
71 static int is_comma_next(void);
74 static struct tokenval tokval
;
76 static struct ofmt
*outfmt
; /* Structure of addresses of output routines */
77 static struct location
*location
; /* Pointer to current line's segment,offset */
79 void parser_global_info(struct ofmt
*output
, struct location
* locp
)
85 static int prefix_slot(enum prefixes prefix
)
115 error(ERR_PANIC
, "Invalid value %d passed to prefix_slot()", prefix
);
120 static void process_size_override(insn
* result
, int operand
)
122 if (tasm_compatible_mode
) {
123 switch ((int)tokval
.t_integer
) {
124 /* For TASM compatibility a size override inside the
125 * brackets changes the size of the operand, not the
126 * address type of the operand as it does in standard
127 * NASM syntax. Hence:
129 * mov eax,[DWORD val]
131 * is valid syntax in TASM compatibility mode. Note that
132 * you lose the ability to override the default address
133 * type for the instruction, but we never use anything
134 * but 32-bit flat model addressing in our code.
137 result
->oprs
[operand
].type
|= BITS8
;
140 result
->oprs
[operand
].type
|= BITS16
;
144 result
->oprs
[operand
].type
|= BITS32
;
147 result
->oprs
[operand
].type
|= BITS64
;
150 result
->oprs
[operand
].type
|= BITS80
;
153 result
->oprs
[operand
].type
|= BITS128
;
157 "invalid operand size specification");
161 /* Standard NASM compatible syntax */
162 switch ((int)tokval
.t_integer
) {
164 result
->oprs
[operand
].eaflags
|= EAF_TIMESTWO
;
167 result
->oprs
[operand
].eaflags
|= EAF_REL
;
170 result
->oprs
[operand
].eaflags
|= EAF_ABS
;
173 result
->oprs
[operand
].disp_size
= 8;
174 result
->oprs
[operand
].eaflags
|= EAF_BYTEOFFS
;
179 if (result
->prefixes
[PPS_ASIZE
] &&
180 result
->prefixes
[PPS_ASIZE
] != tokval
.t_integer
)
182 "conflicting address size specifications");
184 result
->prefixes
[PPS_ASIZE
] = tokval
.t_integer
;
187 result
->oprs
[operand
].disp_size
= 16;
188 result
->oprs
[operand
].eaflags
|= EAF_WORDOFFS
;
192 result
->oprs
[operand
].disp_size
= 32;
193 result
->oprs
[operand
].eaflags
|= EAF_WORDOFFS
;
196 result
->oprs
[operand
].disp_size
= 64;
197 result
->oprs
[operand
].eaflags
|= EAF_WORDOFFS
;
200 error(ERR_NONFATAL
, "invalid size specification in"
201 " effective address");
207 insn
*parse_line(int pass
, char *buffer
, insn
* result
,
208 efunc errfunc
, evalfunc evaluate
, ldfunc ldef
)
212 struct eval_hints hints
;
215 bool insn_is_label
= false;
220 result
->forw_ref
= false;
224 stdscan_bufptr
= buffer
;
225 i
= stdscan(NULL
, &tokval
);
227 result
->label
= NULL
; /* Assume no label */
228 result
->eops
= NULL
; /* must do this, whatever happens */
229 result
->operands
= 0; /* must initialize this */
231 if (i
== 0) { /* blank line - ignore */
232 result
->opcode
= -1; /* and no instruction either */
235 if (i
!= TOKEN_ID
&& i
!= TOKEN_INSN
&& i
!= TOKEN_PREFIX
&&
236 (i
!= TOKEN_REG
|| (REG_SREG
& ~nasm_reg_flags
[tokval
.t_integer
]))) {
237 error(ERR_NONFATAL
, "label or instruction expected"
238 " at start of line");
243 if (i
== TOKEN_ID
|| (insn_is_label
&& i
== TOKEN_INSN
)) {
244 /* there's a label here */
246 result
->label
= tokval
.t_charptr
;
247 i
= stdscan(NULL
, &tokval
);
248 if (i
== ':') { /* skip over the optional colon */
249 i
= stdscan(NULL
, &tokval
);
251 error(ERR_WARNING
| ERR_WARN_OL
| ERR_PASS1
,
252 "label alone on a line without a colon might be in error");
254 if (i
!= TOKEN_INSN
|| tokval
.t_integer
!= I_EQU
) {
256 * FIXME: location->segment could be NO_SEG, in which case
257 * it is possible we should be passing 'abs_seg'. Look into this.
258 * Work out whether that is *really* what we should be doing.
259 * Generally fix things. I think this is right as it is, but
260 * am still not certain.
262 ldef(result
->label
, in_abs_seg
? abs_seg
: location
->segment
,
263 location
->offset
, NULL
, true, false, outfmt
, errfunc
);
268 result
->opcode
= -1; /* this line contains just a label */
272 for (j
= 0; j
< MAXPREFIX
; j
++)
273 result
->prefixes
[j
] = P_none
;
276 while (i
== TOKEN_PREFIX
||
277 (i
== TOKEN_REG
&& !(REG_SREG
& ~nasm_reg_flags
[tokval
.t_integer
])))
282 * Handle special case: the TIMES prefix.
284 if (i
== TOKEN_PREFIX
&& tokval
.t_integer
== P_TIMES
) {
287 i
= stdscan(NULL
, &tokval
);
289 evaluate(stdscan
, NULL
, &tokval
, NULL
, pass0
, error
, NULL
);
291 if (!value
) { /* but, error in evaluator */
292 result
->opcode
= -1; /* unrecoverable parse error: */
293 return result
; /* ignore this instruction */
295 if (!is_simple(value
)) {
297 "non-constant argument supplied to TIMES");
300 result
->times
= value
->value
;
301 if (value
->value
< 0 && pass0
== 2) {
302 error(ERR_NONFATAL
, "TIMES value %d is negative",
308 int slot
= prefix_slot(tokval
.t_integer
);
309 if (result
->prefixes
[slot
]) {
310 if (result
->prefixes
[slot
] == tokval
.t_integer
)
312 "instruction has redundant prefixes");
315 "instruction has conflicting prefixes");
317 result
->prefixes
[slot
] = tokval
.t_integer
;
318 i
= stdscan(NULL
, &tokval
);
322 if (i
!= TOKEN_INSN
) {
326 for (j
= 0; j
< MAXPREFIX
; j
++)
327 if ((pfx
= result
->prefixes
[j
]) != P_none
)
330 if (i
== 0 && pfx
!= P_none
) {
332 * Instruction prefixes are present, but no actual
333 * instruction. This is allowed: at this point we
334 * invent a notional instruction of RESB 0.
336 result
->opcode
= I_RESB
;
337 result
->operands
= 1;
338 result
->oprs
[0].type
= IMMEDIATE
;
339 result
->oprs
[0].offset
= 0L;
340 result
->oprs
[0].segment
= result
->oprs
[0].wrt
= NO_SEG
;
343 error(ERR_NONFATAL
, "parser: instruction expected");
349 result
->opcode
= tokval
.t_integer
;
350 result
->condition
= tokval
.t_inttwo
;
353 * INCBIN cannot be satisfied with incorrectly
354 * evaluated operands, since the correct values _must_ be known
355 * on the first pass. Hence, even in pass one, we set the
356 * `critical' flag on calling evaluate(), so that it will bomb
357 * out on undefined symbols.
359 if (result
->opcode
== I_INCBIN
) {
360 critical
= (pass0
< 2 ? 1 : 2);
363 critical
= (pass
== 2 ? 2 : 0);
365 if (result
->opcode
== I_DB
|| result
->opcode
== I_DW
||
366 result
->opcode
== I_DD
|| result
->opcode
== I_DQ
||
367 result
->opcode
== I_DT
|| result
->opcode
== I_DO
||
368 result
->opcode
== I_DY
|| result
->opcode
== I_INCBIN
) {
369 extop
*eop
, **tail
= &result
->eops
, **fixptr
;
373 result
->eops_float
= false;
376 * Begin to read the DB/DW/DD/DQ/DT/DO/INCBIN operands.
379 i
= stdscan(NULL
, &tokval
);
382 else if (first
&& i
== ':') {
383 insn_is_label
= true;
388 eop
= *tail
= nasm_malloc(sizeof(extop
));
391 eop
->type
= EOT_NOTHING
;
395 /* is_comma_next() here is to distinguish this from
396 a string used as part of an expression... */
397 if (i
== TOKEN_STR
&& is_comma_next()) {
398 eop
->type
= EOT_DB_STRING
;
399 eop
->stringval
= tokval
.t_charptr
;
400 eop
->stringlen
= tokval
.t_inttwo
;
401 i
= stdscan(NULL
, &tokval
); /* eat the comma */
402 } else if (i
== TOKEN_STRFUNC
) {
404 const char *funcname
= tokval
.t_charptr
;
405 enum strfunc func
= tokval
.t_integer
;
406 i
= stdscan(NULL
, &tokval
);
409 i
= stdscan(NULL
, &tokval
);
411 if (i
!= TOKEN_STR
) {
413 "%s must be followed by a string constant",
415 eop
->type
= EOT_NOTHING
;
417 eop
->type
= EOT_DB_STRING_FREE
;
419 string_transform(tokval
.t_charptr
, tokval
.t_inttwo
,
420 &eop
->stringval
, func
);
421 if (eop
->stringlen
== (size_t)-1) {
422 error(ERR_NONFATAL
, "invalid string for transform");
423 eop
->type
= EOT_NOTHING
;
426 if (parens
&& i
&& i
!= ')') {
427 i
= stdscan(NULL
, &tokval
);
429 error(ERR_NONFATAL
, "unterminated %s function",
434 i
= stdscan(NULL
, &tokval
);
435 } else if (i
== '-' || i
== '+') {
436 char *save
= stdscan_bufptr
;
438 sign
= (i
== '-') ? -1 : 1;
439 i
= stdscan(NULL
, &tokval
);
440 if (i
!= TOKEN_FLOAT
) {
441 stdscan_bufptr
= save
;
442 i
= tokval
.t_type
= token
;
447 } else if (i
== TOKEN_FLOAT
) {
449 eop
->type
= EOT_DB_STRING
;
450 result
->eops_float
= true;
451 switch (result
->opcode
) {
471 error(ERR_NONFATAL
, "floating-point constant"
472 " encountered in DY instruction");
476 error(ERR_NONFATAL
, "floating-point constant"
477 " encountered in unknown instruction");
479 * fix suggested by Pedro Gimeno... original line
481 * eop->type = EOT_NOTHING;
486 eop
= nasm_realloc(eop
, sizeof(extop
) + eop
->stringlen
);
489 eop
->stringval
= (char *)eop
+ sizeof(extop
);
490 if (!eop
->stringlen
||
491 !float_const(tokval
.t_charptr
, sign
,
492 (uint8_t *)eop
->stringval
,
493 eop
->stringlen
, error
))
494 eop
->type
= EOT_NOTHING
;
495 i
= stdscan(NULL
, &tokval
); /* eat the comma */
497 /* anything else, assume it is an expression */
501 value
= evaluate(stdscan
, NULL
, &tokval
, NULL
,
502 critical
, error
, NULL
);
504 if (!value
) { /* error in evaluator */
505 result
->opcode
= -1; /* unrecoverable parse error: */
506 return result
; /* ignore this instruction */
508 if (is_unknown(value
)) {
509 eop
->type
= EOT_DB_NUMBER
;
510 eop
->offset
= 0; /* doesn't matter what we put */
511 eop
->segment
= eop
->wrt
= NO_SEG
; /* likewise */
512 } else if (is_reloc(value
)) {
513 eop
->type
= EOT_DB_NUMBER
;
514 eop
->offset
= reloc_value(value
);
515 eop
->segment
= reloc_seg(value
);
516 eop
->wrt
= reloc_wrt(value
);
519 "operand %d: expression is not simple"
520 " or relocatable", oper_num
);
525 * We're about to call stdscan(), which will eat the
526 * comma that we're currently sitting on between
527 * arguments. However, we'd better check first that it
530 if (i
== 0) /* also could be EOL */
533 error(ERR_NONFATAL
, "comma expected after operand %d",
535 result
->opcode
= -1; /* unrecoverable parse error: */
536 return result
; /* ignore this instruction */
540 if (result
->opcode
== I_INCBIN
) {
542 * Correct syntax for INCBIN is that there should be
543 * one string operand, followed by one or two numeric
546 if (!result
->eops
|| result
->eops
->type
!= EOT_DB_STRING
)
547 error(ERR_NONFATAL
, "`incbin' expects a file name");
548 else if (result
->eops
->next
&&
549 result
->eops
->next
->type
!= EOT_DB_NUMBER
)
550 error(ERR_NONFATAL
, "`incbin': second parameter is",
552 else if (result
->eops
->next
&& result
->eops
->next
->next
&&
553 result
->eops
->next
->next
->type
!= EOT_DB_NUMBER
)
554 error(ERR_NONFATAL
, "`incbin': third parameter is",
556 else if (result
->eops
->next
&& result
->eops
->next
->next
&&
557 result
->eops
->next
->next
->next
)
559 "`incbin': more than three parameters");
563 * If we reach here, one of the above errors happened.
564 * Throw the instruction away.
568 } else /* DB ... */ if (oper_num
== 0)
569 error(ERR_WARNING
| ERR_PASS1
,
570 "no operand for data declaration");
572 result
->operands
= oper_num
;
577 /* right. Now we begin to parse the operands. There may be up to four
578 * of these, separated by commas, and terminated by a zero token. */
580 for (operand
= 0; operand
< MAX_OPERANDS
; operand
++) {
581 expr
*value
; /* used most of the time */
582 int mref
; /* is this going to be a memory ref? */
583 int bracket
; /* is it a [] mref, or a & mref? */
586 result
->oprs
[operand
].disp_size
= 0; /* have to zero this whatever */
587 result
->oprs
[operand
].eaflags
= 0; /* and this */
588 result
->oprs
[operand
].opflags
= 0;
590 i
= stdscan(NULL
, &tokval
);
592 break; /* end of operands: get out of here */
593 else if (first
&& i
== ':') {
594 insn_is_label
= true;
598 result
->oprs
[operand
].type
= 0; /* so far, no override */
599 while (i
== TOKEN_SPECIAL
) { /* size specifiers */
600 switch ((int)tokval
.t_integer
) {
602 if (!setsize
) /* we want to use only the first */
603 result
->oprs
[operand
].type
|= BITS8
;
608 result
->oprs
[operand
].type
|= BITS16
;
614 result
->oprs
[operand
].type
|= BITS32
;
619 result
->oprs
[operand
].type
|= BITS64
;
624 result
->oprs
[operand
].type
|= BITS80
;
629 result
->oprs
[operand
].type
|= BITS128
;
634 result
->oprs
[operand
].type
|= BITS256
;
638 result
->oprs
[operand
].type
|= TO
;
641 result
->oprs
[operand
].type
|= STRICT
;
644 result
->oprs
[operand
].type
|= FAR
;
647 result
->oprs
[operand
].type
|= NEAR
;
650 result
->oprs
[operand
].type
|= SHORT
;
653 error(ERR_NONFATAL
, "invalid operand size specification");
655 i
= stdscan(NULL
, &tokval
);
658 if (i
== '[' || i
== '&') { /* memory reference */
660 bracket
= (i
== '[');
661 i
= stdscan(NULL
, &tokval
); /* then skip the colon */
662 while (i
== TOKEN_SPECIAL
|| i
== TOKEN_PREFIX
) {
663 process_size_override(result
, operand
);
664 i
= stdscan(NULL
, &tokval
);
666 } else { /* immediate operand, or register */
668 bracket
= false; /* placate optimisers */
671 if ((result
->oprs
[operand
].type
& FAR
) && !mref
&&
672 result
->opcode
!= I_JMP
&& result
->opcode
!= I_CALL
) {
673 error(ERR_NONFATAL
, "invalid use of FAR operand specifier");
676 value
= evaluate(stdscan
, NULL
, &tokval
,
677 &result
->oprs
[operand
].opflags
,
678 critical
, error
, &hints
);
680 if (result
->oprs
[operand
].opflags
& OPFLAG_FORWARD
) {
681 result
->forw_ref
= true;
683 if (!value
) { /* error in evaluator */
684 result
->opcode
= -1; /* unrecoverable parse error: */
685 return result
; /* ignore this instruction */
687 if (i
== ':' && mref
) { /* it was seg:offset */
689 * Process the segment override.
691 if (value
[1].type
!= 0 || value
->value
!= 1 ||
692 REG_SREG
& ~nasm_reg_flags
[value
->type
])
693 error(ERR_NONFATAL
, "invalid segment override");
694 else if (result
->prefixes
[PPS_SEG
])
696 "instruction has conflicting segment overrides");
698 result
->prefixes
[PPS_SEG
] = value
->type
;
699 if (!(REG_FSGS
& ~nasm_reg_flags
[value
->type
]))
700 result
->oprs
[operand
].eaflags
|= EAF_FSGS
;
703 i
= stdscan(NULL
, &tokval
); /* then skip the colon */
704 while (i
== TOKEN_SPECIAL
|| i
== TOKEN_PREFIX
) {
705 process_size_override(result
, operand
);
706 i
= stdscan(NULL
, &tokval
);
708 value
= evaluate(stdscan
, NULL
, &tokval
,
709 &result
->oprs
[operand
].opflags
,
710 critical
, error
, &hints
);
712 if (result
->oprs
[operand
].opflags
& OPFLAG_FORWARD
) {
713 result
->forw_ref
= true;
715 /* and get the offset */
716 if (!value
) { /* but, error in evaluator */
717 result
->opcode
= -1; /* unrecoverable parse error: */
718 return result
; /* ignore this instruction */
723 if (mref
&& bracket
) { /* find ] at the end */
725 error(ERR_NONFATAL
, "parser: expecting ]");
727 } else { /* we got the required ] */
728 i
= stdscan(NULL
, &tokval
);
729 if (i
!= 0 && i
!= ',') {
730 error(ERR_NONFATAL
, "comma or end of line expected");
734 } else { /* immediate operand */
735 if (i
!= 0 && i
!= ',' && i
!= ':') {
736 error(ERR_NONFATAL
, "comma, colon or end of line expected");
738 } else if (i
== ':') {
739 result
->oprs
[operand
].type
|= COLON
;
743 do { /* error recovery */
744 i
= stdscan(NULL
, &tokval
);
745 } while (i
!= 0 && i
!= ',');
748 /* now convert the exprs returned from evaluate() into operand
751 if (mref
) { /* it's a memory reference */
753 int b
, i
, s
; /* basereg, indexreg, scale */
754 int64_t o
; /* offset */
756 b
= i
= -1, o
= s
= 0;
757 result
->oprs
[operand
].hintbase
= hints
.base
;
758 result
->oprs
[operand
].hinttype
= hints
.type
;
760 if (e
->type
&& e
->type
<= EXPR_REG_END
) { /* this bit's a register */
761 if (e
->value
== 1) /* in fact it can be basereg */
763 else /* no, it has to be indexreg */
764 i
= e
->type
, s
= e
->value
;
767 if (e
->type
&& e
->type
<= EXPR_REG_END
) { /* it's a 2nd register */
768 if (b
!= -1) /* If the first was the base, ... */
769 i
= e
->type
, s
= e
->value
; /* second has to be indexreg */
771 else if (e
->value
!= 1) { /* If both want to be index */
773 "beroset-p-592-invalid effective address");
780 if (e
->type
!= 0) { /* is there an offset? */
781 if (e
->type
<= EXPR_REG_END
) { /* in fact, is there an error? */
783 "beroset-p-603-invalid effective address");
787 if (e
->type
== EXPR_UNKNOWN
) {
788 result
->oprs
[operand
].opflags
|= OPFLAG_UNKNOWN
;
789 o
= 0; /* doesn't matter what */
790 result
->oprs
[operand
].wrt
= NO_SEG
; /* nor this */
791 result
->oprs
[operand
].segment
= NO_SEG
; /* or this */
793 e
++; /* go to the end of the line */
795 if (e
->type
== EXPR_SIMPLE
) {
799 if (e
->type
== EXPR_WRT
) {
800 result
->oprs
[operand
].wrt
= e
->value
;
803 result
->oprs
[operand
].wrt
= NO_SEG
;
805 * Look for a segment base type.
807 if (e
->type
&& e
->type
< EXPR_SEGBASE
) {
809 "beroset-p-630-invalid effective address");
813 while (e
->type
&& e
->value
== 0)
815 if (e
->type
&& e
->value
!= 1) {
817 "beroset-p-637-invalid effective address");
822 result
->oprs
[operand
].segment
=
823 e
->type
- EXPR_SEGBASE
;
826 result
->oprs
[operand
].segment
= NO_SEG
;
827 while (e
->type
&& e
->value
== 0)
831 "beroset-p-650-invalid effective address");
839 result
->oprs
[operand
].wrt
= NO_SEG
;
840 result
->oprs
[operand
].segment
= NO_SEG
;
843 if (e
->type
!= 0) { /* there'd better be nothing left! */
845 "beroset-p-663-invalid effective address");
850 /* It is memory, but it can match any r/m operand */
851 result
->oprs
[operand
].type
|= MEMORY_ANY
;
853 if (b
== -1 && (i
== -1 || s
== 0)) {
854 int is_rel
= globalbits
== 64 &&
855 !(result
->oprs
[operand
].eaflags
& EAF_ABS
) &&
857 !(result
->oprs
[operand
].eaflags
& EAF_FSGS
)) ||
858 (result
->oprs
[operand
].eaflags
& EAF_REL
));
860 result
->oprs
[operand
].type
|= is_rel
? IP_REL
: MEM_OFFS
;
862 result
->oprs
[operand
].basereg
= b
;
863 result
->oprs
[operand
].indexreg
= i
;
864 result
->oprs
[operand
].scale
= s
;
865 result
->oprs
[operand
].offset
= o
;
866 } else { /* it's not a memory reference */
867 if (is_just_unknown(value
)) { /* it's immediate but unknown */
868 result
->oprs
[operand
].type
|= IMMEDIATE
;
869 result
->oprs
[operand
].opflags
|= OPFLAG_UNKNOWN
;
870 result
->oprs
[operand
].offset
= 0; /* don't care */
871 result
->oprs
[operand
].segment
= NO_SEG
; /* don't care again */
872 result
->oprs
[operand
].wrt
= NO_SEG
; /* still don't care */
874 if(optimizing
>= 0 && !(result
->oprs
[operand
].type
& STRICT
))
877 result
->oprs
[operand
].type
|= SBYTE16
| SBYTE32
| SBYTE64
;
879 } else if (is_reloc(value
)) { /* it's immediate */
880 result
->oprs
[operand
].type
|= IMMEDIATE
;
881 result
->oprs
[operand
].offset
= reloc_value(value
);
882 result
->oprs
[operand
].segment
= reloc_seg(value
);
883 result
->oprs
[operand
].wrt
= reloc_wrt(value
);
884 if (is_simple(value
)) {
885 if (reloc_value(value
) == 1)
886 result
->oprs
[operand
].type
|= UNITY
;
887 if (optimizing
>= 0 &&
888 !(result
->oprs
[operand
].type
& STRICT
)) {
889 int64_t v64
= reloc_value(value
);
890 int32_t v32
= (int32_t)v64
;
891 int16_t v16
= (int16_t)v32
;
893 if (v64
>= -128 && v64
<= 127)
894 result
->oprs
[operand
].type
|= SBYTE64
;
895 if (v32
>= -128 && v32
<= 127)
896 result
->oprs
[operand
].type
|= SBYTE32
;
897 if (v16
>= -128 && v16
<= 127)
898 result
->oprs
[operand
].type
|= SBYTE16
;
901 } else { /* it's a register */
904 if (value
->type
>= EXPR_SIMPLE
|| value
->value
!= 1) {
905 error(ERR_NONFATAL
, "invalid operand type");
911 * check that its only 1 register, not an expression...
913 for (i
= 1; value
[i
].type
; i
++)
914 if (value
[i
].value
) {
915 error(ERR_NONFATAL
, "invalid operand type");
920 /* clear overrides, except TO which applies to FPU regs */
921 if (result
->oprs
[operand
].type
& ~TO
) {
923 * we want to produce a warning iff the specified size
924 * is different from the register size
926 rs
= result
->oprs
[operand
].type
& SIZE_MASK
;
930 result
->oprs
[operand
].type
&= TO
;
931 result
->oprs
[operand
].type
|= REGISTER
;
932 result
->oprs
[operand
].type
|= nasm_reg_flags
[value
->type
];
933 result
->oprs
[operand
].basereg
= value
->type
;
935 if (rs
&& (result
->oprs
[operand
].type
& SIZE_MASK
) != rs
)
936 error(ERR_WARNING
| ERR_PASS1
,
937 "register size specification ignored");
942 result
->operands
= operand
; /* set operand count */
944 /* clear remaining operands */
945 while (operand
< MAX_OPERANDS
)
946 result
->oprs
[operand
++].type
= 0;
949 * Transform RESW, RESD, RESQ, REST, RESO, RESY into RESB.
951 switch (result
->opcode
) {
953 result
->opcode
= I_RESB
;
954 result
->oprs
[0].offset
*= 2;
957 result
->opcode
= I_RESB
;
958 result
->oprs
[0].offset
*= 4;
961 result
->opcode
= I_RESB
;
962 result
->oprs
[0].offset
*= 8;
965 result
->opcode
= I_RESB
;
966 result
->oprs
[0].offset
*= 10;
969 result
->opcode
= I_RESB
;
970 result
->oprs
[0].offset
*= 16;
973 result
->opcode
= I_RESB
;
974 result
->oprs
[0].offset
*= 32;
983 static int is_comma_next(void)
990 i
= stdscan(NULL
, &tv
);
992 return (i
== ',' || i
== ';' || !i
);
995 void cleanup_insn(insn
* i
)
999 while ((e
= i
->eops
)) {
1001 if (e
->type
== EOT_DB_STRING_FREE
)
1002 nasm_free(e
->stringval
);