Initial WebM release
[libvpx.git] / build / make / ads2gas_apple.pl
blob569c3e762a741915125fa37f223512da5bbfabcb
1 #!/usr/bin/env perl
2 ##
3 ## Copyright (c) 2010 The VP8 project authors. All Rights Reserved.
4 ##
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.
9 ##
12 # ads2gas.pl
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";
25 my %register_aliases;
26 my %macro_aliases;
28 my @mapping_list = ("\$0", "\$1", "\$2", "\$3", "\$4", "\$5", "\$6", "\$7", "\$8", "\$9");
30 my @incoming_array;
32 # Perl trim function to remove whitespace from the start and end of the string
33 sub trim($)
35 my $string = shift;
36 $string =~ s/^\s+//;
37 $string =~ s/\s+$//;
38 return $string;
41 while (<STDIN>)
43 # Comment character
44 s/;/@/g;
46 # Hexadecimal constants prefaced by 0x
47 s/#&/#0x/g;
49 # Convert :OR: to |
50 s/:OR:/ | /g;
52 # Convert :AND: to &
53 s/:AND:/ & /g;
55 # Convert :NOT: to ~
56 s/:NOT:/ ~ /g;
58 # Convert :SHL: to <<
59 s/:SHL:/ << /g;
61 # Convert :SHR: to >>
62 s/:SHR:/ >> /g;
64 # Convert ELSE to .else
65 s/ELSE/.else/g;
67 # Convert ENDIF to .endif
68 s/ENDIF/.endif/g;
70 # Convert ELSEIF to .elseif
71 s/ELSEIF/.elseif/g;
73 # Convert LTORG to .ltorg
74 s/LTORG/.ltorg/g;
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)
83 s/=/==/g;
86 # Convert IF to .if
87 if (s/\bIF\b/.if/g)
89 s/=/==/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/;
98 # No AREA required
99 s/^\s*AREA.*$/.text/;
101 # DCD to .word
102 # This one is for incoming symbols
103 s/DCD\s+\|(\w*)\|/.long $1/;
105 # DCW to .short
106 s/DCW\s+\|(\w*)\|/.short $1/;
107 s/DCW(.*)/.short $1/;
109 # Constants defined in scope
110 s/DCD(.*)/.long $1/;
111 s/DCB(.*)/.byte $1/;
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);
117 next;
120 while (($key, $value) = each(%register_aliases))
122 s/\b$key\b/$value/g;
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
131 # underscore
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/;
139 # Strip ALIGN
140 s/\sALIGN/@ ALIGN/g;
142 # Strip ARM
143 s/\sARM/@ ARM/g;
145 # Strip REQUIRE8
146 #s/\sREQUIRE8/@ REQUIRE8/g;
147 s/\sREQUIRE8/@ /g;
149 # Strip PRESERVE8
150 s/\sPRESERVE8/@ PRESERVE8/g;
152 # Strip PROC and ENDPROC
153 s/PROC/@/g;
154 s/ENDP/@/g;
156 # EQU directive
157 s/(.*)EQU(.*)/.set $1, $2/;
159 # Begin macro definition
160 if (/MACRO/)
162 # Process next line down, which will be the macro definition
163 $_ = <STDIN>;
165 $trimmed = trim($_);
167 # remove commas that are separating list
168 $trimmed =~ s/,//g;
170 # string to array
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;
180 next;
183 while (($key, $value) = each(%macro_aliases))
185 $key =~ s/\$/\\\$/;
186 s/$key\b/$value/g;
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*$/;
193 print;