Source-Changes archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

asm2gas (Re: CVS commit: src)



On Thu, 27 Mar 2008, Izumi Tsutsui wrote:
> >     src/regress/sys/arch/m68k/060sp: Makefile
> >     src/sys/arch/m68k/060sp: Makefile asm2gas
> > Use "${TOOL_SED}" instead of just "sed" in sys/arch/m68k/060sp/asm2gas.
> 
> Maybe it's better to sync sys/arch/m68k/fpsp/asm2gas.

I have attempted to sync the two asm2gas scripts, and attach diffs.  (I
will also adjust Makefiles as necessary, but am not including those
diffs here.)  Does this look OK?  I don't know why one of the asm2gas
scripts uses "%" in register names while the other doesn't, but I
rewrote them to use $P to parameterise that difference.  Many of the sed
substitutions are no-ops in the case that $P is blank, but I prefer to
keep the two scripts as similar as possible.  I added comments saying
"probably redundant" to several sed substitutions; could you check
whether they can just be removed?

--apb (Alan Barrett)

Index: sys/arch/m68k/060sp/asm2gas
===================================================================
--- sys/arch/m68k/060sp/asm2gas 27 Mar 2008 07:15:16 -0000      1.7
+++ sys/arch/m68k/060sp/asm2gas 27 Mar 2008 21:15:17 -0000
@@ -2,7 +2,7 @@
 #      $NetBSD: asm2gas,v 1.7 2008/03/27 07:15:16 apb Exp $
 
 #
-# Copyright (c) 1998 The NetBSD Foundation, Inc.
+# Copyright (c) 1998,2008 The NetBSD Foundation, Inc.
 # All rights reserved.
 #
 # This code is derived from software contributed to The NetBSD Foundation
@@ -40,9 +40,10 @@
 # This ugly script converts assembler code from Motorola's format to a
 # form that gas (MIT syntax) can digest.
 
-: ${TOOL_SED:=sed}
+: ${SED:=sed}  # Which sed to use
+P=''           # Prefix for register names, may be '%' or ''
 
-cat "$1" | "${TOOL_SED}" -e '
+cat "$1" | "${SED}" -e '
   # format canonicalization
 
   s/^#/|#/
@@ -80,7 +81,7 @@
     G
     s/\n//
   }
-' | sed -e '
+' | "${SED}" -e '
   # operator conversion
 
   s/^  section 7/      .text/
