Merge "Skip computation of distortion in vp8_pick_inter_mode if active_map is used"
[libvpx.git] / build / make / ads2gas_apple.pl
blob78f4a97f52d390d515c7495055b43d4c33cce9c4
1 #!/usr/bin/env perl
2 ##
3 ## Copyright (c) 2010 The WebM project authors. All Rights Reserved.
4 ##
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.
13 # ads2gas.pl
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_apple.pl script.\n\n";
22 print "\t.set WIDE_REFERENCE, 0\n";
23 print "\t.set ARCHITECTURE, 5\n";
24 print "\t.set DO1STROUNDING, 0\n";
26 my %register_aliases;
27 my %macro_aliases;
29 my @mapping_list = ("\$0", "\$1", "\$2", "\$3", "\$4", "\$5", "\$6", "\$7", "\$8", "\$9");
31 my @incoming_array;
33 # Perl trim function to remove whitespace from the start and end of the string
34 sub trim($)
36 my $string = shift;
37 $string =~ s/^\s+//;
38 $string =~ s/\s+$//;
39 return $string;
42 while (<STDIN>)
44 # Load and store alignment
45 s/@/,:/g;
47 # Comment character
48 s/;/@/g;
50 # Hexadecimal constants prefaced by 0x
51 s/#&/#0x/g;
53 # Convert :OR: to |
54 s/:OR:/ | /g;
56 # Convert :AND: to &
57 s/:AND:/ & /g;
59 # Convert :NOT: to ~
60 s/:NOT:/ ~ /g;
62 # Convert :SHL: to <<
63 s/:SHL:/ << /g;
65 # Convert :SHR: to >>
66 s/:SHR:/ >> /g;
68 # Convert ELSE to .else
69 s/ELSE/.else/g;
71 # Convert ENDIF to .endif
72 s/ENDIF/.endif/g;
74 # Convert ELSEIF to .elseif
75 s/ELSEIF/.elseif/g;
77 # Convert LTORG to .ltorg
78 s/LTORG/.ltorg/g;
80 # Convert IF :DEF:to .if
81 # gcc doesn't have the ability to do a conditional
82 # if defined variable that is set by IF :DEF: on
83 # armasm, so convert it to a normal .if and then
84 # make sure to define a value elesewhere
85 if (s/\bIF :DEF:\b/.if /g)
87 s/=/==/g;
90 # Convert IF to .if
91 if (s/\bIF\b/.if/g)
93 s/=/==/g;
96 # Convert INCLUDE to .INCLUDE "file"
97 s/INCLUDE(\s*)(.*)$/.include $1\"$2\"/;
99 # Code directive (ARM vs Thumb)
100 s/CODE([0-9][0-9])/.code $1/;
102 # No AREA required
103 # But ALIGNs in AREA must be obeyed
104 s/^\s*AREA.*ALIGN=([0-9])$/.text\n.p2align $1/;
105 # If no ALIGN, strip the AREA and align to 4 bytes
106 s/^\s*AREA.*$/.text\n.p2align 2/;
108 # DCD to .word
109 # This one is for incoming symbols
110 s/DCD\s+\|(\w*)\|/.long $1/;
112 # DCW to .short
113 s/DCW\s+\|(\w*)\|/.short $1/;
114 s/DCW(.*)/.short $1/;
116 # Constants defined in scope
117 s/DCD(.*)/.long $1/;
118 s/DCB(.*)/.byte $1/;
120 # Build a hash of all the register - alias pairs.
121 if (s/(.*)RN(.*)/$1 .req $2/g)
123 $register_aliases{trim($1)} = trim($2);
124 next;
127 while (($key, $value) = each(%register_aliases))
129 s/\b$key\b/$value/g;
132 # Make function visible to linker, and make additional symbol with
133 # prepended underscore
134 s/EXPORT\s+\|([\$\w]*)\|/.globl _$1\n\t.globl $1/;
135 s/IMPORT\s+\|([\$\w]*)\|/.globl $1/;
137 # No vertical bars required; make additional symbol with prepended
138 # underscore
139 s/^\|(\$?\w+)\|/_$1\n\t$1:/g;
141 # Labels need trailing colon
142 # s/^(\w+)/$1:/ if !/EQU/;
143 # put the colon at the end of the line in the macro
144 s/^([a-zA-Z_0-9\$]+)/$1:/ if !/EQU/;
146 # ALIGN directive
147 s/ALIGN/.balign/g;
149 # Strip ARM
150 s/\sARM/@ ARM/g;
152 # Strip REQUIRE8
153 #s/\sREQUIRE8/@ REQUIRE8/g;
154 s/\sREQUIRE8/@ /g;
156 # Strip PRESERVE8
157 s/\sPRESERVE8/@ PRESERVE8/g;
159 # Strip PROC and ENDPROC
160 s/PROC/@/g;
161 s/ENDP/@/g;
163 # EQU directive
164 s/(.*)EQU(.*)/.set $1, $2/;
166 # Begin macro definition
167 if (/MACRO/)
169 # Process next line down, which will be the macro definition
170 $_ = <STDIN>;
172 $trimmed = trim($_);
174 # remove commas that are separating list
175 $trimmed =~ s/,//g;
177 # string to array
178 @incoming_array = split(/ /, $trimmed);
180 print ".macro @incoming_array[0]\n";
182 # remove the first element, as that is the name of the macro
183 shift (@incoming_array);
185 @macro_aliases{@incoming_array} = @mapping_list;
187 next;
190 while (($key, $value) = each(%macro_aliases))
192 $key =~ s/\$/\\\$/;
193 s/$key\b/$value/g;
196 # For macros, use \ to reference formal params
197 # s/\$/\\/g; # End macro definition
198 s/MEND/.endm/; # No need to tell it where to stop assembling
199 next if /^\s*END\s*$/;
200 print;