]> granicus.if.org Git - yasm/commitdiff
Make jcc's default to JR_SHORT in NASM syntax, and test for this possibility
authorPeter Johnson <peter@tortall.net>
Fri, 11 Jan 2002 07:12:57 +0000 (07:12 -0000)
committerPeter Johnson <peter@tortall.net>
Fri, 11 Jan 2002 07:12:57 +0000 (07:12 -0000)
in calc_len().

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

modules/arch/x86/x86bc.c
modules/parsers/nasm/gen_instr.pl
src/arch/x86/x86bc.c
src/parsers/nasm/gen_instr.pl

index 092c3f6b2b96cab4fbc16777da84134fc7cc616b..3c9ae78908581bcc464942efaa6d104c334a9e2f 100644 (file)
@@ -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);
index 5fdc1910faef3481c88ef14f07edc2310e09f93e..4d67f0183aebadb574a099dc336e4d38c114794d 100755 (executable)
@@ -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
                    {
index 092c3f6b2b96cab4fbc16777da84134fc7cc616b..3c9ae78908581bcc464942efaa6d104c334a9e2f 100644 (file)
@@ -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);
index 5fdc1910faef3481c88ef14f07edc2310e09f93e..4d67f0183aebadb574a099dc336e4d38c114794d 100755 (executable)
@@ -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
                    {