3 ## Copyright (c) 2010 The VP8 project authors. All Rights Reserved.
5 ## Use of this source code is governed by a BSD-style license and patent
6 ## grant that can be found in the LICENSE file in the root of the source
7 ## tree. All contributing project authors may be found in the AUTHORS
8 ## file in the root of the source tree.
13 # Author: Eric Fung (efung (at) acm.org)
15 # Convert ARM Developer Suite 1.0.1 syntax assembly source to GNU as format
17 # Usage: cat inputfile | perl ads2gas.pl > outputfile
19 print "@ This file was created from a .asm file\n";
20 print "@ using the ads2gas_apple.pl script.\n\n";
21 print "\t.set WIDE_REFERENCE, 0\n";
22 print "\t.set ARCHITECTURE, 5\n";
23 print "\t.set DO1STROUNDING, 0\n";
28 my @mapping_list = ("\$0", "\$1", "\$2", "\$3", "\$4", "\$5", "\$6", "\$7", "\$8", "\$9");
32 # Perl trim function to remove whitespace from the start and end of the string
46 # Hexadecimal constants prefaced by 0x
64 # Convert ELSE to .else
67 # Convert ENDIF to .endif
70 # Convert ELSEIF to .elseif
73 # Convert LTORG to .ltorg
76 # Convert IF :DEF:to .if
77 # gcc doesn't have the ability to do a conditional
78 # if defined variable that is set by IF :DEF: on
79 # armasm, so convert it to a normal .if and then
80 # make sure to define a value elesewhere
81 if (s/\bIF :DEF:\b/.if /g)
92 # Convert INCLUDE to .INCLUDE "file"
93 s/INCLUDE(\s*)(.*)$/.include $1\"$2\"/;
95 # Code directive (ARM vs Thumb)
96 s/CODE([0-9][0-9])/.code $1/;
102 # This one is for incoming symbols
103 s/DCD\s+\|(\w*)\|/.long $1/;
106 s/DCW\s+\|(\w*)\|/.short $1/;
107 s/DCW(.*)/.short $1/;
109 # Constants defined in scope
113 # Build a hash of all the register - alias pairs.
114 if (s/(.*)RN(.*)/$1 .req $2/g)
116 $register_aliases{trim
($1)} = trim
($2);
120 while (($key, $value) = each(%register_aliases))
125 # Make function visible to linker, and make additional symbol with
126 # prepended underscore
127 s/EXPORT\s+\|([\$\w]*)\|/.globl _$1\n\t.globl $1/;
128 s/IMPORT\s+\|([\$\w]*)\|/.globl $1/;
130 # No vertical bars required; make additional symbol with prepended
132 s/^\|(\$?\w+)\|/_$1\n\t$1:/g;
134 # Labels need trailing colon
135 # s/^(\w+)/$1:/ if !/EQU/;
136 # put the colon at the end of the line in the macro
137 s/^([a-zA-Z_0-9\$]+)/$1:/ if !/EQU/;
146 #s/\sREQUIRE8/@ REQUIRE8/g;
150 s/\sPRESERVE8/@ PRESERVE8/g;
152 # Strip PROC and ENDPROC
157 s/(.*)EQU(.*)/.set $1, $2/;
159 # Begin macro definition
162 # Process next line down, which will be the macro definition
167 # remove commas that are separating list
171 @incoming_array = split(/ /, $trimmed);
173 print ".macro @incoming_array[0]\n";
175 # remove the first element, as that is the name of the macro
176 shift (@incoming_array);
178 @macro_aliases{@incoming_array} = @mapping_list;
183 while (($key, $value) = each(%macro_aliases))
189 # For macros, use \ to reference formal params
190 # s/\$/\\/g; # End macro definition
191 s/MEND/.endm/; # No need to tell it where to stop assembling
192 next if /^\s*END\s*$/;