From: Peter Johnson Date: Fri, 11 Jan 2002 07:12:57 +0000 (-0000) Subject: Make jcc's default to JR_SHORT in NASM syntax, and test for this possibility X-Git-Tag: v0.1.0~79 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=044cc90233aad59cda48eaa02734fe14793a9f39;p=yasm Make jcc's default to JR_SHORT in NASM syntax, and test for this possibility in calc_len(). svn path=/trunk/yasm/; revision=460 --- diff --git a/modules/arch/x86/x86bc.c b/modules/arch/x86/x86bc.c index 092c3f6b..3c9ae789 100644 --- a/modules/arch/x86/x86bc.c +++ b/modules/arch/x86/x86bc.c @@ -612,10 +612,7 @@ x86_bc_calc_len_jmprel(x86_jmprel *jmprel, unsigned long *len, rel = (long)(target-offset); /* short displacement must fit within -128 <= rel <= +127 */ if (rel >= -128 && rel <= 127) { - /* It fits into a short displacement. Remember it fit as - * such, and return minimal sizing. - */ - jmprel->op_sel = JR_SHORT; + /* It fits into a short displacement. */ jrshort = 1; } else { /* Near for now, but could get shorter in the future. */ @@ -623,8 +620,11 @@ x86_bc_calc_len_jmprel(x86_jmprel *jmprel, unsigned long *len, retval = 0; } } else { - /* We have to assume it'll be a near displacement */ - jrshort = 0; + /* Assume whichever size is claimed as default by op_sel */ + if (jmprel->op_sel == JR_SHORT) + jrshort = 1; + else + jrshort = 0; retval = 0; } expr_delete(temp); diff --git a/modules/parsers/nasm/gen_instr.pl b/modules/parsers/nasm/gen_instr.pl index 5fdc1910..4d67f018 100755 --- a/modules/parsers/nasm/gen_instr.pl +++ b/modules/parsers/nasm/gen_instr.pl @@ -406,6 +406,17 @@ sub action_setshiftflag ( @ $ ) . rule_footer; } +sub action_setjrshort ( @ $ ) +{ + my ($rule, $tokens, $func, $a_args, $count) = splice @_; + return rule_header ($rule, $tokens, $count) + . " if (\$2.op_sel == JR_NONE)\n" + . " \$2.op_sel = JR_SHORT;\n" + . " @$a_args\n" + . " \$\$ = $func;\n" + . rule_footer; +} + sub get_token_number ( $ $ ) { my ($tokens, $str) = splice @_; @@ -579,7 +590,15 @@ sub output_yacc ($@) } # generate the grammar - print GRAMMAR action ($rule, $tokens, $func, \@args, $count++); + # Specialcase jcc to set op_sel=JR_SHORT. + if ($rule =~ m/jcc/) + { + print GRAMMAR action_setjrshort ($rule, $tokens, $func, \@args, $count++); + } + else + { + print GRAMMAR action ($rule, $tokens, $func, \@args, $count++); + } } else { diff --git a/src/arch/x86/x86bc.c b/src/arch/x86/x86bc.c index 092c3f6b..3c9ae789 100644 --- a/src/arch/x86/x86bc.c +++ b/src/arch/x86/x86bc.c @@ -612,10 +612,7 @@ x86_bc_calc_len_jmprel(x86_jmprel *jmprel, unsigned long *len, rel = (long)(target-offset); /* short displacement must fit within -128 <= rel <= +127 */ if (rel >= -128 && rel <= 127) { - /* It fits into a short displacement. Remember it fit as - * such, and return minimal sizing. - */ - jmprel->op_sel = JR_SHORT; + /* It fits into a short displacement. */ jrshort = 1; } else { /* Near for now, but could get shorter in the future. */ @@ -623,8 +620,11 @@ x86_bc_calc_len_jmprel(x86_jmprel *jmprel, unsigned long *len, retval = 0; } } else { - /* We have to assume it'll be a near displacement */ - jrshort = 0; + /* Assume whichever size is claimed as default by op_sel */ + if (jmprel->op_sel == JR_SHORT) + jrshort = 1; + else + jrshort = 0; retval = 0; } expr_delete(temp); diff --git a/src/parsers/nasm/gen_instr.pl b/src/parsers/nasm/gen_instr.pl index 5fdc1910..4d67f018 100755 --- a/src/parsers/nasm/gen_instr.pl +++ b/src/parsers/nasm/gen_instr.pl @@ -406,6 +406,17 @@ sub action_setshiftflag ( @ $ ) . rule_footer; } +sub action_setjrshort ( @ $ ) +{ + my ($rule, $tokens, $func, $a_args, $count) = splice @_; + return rule_header ($rule, $tokens, $count) + . " if (\$2.op_sel == JR_NONE)\n" + . " \$2.op_sel = JR_SHORT;\n" + . " @$a_args\n" + . " \$\$ = $func;\n" + . rule_footer; +} + sub get_token_number ( $ $ ) { my ($tokens, $str) = splice @_; @@ -579,7 +590,15 @@ sub output_yacc ($@) } # generate the grammar - print GRAMMAR action ($rule, $tokens, $func, \@args, $count++); + # Specialcase jcc to set op_sel=JR_SHORT. + if ($rule =~ m/jcc/) + { + print GRAMMAR action_setjrshort ($rule, $tokens, $func, \@args, $count++); + } + else + { + print GRAMMAR action ($rule, $tokens, $func, \@args, $count++); + } } else {