]> granicus.if.org Git - yasm/commitdiff
Fix use of arithmetic with single-character constants in data declarations.
authorPeter Johnson <peter@tortall.net>
Thu, 1 Jun 2006 06:40:12 +0000 (06:40 -0000)
committerPeter Johnson <peter@tortall.net>
Thu, 1 Jun 2006 06:40:12 +0000 (06:40 -0000)
Multi-character constants are still not valid, as they are somewhat
difficult to handle without adding some sort of string handling into
yasm_expr.  This fix may break big-endian targets (we don't have any yet).

* nasm-bison.y: Add new token ONECHARSTR.  Add string rule that takes
STRING and ONECHARSTR; use this instead of STRING everywhere but dataval.
In dvexpr, take ONECHARSTR as character constant.
* nasm-token.re: Generate ONECHARSTR for one-character string contants.

Reported by: Robert Riebisch <rr@bttr-software.de>

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

modules/parsers/nasm/nasm-bison.y
modules/parsers/nasm/nasm-token.re
modules/parsers/nasm/tests/Makefile.inc
modules/parsers/nasm/tests/charconstmath.asm [new file with mode: 0644]
modules/parsers/nasm/tests/charconstmath.errwarn [new file with mode: 0644]
modules/parsers/nasm/tests/charconstmath.hex [new file with mode: 0644]

index ab5c0b67e7390f4a581204e8b241b435bfb59388..d874f2ed1bdee68ffe73b9ea8e2a1737bf8df96f 100644 (file)
@@ -91,7 +91,7 @@ static void define_label(yasm_parser_nasm *parser_nasm, /*@only@*/ char *name,
 %token <intn> INTNUM
 %token <flt> FLTNUM
 %token <str_val> DIRECTIVE_NAME FILENAME
-%token <str> STRING
+%token <str> STRING ONECHARSTR
 %token <int_info> SIZE_OVERRIDE
 %token <int_info> DECLARE_DATA
 %token <int_info> RESERVE_SPACE
@@ -114,6 +114,7 @@ static void define_label(yasm_parser_nasm *parser_nasm, /*@only@*/ char *name,
 %type <dir_valparam> directive_valparam
 %type <insn_operands> operands
 %type <insn_operand> operand
+%type <str> string
 
 %left ':'
 %left WRT
@@ -202,19 +203,19 @@ exp: instr
     | RESERVE_SPACE expr               {
        $$ = yasm_bc_create_reserve($2, $1/8, cur_line);
     }
-    | INCBIN STRING                    {
+    | INCBIN string                    {
        $$ = yasm_bc_create_incbin($2.contents, NULL, NULL, cur_line);
     }
-    | INCBIN STRING ','                        {
+    | INCBIN string ','                        {
        $$ = yasm_bc_create_incbin($2.contents, NULL, NULL, cur_line);
     }
-    | INCBIN STRING ',' expr           {
+    | INCBIN string ',' expr           {
        $$ = yasm_bc_create_incbin($2.contents, $4, NULL, cur_line);
     }
-    | INCBIN STRING ',' expr ','       {
+    | INCBIN string ',' expr ','       {
        $$ = yasm_bc_create_incbin($2.contents, $4, NULL, cur_line);
     }
-    | INCBIN STRING ',' expr ',' expr  {
+    | INCBIN string ',' expr ',' expr  {
        $$ = yasm_bc_create_incbin($2.contents, $4, $6, cur_line);
     }
 ;
@@ -317,7 +318,7 @@ directive_valparam: direxpr {
            $$ = yasm_vp_create(NULL, $1);
        }
     }
-    | STRING                   { $$ = yasm_vp_create($1.contents, NULL); }
+    | string                   { $$ = yasm_vp_create($1.contents, NULL); }
     | ID '=' direxpr           {
        yasm_expr__traverse_leaves_in($3, parser_nasm, fix_directive_symrec);
        $$ = yasm_vp_create($1, $3);
@@ -394,6 +395,11 @@ direxpr: INTNUM                    { $$ = p_expr_new_ident(yasm_expr_int($1)); }
 
 dvexpr: INTNUM             { $$ = p_expr_new_ident(yasm_expr_int($1)); }
     | FLTNUM               { $$ = p_expr_new_ident(yasm_expr_float($1)); }
+    | ONECHARSTR           {
+       $$ = p_expr_new_ident(yasm_expr_int(
+           yasm_intnum_create_charconst_nasm($1.contents)));
+       yasm_xfree($1.contents);
+    }
     | explabel             { $$ = p_expr_new_ident(yasm_expr_sym($1)); }
     /*| dvexpr '||' dvexpr  { $$ = p_expr_new_tree($1, YASM_EXPR_LOR, $3); }*/
     | dvexpr '|' dvexpr            { $$ = p_expr_new_tree($1, YASM_EXPR_OR, $3); }
@@ -426,12 +432,12 @@ dvexpr: INTNUM                { $$ = p_expr_new_ident(yasm_expr_int($1)); }
 
 /* Expressions for operands and memory expressions.
  * We don't attempt to check memory expressions for validity here.
- * Essentially the same as expr_no_string above but adds REG and STRING.
+ * Essentially the same as dvexpr above but adds REG and string.
  */
 expr: INTNUM           { $$ = p_expr_new_ident(yasm_expr_int($1)); }
     | FLTNUM           { $$ = p_expr_new_ident(yasm_expr_float($1)); }
     | REG              { $$ = p_expr_new_ident(yasm_expr_reg($1[0])); }
-    | STRING           {
+    | string           {
        $$ = p_expr_new_ident(yasm_expr_int(
            yasm_intnum_create_charconst_nasm($1.contents)));
        yasm_xfree($1.contents);
@@ -491,6 +497,8 @@ explabel: ID                {
     }
 ;
 
+string: STRING | ONECHARSTR;
+
 %%
 /*@=usedef =nullassign =memtrans =usereleased =compdef =mustfree@*/
 
index b529e35099827c8c6a86213c429e20b5fe5f50bf..4030e0d90dfb525dbcc88c65085b3248e65aaae3 100644 (file)
@@ -542,6 +542,8 @@ stringconst_scan:
            lvalp->str.len = count;
            if (parser_nasm->save_input && cursor != s->eof)
                cursor = save_line(parser_nasm, cursor);
+           if (count == 1)
+               RETURN(ONECHARSTR);
            RETURN(STRING);
        }
 
@@ -550,6 +552,8 @@ stringconst_scan:
                strbuf[count] = '\0';
                lvalp->str.contents = (char *)strbuf;
                lvalp->str.len = count;
+               if (count == 1)
+                   RETURN(ONECHARSTR);
                RETURN(STRING);
            }
 
index a435179869ea49cd0f41318bf786ce9b3eceb6ed..4c9fdf8f7bedb08ff1f12d7b80252ffd7d539ce8 100644 (file)
@@ -9,6 +9,9 @@ EXTRA_DIST += modules/parsers/nasm/tests/alignnop16.hex
 EXTRA_DIST += modules/parsers/nasm/tests/alignnop32.asm
 EXTRA_DIST += modules/parsers/nasm/tests/alignnop32.errwarn
 EXTRA_DIST += modules/parsers/nasm/tests/alignnop32.hex
+EXTRA_DIST += modules/parsers/nasm/tests/charconstmath.asm
+EXTRA_DIST += modules/parsers/nasm/tests/charconstmath.errwarn
+EXTRA_DIST += modules/parsers/nasm/tests/charconstmath.hex
 EXTRA_DIST += modules/parsers/nasm/tests/endcomma.asm
 EXTRA_DIST += modules/parsers/nasm/tests/endcomma.errwarn
 EXTRA_DIST += modules/parsers/nasm/tests/endcomma.hex
diff --git a/modules/parsers/nasm/tests/charconstmath.asm b/modules/parsers/nasm/tests/charconstmath.asm
new file mode 100644 (file)
index 0000000..b673bab
--- /dev/null
@@ -0,0 +1 @@
+db "string", " "+80h
diff --git a/modules/parsers/nasm/tests/charconstmath.errwarn b/modules/parsers/nasm/tests/charconstmath.errwarn
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/modules/parsers/nasm/tests/charconstmath.hex b/modules/parsers/nasm/tests/charconstmath.hex
new file mode 100644 (file)
index 0000000..199e34f
--- /dev/null
@@ -0,0 +1,7 @@
+73 
+74 
+72 
+69 
+6e 
+67 
+a0