@@ -138,36 +139,76 @@
   /^   db[a-z][a-z]*\.w        /{s/\.w//;p;d;}
   /^   fb[a-eg-z][a-z]*\.w     /{s/\.w//;p;d;}
   /^   fb[a-eg-z][a-z]*\.l     /{s/\.l/l/;p;d;}
-' | sed -e '
+' | "${SED}" -e '
   # operand conversion
 
-  s/\([^_a-zA-Z0-9]\)FPIAR\([^_a-zA-Z0-9]\)/\1FPI\2/g
-  s/\([^_a-zA-Z0-9]\)FPIAR\([^_a-zA-Z0-9]\)/\1FPI\2/g
-  s/\([^_a-zA-Z0-9]\)FPIAR$/\1FPI/g
-  s/\([^_a-zA-Z0-9]\)fpiar\([^_a-zA-Z0-9]\)/\1fpi\2/g
-  s/\([^_a-zA-Z0-9]\)fpiar\([^_a-zA-Z0-9]\)/\1fpi\2/g
-  s/\([^_a-zA-Z0-9]\)fpiar$/\1fpi/g
+  # register names "FPIAR" -> "%FPI", etc., possibly without the "%"
+  s/\([^_a-zA-Z0-9]\)FPIAR\([^_a-zA-Z0-9]\)/\1'"$P"'FPI\2/g
+  s/\([^_a-zA-Z0-9]\)FPIAR$/\1'"$P"'FPI/g
+  s/\([^_a-zA-Z0-9]\)fpiar\([^_a-zA-Z0-9]\)/\1'"$P"'fpi\2/g
+  s/\([^_a-zA-Z0-9]\)fpiar$/\1'"$P"'fpi/g
+  s/\([^_a-zA-Z0-9]\)FPCR\([^_a-zA-Z0-9]\)/\1'"$P"'FPCR\2/g
+  s/\([^_a-zA-Z0-9]\)FPCR$/\1'"$P"'FPCR/g
+  s/\([^_a-zA-Z0-9]\)fpcr\([^_a-zA-Z0-9]\)/\1'"$P"'fpcr\2/g
+  s/\([^_a-zA-Z0-9]\)fpcr$/\1'"$P"'fpcr/g
+  s/\([^_a-zA-Z0-9]\)FPSR\([^_a-zA-Z0-9]\)/\1'"$P"'FPSR\2/g
+  s/\([^_a-zA-Z0-9]\)FPSR$/\1'"$P"'FPSR/g
+  s/\([^_a-zA-Z0-9]\)fpsr\([^_a-zA-Z0-9]\)/\1'"$P"'fpsr\2/g
+  s/\([^_a-zA-Z0-9]\)fpsr$/\1'"$P"'fpsr/g
 
+  # Hexadecimal numbers
   s/\$\([0-9a-fA-F]\)/0x\1/g
   s/#:/#:0x/g
 
-  s/-(\([sSpPaA][pPcC0-7]\))/\1@-/g
-  s/(\([sSpPaA][pPcC0-7]\))+/\1@+/g
-  s/\([-+A-Za-z0-9_]*\)(\([sSpPaA][pPcC0-7]\)\([),]\)/\2@(\1\3/g
+  # Insert "%" before more register names (only if $P = "%")
+  s/\([^[:alnum:]_]\)\([dDaA][0-7]\)\([^[:alnum:]_]\)/\1'"$P"'\2\3/g
+  s/\([^[:alnum:]_]\)\([fF][pP][0-7]\)\([^[:alnum:]_]\)/\1'"$P"'\2\3/g
+  s/\([^[:alnum:]_]\)\(sp\)\([^[:alnum:]_]\)/\1'"$P"'\2\3/g
+  s/\([^[:alnum:]_]\)\(pc\)\([^[:alnum:]_]\)/\1'"$P"'\2\3/g
 
+  s/\([^[:alnum:]_]\)\([dDaA][0-7]\)$/\1'"$P"'\2/g
+  s/\([^[:alnum:]_]\)\([fF][pP][0-7]\)$/\1'"$P"'\2/g
+  s/\([^[:alnum:]_]\)\(sp\)$/\1'"$P"'\2/g
+
+  s/\(,\)\([dDaA][0-7]\)/\1'"$P"'\2/g
+  s/\(,\)\([fF][pP][0-7]\)/\1'"$P"'\2/g
+
+  # "-(%sp)" -> "%sp@-", etc. (possibly without the "%")
+  s/-(\('"$P"'[sSpPaA][pPcC0-7]\))/\1@-/g
+  # "(%sp)+" -> "%sp@+", etc. (possibly without the "%")
+  s/(\('"$P"'[sSpPaA][pPcC0-7]\))+/\1@+/g
+  # "foo(%sp,...)" -> "%sp@(foo,...)", etc. (possibly without the "%")
+  s/\([-+A-Za-z0-9_]*\)(\('"$P"'[sSpPaA][pPcC0-7]\)\([),]\)/\2@(\1\3/g
+
+  # ".w" -> ":w"; ".w*nn" -> ":w:nn"; "*nn" -> ":l:nn"; etc.
   s/\.\([bBwWlL])\)/:\1/g
   s/\.\([bBwWlL]\)\*\([0-9][0-9]*)\)/:\1:\2/g
   s/\*\([0-9][0-9]*\))/:l:\1)/g
