From 794ccb4cd16e701942ca6fc3406030dd5ab704b1 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Thu, 14 Aug 2003 03:25:44 +0000 Subject: [PATCH] Add word size to arch module interface for better support of future archs which have a "word" size != 2. svn path=/trunk/yasm/; revision=1034 --- libyasm/arch.h | 5 ++- modules/arch/lc3b/lc3barch.c | 3 +- modules/arch/x86/x86arch.c | 3 +- modules/parsers/nasm/nasm-bison.y | 60 +++++++++++++++++++++++-------- 4 files changed, 53 insertions(+), 18 deletions(-) diff --git a/libyasm/arch.h b/libyasm/arch.h index c374e2d0..e3a2ba17 100644 --- a/libyasm/arch.h +++ b/libyasm/arch.h @@ -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 diff --git a/modules/arch/lc3b/lc3barch.c b/modules/arch/lc3b/lc3barch.c index f7485bde..4bb088d1 100644 --- a/modules/arch/lc3b/lc3barch.c +++ b/modules/arch/lc3b/lc3barch.c @@ -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 }; diff --git a/modules/arch/x86/x86arch.c b/modules/arch/x86/x86arch.c index 568dd980..888b25b5 100644 --- a/modules/arch/x86/x86arch.c +++ b/modules/arch/x86/x86arch.c @@ -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 }; diff --git a/modules/parsers/nasm/nasm-bison.y b/modules/parsers/nasm/nasm-bison.y index 6c8c120a..1a1f24e2 100644 --- a/modules/parsers/nasm/nasm-bison.y +++ b/modules/parsers/nasm/nasm-bison.y @@ -80,7 +80,7 @@ static yasm_bytecode *nasm_parser_temp_bc; %token INTNUM %token FLTNUM %token DIRECTIVE_NAME STRING FILENAME -%token BYTE WORD DWORD QWORD TWORD DQWORD +%token BYTE WORD HWORD DWORD QWORD TWORD DQWORD %token DECLARE_DATA %token 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]; } ; -- 2.40.0