3 ## Copyright (c) 2010 The WebM project authors. All Rights Reserved.
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
7 ## tree. An additional intellectual property rights grant can be found
8 ## in the file PATENTS. All contributing project authors may
9 ## be found in the AUTHORS file in the root of the source tree.
14 # Author: Eric Fung (efung (at) acm.org)
16 # Convert ARM Developer Suite 1.0.1 syntax assembly source to GNU as format
18 # Usage: cat inputfile | perl ads2gas.pl > outputfile
20 print "@ This file was created from a .asm file\n";
21 print "@ using the ads2gas.pl script.\n";
22 print "\t.equ DO1STROUNDING, 0\n";
24 # Stack of procedure names.
29 # Load and store alignment
35 # Hexadecimal constants prefaced by 0x
53 # Convert ELSE to .else
56 # Convert ENDIF to .endif
59 # Convert ELSEIF to .elseif
62 # Convert LTORG to .ltorg
65 # Convert IF :DEF:to .if
66 # gcc doesn't have the ability to do a conditional
67 # if defined variable that is set by IF :DEF: on
68 # armasm, so convert it to a normal .if and then
69 # make sure to define a value elesewhere
70 if (s/\bIF :DEF:\b/.if /g)
81 # Convert INCLUDE to .INCLUDE "file"
82 s/INCLUDE(\s*)(.*)$/.include $1\"$2\"/;
84 # Code directive (ARM vs Thumb)
85 s/CODE([0-9][0-9])/.code $1/;
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/;
94 # This one is for incoming symbols
95 s/DCD\s+\|(\w*)\|/.long $1/;
98 s/DCW\s+\|(\w*)\|/.short $1/;
101 # Constants defined in scope
106 if (s/RN\s+([Rr]\d+|lr)/.req $1/)
112 # Make function visible to linker, and make additional symbol with
113 # prepended underscore
114 s/EXPORT\s+\|([\$\w]*)\|/.global $1 \n\t.type $1, function/;
115 s/IMPORT\s+\|([\$\w]*)\|/.global $1/;
117 # No vertical bars required; make additional symbol with prepended
119 s/^\|(\$?\w+)\|/_$1\n\t$1:/g;
121 # Labels need trailing colon
122 # s/^(\w+)/$1:/ if !/EQU/;
123 # put the colon at the end of the line in the macro
124 s/^([a-zA-Z_0-9\$]+)/$1:/ if !/EQU/;
133 #s/\sREQUIRE8/@ REQUIRE8/g;
134 s/\sREQUIRE8/@ /g; #EQU cause problem
137 s/\sPRESERVE8/@ PRESERVE8/g;
139 # Use PROC and ENDP to give the symbols a .size directive.
140 # This makes them show up properly in debugging tools like gdb and valgrind.
144 /^_([\.0-9A-Z_a-z]\w+)\b/;
146 push(@proc_stack, $proc) if ($proc);
153 $proc = pop(@proc_stack);
154 $_ = "\t.size $proc, .-$proc".$_ if ($proc);
158 s/(.*)EQU(.*)/.equ $1, $2/;
160 # Begin macro definition
164 s/\$//g; # remove formal param reference
165 s/;/@/g; # change comment characters
168 # For macros, use \ to reference formal params
169 s/\$/\\/g; # End macro definition
170 s/MEND/.endm/; # No need to tell it where to stop assembling
171 next if /^\s*END\s*$/;
175 # Mark that this object doesn't need an executable stack.
176 printf ("\t.section\t.note.GNU-stack,\"\",\%\%progbits\n");