]> granicus.if.org Git - yasm/commitdiff
Add word size to arch module interface for better support of future archs which
authorPeter Johnson <peter@tortall.net>
Thu, 14 Aug 2003 03:25:44 +0000 (03:25 -0000)
committerPeter Johnson <peter@tortall.net>
Thu, 14 Aug 2003 03:25:44 +0000 (03:25 -0000)
have a "word" size != 2.

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

libyasm/arch.h
modules/arch/lc3b/lc3barch.c
modules/arch/x86/x86arch.c
modules/parsers/nasm/nasm-bison.y

index c374e2d075d4b03d87ad929a6c50bc778fd2e920..e3a2ba17c51b9e75115499af8179744d5816e1f8 100644 (file)
@@ -93,7 +93,7 @@ typedef struct yasm_arch_machine {
  * definitions match the module loader's function definitions.  The version
  * number must never be decreased.
  */
-#define YASM_ARCH_VERSION      0
+#define YASM_ARCH_VERSION      1
 
 /** YASM architecture interface.
  * \note All "data" in parser-related functions (parse_*) needs to start the
@@ -337,6 +337,9 @@ struct yasm_arch {
 
     /** Default machine keyword. */
     const char *default_machine_keyword;
+
+    /** Canonical "word" size in bytes. */
+    unsigned int wordsize;
 };
 
 #ifdef YASM_LIB_INTERNAL
index f7485bde5f5dc0979f7ce2885e86125dd2706a32..4bb088d142a6c435f2bf1ff1893148d81c4a882e 100644 (file)
@@ -119,5 +119,6 @@ yasm_arch yasm_lc3b_LTX_arch = {
     NULL,      /*yasm_lc3b__ea_data_delete*/
     NULL,      /*yasm_lc3b__ea_data_print*/
     lc3b_machines,
-    "lc3b"
+    "lc3b",
+    2
 };
index 568dd980bc2cc5097b276977a676015482d84318..888b25b592f9335b2d7cf358cda4b1c2dbdfd3b2 100644 (file)
@@ -243,5 +243,6 @@ yasm_arch yasm_x86_LTX_arch = {
     NULL,      /* x86_ea_data_delete */
     yasm_x86__ea_data_print,
     x86_machines,
-    "x86"
+    "x86",
+    2
 };
index 6c8c120a5004b83b109e0c69131aac8753fac60d..1a1f24e2fa99dfcd68ff4583c551ca04e85ed97c 100644 (file)
@@ -80,7 +80,7 @@ static yasm_bytecode *nasm_parser_temp_bc;
 %token <intn> INTNUM
 %token <flt> FLTNUM
 %token <str_val> DIRECTIVE_NAME STRING FILENAME
-%token <int_info> BYTE WORD DWORD QWORD TWORD DQWORD
+%token <int_info> BYTE WORD HWORD DWORD QWORD TWORD DQWORD
 %token <int_info> DECLARE_DATA
 %token <int_info> RESERVE_SPACE
 %token INCBIN EQU TIMES
@@ -313,10 +313,26 @@ memaddr: expr                 {
        $$ = $3;
        nasm_parser_arch->parse_seg_override($$, $1[0], cur_lindex);
     }
-    | BYTE memaddr         { $$ = $2; yasm_ea_set_len($$, 1); }
-    | WORD memaddr         { $$ = $2; yasm_ea_set_len($$, 2); }
-    | DWORD memaddr        { $$ = $2; yasm_ea_set_len($$, 4); }
-    | QWORD memaddr        { $$ = $2; yasm_ea_set_len($$, 8); }
+    | BYTE memaddr         {
+       $$ = $2;
+       yasm_ea_set_len($$, 1);
+    }
+    | HWORD memaddr        {
+       $$ = $2;
+       yasm_ea_set_len($$, nasm_parser_arch->wordsize/2);
+    }
+    | WORD memaddr         {
+       $$ = $2;
+       yasm_ea_set_len($$, nasm_parser_arch->wordsize);
+    }
+    | DWORD memaddr        {
+       $$ = $2;
+       yasm_ea_set_len($$, nasm_parser_arch->wordsize*2);
+    }
+    | QWORD memaddr        {
+       $$ = $2;
+       yasm_ea_set_len($$, nasm_parser_arch->wordsize*4);
+    }
     | NOSPLIT memaddr      { $$ = $2; yasm_ea_set_nosplit($$, 1); }
 ;
 
@@ -344,45 +360,59 @@ operand: '[' memaddr ']'    { $$ = yasm_operand_new_mem($2); }
        else
            $$->size = 1;
     }
+    | HWORD operand        {
+       $$ = $2;
+       if ($$->type == YASM_INSN__OPERAND_REG &&
+           nasm_parser_arch->get_reg_size($$->data.reg) !=
+           nasm_parser_arch->wordsize/2)
+           yasm__error(cur_lindex, N_("cannot override register size"));
+       else
+           $$->size = nasm_parser_arch->wordsize/2;
+    }
     | WORD operand         {
        $$ = $2;
        if ($$->type == YASM_INSN__OPERAND_REG &&
-           nasm_parser_arch->get_reg_size($$->data.reg) != 2)
+           nasm_parser_arch->get_reg_size($$->data.reg) !=
+           nasm_parser_arch->wordsize)
            yasm__error(cur_lindex, N_("cannot override register size"));
        else
-           $$->size = 2;
+           $$->size = nasm_parser_arch->wordsize;
     }
     | DWORD operand        {
        $$ = $2;
        if ($$->type == YASM_INSN__OPERAND_REG &&
-           nasm_parser_arch->get_reg_size($$->data.reg) != 4)
+           nasm_parser_arch->get_reg_size($$->data.reg) !=
+           nasm_parser_arch->wordsize*2)
            yasm__error(cur_lindex, N_("cannot override register size"));
        else
-           $$->size = 4;
+           $$->size = nasm_parser_arch->wordsize*2;
     }
     | QWORD operand        {
        $$ = $2;
        if ($$->type == YASM_INSN__OPERAND_REG &&
-           nasm_parser_arch->get_reg_size($$->data.reg) != 8)
+           nasm_parser_arch->get_reg_size($$->data.reg) !=
+           nasm_parser_arch->wordsize*4)
            yasm__error(cur_lindex, N_("cannot override register size"));
        else
-           $$->size = 8;
+           $$->size = nasm_parser_arch->wordsize*4;
     }
     | TWORD operand        {
        $$ = $2;
        if ($$->type == YASM_INSN__OPERAND_REG &&
-           nasm_parser_arch->get_reg_size($$->data.reg) != 10)
+           nasm_parser_arch->get_reg_size($$->data.reg) !=
+           nasm_parser_arch->wordsize*5)
            yasm__error(cur_lindex, N_("cannot override register size"));
        else
-           $$->size = 10;
+           $$->size = nasm_parser_arch->wordsize*5;
     }
     | DQWORD operand       {
        $$ = $2;
        if ($$->type == YASM_INSN__OPERAND_REG &&
-           nasm_parser_arch->get_reg_size($$->data.reg) != 16)
+           nasm_parser_arch->get_reg_size($$->data.reg) !=
+           nasm_parser_arch->wordsize*8)
            yasm__error(cur_lindex, N_("cannot override register size"));
        else
-           $$->size = 16;
+           $$->size = nasm_parser_arch->wordsize*8;
     }
     | TARGETMOD operand            { $$ = $2; $$->targetmod = $1[0]; }
 ;