+  # "{nn:mm}" -> "{#nn:#mm}"
   s/{\([0-9][0-9]*\):\([0-9][0-9]*\)}/{#\1:#\2}/g
-  s/{\([dD][0-7]\):\([0-9][0-9]*\)}/{\1:#\2}/g
+  # "{%d0:nn}" -> "{%d0:#nn}", etc. (possibly without the "%")
+  s/{\('"$P"'[dD][0-7]\):\([0-9][0-9]*\)}/{\1:#\2}/g
+  # Add possibly missing "%" in register names
+  # (Probably redundant, since we added "%" to all register names earlier.)
+  s/{\([dD][0-7]\):\([0-9][0-9]*\)}/{'"$P"'\1:#\2}/g
+  s/{\([dD][0-7]\):\('"$P"'[dD][0-9]*\)}/{'"$P"'\1:\2}/g
+
+  # More (probably redundant) addition of "%" to register names 
+  s/\(-\)\([dDaA][0-7]\)\([^_a-zA-Z0-9]\)/\1'"$P"'\2\3/g
+  s/\(-\)\([fF][pP][0-7]\)\([^_a-zA-Z0-9]\)/\1'"$P"'\2\3/g
 
+  s/\(\/\)\([dDaA][0-7]\)\([^_a-zA-Z0-9]\)/\1'"$P"'\2\3/g
+  s/\(\/\)\([fF][pP][0-7]\)\([^_a-zA-Z0-9]\)/\1'"$P"'\2\3/g
+
+  # Remove empty "()" or "(0)" after "@"
   s/@(0*)/@/g
+  # Remove leading "," or trailing ":" in parentheses
   s/(,/(/g;s/:)/)/g
 
   # make up for a gas bug
   /^   fmovemx /{
-       s/      \([fF][pP][0-7]\),/     \1-\1,/
-       s/,\([fF][pP][0-7]\)    /,\1-\1 /
-       s/,\([fF][pP][0-7]\)$/,\1-\1/
+       s/      \('"$P"'[fF][pP][0-7]\),/       \1-\1,/
+       s/,\('"$P"'[fF][pP][0-7]\)      /,\1-\1 /
+       s/,\('"$P"'[fF][pP][0-7]\)$/,\1-\1/
   }
 '
Index: sys/arch/m68k/fpsp/asm2gas
===================================================================
--- sys/arch/m68k/fpsp/asm2gas  24 Jun 2006 03:28:42 -0000      1.8
+++ sys/arch/m68k/fpsp/asm2gas  27 Mar 2008 21:15:17 -0000
@@ -2,7 +2,7 @@
 #      $NetBSD: asm2gas,v 1.8 2006/06/24 03:28:42 tsutsui Exp $
 
 #
-# Copyright (c) 1998 The NetBSD Foundation, Inc.
+# Copyright (c) 1998,2008 The NetBSD Foundation, Inc.
 # All rights reserved.
 #
 # This code is derived from software contributed to The NetBSD Foundation
@@ -40,10 +40,13 @@
 # This ugly script converts assembler code from Motorola's format to a
 # form that gas (MIT syntax) can digest.
 
-: ${SED:=sed}
-cat $1 | ${SED} -e '
+: ${SED:=sed}  # Which sed to use
+P='%'          # Prefix for register names, may be '%' or ''
+
+cat "$1" | "${SED}" -e '
   # format canonicalization
 
+  s/^#/|#/
   /[   ]IDNT[  ]/{s/^/|/;p;d;}
   /^\*/{s//|/;p;d;}
   s/;/|/
@@ -78,7 +81,7 @@
     G
     s/\n//
   }
-' | ${SED} -e '
+' | "${SED}" -e '
   # operator conversion
 
   s/^  section 7/      .text/
@@ -136,65 +139,79 @@
   /^   db[a-z][a-z]*\.w        /{s/\.w//;p;d;}
   /^   fb[a-eg-z][a-z]*\.w     /{s/\.w//;p;d;}
   /^   fb[a-eg-z][a-z]*\.l     /{s/\.l/l/;p;d;}
-' | ${SED} -e '
+' | "${SED}" -e '
   # operand conversion
 
-  s/\([^_a-zA-Z0-9]\)FPIAR\([^_a-zA-Z0-9]\)/\1%FPI\2/g
-  s/\([^_a-zA-Z0-9]\)FPIAR$/\1%FPI/g
-  s/\([^_a-zA-Z0-9]\)fpiar\([^_a-zA-Z0-9]\)/\1%fpi\2/g
-  s/\([^_a-zA-Z0-9]\)fpiar$/\1%fpi/g
-  s/\([^_a-zA-Z0-9]\)FPCR\([^_a-zA-Z0-9]\)/\1%FPCR\2/g
-  s/\([^_a-zA-Z0-9]\)FPCR$/\1%FPCR/g
-  s/\([^_a-zA-Z0-9]\)fpcr\([^_a-zA-Z0-9]\)/\1%fpcr\2/g
-  s/\([^_a-zA-Z0-9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\3/g
-  s/\([^[:alnum:]_]\)\(sp\)\([^[:alnum:]_]\)/\1%\2\3/g
-  s/\([^[:alnum:]_]\)\(pc\)\([^[:alnum:]_]\)/\1%\2\3/g
+  # Insert "%" before more register names (only if $P = "%")
+  s/\([^[:alnum:]_]\)\([dDaA][0-7]\)\([^[:alnum:]_]\)/\1'"$P"'\2\3/g
+  s/\([^[:alnum:]_]\)\([fF][pP][0-7]\)\([^[:alnum:]_]\)/\1'"$P"'\2\3/g
+  s/\([^[:alnum:]_]\)\(sp\)\([^[:alnum:]_]\)/\1'"$P"'\2\3/g
+  s/\([^[:alnum:]_]\)\(pc\)\([^[:alnum:]_]\)/\1'"$P"'\2\3/g
 
-  s/\([^[:alnum:]_]\)\([dDaA][0-7]\)$/\1%\2/g
-  s/\([^[:alnum:]_]\)\([fF][pP][0-7]\)$/\1%\2/g
-  s/\([^[:alnum:]_]\)\(sp\)$/\1%\2/g
+  s/\([^[:alnum:]_]\)\([dDaA][0-7]\)$/\1'"$P"'\2/g
+  s/\([^[:alnum:]_]\)\([fF][pP][0-7]\)$/\1'"$P"'\2/g
+  s/\([^[:alnum:]_]\)\(sp\)$/\1'"$P"'\2/g
 
-  s/\(,\)\([dDaA][0-7]\)/\1%\2/g
-  s/\(,\)\([fF][pP][0-7]\)/\1%\2/g
+  s/\(,\)\([dDaA][0-7]\)/\1'"$P"'\2/g
+  s/\(,\)\([fF][pP][0-7]\)/\1'"$P"'\2/g
 
-  s/-(\(%[sSpPaA][pPcC0-7]\))/\1@-/g
-  s/(\(%[sSpPaA][pPcC0-7]\))+/\1@+/g
-  s/\([-+A-Za-z0-9_]*\)(\(%[sSpPaA][pPcC0-7]\)\([),]\)/\2@(\1\3/g
+  # "-(%sp)" -> "%sp@-", etc. (possibly without the "%")
+  s/-(\('"$P"'[sSpPaA][pPcC0-7]\))/\1@-/g
+  # "(%sp)+" -> "%sp@+", etc. (possibly without the "%")
+  s/(\('"$P"'[sSpPaA][pPcC0-7]\))+/\1@+/g
+  # "foo(%sp,...)" -> "%sp@(foo,...)", etc. (possibly without the "%")
+  s/\([-+A-Za-z0-9_]*\)(\('"$P"'[sSpPaA][pPcC0-7]\)\([),]\)/\2@(\1\3/g
 
+  # ".w" -> ":w"; ".w*nn" -> ":w:nn"; "*nn" -> ":l:nn"; etc.
   s/\.\([bBwWlL])\)/:\1/g
   s/\.\([bBwWlL]\)\*\([0-9][0-9]*)\)/:\1:\2/g
   s/\*\([0-9][0-9]*\))/:l:\1)/g
+  # "{nn:mm}" -> "{#nn:#mm}"
   s/{\([0-9][0-9]*\):\([0-9][0-9]*\)}/{#\1:#\2}/g
-  s/{\(%[dD][0-7]\):\([0-9][0-9]*\)}/{\1:#\2}/g
-  s/{\([dD][0-7]\):\([0-9][0-9]*\)}/{%\1:#\2}/g
-  s/{\([dD][0-7]\):\(%[dD][0-9]*\)}/{%\1:\2}/g
+  # "{%d0:nn}" -> "{%d0:#nn}", etc. (possibly without the "%")
+  s/{\('"$P"'[dD][0-7]\):\([0-9][0-9]*\)}/{\1:#\2}/g
+  # Add possibly missing "%" in register names
+  # (Probably redundant, since we added "%" to all register names earlier.)
+  s/{\([dD][0-7]\):\([0-9][0-9]*\)}/{'"$P"'\1:#\2}/g
+  s/{\([dD][0-7]\):\('"$P"'[dD][0-9]*\)}/{'"$P"'\1:\2}/g
 
-  s/\(-\)\([dDaA][0-7]\)\([^_a-zA-Z0-9]\)/\1%\2\3/g
-  s/\(-\)\([fF][pP][0-7]\)\([^_a-zA-Z0-9]\)/\1%\2\3/g
+  # More (probably redundant) addition of "%" to register names 
+  s/\(-\)\([dDaA][0-7]\)\([^_a-zA-Z0-9]\)/\1'"$P"'\2\3/g
+  s/\(-\)\([fF][pP][0-7]\)\([^_a-zA-Z0-9]\)/\1'"$P"'\2\3/g
 
-  s/\(\/\)\([dDaA][0-7]\)\([^_a-zA-Z0-9]\)/\1%\2\3/g
-  s/\(\/\)\([fF][pP][0-7]\)\([^_a-zA-Z0-9]\)/\1%\2\3/g
+  s/\(\/\)\([dDaA][0-7]\)\([^_a-zA-Z0-9]\)/\1'"$P"'\2\3/g
+  s/\(\/\)\([fF][pP][0-7]\)\([^_a-zA-Z0-9]\)/\1'"$P"'\2\3/g
 
+  # Remove empty "()" or "(0)" after "@"
   s/@(0*)/@/g
+  # Remove leading "," or trailing ":" in parentheses
   s/(,/(/g;s/:)/)/g
 
   # make up for a gas bug
   /^   fmovemx /{
-       s/      \(%[fF][pP][0-7]\),/    \1-\1,/
-       s/,\(%[fF][pP][0-7]\)   /,\1-\1 /
-       s/,\(%[fF][pP][0-7]\)$/,\1-\1/
+       s/      \('"$P"'[fF][pP][0-7]\),/       \1-\1,/
+       s/,\('"$P"'[fF][pP][0-7]\)      /,\1-\1 /
+       s/,\('"$P"'[fF][pP][0-7]\)$/,\1-\1/
   }
-' | ${SED} -e '
+' | "${SED}" -e '
   # Floating point literal conversion
 
   s/:0x41dfffffffc00000/0r2147483647.0/g
@@ -228,10 +245,10 @@
   s/:0x40000000/0r2.0/g
   s/:0x42800000/0r6.40e+01/g
   s/:0x3C800000/0r1.56250e-02/g
-  s/fadds      #:0x00800000,%[fF][pP]0/        .long   0xf23c4422,0x00800000/
-  s/fsubs      #:0x00800000,%[fF][pP]0/        .long   0xf23c4428,0x00800000/
-  s/fsubs      #:0x00800000,%[fF][pP]1/        .long   0xf23c44a8,0x00800000/
-  s/fmoves     #:0x80000000,%[fF][pP]0/        .long   0xf23c4400,0x80000000/
-  s/fmoves             #:0x00000000,%[fF][pP]0/        .long   
0xf23c4400,0x00000000/
+  s/fadds      #:0x00800000,'"$P"'[fF][pP]0/   .long   0xf23c4422,0x00800000/
+  s/fsubs      #:0x00800000,'"$P"'[fF][pP]0/   .long   0xf23c4428,0x00800000/
+  s/fsubs      #:0x00800000,'"$P"'[fF][pP]1/   .long   0xf23c44a8,0x00800000/
+  s/fmoves     #:0x80000000,'"$P"'[fF][pP]0/   .long   0xf23c4400,0x80000000/
+  s/fmoves             #:0x00000000,'"$P"'[fF][pP]0/   .long   
0xf23c4400,0x00000000/
 
 '


Home | Main Index | Thread Index | Old Index