| OLD | NEW | 
|---|
| 1 #!/usr/bin/perl | 1 #!/usr/bin/perl | 
| 2 ## | 2 ## | 
| 3 ##  Copyright (c) 2010 The WebM project authors. All Rights Reserved. | 3 ##  Copyright (c) 2010 The WebM project authors. All Rights Reserved. | 
| 4 ## | 4 ## | 
| 5 ##  Use of this source code is governed by a BSD-style license | 5 ##  Use of this source code is governed by a BSD-style license | 
| 6 ##  that can be found in the LICENSE file in the root of the source | 6 ##  that can be found in the LICENSE file in the root of the source | 
| 7 ##  tree. An additional intellectual property rights grant can be found | 7 ##  tree. An additional intellectual property rights grant can be found | 
| 8 ##  in the file PATENTS.  All contributing project authors may | 8 ##  in the file PATENTS.  All contributing project authors may | 
| 9 ##  be found in the AUTHORS file in the root of the source tree. | 9 ##  be found in the AUTHORS file in the root of the source tree. | 
| 10 ## | 10 ## | 
| 11 | 11 | 
| 12 | 12 | 
| 13 # ads2gas.pl | 13 # ads2gas.pl | 
| 14 # Author: Eric Fung (efung (at) acm.org) | 14 # Author: Eric Fung (efung (at) acm.org) | 
| 15 # | 15 # | 
| 16 # Convert ARM Developer Suite 1.0.1 syntax assembly source to GNU as format | 16 # Convert ARM Developer Suite 1.0.1 syntax assembly source to GNU as format | 
| 17 # | 17 # | 
| 18 # Usage: cat inputfile | perl ads2gas.pl > outputfile | 18 # Usage: cat inputfile | perl ads2gas.pl > outputfile | 
| 19 # | 19 # | 
| 20 print "@ This file was created from a .asm file\n"; | 20 print "@ This file was created from a .asm file\n"; | 
| 21 print "@  using the ads2gas.pl script.\n"; | 21 print "@  using the ads2gas.pl script.\n"; | 
| 22 print "\t.equ DO1STROUNDING, 0\n"; | 22 print "\t.equ DO1STROUNDING, 0\n"; | 
| 23 | 23 | 
|  | 24 # Stack of procedure names. | 
|  | 25 @proc_stack = (); | 
|  | 26 | 
| 24 while (<STDIN>) | 27 while (<STDIN>) | 
| 25 { | 28 { | 
|  | 29     # Load and store alignment | 
|  | 30     s/@/,:/g; | 
|  | 31 | 
| 26     # Comment character | 32     # Comment character | 
| 27     s/;/@/g; | 33     s/;/@/g; | 
| 28 | 34 | 
| 29     # Hexadecimal constants prefaced by 0x | 35     # Hexadecimal constants prefaced by 0x | 
| 30     s/#&/#0x/g; | 36     s/#&/#0x/g; | 
| 31 | 37 | 
| 32     # Convert :OR: to | | 38     # Convert :OR: to | | 
| 33     s/:OR:/ | /g; | 39     s/:OR:/ | /g; | 
| 34 | 40 | 
| 35     # Convert :AND: to & | 41     # Convert :AND: to & | 
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 72         s/=+/==/g; | 78         s/=+/==/g; | 
| 73     } | 79     } | 
| 74 | 80 | 
| 75     # Convert INCLUDE to .INCLUDE "file" | 81     # Convert INCLUDE to .INCLUDE "file" | 
| 76     s/INCLUDE(\s*)(.*)$/.include $1\"$2\"/; | 82     s/INCLUDE(\s*)(.*)$/.include $1\"$2\"/; | 
| 77 | 83 | 
| 78     # Code directive (ARM vs Thumb) | 84     # Code directive (ARM vs Thumb) | 
| 79     s/CODE([0-9][0-9])/.code $1/; | 85     s/CODE([0-9][0-9])/.code $1/; | 
| 80 | 86 | 
| 81     # No AREA required | 87     # No AREA required | 
| 82     s/^\s*AREA.*$/.text/; | 88     # But ALIGNs in AREA must be obeyed | 
|  | 89     s/^\s*AREA.*ALIGN=([0-9])$/.text\n.p2align $1/; | 
|  | 90     # If no ALIGN, strip the AREA and align to 4 bytes | 
|  | 91     s/^\s*AREA.*$/.text\n.p2align 2/; | 
| 83 | 92 | 
| 84     # DCD to .word | 93     # DCD to .word | 
| 85     # This one is for incoming symbols | 94     # This one is for incoming symbols | 
| 86     s/DCD\s+\|(\w*)\|/.long $1/; | 95     s/DCD\s+\|(\w*)\|/.long $1/; | 
| 87 | 96 | 
| 88     # DCW to .short | 97     # DCW to .short | 
| 89     s/DCW\s+\|(\w*)\|/.short $1/; | 98     s/DCW\s+\|(\w*)\|/.short $1/; | 
| 90     s/DCW(.*)/.short $1/; | 99     s/DCW(.*)/.short $1/; | 
| 91 | 100 | 
| 92     # Constants defined in scope | 101     # Constants defined in scope | 
| (...skipping 14 matching lines...) Expand all  Loading... | 
| 107 | 116 | 
| 108     # No vertical bars required; make additional symbol with prepended | 117     # No vertical bars required; make additional symbol with prepended | 
| 109     # underscore | 118     # underscore | 
| 110     s/^\|(\$?\w+)\|/_$1\n\t$1:/g; | 119     s/^\|(\$?\w+)\|/_$1\n\t$1:/g; | 
| 111 | 120 | 
| 112     # Labels need trailing colon | 121     # Labels need trailing colon | 
| 113 #   s/^(\w+)/$1:/ if !/EQU/; | 122 #   s/^(\w+)/$1:/ if !/EQU/; | 
| 114     # put the colon at the end of the line in the macro | 123     # put the colon at the end of the line in the macro | 
| 115     s/^([a-zA-Z_0-9\$]+)/$1:/ if !/EQU/; | 124     s/^([a-zA-Z_0-9\$]+)/$1:/ if !/EQU/; | 
| 116 | 125 | 
| 117     # Strip ALIGN | 126     # ALIGN directive | 
| 118     s/\sALIGN/@ ALIGN/g; | 127     s/ALIGN/.balign/g; | 
| 119 | 128 | 
| 120     # Strip ARM | 129     # Strip ARM | 
| 121     s/\sARM/@ ARM/g; | 130     s/\sARM/@ ARM/g; | 
| 122 | 131 | 
| 123     # Strip REQUIRE8 | 132     # Strip REQUIRE8 | 
| 124     #s/\sREQUIRE8/@ REQUIRE8/g; | 133     #s/\sREQUIRE8/@ REQUIRE8/g; | 
| 125     s/\sREQUIRE8/@ /g;      #EQU cause problem | 134     s/\sREQUIRE8/@ /g;      #EQU cause problem | 
| 126 | 135 | 
| 127     # Strip PRESERVE8 | 136     # Strip PRESERVE8 | 
| 128     s/\sPRESERVE8/@ PRESERVE8/g; | 137     s/\sPRESERVE8/@ PRESERVE8/g; | 
| 129 | 138 | 
| 130     # Strip PROC and ENDPROC | 139     # Use PROC and ENDP to give the symbols a .size directive. | 
| 131     s/\sPROC/@/g; | 140     # This makes them show up properly in debugging tools like gdb and valgrind. | 
| 132     s/\sENDP/@/g; | 141     if (/\bPROC\b/) | 
|  | 142     { | 
|  | 143         my $proc; | 
|  | 144         /^_([\.0-9A-Z_a-z]\w+)\b/; | 
|  | 145         $proc = $1; | 
|  | 146         push(@proc_stack, $proc) if ($proc); | 
|  | 147         s/\bPROC\b/@ $&/; | 
|  | 148     } | 
|  | 149     if (/\bENDP\b/) | 
|  | 150     { | 
|  | 151         my $proc; | 
|  | 152         s/\bENDP\b/@ $&/; | 
|  | 153         $proc = pop(@proc_stack); | 
|  | 154         $_ = "\t.size $proc, .-$proc".$_ if ($proc); | 
|  | 155     } | 
| 133 | 156 | 
| 134     # EQU directive | 157     # EQU directive | 
| 135     s/(.*)EQU(.*)/.equ $1, $2/; | 158     s/(.*)EQU(.*)/.equ $1, $2/; | 
| 136 | 159 | 
| 137     # Begin macro definition | 160     # Begin macro definition | 
| 138     if (/MACRO/) { | 161     if (/MACRO/) { | 
| 139         $_ = <STDIN>; | 162         $_ = <STDIN>; | 
| 140         s/^/.macro/; | 163         s/^/.macro/; | 
| 141         s/\$//g;                # remove formal param reference | 164         s/\$//g;                # remove formal param reference | 
| 142         s/;/@/g;                # change comment characters | 165         s/;/@/g;                # change comment characters | 
| 143     } | 166     } | 
| 144 | 167 | 
| 145     # For macros, use \ to reference formal params | 168     # For macros, use \ to reference formal params | 
| 146     s/\$/\\/g;                  # End macro definition | 169     s/\$/\\/g;                  # End macro definition | 
| 147     s/MEND/.endm/;              # No need to tell it where to stop assembling | 170     s/MEND/.endm/;              # No need to tell it where to stop assembling | 
| 148     next if /^\s*END\s*$/; | 171     next if /^\s*END\s*$/; | 
| 149     print; | 172     print; | 
| 150 } | 173 } | 
|  | 174 | 
|  | 175 # Mark that this object doesn't need an executable stack. | 
|  | 176 printf ("\t.section\t.note.GNU-stack,\"\",\%\%progbits\n"); | 
| OLD | NEW | 
|---|