1 /* ----------------------------------------------------------------------- *
3 * Copyright 1996-2013 The NASM Authors - All Rights Reserved
4 * See the file AUTHORS included with the NASM distribution for
5 * the specific copyright holders.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following
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.
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.
32 * ----------------------------------------------------------------------- */
35 * parser.c source line parser for the Netwide Assembler
56 extern int in_abs_seg
; /* ABSOLUTE segment flag */
57 extern int32_t abs_seg
; /* ABSOLUTE segment */
58 extern int32_t abs_offset
; /* ABSOLUTE segment offset */
60 static int is_comma_next(void);
63 static struct tokenval tokval
;
64 static struct location
*location
; /* Pointer to current line's segment,offset */
66 void parser_global_info(struct location
* locp
)
71 static int prefix_slot(int prefix
)
104 nasm_error(ERR_PANIC
, "Invalid value %d passed to prefix_slot()", prefix
);
109 static void process_size_override(insn
*result
, operand
*op
)
111 if (tasm_compatible_mode
) {
112 switch ((int)tokval
.t_integer
) {
113 /* For TASM compatibility a size override inside the
114 * brackets changes the size of the operand, not the
115 * address type of the operand as it does in standard
116 * NASM syntax. Hence:
118 * mov eax,[DWORD val]
120 * is valid syntax in TASM compatibility mode. Note that
121 * you lose the ability to override the default address
122 * type for the instruction, but we never use anything
123 * but 32-bit flat model addressing in our code.
145 nasm_error(ERR_NONFATAL
,
146 "invalid operand size specification");
150 /* Standard NASM compatible syntax */
151 switch ((int)tokval
.t_integer
) {
153 op
->eaflags
|= EAF_TIMESTWO
;
156 op
->eaflags
|= EAF_REL
;
159 op
->eaflags
|= EAF_ABS
;
163 op
->eaflags
|= EAF_BYTEOFFS
;
168 if (result
->prefixes
[PPS_ASIZE
] &&
169 result
->prefixes
[PPS_ASIZE
] != tokval
.t_integer
)
170 nasm_error(ERR_NONFATAL
,
171 "conflicting address size specifications");
173 result
->prefixes
[PPS_ASIZE
] = tokval
.t_integer
;
177 op
->eaflags
|= EAF_WORDOFFS
;
182 op
->eaflags
|= EAF_WORDOFFS
;
186 op
->eaflags
|= EAF_WORDOFFS
;
189 nasm_error(ERR_NONFATAL
, "invalid size specification in"
190 " effective address");
197 * when two or more decorators follow a register operand,
198 * consecutive decorators are parsed here.
199 * opmask and zeroing decorators can be placed in any order.
200 * e.g. zmm1 {k2}{z} or zmm2 {z,k3}
201 * decorator(s) are placed at the end of an operand.
203 static bool parse_braces(decoflags_t
*decoflags
)
206 bool recover
= false;
210 if (i
== TOKEN_OPMASK
) {
211 if (*decoflags
& OPMASK_MASK
) {
212 nasm_error(ERR_NONFATAL
, "opmask k%lu is already set",
213 *decoflags
& OPMASK_MASK
);
214 *decoflags
&= ~OPMASK_MASK
;
216 *decoflags
|= VAL_OPMASK(nasm_regvals
[tokval
.t_integer
]);
217 } else if (i
== TOKEN_DECORATOR
) {
218 switch (tokval
.t_integer
) {
221 * according to AVX512 spec, only zeroing/merging decorator
222 * is supported with opmask
224 *decoflags
|= GEN_Z(0);
227 nasm_error(ERR_NONFATAL
, "{%s} is not an expected decorator",
231 } else if (i
== ',' || i
== TOKEN_EOS
){
234 nasm_error(ERR_NONFATAL
, "only a series of valid decorators"
239 i
= stdscan(NULL
, &tokval
);
245 static int parse_mref(operand
*op
, const expr
*e
,
246 const struct eval_hints
*hints
, decoflags_t brace_flags
)
248 int b
, i
, s
; /* basereg, indexreg, scale */
249 int64_t o
; /* offset */
251 b
= i
= -1, o
= s
= 0;
252 op
->hintbase
= hints
->base
;
253 op
->hinttype
= hints
->type
;
255 if (e
->type
&& e
->type
<= EXPR_REG_END
) { /* this bit's a register */
256 bool is_gpr
= is_class(REG_GPR
,nasm_reg_flags
[e
->type
]);
258 if (is_gpr
&& e
->value
== 1)
259 b
= e
->type
; /* It can be basereg */
260 else /* No, it has to be indexreg */
261 i
= e
->type
, s
= e
->value
;
264 if (e
->type
&& e
->type
<= EXPR_REG_END
) { /* it's a 2nd register */
265 bool is_gpr
= is_class(REG_GPR
,nasm_reg_flags
[e
->type
]);
267 if (b
!= -1) /* If the first was the base, ... */
268 i
= e
->type
, s
= e
->value
; /* second has to be indexreg */
270 else if (!is_gpr
|| e
->value
!= 1) {
271 /* If both want to be index */
272 nasm_error(ERR_NONFATAL
,
273 "invalid effective address: two index registers");
279 if (e
->type
!= 0) { /* is there an offset? */
280 if (e
->type
<= EXPR_REG_END
) { /* in fact, is there an error? */
281 nasm_error(ERR_NONFATAL
,
282 "beroset-p-603-invalid effective address");
285 if (e
->type
== EXPR_UNKNOWN
) {
286 op
->opflags
|= OPFLAG_UNKNOWN
;
287 o
= 0; /* doesn't matter what */
288 op
->wrt
= NO_SEG
; /* nor this */
289 op
->segment
= NO_SEG
; /* or this */
291 e
++; /* go to the end of the line */
293 if (e
->type
== EXPR_SIMPLE
) {
297 if (e
->type
== EXPR_WRT
) {
303 * Look for a segment base type.
305 if (e
->type
&& e
->type
< EXPR_SEGBASE
) {
306 nasm_error(ERR_NONFATAL
,
307 "beroset-p-630-invalid effective address");
310 while (e
->type
&& e
->value
== 0)
312 if (e
->type
&& e
->value
!= 1) {
313 nasm_error(ERR_NONFATAL
,
314 "beroset-p-637-invalid effective address");
319 e
->type
- EXPR_SEGBASE
;
322 op
->segment
= NO_SEG
;
323 while (e
->type
&& e
->value
== 0)
326 nasm_error(ERR_NONFATAL
,
327 "beroset-p-650-invalid effective address");
335 op
->segment
= NO_SEG
;
338 if (e
->type
!= 0) { /* there'd better be nothing left! */
339 nasm_error(ERR_NONFATAL
,
340 "beroset-p-663-invalid effective address");
344 /* It is memory, but it can match any r/m operand */
345 op
->type
|= MEMORY_ANY
;
347 if (b
== -1 && (i
== -1 || s
== 0)) {
348 int is_rel
= globalbits
== 64 &&
349 !(op
->eaflags
& EAF_ABS
) &&
351 !(op
->eaflags
& EAF_FSGS
)) ||
352 (op
->eaflags
& EAF_REL
));
354 op
->type
|= is_rel
? IP_REL
: MEM_OFFS
;
358 opflags_t iclass
= nasm_reg_flags
[i
];
360 if (is_class(XMMREG
,iclass
))
362 else if (is_class(YMMREG
,iclass
))
364 else if (is_class(ZMMREG
,iclass
))
372 op
->decoflags
|= brace_flags
;
376 insn
*parse_line(int pass
, char *buffer
, insn
*result
, ldfunc ldef
)
378 bool insn_is_label
= false;
379 struct eval_hints hints
;
387 result
->forw_ref
= false;
391 i
= stdscan(NULL
, &tokval
);
393 result
->label
= NULL
; /* Assume no label */
394 result
->eops
= NULL
; /* must do this, whatever happens */
395 result
->operands
= 0; /* must initialize this */
396 result
->evex_rm
= 0; /* Ensure EVEX rounding mode is reset */
397 result
->evex_brerop
= -1; /* Reset EVEX broadcasting/ER op position */
399 /* Ignore blank lines */
406 (i
!= TOKEN_REG
|| !IS_SREG(tokval
.t_integer
))) {
407 nasm_error(ERR_NONFATAL
,
408 "label or instruction expected at start of line");
412 if (i
== TOKEN_ID
|| (insn_is_label
&& i
== TOKEN_INSN
)) {
413 /* there's a label here */
415 result
->label
= tokval
.t_charptr
;
416 i
= stdscan(NULL
, &tokval
);
417 if (i
== ':') { /* skip over the optional colon */
418 i
= stdscan(NULL
, &tokval
);
420 nasm_error(ERR_WARNING
| ERR_WARN_OL
| ERR_PASS1
,
421 "label alone on a line without a colon might be in error");
423 if (i
!= TOKEN_INSN
|| tokval
.t_integer
!= I_EQU
) {
425 * FIXME: location->segment could be NO_SEG, in which case
426 * it is possible we should be passing 'abs_seg'. Look into this.
427 * Work out whether that is *really* what we should be doing.
428 * Generally fix things. I think this is right as it is, but
429 * am still not certain.
431 ldef(result
->label
, in_abs_seg
? abs_seg
: location
->segment
,
432 location
->offset
, NULL
, true, false);
436 /* Just a label here */
440 nasm_build_assert(P_none
!= 0);
441 memset(result
->prefixes
, P_none
, sizeof(result
->prefixes
));
444 while (i
== TOKEN_PREFIX
||
445 (i
== TOKEN_REG
&& IS_SREG(tokval
.t_integer
))) {
449 * Handle special case: the TIMES prefix.
451 if (i
== TOKEN_PREFIX
&& tokval
.t_integer
== P_TIMES
) {
454 i
= stdscan(NULL
, &tokval
);
455 value
= evaluate(stdscan
, NULL
, &tokval
, NULL
, pass0
, nasm_error
, NULL
);
457 if (!value
) /* Error in evaluator */
459 if (!is_simple(value
)) {
460 nasm_error(ERR_NONFATAL
,
461 "non-constant argument supplied to TIMES");
464 result
->times
= value
->value
;
465 if (value
->value
< 0 && pass0
== 2) {
466 nasm_error(ERR_NONFATAL
, "TIMES value %"PRId64
" is negative",
472 int slot
= prefix_slot(tokval
.t_integer
);
473 if (result
->prefixes
[slot
]) {
474 if (result
->prefixes
[slot
] == tokval
.t_integer
)
475 nasm_error(ERR_WARNING
| ERR_PASS1
,
476 "instruction has redundant prefixes");
478 nasm_error(ERR_NONFATAL
,
479 "instruction has conflicting prefixes");
481 result
->prefixes
[slot
] = tokval
.t_integer
;
482 i
= stdscan(NULL
, &tokval
);
486 if (i
!= TOKEN_INSN
) {
490 for (j
= 0; j
< MAXPREFIX
; j
++) {
491 if ((pfx
= result
->prefixes
[j
]) != P_none
)
495 if (i
== 0 && pfx
!= P_none
) {
497 * Instruction prefixes are present, but no actual
498 * instruction. This is allowed: at this point we
499 * invent a notional instruction of RESB 0.
501 result
->opcode
= I_RESB
;
502 result
->operands
= 1;
503 result
->oprs
[0].type
= IMMEDIATE
;
504 result
->oprs
[0].offset
= 0L;
505 result
->oprs
[0].segment
= result
->oprs
[0].wrt
= NO_SEG
;
508 nasm_error(ERR_NONFATAL
, "parser: instruction expected");
513 result
->opcode
= tokval
.t_integer
;
514 result
->condition
= tokval
.t_inttwo
;
517 * INCBIN cannot be satisfied with incorrectly
518 * evaluated operands, since the correct values _must_ be known
519 * on the first pass. Hence, even in pass one, we set the
520 * `critical' flag on calling evaluate(), so that it will bomb
521 * out on undefined symbols.
523 if (result
->opcode
== I_INCBIN
) {
524 critical
= (pass0
< 2 ? 1 : 2);
527 critical
= (pass
== 2 ? 2 : 0);
529 if (result
->opcode
== I_DB
|| result
->opcode
== I_DW
||
530 result
->opcode
== I_DD
|| result
->opcode
== I_DQ
||
531 result
->opcode
== I_DT
|| result
->opcode
== I_DO
||
532 result
->opcode
== I_DY
|| result
->opcode
== I_INCBIN
) {
533 extop
*eop
, **tail
= &result
->eops
, **fixptr
;
537 result
->eops_float
= false;
540 * Begin to read the DB/DW/DD/DQ/DT/DO/INCBIN operands.
543 i
= stdscan(NULL
, &tokval
);
546 else if (first
&& i
== ':') {
547 insn_is_label
= true;
552 eop
= *tail
= nasm_malloc(sizeof(extop
));
555 eop
->type
= EOT_NOTHING
;
560 * is_comma_next() here is to distinguish this from
561 * a string used as part of an expression...
563 if (i
== TOKEN_STR
&& is_comma_next()) {
564 eop
->type
= EOT_DB_STRING
;
565 eop
->stringval
= tokval
.t_charptr
;
566 eop
->stringlen
= tokval
.t_inttwo
;
567 i
= stdscan(NULL
, &tokval
); /* eat the comma */
568 } else if (i
== TOKEN_STRFUNC
) {
570 const char *funcname
= tokval
.t_charptr
;
571 enum strfunc func
= tokval
.t_integer
;
572 i
= stdscan(NULL
, &tokval
);
575 i
= stdscan(NULL
, &tokval
);
577 if (i
!= TOKEN_STR
) {
578 nasm_error(ERR_NONFATAL
,
579 "%s must be followed by a string constant",
581 eop
->type
= EOT_NOTHING
;
583 eop
->type
= EOT_DB_STRING_FREE
;
585 string_transform(tokval
.t_charptr
, tokval
.t_inttwo
,
586 &eop
->stringval
, func
);
587 if (eop
->stringlen
== (size_t)-1) {
588 nasm_error(ERR_NONFATAL
, "invalid string for transform");
589 eop
->type
= EOT_NOTHING
;
592 if (parens
&& i
&& i
!= ')') {
593 i
= stdscan(NULL
, &tokval
);
595 nasm_error(ERR_NONFATAL
, "unterminated %s function",
600 i
= stdscan(NULL
, &tokval
);
601 } else if (i
== '-' || i
== '+') {
602 char *save
= stdscan_get();
604 sign
= (i
== '-') ? -1 : 1;
605 i
= stdscan(NULL
, &tokval
);
606 if (i
!= TOKEN_FLOAT
) {
608 i
= tokval
.t_type
= token
;
613 } else if (i
== TOKEN_FLOAT
) {
615 eop
->type
= EOT_DB_STRING
;
616 result
->eops_float
= true;
618 eop
->stringlen
= idata_bytes(result
->opcode
);
619 if (eop
->stringlen
> 16) {
620 nasm_error(ERR_NONFATAL
, "floating-point constant"
621 " encountered in DY instruction");
623 } else if (eop
->stringlen
< 1) {
624 nasm_error(ERR_NONFATAL
, "floating-point constant"
625 " encountered in unknown instruction");
627 * fix suggested by Pedro Gimeno... original line was:
628 * eop->type = EOT_NOTHING;
633 eop
= nasm_realloc(eop
, sizeof(extop
) + eop
->stringlen
);
636 eop
->stringval
= (char *)eop
+ sizeof(extop
);
637 if (!eop
->stringlen
||
638 !float_const(tokval
.t_charptr
, sign
,
639 (uint8_t *)eop
->stringval
,
640 eop
->stringlen
, nasm_error
))
641 eop
->type
= EOT_NOTHING
;
642 i
= stdscan(NULL
, &tokval
); /* eat the comma */
644 /* anything else, assume it is an expression */
648 value
= evaluate(stdscan
, NULL
, &tokval
, NULL
,
649 critical
, nasm_error
, NULL
);
651 if (!value
) /* Error in evaluator */
653 if (is_unknown(value
)) {
654 eop
->type
= EOT_DB_NUMBER
;
655 eop
->offset
= 0; /* doesn't matter what we put */
656 eop
->segment
= eop
->wrt
= NO_SEG
; /* likewise */
657 } else if (is_reloc(value
)) {
658 eop
->type
= EOT_DB_NUMBER
;
659 eop
->offset
= reloc_value(value
);
660 eop
->segment
= reloc_seg(value
);
661 eop
->wrt
= reloc_wrt(value
);
663 nasm_error(ERR_NONFATAL
,
664 "operand %d: expression is not simple"
665 " or relocatable", oper_num
);
670 * We're about to call stdscan(), which will eat the
671 * comma that we're currently sitting on between
672 * arguments. However, we'd better check first that it
675 if (i
== TOKEN_EOS
) /* also could be EOL */
678 nasm_error(ERR_NONFATAL
, "comma expected after operand %d",
684 if (result
->opcode
== I_INCBIN
) {
686 * Correct syntax for INCBIN is that there should be
687 * one string operand, followed by one or two numeric
690 if (!result
->eops
|| result
->eops
->type
!= EOT_DB_STRING
)
691 nasm_error(ERR_NONFATAL
, "`incbin' expects a file name");
692 else if (result
->eops
->next
&&
693 result
->eops
->next
->type
!= EOT_DB_NUMBER
)
694 nasm_error(ERR_NONFATAL
, "`incbin': second parameter is"
696 else if (result
->eops
->next
&& result
->eops
->next
->next
&&
697 result
->eops
->next
->next
->type
!= EOT_DB_NUMBER
)
698 nasm_error(ERR_NONFATAL
, "`incbin': third parameter is"
700 else if (result
->eops
->next
&& result
->eops
->next
->next
&&
701 result
->eops
->next
->next
->next
)
702 nasm_error(ERR_NONFATAL
,
703 "`incbin': more than three parameters");
707 * If we reach here, one of the above errors happened.
708 * Throw the instruction away.
711 } else /* DB ... */ if (oper_num
== 0)
712 nasm_error(ERR_WARNING
| ERR_PASS1
,
713 "no operand for data declaration");
715 result
->operands
= oper_num
;
721 * Now we begin to parse the operands. There may be up to four
722 * of these, separated by commas, and terminated by a zero token.
725 for (opnum
= 0; opnum
< MAX_OPERANDS
; opnum
++) {
726 operand
*op
= &result
->oprs
[opnum
];
727 expr
*value
; /* used most of the time */
728 int mref
; /* is this going to be a memory ref? */
729 int bracket
; /* is it a [] mref, or a & mref? */
731 decoflags_t brace_flags
= 0; /* flags for decorators in braces */
733 op
->disp_size
= 0; /* have to zero this whatever */
734 op
->eaflags
= 0; /* and this */
738 i
= stdscan(NULL
, &tokval
);
740 break; /* end of operands: get out of here */
741 else if (first
&& i
== ':') {
742 insn_is_label
= true;
746 op
->type
= 0; /* so far, no override */
747 while (i
== TOKEN_SPECIAL
) { /* size specifiers */
748 switch ((int)tokval
.t_integer
) {
750 if (!setsize
) /* we want to use only the first */
806 nasm_error(ERR_NONFATAL
, "invalid operand size specification");
808 i
= stdscan(NULL
, &tokval
);
811 if (i
== '[' || i
== '&') { /* memory reference */
813 bracket
= (i
== '[');
814 i
= stdscan(NULL
, &tokval
); /* then skip the colon */
815 while (i
== TOKEN_SPECIAL
|| i
== TOKEN_PREFIX
) {
816 process_size_override(result
, op
);
817 i
= stdscan(NULL
, &tokval
);
819 } else { /* immediate operand, or register */
821 bracket
= false; /* placate optimisers */
824 if ((op
->type
& FAR
) && !mref
&&
825 result
->opcode
!= I_JMP
&& result
->opcode
!= I_CALL
) {
826 nasm_error(ERR_NONFATAL
, "invalid use of FAR operand specifier");
829 value
= evaluate(stdscan
, NULL
, &tokval
,
831 critical
, nasm_error
, &hints
);
833 if (op
->opflags
& OPFLAG_FORWARD
) {
834 result
->forw_ref
= true;
836 if (!value
) /* Error in evaluator */
838 if (i
== ':' && mref
) { /* it was seg:offset */
840 * Process the segment override.
842 if (value
[1].type
!= 0 ||
844 !IS_SREG(value
->type
))
845 nasm_error(ERR_NONFATAL
, "invalid segment override");
846 else if (result
->prefixes
[PPS_SEG
])
847 nasm_error(ERR_NONFATAL
,
848 "instruction has conflicting segment overrides");
850 result
->prefixes
[PPS_SEG
] = value
->type
;
851 if (IS_FSGS(value
->type
))
852 op
->eaflags
|= EAF_FSGS
;
855 i
= stdscan(NULL
, &tokval
); /* then skip the colon */
856 while (i
== TOKEN_SPECIAL
|| i
== TOKEN_PREFIX
) {
857 process_size_override(result
, op
);
858 i
= stdscan(NULL
, &tokval
);
860 value
= evaluate(stdscan
, NULL
, &tokval
,
862 critical
, nasm_error
, &hints
);
864 if (op
->opflags
& OPFLAG_FORWARD
) {
865 result
->forw_ref
= true;
867 /* and get the offset */
868 if (!value
) /* Error in evaluator */
873 if (mref
&& bracket
) { /* find ] at the end */
875 nasm_error(ERR_NONFATAL
, "parser: expecting ]");
877 } else { /* we got the required ] */
878 i
= stdscan(NULL
, &tokval
);
879 if ((i
== TOKEN_DECORATOR
) || (i
== TOKEN_OPMASK
)) {
881 * according to AVX512 spec, broacast or opmask decorator
882 * is expected for memory reference operands
884 if (tokval
.t_flag
& TFLAG_BRDCAST
) {
885 brace_flags
|= GEN_BRDCAST(0);
886 i
= stdscan(NULL
, &tokval
);
887 } else if (i
== TOKEN_OPMASK
) {
888 brace_flags
|= VAL_OPMASK(nasm_regvals
[tokval
.t_integer
]);
889 i
= stdscan(NULL
, &tokval
);
891 nasm_error(ERR_NONFATAL
, "broadcast or opmask "
892 "decorator expected inside braces");
897 if (i
!= 0 && i
!= ',') {
898 nasm_error(ERR_NONFATAL
, "comma or end of line expected");
902 } else { /* immediate operand */
903 if (i
!= 0 && i
!= ',' && i
!= ':' &&
904 i
!= TOKEN_DECORATOR
&& i
!= TOKEN_OPMASK
) {
905 nasm_error(ERR_NONFATAL
, "comma, colon, decorator or end of "
906 "line expected after operand");
908 } else if (i
== ':') {
910 } else if (i
== TOKEN_DECORATOR
|| i
== TOKEN_OPMASK
) {
911 /* parse opmask (and zeroing) after an operand */
912 recover
= parse_braces(&brace_flags
);
916 do { /* error recovery */
917 i
= stdscan(NULL
, &tokval
);
918 } while (i
!= 0 && i
!= ',');
922 * now convert the exprs returned from evaluate()
923 * into operand descriptions...
926 if (mref
) { /* it's a memory reference */
927 if (parse_mref(op
, value
, &hints
, brace_flags
))
929 } else { /* it's not a memory reference */
930 if (is_just_unknown(value
)) { /* it's immediate but unknown */
931 op
->type
|= IMMEDIATE
;
932 op
->opflags
|= OPFLAG_UNKNOWN
;
933 op
->offset
= 0; /* don't care */
934 op
->segment
= NO_SEG
; /* don't care again */
935 op
->wrt
= NO_SEG
; /* still don't care */
937 if(optimizing
>= 0 && !(op
->type
& STRICT
)) {
940 UNITY
| SBYTEWORD
| SBYTEDWORD
| UDWORD
| SDWORD
;
942 } else if (is_reloc(value
)) { /* it's immediate */
943 op
->type
|= IMMEDIATE
;
944 op
->offset
= reloc_value(value
);
945 op
->segment
= reloc_seg(value
);
946 op
->wrt
= reloc_wrt(value
);
948 if (is_simple(value
)) {
949 uint64_t n
= reloc_value(value
);
952 if (optimizing
>= 0 &&
953 !(op
->type
& STRICT
)) {
954 if ((uint32_t) (n
+ 128) <= 255)
955 op
->type
|= SBYTEDWORD
;
956 if ((uint16_t) (n
+ 128) <= 255)
957 op
->type
|= SBYTEWORD
;
960 if (n
+ 0x80000000 <= 0xFFFFFFFF)
964 } else if(value
->type
== EXPR_RDSAE
) {
966 * it's not an operand but a rounding or SAE decorator.
967 * put the decorator information in the (opflag_t) type field
968 * of previous operand.
971 switch (value
->value
) {
977 op
->decoflags
|= (value
->value
== BRC_SAE
? SAE
: ER
);
978 result
->evex_rm
= value
->value
;
981 nasm_error(ERR_NONFATAL
, "invalid decorator");
984 } else { /* it's a register */
987 if (value
->type
>= EXPR_SIMPLE
|| value
->value
!= 1) {
988 nasm_error(ERR_NONFATAL
, "invalid operand type");
993 * check that its only 1 register, not an expression...
995 for (i
= 1; value
[i
].type
; i
++)
996 if (value
[i
].value
) {
997 nasm_error(ERR_NONFATAL
, "invalid operand type");
1001 /* clear overrides, except TO which applies to FPU regs */
1002 if (op
->type
& ~TO
) {
1004 * we want to produce a warning iff the specified size
1005 * is different from the register size
1007 rs
= op
->type
& SIZE_MASK
;
1012 op
->type
|= REGISTER
;
1013 op
->type
|= nasm_reg_flags
[value
->type
];
1014 op
->decoflags
|= brace_flags
;
1015 op
->basereg
= value
->type
;
1017 if (rs
&& (op
->type
& SIZE_MASK
) != rs
)
1018 nasm_error(ERR_WARNING
| ERR_PASS1
,
1019 "register size specification ignored");
1023 /* remember the position of operand having broadcasting/ER mode */
1024 if (op
->decoflags
& (BRDCAST_MASK
| ER
| SAE
))
1025 result
->evex_brerop
= opnum
;
1028 result
->operands
= opnum
; /* set operand count */
1030 /* clear remaining operands */
1031 while (opnum
< MAX_OPERANDS
)
1032 result
->oprs
[opnum
++].type
= 0;
1035 * Transform RESW, RESD, RESQ, REST, RESO, RESY into RESB.
1037 switch (result
->opcode
) {
1039 result
->opcode
= I_RESB
;
1040 result
->oprs
[0].offset
*= 2;
1043 result
->opcode
= I_RESB
;
1044 result
->oprs
[0].offset
*= 4;
1047 result
->opcode
= I_RESB
;
1048 result
->oprs
[0].offset
*= 8;
1051 result
->opcode
= I_RESB
;
1052 result
->oprs
[0].offset
*= 10;
1055 result
->opcode
= I_RESB
;
1056 result
->oprs
[0].offset
*= 16;
1059 result
->opcode
= I_RESB
;
1060 result
->oprs
[0].offset
*= 32;
1069 result
->opcode
= I_none
;
1073 static int is_comma_next(void)
1080 i
= stdscan(NULL
, &tv
);
1083 return (i
== ',' || i
== ';' || !i
);
1086 void cleanup_insn(insn
* i
)
1090 while ((e
= i
->eops
)) {
1092 if (e
->type
== EOT_DB_STRING_FREE
)
1093 nasm_free(e
->stringval
);