1 /* ----------------------------------------------------------------------- *
3 * Copyright 1996-2017 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
58 static int is_comma_next(void);
60 static struct tokenval tokval
;
62 static int prefix_slot(int prefix
)
101 nasm_panic(0, "Invalid value %d passed to prefix_slot()", prefix
);
106 static void process_size_override(insn
*result
, operand
*op
)
108 if (tasm_compatible_mode
) {
109 switch (tokval
.t_integer
) {
110 /* For TASM compatibility a size override inside the
111 * brackets changes the size of the operand, not the
112 * address type of the operand as it does in standard
113 * NASM syntax. Hence:
115 * mov eax,[DWORD val]
117 * is valid syntax in TASM compatibility mode. Note that
118 * you lose the ability to override the default address
119 * type for the instruction, but we never use anything
120 * but 32-bit flat model addressing in our code.
142 nasm_error(ERR_NONFATAL
,
143 "invalid operand size specification");
147 /* Standard NASM compatible syntax */
148 switch (tokval
.t_integer
) {
150 op
->eaflags
|= EAF_TIMESTWO
;
153 op
->eaflags
|= EAF_REL
;
156 op
->eaflags
|= EAF_ABS
;
160 op
->eaflags
|= EAF_BYTEOFFS
;
165 if (result
->prefixes
[PPS_ASIZE
] &&
166 result
->prefixes
[PPS_ASIZE
] != tokval
.t_integer
)
167 nasm_error(ERR_NONFATAL
,
168 "conflicting address size specifications");
170 result
->prefixes
[PPS_ASIZE
] = tokval
.t_integer
;
174 op
->eaflags
|= EAF_WORDOFFS
;
179 op
->eaflags
|= EAF_WORDOFFS
;
183 op
->eaflags
|= EAF_WORDOFFS
;
186 nasm_error(ERR_NONFATAL
, "invalid size specification in"
187 " effective address");
194 * Brace decorators are are parsed here. opmask and zeroing
195 * decorators can be placed in any order. e.g. zmm1 {k2}{z} or zmm2
196 * {z}{k3} decorator(s) are placed at the end of an operand.
198 static bool parse_braces(decoflags_t
*decoflags
)
207 if (*decoflags
& OPMASK_MASK
) {
208 nasm_error(ERR_NONFATAL
,
209 "opmask k%"PRIu64
" is already set",
210 *decoflags
& OPMASK_MASK
);
211 *decoflags
&= ~OPMASK_MASK
;
213 *decoflags
|= VAL_OPMASK(nasm_regvals
[tokval
.t_integer
]);
215 case TOKEN_DECORATOR
:
216 j
= tokval
.t_integer
;
219 *decoflags
|= Z_MASK
;
225 *decoflags
|= BRDCAST_MASK
| VAL_BRNUM(j
- BRC_1TO2
);
228 nasm_error(ERR_NONFATAL
,
229 "{%s} is not an expected decorator",
238 nasm_error(ERR_NONFATAL
,
239 "only a series of valid decorators expected");
242 i
= stdscan(NULL
, &tokval
);
246 static int parse_mref(operand
*op
, const expr
*e
)
248 int b
, i
, s
; /* basereg, indexreg, scale */
249 int64_t o
; /* offset */
253 op
->segment
= op
->wrt
= NO_SEG
;
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");
280 if (e
->type
) { /* is there an offset? */
281 if (e
->type
<= EXPR_REG_END
) { /* in fact, is there an error? */
282 nasm_error(ERR_NONFATAL
,
283 "invalid effective address: impossible register");
286 if (e
->type
== EXPR_UNKNOWN
) {
287 op
->opflags
|= OPFLAG_UNKNOWN
;
288 o
= 0; /* doesn't matter what */
290 e
++; /* go to the end of the line */
292 if (e
->type
== EXPR_SIMPLE
) {
296 if (e
->type
== EXPR_WRT
) {
301 * Look for a segment base type.
303 for (; e
->type
; e
++) {
307 if (e
->type
<= EXPR_REG_END
) {
308 nasm_error(ERR_NONFATAL
,
309 "invalid effective address: too many registers");
311 } else if (e
->type
< EXPR_SEGBASE
) {
312 nasm_error(ERR_NONFATAL
,
313 "invalid effective address: bad subexpression type");
315 } else if (e
->value
== 1) {
316 if (op
->segment
!= NO_SEG
) {
317 nasm_error(ERR_NONFATAL
,
318 "invalid effective address: multiple base segments");
321 op
->segment
= e
->type
- EXPR_SEGBASE
;
322 } else if (e
->value
== -1 &&
323 e
->type
== location
.segment
+ EXPR_SEGBASE
&&
324 !(op
->opflags
& OPFLAG_RELATIVE
)) {
325 op
->opflags
|= OPFLAG_RELATIVE
;
327 nasm_error(ERR_NONFATAL
,
328 "invalid effective address: impossible segment base multiplier");
336 nasm_assert(!e
->type
); /* We should be at the end */
345 static void mref_set_optype(operand
*op
)
348 int i
= op
->indexreg
;
351 /* It is memory, but it can match any r/m operand */
352 op
->type
|= MEMORY_ANY
;
354 if (b
== -1 && (i
== -1 || s
== 0)) {
355 int is_rel
= globalbits
== 64 &&
356 !(op
->eaflags
& EAF_ABS
) &&
358 !(op
->eaflags
& EAF_FSGS
)) ||
359 (op
->eaflags
& EAF_REL
));
361 op
->type
|= is_rel
? IP_REL
: MEM_OFFS
;
365 opflags_t iclass
= nasm_reg_flags
[i
];
367 if (is_class(XMMREG
,iclass
))
369 else if (is_class(YMMREG
,iclass
))
371 else if (is_class(ZMMREG
,iclass
))
377 * Convert an expression vector returned from evaluate() into an
378 * extop structure. Return zero on success.
380 static int value_to_extop(expr
* vect
, extop
*eop
, int32_t myseg
)
382 eop
->type
= EOT_DB_NUMBER
;
384 eop
->segment
= eop
->wrt
= NO_SEG
;
385 eop
->relative
= false;
387 for (; vect
->type
; vect
++) {
388 if (!vect
->value
) /* zero term, safe to ignore */
391 if (vect
->type
<= EXPR_REG_END
) /* false if a register is present */
394 if (vect
->type
== EXPR_UNKNOWN
) /* something we can't resolve yet */
397 if (vect
->type
== EXPR_SIMPLE
) {
398 /* Simple number expression */
399 eop
->offset
+= vect
->value
;
402 if (eop
->wrt
== NO_SEG
&& !eop
->relative
&& vect
->type
== EXPR_WRT
) {
404 eop
->wrt
= vect
->value
;
408 if (!eop
->relative
&&
409 vect
->type
== EXPR_SEGBASE
+ myseg
&& vect
->value
== -1) {
410 /* Expression of the form: foo - $ */
411 eop
->relative
= true;
415 if (eop
->segment
== NO_SEG
&& vect
->type
>= EXPR_SEGBASE
&&
417 eop
->segment
= vect
->type
- EXPR_SEGBASE
;
421 /* Otherwise, badness */
425 /* We got to the end and it was all okay */
429 insn
*parse_line(int pass
, char *buffer
, insn
*result
, ldfunc ldef
)
431 bool insn_is_label
= false;
432 struct eval_hints hints
;
441 result
->forw_ref
= false;
445 i
= stdscan(NULL
, &tokval
);
447 nasm_static_assert(P_none
== 0);
448 memset(result
->prefixes
, P_none
, sizeof(result
->prefixes
));
449 result
->times
= 1; /* No TIMES either yet */
450 result
->label
= NULL
; /* Assume no label */
451 result
->eops
= NULL
; /* must do this, whatever happens */
452 result
->operands
= 0; /* must initialize this */
453 result
->evex_rm
= 0; /* Ensure EVEX rounding mode is reset */
454 result
->evex_brerop
= -1; /* Reset EVEX broadcasting/ER op position */
456 /* Ignore blank lines */
463 (i
!= TOKEN_REG
|| !IS_SREG(tokval
.t_integer
))) {
464 nasm_error(ERR_NONFATAL
,
465 "label or instruction expected at start of line");
469 if (i
== TOKEN_ID
|| (insn_is_label
&& i
== TOKEN_INSN
)) {
470 /* there's a label here */
472 result
->label
= tokval
.t_charptr
;
473 i
= stdscan(NULL
, &tokval
);
474 if (i
== ':') { /* skip over the optional colon */
475 i
= stdscan(NULL
, &tokval
);
477 nasm_error(ERR_WARNING
| ERR_WARN_OL
| ERR_PASS1
,
478 "label alone on a line without a colon might be in error");
480 if (i
!= TOKEN_INSN
|| tokval
.t_integer
!= I_EQU
) {
482 * FIXME: location.segment could be NO_SEG, in which case
483 * it is possible we should be passing 'absolute.segment'. Look into this.
484 * Work out whether that is *really* what we should be doing.
485 * Generally fix things. I think this is right as it is, but
486 * am still not certain.
488 ldef(result
->label
, in_absolute
? absolute
.segment
: location
.segment
,
489 location
.offset
, NULL
, true, false);
493 /* Just a label here */
497 while (i
== TOKEN_PREFIX
||
498 (i
== TOKEN_REG
&& IS_SREG(tokval
.t_integer
))) {
502 * Handle special case: the TIMES prefix.
504 if (i
== TOKEN_PREFIX
&& tokval
.t_integer
== P_TIMES
) {
507 i
= stdscan(NULL
, &tokval
);
508 value
= evaluate(stdscan
, NULL
, &tokval
, NULL
, pass0
, NULL
);
510 if (!value
) /* Error in evaluator */
512 if (!is_simple(value
)) {
513 nasm_error(ERR_NONFATAL
,
514 "non-constant argument supplied to TIMES");
517 result
->times
= value
->value
;
518 if (value
->value
< 0 && pass0
== 2) {
519 nasm_error(ERR_NONFATAL
, "TIMES value %"PRId64
" is negative",
525 int slot
= prefix_slot(tokval
.t_integer
);
526 if (result
->prefixes
[slot
]) {
527 if (result
->prefixes
[slot
] == tokval
.t_integer
)
528 nasm_error(ERR_WARNING
| ERR_PASS1
,
529 "instruction has redundant prefixes");
531 nasm_error(ERR_NONFATAL
,
532 "instruction has conflicting prefixes");
534 result
->prefixes
[slot
] = tokval
.t_integer
;
535 i
= stdscan(NULL
, &tokval
);
539 if (i
!= TOKEN_INSN
) {
543 for (j
= 0; j
< MAXPREFIX
; j
++) {
544 if ((pfx
= result
->prefixes
[j
]) != P_none
)
548 if (i
== 0 && pfx
!= P_none
) {
550 * Instruction prefixes are present, but no actual
551 * instruction. This is allowed: at this point we
552 * invent a notional instruction of RESB 0.
554 result
->opcode
= I_RESB
;
555 result
->operands
= 1;
556 nasm_zero(result
->oprs
);
557 result
->oprs
[0].type
= IMMEDIATE
;
558 result
->oprs
[0].offset
= 0L;
559 result
->oprs
[0].segment
= result
->oprs
[0].wrt
= NO_SEG
;
562 nasm_error(ERR_NONFATAL
, "parser: instruction expected");
567 result
->opcode
= tokval
.t_integer
;
568 result
->condition
= tokval
.t_inttwo
;
571 * INCBIN cannot be satisfied with incorrectly
572 * evaluated operands, since the correct values _must_ be known
573 * on the first pass. Hence, even in pass one, we set the
574 * `critical' flag on calling evaluate(), so that it will bomb
575 * out on undefined symbols.
577 if (result
->opcode
== I_INCBIN
) {
578 critical
= (pass0
< 2 ? 1 : 2);
581 critical
= (pass
== 2 ? 2 : 0);
583 if (opcode_is_db(result
->opcode
) || result
->opcode
== I_INCBIN
) {
584 extop
*eop
, **tail
= &result
->eops
, **fixptr
;
588 result
->eops_float
= false;
591 * Begin to read the DB/DW/DD/DQ/DT/DO/DY/DZ/INCBIN operands.
594 i
= stdscan(NULL
, &tokval
);
597 else if (first
&& i
== ':') {
598 insn_is_label
= true;
603 eop
= *tail
= nasm_malloc(sizeof(extop
));
606 eop
->type
= EOT_NOTHING
;
611 * is_comma_next() here is to distinguish this from
612 * a string used as part of an expression...
614 if (i
== TOKEN_STR
&& is_comma_next()) {
615 eop
->type
= EOT_DB_STRING
;
616 eop
->stringval
= tokval
.t_charptr
;
617 eop
->stringlen
= tokval
.t_inttwo
;
618 i
= stdscan(NULL
, &tokval
); /* eat the comma */
619 } else if (i
== TOKEN_STRFUNC
) {
621 const char *funcname
= tokval
.t_charptr
;
622 enum strfunc func
= tokval
.t_integer
;
623 i
= stdscan(NULL
, &tokval
);
626 i
= stdscan(NULL
, &tokval
);
628 if (i
!= TOKEN_STR
) {
629 nasm_error(ERR_NONFATAL
,
630 "%s must be followed by a string constant",
632 eop
->type
= EOT_NOTHING
;
634 eop
->type
= EOT_DB_STRING_FREE
;
636 string_transform(tokval
.t_charptr
, tokval
.t_inttwo
,
637 &eop
->stringval
, func
);
638 if (eop
->stringlen
== (size_t)-1) {
639 nasm_error(ERR_NONFATAL
, "invalid string for transform");
640 eop
->type
= EOT_NOTHING
;
643 if (parens
&& i
&& i
!= ')') {
644 i
= stdscan(NULL
, &tokval
);
646 nasm_error(ERR_NONFATAL
, "unterminated %s function",
651 i
= stdscan(NULL
, &tokval
);
652 } else if (i
== '-' || i
== '+') {
653 char *save
= stdscan_get();
655 sign
= (i
== '-') ? -1 : 1;
656 i
= stdscan(NULL
, &tokval
);
657 if (i
!= TOKEN_FLOAT
) {
659 i
= tokval
.t_type
= token
;
664 } else if (i
== TOKEN_FLOAT
) {
666 eop
->type
= EOT_DB_STRING
;
667 result
->eops_float
= true;
669 eop
->stringlen
= idata_bytes(result
->opcode
);
670 if (eop
->stringlen
> 16) {
671 nasm_error(ERR_NONFATAL
, "floating-point constant"
672 " encountered in DY or DZ instruction");
674 } else if (eop
->stringlen
< 1) {
675 nasm_error(ERR_NONFATAL
, "floating-point constant"
676 " encountered in unknown instruction");
678 * fix suggested by Pedro Gimeno... original line was:
679 * eop->type = EOT_NOTHING;
684 eop
= nasm_realloc(eop
, sizeof(extop
) + eop
->stringlen
);
687 eop
->stringval
= (char *)eop
+ sizeof(extop
);
688 if (!eop
->stringlen
||
689 !float_const(tokval
.t_charptr
, sign
,
690 (uint8_t *)eop
->stringval
, eop
->stringlen
))
691 eop
->type
= EOT_NOTHING
;
692 i
= stdscan(NULL
, &tokval
); /* eat the comma */
694 /* anything else, assume it is an expression */
698 value
= evaluate(stdscan
, NULL
, &tokval
, NULL
,
701 if (!value
) /* Error in evaluator */
703 if (value_to_extop(value
, eop
, location
.segment
)) {
704 nasm_error(ERR_NONFATAL
,
705 "operand %d: expression is not simple or relocatable",
711 * We're about to call stdscan(), which will eat the
712 * comma that we're currently sitting on between
713 * arguments. However, we'd better check first that it
716 if (i
== TOKEN_EOS
) /* also could be EOL */
719 nasm_error(ERR_NONFATAL
, "comma expected after operand %d",
725 if (result
->opcode
== I_INCBIN
) {
727 * Correct syntax for INCBIN is that there should be
728 * one string operand, followed by one or two numeric
731 if (!result
->eops
|| result
->eops
->type
!= EOT_DB_STRING
)
732 nasm_error(ERR_NONFATAL
, "`incbin' expects a file name");
733 else if (result
->eops
->next
&&
734 result
->eops
->next
->type
!= EOT_DB_NUMBER
)
735 nasm_error(ERR_NONFATAL
, "`incbin': second parameter is"
737 else if (result
->eops
->next
&& result
->eops
->next
->next
&&
738 result
->eops
->next
->next
->type
!= EOT_DB_NUMBER
)
739 nasm_error(ERR_NONFATAL
, "`incbin': third parameter is"
741 else if (result
->eops
->next
&& result
->eops
->next
->next
&&
742 result
->eops
->next
->next
->next
)
743 nasm_error(ERR_NONFATAL
,
744 "`incbin': more than three parameters");
748 * If we reach here, one of the above errors happened.
749 * Throw the instruction away.
752 } else /* DB ... */ if (oper_num
== 0)
753 nasm_error(ERR_WARNING
| ERR_PASS1
,
754 "no operand for data declaration");
756 result
->operands
= oper_num
;
762 * Now we begin to parse the operands. There may be up to four
763 * of these, separated by commas, and terminated by a zero token.
766 for (opnum
= 0; opnum
< MAX_OPERANDS
; opnum
++) {
767 operand
*op
= &result
->oprs
[opnum
];
768 expr
*value
; /* used most of the time */
769 bool mref
; /* is this going to be a memory ref? */
770 bool bracket
; /* is it a [] mref, or a & mref? */
771 bool mib
; /* compound (mib) mref? */
773 decoflags_t brace_flags
= 0; /* flags for decorators in braces */
775 op
->disp_size
= 0; /* have to zero this whatever */
776 op
->eaflags
= 0; /* and this */
780 i
= stdscan(NULL
, &tokval
);
782 break; /* end of operands: get out of here */
783 else if (first
&& i
== ':') {
784 insn_is_label
= true;
788 op
->type
= 0; /* so far, no override */
789 while (i
== TOKEN_SPECIAL
) { /* size specifiers */
790 switch (tokval
.t_integer
) {
792 if (!setsize
) /* we want to use only the first */
848 nasm_error(ERR_NONFATAL
, "invalid operand size specification");
850 i
= stdscan(NULL
, &tokval
);
853 if (i
== '[' || i
== '&') { /* memory reference */
855 bracket
= (i
== '[');
856 i
= stdscan(NULL
, &tokval
); /* then skip the colon */
857 while (i
== TOKEN_SPECIAL
|| i
== TOKEN_PREFIX
) {
858 process_size_override(result
, op
);
859 i
= stdscan(NULL
, &tokval
);
861 /* when a comma follows an opening bracket - [ , eax*4] */
863 /* treat as if there is a zero displacement virtually */
864 tokval
.t_type
= TOKEN_NUM
;
865 tokval
.t_integer
= 0;
866 stdscan_set(stdscan_get() - 1); /* rewind the comma */
868 } else { /* immediate operand, or register */
870 bracket
= false; /* placate optimisers */
873 if ((op
->type
& FAR
) && !mref
&&
874 result
->opcode
!= I_JMP
&& result
->opcode
!= I_CALL
) {
875 nasm_error(ERR_NONFATAL
, "invalid use of FAR operand specifier");
878 value
= evaluate(stdscan
, NULL
, &tokval
,
879 &op
->opflags
, critical
, &hints
);
881 if (op
->opflags
& OPFLAG_FORWARD
) {
882 result
->forw_ref
= true;
884 if (!value
) /* Error in evaluator */
886 if (i
== ':' && mref
) { /* it was seg:offset */
888 * Process the segment override.
890 if (value
[1].type
!= 0 ||
892 !IS_SREG(value
->type
))
893 nasm_error(ERR_NONFATAL
, "invalid segment override");
894 else if (result
->prefixes
[PPS_SEG
])
895 nasm_error(ERR_NONFATAL
,
896 "instruction has conflicting segment overrides");
898 result
->prefixes
[PPS_SEG
] = value
->type
;
899 if (IS_FSGS(value
->type
))
900 op
->eaflags
|= EAF_FSGS
;
903 i
= stdscan(NULL
, &tokval
); /* then skip the colon */
904 while (i
== TOKEN_SPECIAL
|| i
== TOKEN_PREFIX
) {
905 process_size_override(result
, op
);
906 i
= stdscan(NULL
, &tokval
);
908 value
= evaluate(stdscan
, NULL
, &tokval
,
909 &op
->opflags
, critical
, &hints
);
911 if (op
->opflags
& OPFLAG_FORWARD
) {
912 result
->forw_ref
= true;
914 /* and get the offset */
915 if (!value
) /* Error in evaluator */
920 if (mref
&& bracket
&& i
== ',') {
921 /* [seg:base+offset,index*scale] syntax (mib) */
923 operand o1
, o2
; /* Partial operands */
925 if (parse_mref(&o1
, value
))
928 i
= stdscan(NULL
, &tokval
); /* Eat comma */
929 value
= evaluate(stdscan
, NULL
, &tokval
, &op
->opflags
,
935 if (parse_mref(&o2
, value
))
938 if (o2
.basereg
!= -1 && o2
.indexreg
== -1) {
939 o2
.indexreg
= o2
.basereg
;
944 if (o1
.indexreg
!= -1 || o2
.basereg
!= -1 || o2
.offset
!= 0 ||
945 o2
.segment
!= NO_SEG
|| o2
.wrt
!= NO_SEG
) {
946 nasm_error(ERR_NONFATAL
, "invalid mib expression");
950 op
->basereg
= o1
.basereg
;
951 op
->indexreg
= o2
.indexreg
;
952 op
->scale
= o2
.scale
;
953 op
->offset
= o1
.offset
;
954 op
->segment
= o1
.segment
;
957 if (op
->basereg
!= -1) {
958 op
->hintbase
= op
->basereg
;
959 op
->hinttype
= EAH_MAKEBASE
;
960 } else if (op
->indexreg
!= -1) {
961 op
->hintbase
= op
->indexreg
;
962 op
->hinttype
= EAH_NOTBASE
;
965 op
->hinttype
= EAH_NOHINT
;
972 if (mref
&& bracket
) { /* find ] at the end */
974 nasm_error(ERR_NONFATAL
, "parser: expecting ]");
976 } else { /* we got the required ] */
977 i
= stdscan(NULL
, &tokval
);
978 if (i
== TOKEN_DECORATOR
|| i
== TOKEN_OPMASK
) {
979 /* parse opmask (and zeroing) after an operand */
980 recover
= parse_braces(&brace_flags
);
983 if (i
!= 0 && i
!= ',') {
984 nasm_error(ERR_NONFATAL
, "comma or end of line expected");
988 } else { /* immediate operand */
989 if (i
!= 0 && i
!= ',' && i
!= ':' &&
990 i
!= TOKEN_DECORATOR
&& i
!= TOKEN_OPMASK
) {
991 nasm_error(ERR_NONFATAL
, "comma, colon, decorator or end of "
992 "line expected after operand");
994 } else if (i
== ':') {
996 } else if (i
== TOKEN_DECORATOR
|| i
== TOKEN_OPMASK
) {
997 /* parse opmask (and zeroing) after an operand */
998 recover
= parse_braces(&brace_flags
);
1002 do { /* error recovery */
1003 i
= stdscan(NULL
, &tokval
);
1004 } while (i
!= 0 && i
!= ',');
1008 * now convert the exprs returned from evaluate()
1009 * into operand descriptions...
1011 op
->decoflags
|= brace_flags
;
1013 if (mref
) { /* it's a memory reference */
1014 /* A mib reference was fully parsed already */
1016 if (parse_mref(op
, value
))
1018 op
->hintbase
= hints
.base
;
1019 op
->hinttype
= hints
.type
;
1021 mref_set_optype(op
);
1022 } else { /* it's not a memory reference */
1023 if (is_just_unknown(value
)) { /* it's immediate but unknown */
1024 op
->type
|= IMMEDIATE
;
1025 op
->opflags
|= OPFLAG_UNKNOWN
;
1026 op
->offset
= 0; /* don't care */
1027 op
->segment
= NO_SEG
; /* don't care again */
1028 op
->wrt
= NO_SEG
; /* still don't care */
1030 if(optimizing
>= 0 && !(op
->type
& STRICT
)) {
1033 UNITY
| SBYTEWORD
| SBYTEDWORD
| UDWORD
| SDWORD
;
1035 } else if (is_reloc(value
)) { /* it's immediate */
1036 uint64_t n
= reloc_value(value
);
1038 op
->type
|= IMMEDIATE
;
1040 op
->segment
= reloc_seg(value
);
1041 op
->wrt
= reloc_wrt(value
);
1042 op
->opflags
|= is_self_relative(value
) ? OPFLAG_RELATIVE
: 0;
1044 if (is_simple(value
)) {
1047 if (optimizing
>= 0 && !(op
->type
& STRICT
)) {
1048 if ((uint32_t) (n
+ 128) <= 255)
1049 op
->type
|= SBYTEDWORD
;
1050 if ((uint16_t) (n
+ 128) <= 255)
1051 op
->type
|= SBYTEWORD
;
1052 if (n
<= UINT64_C(0xFFFFFFFF))
1054 if (n
+ UINT64_C(0x80000000) <= UINT64_C(0xFFFFFFFF))
1058 } else if (value
->type
== EXPR_RDSAE
) {
1060 * it's not an operand but a rounding or SAE decorator.
1061 * put the decorator information in the (opflag_t) type field
1062 * of previous operand.
1065 switch (value
->value
) {
1071 op
->decoflags
|= (value
->value
== BRC_SAE
? SAE
: ER
);
1072 result
->evex_rm
= value
->value
;
1075 nasm_error(ERR_NONFATAL
, "invalid decorator");
1078 } else { /* it's a register */
1081 if (value
->type
>= EXPR_SIMPLE
|| value
->value
!= 1) {
1082 nasm_error(ERR_NONFATAL
, "invalid operand type");
1087 * check that its only 1 register, not an expression...
1089 for (i
= 1; value
[i
].type
; i
++)
1090 if (value
[i
].value
) {
1091 nasm_error(ERR_NONFATAL
, "invalid operand type");
1095 /* clear overrides, except TO which applies to FPU regs */
1096 if (op
->type
& ~TO
) {
1098 * we want to produce a warning iff the specified size
1099 * is different from the register size
1101 rs
= op
->type
& SIZE_MASK
;
1106 op
->type
|= REGISTER
;
1107 op
->type
|= nasm_reg_flags
[value
->type
];
1108 op
->decoflags
|= brace_flags
;
1109 op
->basereg
= value
->type
;
1111 if (rs
&& (op
->type
& SIZE_MASK
) != rs
)
1112 nasm_error(ERR_WARNING
| ERR_PASS1
,
1113 "register size specification ignored");
1117 /* remember the position of operand having broadcasting/ER mode */
1118 if (op
->decoflags
& (BRDCAST_MASK
| ER
| SAE
))
1119 result
->evex_brerop
= opnum
;
1122 result
->operands
= opnum
; /* set operand count */
1124 /* clear remaining operands */
1125 while (opnum
< MAX_OPERANDS
)
1126 result
->oprs
[opnum
++].type
= 0;
1129 * Transform RESW, RESD, RESQ, REST, RESO, RESY, RESZ into RESB.
1131 if (opcode_is_resb(result
->opcode
)) {
1132 result
->oprs
[0].offset
*= resv_bytes(result
->opcode
);
1133 result
->oprs
[0].offset
*= result
->times
;
1135 result
->opcode
= I_RESB
;
1141 result
->opcode
= I_none
;
1145 static int is_comma_next(void)
1152 i
= stdscan(NULL
, &tv
);
1155 return (i
== ',' || i
== ';' || !i
);
1158 void cleanup_insn(insn
* i
)
1162 while ((e
= i
->eops
)) {
1164 if (e
->type
== EOT_DB_STRING_FREE
)
1165 nasm_free(e
->stringval
);