]> granicus.if.org Git - yasm/commitdiff
More cleanly implement size overrides (based on arch word size).
authorPeter Johnson <peter@tortall.net>
Sun, 5 Oct 2003 23:29:04 +0000 (23:29 -0000)
committerPeter Johnson <peter@tortall.net>
Sun, 5 Oct 2003 23:29:04 +0000 (23:29 -0000)
svn path=/trunk/yasm/; revision=1065

modules/parsers/nasm/nasm-bison.y
modules/parsers/nasm/nasm-token.re

index 6527bf427a037d37dce2ca68e146411ff6db47ad..da3632d74388ed57bbbc2e08564f8d6f4a7f4fa3 100644 (file)
@@ -81,7 +81,7 @@ static int fix_directive_symrec(/*@null@*/ yasm_expr__item *ei,
 %token <intn> INTNUM
 %token <flt> FLTNUM
 %token <str_val> DIRECTIVE_NAME STRING FILENAME
-%token <int_info> BYTE WORD HWORD DWORD QWORD TWORD DQWORD
+%token <int_info> SIZE_OVERRIDE
 %token <int_info> DECLARE_DATA
 %token <int_info> RESERVE_SPACE
 %token INCBIN EQU TIMES
@@ -313,26 +313,7 @@ memaddr: expr                  {
        $$ = $3;
        p_arch->module->parse_seg_override(p_arch, $$, $1[0], cur_line);
     }
-    | BYTE memaddr         {
-       $$ = $2;
-       yasm_ea_set_len($$, 1);
-    }
-    | HWORD memaddr        {
-       $$ = $2;
-       yasm_ea_set_len($$, p_arch->module->wordsize/2);
-    }
-    | WORD memaddr         {
-       $$ = $2;
-       yasm_ea_set_len($$, p_arch->module->wordsize);
-    }
-    | DWORD memaddr        {
-       $$ = $2;
-       yasm_ea_set_len($$, p_arch->module->wordsize*2);
-    }
-    | QWORD memaddr        {
-       $$ = $2;
-       yasm_ea_set_len($$, p_arch->module->wordsize*4);
-    }
+    | SIZE_OVERRIDE memaddr { $$ = $2; yasm_ea_set_len($$, $1); }
     | NOSPLIT memaddr      { $$ = $2; yasm_ea_set_nosplit($$, 1); }
 ;
 
@@ -352,67 +333,13 @@ operands: operand     {
 operand: '[' memaddr ']'    { $$ = yasm_operand_create_mem($2); }
     | expr                 { $$ = yasm_operand_create_imm($1); }
     | SEGREG               { $$ = yasm_operand_create_segreg($1[0]); }
-    | BYTE operand         {
-       $$ = $2;
-       if ($$->type == YASM_INSN__OPERAND_REG &&
-           p_arch->module->get_reg_size(p_arch, $$->data.reg) != 1)
-           yasm__error(cur_line, N_("cannot override register size"));
-       else
-           $$->size = 1;
-    }
-    | HWORD operand        {
-       $$ = $2;
-       if ($$->type == YASM_INSN__OPERAND_REG &&
-           p_arch->module->get_reg_size(p_arch, $$->data.reg) !=
-           p_arch->module->wordsize/2)
-           yasm__error(cur_line, N_("cannot override register size"));
-       else
-           $$->size = p_arch->module->wordsize/2;
-    }
-    | WORD operand         {
-       $$ = $2;
-       if ($$->type == YASM_INSN__OPERAND_REG &&
-           p_arch->module->get_reg_size(p_arch, $$->data.reg) !=
-           p_arch->module->wordsize)
-           yasm__error(cur_line, N_("cannot override register size"));
-       else
-           $$->size = p_arch->module->wordsize;
-    }
-    | DWORD operand        {
-       $$ = $2;
-       if ($$->type == YASM_INSN__OPERAND_REG &&
-           p_arch->module->get_reg_size(p_arch, $$->data.reg) !=
-           p_arch->module->wordsize*2)
-           yasm__error(cur_line, N_("cannot override register size"));
-       else
-           $$->size = p_arch->module->wordsize*2;
-    }
-    | QWORD operand        {
-       $$ = $2;
-       if ($$->type == YASM_INSN__OPERAND_REG &&
-           p_arch->module->get_reg_size(p_arch, $$->data.reg) !=
-           p_arch->module->wordsize*4)
-           yasm__error(cur_line, N_("cannot override register size"));
-       else
-           $$->size = p_arch->module->wordsize*4;
-    }
-    | TWORD operand        {
-       $$ = $2;
-       if ($$->type == YASM_INSN__OPERAND_REG &&
-           p_arch->module->get_reg_size(p_arch, $$->data.reg) !=
-           p_arch->module->wordsize*5)
-           yasm__error(cur_line, N_("cannot override register size"));
-       else
-           $$->size = p_arch->module->wordsize*5;
-    }
-    | DQWORD operand       {
+    | SIZE_OVERRIDE operand {
        $$ = $2;
        if ($$->type == YASM_INSN__OPERAND_REG &&
-           p_arch->module->get_reg_size(p_arch, $$->data.reg) !=
-           p_arch->module->wordsize*8)
+           p_arch->module->get_reg_size(p_arch, $$->data.reg) != $1)
            yasm__error(cur_line, N_("cannot override register size"));
        else
-           $$->size = p_arch->module->wordsize*8;
+           $$->size = $1;
     }
     | TARGETMOD operand            { $$ = $2; $$->targetmod = $1[0]; }
 ;
index de1f4522ac47bcb3b96848c8624faf18de7004b0..f6e5038b5d0b50109a577dc125fdc11587301a3c 100644 (file)
@@ -287,25 +287,75 @@ scan:
        }
 
        /* size specifiers */
-       B Y T E         { lvalp->int_info = 1; RETURN(BYTE); }
-       W O R D         { lvalp->int_info = 2; RETURN(WORD); }
-       D W O R D       { lvalp->int_info = 4; RETURN(DWORD); }
-       Q W O R D       { lvalp->int_info = 8; RETURN(QWORD); }
-       T W O R D       { lvalp->int_info = 10; RETURN(TWORD); }
-       D Q W O R D     { lvalp->int_info = 16; RETURN(DQWORD); }
+       B Y T E         { lvalp->int_info = 1; RETURN(SIZE_OVERRIDE); }
+       H W O R D       {
+           lvalp->int_info = p_arch->module->wordsize/2;
+           RETURN(SIZE_OVERRIDE);
+       }
+       W O R D         {
+           lvalp->int_info = p_arch->module->wordsize;
+           RETURN(SIZE_OVERRIDE);
+       }
+       D W O R D       {
+           lvalp->int_info = p_arch->module->wordsize*2;
+           RETURN(SIZE_OVERRIDE);
+       }
+       Q W O R D       {
+           lvalp->int_info = p_arch->module->wordsize*4;
+           RETURN(SIZE_OVERRIDE);
+       }
+       T W O R D       { lvalp->int_info = 10; RETURN(SIZE_OVERRIDE); }
+       D Q W O R D     {
+           lvalp->int_info = p_arch->module->wordsize*8;
+           RETURN(SIZE_OVERRIDE);
+       }
 
        /* pseudo-instructions */
        D B             { lvalp->int_info = 1; RETURN(DECLARE_DATA); }
-       D W             { lvalp->int_info = 2; RETURN(DECLARE_DATA); }
-       D D             { lvalp->int_info = 4; RETURN(DECLARE_DATA); }
-       D Q             { lvalp->int_info = 8; RETURN(DECLARE_DATA); }
+       D H W           {
+           lvalp->int_info = p_arch->module->wordsize/2;
+           RETURN(DECLARE_DATA);
+       }
+       D W             {
+           lvalp->int_info = p_arch->module->wordsize;
+           RETURN(DECLARE_DATA);
+       }
+       D D             {
+           lvalp->int_info = p_arch->module->wordsize*2;
+           RETURN(DECLARE_DATA);
+       }
+       D Q             {
+           lvalp->int_info = p_arch->module->wordsize*4;
+           RETURN(DECLARE_DATA);
+       }
        D T             { lvalp->int_info = 10; RETURN(DECLARE_DATA); }
+       D D Q           {
+           lvalp->int_info = p_arch->module->wordsize*8;
+           RETURN(DECLARE_DATA);
+       }
 
        R E S B         { lvalp->int_info = 1; RETURN(RESERVE_SPACE); }
-       R E S W         { lvalp->int_info = 2; RETURN(RESERVE_SPACE); }
-       R E S D         { lvalp->int_info = 4; RETURN(RESERVE_SPACE); }
-       R E S Q         { lvalp->int_info = 8; RETURN(RESERVE_SPACE); }
+       R E S H W       {
+           lvalp->int_info = p_arch->module->wordsize/2;
+           RETURN(RESERVE_SPACE);
+       }
+       R E S W         {
+           lvalp->int_info = p_arch->module->wordsize;
+           RETURN(RESERVE_SPACE);
+       }
+       R E S D         {
+           lvalp->int_info = p_arch->module->wordsize*2;
+           RETURN(RESERVE_SPACE);
+       }
+       R E S Q         {
+           lvalp->int_info = p_arch->module->wordsize*4;
+           RETURN(RESERVE_SPACE);
+       }
        R E S T         { lvalp->int_info = 10; RETURN(RESERVE_SPACE); }
+       R E S D Q       {
+           lvalp->int_info = p_arch->module->wordsize*8;
+           RETURN(RESERVE_SPACE);
+       }
 
        I N C B I N     { RETURN(INCBIN); }