]> granicus.if.org Git - yasm/commitdiff
Support "strict" in NASM parser. Still need to implement its desired
authorPeter Johnson <peter@tortall.net>
Mon, 6 Nov 2006 02:33:11 +0000 (02:33 -0000)
committerPeter Johnson <peter@tortall.net>
Mon, 6 Nov 2006 02:33:11 +0000 (02:33 -0000)
behavior in the x86 architecture.

svn path=/trunk/yasm/; revision=1679

libyasm/arch.c
libyasm/arch.h
modules/parsers/nasm/nasm-bison.y
modules/parsers/nasm/nasm-token.re

index 90f7a2333917443d0d6a4975f322aa61e131aef3..89872c5741acb30f6b8029236c3fd6bbd6aebdc4 100644 (file)
@@ -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
index 0d94c7b20ed1961aafba308c0b2925409dc5381d..e285fe21e392334eb17a293850a6f10c84f31ec9 100644 (file)
@@ -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
 
index 60a33bbc2f768bbcc8e0b13c1c523bd2abc5fa9d..038df52dfbd0b93602f5be58de43bb7006faeb75 100644 (file)
@@ -96,7 +96,7 @@ static void define_label(yasm_parser_nasm *parser_nasm, /*@only@*/ char *name,
 %token <int_info> DECLARE_DATA
 %token <int_info> RESERVE_SPACE
 %token INCBIN EQU TIMES
-%token SEG WRT NOSPLIT
+%token SEG WRT NOSPLIT STRICT
 %token <arch_data> INSN PREFIX REG SEGREG TARGETMOD
 %token LEFT_OP RIGHT_OP SIGNDIV SIGNMOD START_SECTION_ID
 %token <str_val> 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 &&
index 2dab17de0a9809030be3ac8eb9bc9735c4825802..060b0bbb04bde20315e876abeace5b67eb2e4927 100644 (file)
@@ -294,6 +294,7 @@ scan:
        'wrt'           { RETURN(WRT); }
 
        'nosplit'       { RETURN(NOSPLIT); }
+       'strict'        { RETURN(STRICT); }
 
        /* operators */
        "<<"                    { RETURN(LEFT_OP); }