From de38a0d27358fe36c9d0765948bebcb193845f8c Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Mon, 6 Nov 2006 02:33:11 +0000 Subject: [PATCH] Support "strict" in NASM parser. Still need to implement its desired behavior in the x86 architecture. svn path=/trunk/yasm/; revision=1679 --- libyasm/arch.c | 6 ++++++ libyasm/arch.h | 13 ++++++++++++- modules/parsers/nasm/nasm-bison.y | 3 ++- modules/parsers/nasm/nasm-token.re | 1 + 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/libyasm/arch.c b/libyasm/arch.c index 90f7a233..89872c57 100644 --- a/libyasm/arch.c +++ b/libyasm/arch.c @@ -48,6 +48,7 @@ yasm_operand_create_reg(unsigned long reg) retval->targetmod = 0; retval->size = 0; retval->deref = 0; + retval->strict = 0; return retval; } @@ -62,6 +63,7 @@ yasm_operand_create_segreg(unsigned long segreg) retval->targetmod = 0; retval->size = 0; retval->deref = 0; + retval->strict = 0; return retval; } @@ -76,6 +78,7 @@ yasm_operand_create_mem(/*@only@*/ yasm_effaddr *ea) retval->targetmod = 0; retval->size = 0; retval->deref = 0; + retval->strict = 0; return retval; } @@ -97,6 +100,7 @@ yasm_operand_create_imm(/*@only@*/ yasm_expr *val) retval->targetmod = 0; retval->size = 0; retval->deref = 0; + retval->strict = 0; } return retval; @@ -129,6 +133,8 @@ yasm_operand_print(const yasm_insn_operand *op, FILE *f, int indent_level, } fprintf(f, "%*sTargetMod=%lx\n", indent_level+1, "", op->targetmod); fprintf(f, "%*sSize=%u\n", indent_level+1, "", op->size); + fprintf(f, "%*sDeref=%d, Strict=%d\n", indent_level+1, "", (int)op->deref, + (int)op->strict); } void diff --git a/libyasm/arch.h b/libyasm/arch.h index 0d94c7b2..e285fe21 100644 --- a/libyasm/arch.h +++ b/libyasm/arch.h @@ -276,7 +276,18 @@ struct yasm_insn_operand { * to indicate the "*" prefix has been used, and the arch needs to adjust * the operand type appropriately depending on the instruction type. */ - int deref; + int deref:1; + + /** Nonzero if strict. Used for "strict foo" in NASM. + * This is used to inhibit optimization on otherwise "sized" values. + * For example, the user may just want to be explicit with the size on + * "push dword 4", but not actually want to force the immediate size to + * 4 bytes (rather wanting the optimizer to optimize it down to 1 byte as + * though "dword" was not specified). To indicate the immediate should + * actually be forced to 4 bytes, the user needs to write + * "push strict dword 4", which sets this flag. + */ + int strict:1; }; #endif diff --git a/modules/parsers/nasm/nasm-bison.y b/modules/parsers/nasm/nasm-bison.y index 60a33bbc..038df52d 100644 --- a/modules/parsers/nasm/nasm-bison.y +++ b/modules/parsers/nasm/nasm-bison.y @@ -96,7 +96,7 @@ static void define_label(yasm_parser_nasm *parser_nasm, /*@only@*/ char *name, %token DECLARE_DATA %token RESERVE_SPACE %token INCBIN EQU TIMES -%token SEG WRT NOSPLIT +%token SEG WRT NOSPLIT STRICT %token INSN PREFIX REG SEGREG TARGETMOD %token LEFT_OP RIGHT_OP SIGNDIV SIGNMOD START_SECTION_ID %token ID LOCAL_ID SPECIAL_ID @@ -358,6 +358,7 @@ operands: operand { operand: '[' memaddr ']' { $$ = yasm_operand_create_mem($2); } | expr { $$ = yasm_operand_create_imm($1); } | SEGREG { $$ = yasm_operand_create_segreg($1[0]); } + | STRICT operand { $$ = $2; $$->strict = 1; } | SIZE_OVERRIDE operand { $$ = $2; if ($$->type == YASM_INSN__OPERAND_REG && diff --git a/modules/parsers/nasm/nasm-token.re b/modules/parsers/nasm/nasm-token.re index 2dab17de..060b0bbb 100644 --- a/modules/parsers/nasm/nasm-token.re +++ b/modules/parsers/nasm/nasm-token.re @@ -294,6 +294,7 @@ scan: 'wrt' { RETURN(WRT); } 'nosplit' { RETURN(NOSPLIT); } + 'strict' { RETURN(STRICT); } /* operators */ "<<" { RETURN(LEFT_OP); } -- 2.40.0