annotate src/opus-1.3/celt/arm/arm2gnu.pl @ 79:91c729825bca pa_catalina

Update build for AUDIO_COMPONENT_FIX
author Chris Cannam
date Wed, 30 Oct 2019 12:40:34 +0000
parents 7aeed7906520
children
rev   line source
Chris@69 1 #!/usr/bin/perl
Chris@69 2 # Copyright (C) 2002-2013 Xiph.org Foundation
Chris@69 3 #
Chris@69 4 # Redistribution and use in source and binary forms, with or without
Chris@69 5 # modification, are permitted provided that the following conditions
Chris@69 6 # are met:
Chris@69 7 #
Chris@69 8 # - Redistributions of source code must retain the above copyright
Chris@69 9 # notice, this list of conditions and the following disclaimer.
Chris@69 10 #
Chris@69 11 # - Redistributions in binary form must reproduce the above copyright
Chris@69 12 # notice, this list of conditions and the following disclaimer in the
Chris@69 13 # documentation and/or other materials provided with the distribution.
Chris@69 14 #
Chris@69 15 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
Chris@69 16 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
Chris@69 17 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
Chris@69 18 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
Chris@69 19 # OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
Chris@69 20 # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
Chris@69 21 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
Chris@69 22 # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
Chris@69 23 # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
Chris@69 24 # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
Chris@69 25 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Chris@69 26
Chris@69 27 my $bigend; # little/big endian
Chris@69 28 my $nxstack;
Chris@69 29 my $apple = 0;
Chris@69 30 my $symprefix = "";
Chris@69 31
Chris@69 32 $nxstack = 0;
Chris@69 33
Chris@69 34 eval 'exec /usr/local/bin/perl -S $0 ${1+"$@"}'
Chris@69 35 if $running_under_some_shell;
Chris@69 36
Chris@69 37 while ($ARGV[0] =~ /^-/) {
Chris@69 38 $_ = shift;
Chris@69 39 last if /^--$/;
Chris@69 40 if (/^-n$/) {
Chris@69 41 $nflag++;
Chris@69 42 next;
Chris@69 43 }
Chris@69 44 if (/^--apple$/) {
Chris@69 45 $apple = 1;
Chris@69 46 $symprefix = "_";
Chris@69 47 next;
Chris@69 48 }
Chris@69 49 die "I don't recognize this switch: $_\\n";
Chris@69 50 }
Chris@69 51 $printit++ unless $nflag;
Chris@69 52
Chris@69 53 $\ = "\n"; # automatically add newline on print
Chris@69 54 $n=0;
Chris@69 55
Chris@69 56 $thumb = 0; # ARM mode by default, not Thumb.
Chris@69 57 @proc_stack = ();
Chris@69 58
Chris@69 59 printf (" .syntax unified\n");
Chris@69 60
Chris@69 61 LINE:
Chris@69 62 while (<>) {
Chris@69 63
Chris@69 64 # For ADRLs we need to add a new line after the substituted one.
Chris@69 65 $addPadding = 0;
Chris@69 66
Chris@69 67 # First, we do not dare to touch *anything* inside double quotes, do we?
Chris@69 68 # Second, if you want a dollar character in the string,
Chris@69 69 # insert two of them -- that's how ARM C and assembler treat strings.
Chris@69 70 s/^([A-Za-z_]\w*)[ \t]+DCB[ \t]*\"/$1: .ascii \"/ && do { s/\$\$/\$/g; next };
Chris@69 71 s/\bDCB\b[ \t]*\"/.ascii \"/ && do { s/\$\$/\$/g; next };
Chris@69 72 s/^(\S+)\s+RN\s+(\S+)/$1 .req r$2/ && do { s/\$\$/\$/g; next };
Chris@69 73 # If there's nothing on a line but a comment, don't try to apply any further
Chris@69 74 # substitutions (this is a cheap hack to avoid mucking up the license header)
Chris@69 75 s/^([ \t]*);/$1@/ && do { s/\$\$/\$/g; next };
Chris@69 76 # If substituted -- leave immediately !
Chris@69 77
Chris@69 78 s/@/,:/;
Chris@69 79 s/;/@/;
Chris@69 80 while ( /@.*'/ ) {
Chris@69 81 s/(@.*)'/$1/g;
Chris@69 82 }
Chris@69 83 s/\{FALSE\}/0/g;
Chris@69 84 s/\{TRUE\}/1/g;
Chris@69 85 s/\{(\w\w\w\w+)\}/$1/g;
Chris@69 86 s/\bINCLUDE[ \t]*([^ \t\n]+)/.include \"$1\"/;
Chris@69 87 s/\bGET[ \t]*([^ \t\n]+)/.include \"${ my $x=$1; $x =~ s|\.s|-gnu.S|; \$x }\"/;
Chris@69 88 s/\bIMPORT\b/.extern/;
Chris@69 89 s/\bEXPORT\b\s*/.global $symprefix/;
Chris@69 90 s/^(\s+)\[/$1IF/;
Chris@69 91 s/^(\s+)\|/$1ELSE/;
Chris@69 92 s/^(\s+)\]/$1ENDIF/;
Chris@69 93 s/IF *:DEF:/ .ifdef/;
Chris@69 94 s/IF *:LNOT: *:DEF:/ .ifndef/;
Chris@69 95 s/ELSE/ .else/;
Chris@69 96 s/ENDIF/ .endif/;
Chris@69 97
Chris@69 98 if( /\bIF\b/ ) {
Chris@69 99 s/\bIF\b/ .if/;
Chris@69 100 s/=/==/;
Chris@69 101 }
Chris@69 102 if ( $n == 2) {
Chris@69 103 s/\$/\\/g;
Chris@69 104 }
Chris@69 105 if ($n == 1) {
Chris@69 106 s/\$//g;
Chris@69 107 s/label//g;
Chris@69 108 $n = 2;
Chris@69 109 }
Chris@69 110 if ( /MACRO/ ) {
Chris@69 111 s/MACRO *\n/.macro/;
Chris@69 112 $n=1;
Chris@69 113 }
Chris@69 114 if ( /\bMEND\b/ ) {
Chris@69 115 s/\bMEND\b/.endm/;
Chris@69 116 $n=0;
Chris@69 117 }
Chris@69 118
Chris@69 119 # ".rdata" doesn't work in 'as' version 2.13.2, as it is ".rodata" there.
Chris@69 120 #
Chris@69 121 if ( /\bAREA\b/ ) {
Chris@69 122 my $align;
Chris@69 123 $align = "2";
Chris@69 124 if ( /ALIGN=(\d+)/ ) {
Chris@69 125 $align = $1;
Chris@69 126 }
Chris@69 127 if ( /CODE/ ) {
Chris@69 128 $nxstack = 1;
Chris@69 129 }
Chris@69 130 s/^(.+)CODE(.+)READONLY(.*)/ .text/;
Chris@69 131 s/^(.+)DATA(.+)READONLY(.*)/ .section .rdata/;
Chris@69 132 s/^(.+)\|\|\.data\|\|(.+)/ .data/;
Chris@69 133 s/^(.+)\|\|\.bss\|\|(.+)/ .bss/;
Chris@69 134 s/$/; .p2align $align/;
Chris@69 135 # Enable NEON instructions but don't produce a binary that requires
Chris@69 136 # ARMv7. RVCT does not have equivalent directives, so we just do this
Chris@69 137 # for all CODE areas.
Chris@69 138 if ( /.text/ ) {
Chris@69 139 # Separating .arch, .fpu, etc., by semicolons does not work (gas
Chris@69 140 # thinks the semicolon is part of the arch name, even when there's
Chris@69 141 # whitespace separating them). Sadly this means our line numbers
Chris@69 142 # won't match the original source file (we could use the .line
Chris@69 143 # directive, which is documented to be obsolete, but then gdb will
Chris@69 144 # show the wrong line in the translated source file).
Chris@69 145 s/$/; .arch armv7-a\n .fpu neon\n .object_arch armv4t/ unless ($apple);
Chris@69 146 }
Chris@69 147 }
Chris@69 148
Chris@69 149 s/\|\|\.constdata\$(\d+)\|\|/.L_CONST$1/; # ||.constdata$3||
Chris@69 150 s/\|\|\.bss\$(\d+)\|\|/.L_BSS$1/; # ||.bss$2||
Chris@69 151 s/\|\|\.data\$(\d+)\|\|/.L_DATA$1/; # ||.data$2||
Chris@69 152 s/\|\|([a-zA-Z0-9_]+)\@([a-zA-Z0-9_]+)\|\|/@ $&/;
Chris@69 153 s/^(\s+)\%(\s)/ .space $1/;
Chris@69 154
Chris@69 155 s/\|(.+)\.(\d+)\|/\.$1_$2/; # |L80.123| -> .L80_123
Chris@69 156 s/\bCODE32\b/.code 32/ && do {$thumb = 0};
Chris@69 157 s/\bCODE16\b/.code 16/ && do {$thumb = 1};
Chris@69 158 if (/\bPROC\b/)
Chris@69 159 {
Chris@69 160 my $prefix;
Chris@69 161 my $proc;
Chris@69 162 /^([A-Za-z_\.]\w+)\b/;
Chris@69 163 $proc = $1;
Chris@69 164 $prefix = "";
Chris@69 165 if ($proc)
Chris@69 166 {
Chris@69 167 $prefix = $prefix.sprintf("\t.type\t%s, %%function", $proc) unless ($apple);
Chris@69 168 # Make sure we $prefix isn't empty here (for the $apple case).
Chris@69 169 # We handle mangling the label here, make sure it doesn't match
Chris@69 170 # the label handling below (if $prefix would be empty).
Chris@69 171 $prefix = $prefix."; ";
Chris@69 172 push(@proc_stack, $proc);
Chris@69 173 s/^[A-Za-z_\.]\w+/$symprefix$&:/;
Chris@69 174 }
Chris@69 175 $prefix = $prefix."\t.thumb_func; " if ($thumb);
Chris@69 176 s/\bPROC\b/@ $&/;
Chris@69 177 $_ = $prefix.$_;
Chris@69 178 }
Chris@69 179 s/^(\s*)(S|Q|SH|U|UQ|UH)ASX\b/$1$2ADDSUBX/;
Chris@69 180 s/^(\s*)(S|Q|SH|U|UQ|UH)SAX\b/$1$2SUBADDX/;
Chris@69 181 if (/\bENDP\b/)
Chris@69 182 {
Chris@69 183 my $proc;
Chris@69 184 s/\bENDP\b/@ $&/;
Chris@69 185 $proc = pop(@proc_stack);
Chris@69 186 $_ = "\t.size $proc, .-$proc".$_ if ($proc && !$apple);
Chris@69 187 }
Chris@69 188 s/\bSUBT\b/@ $&/;
Chris@69 189 s/\bDATA\b/@ $&/; # DATA directive is deprecated -- Asm guide, p.7-25
Chris@69 190 s/\bKEEP\b/@ $&/;
Chris@69 191 s/\bEXPORTAS\b/@ $&/;
Chris@69 192 s/\|\|(.)+\bEQU\b/@ $&/;
Chris@69 193 s/\|\|([\w\$]+)\|\|/$1/;
Chris@69 194 s/\bENTRY\b/@ $&/;
Chris@69 195 s/\bASSERT\b/@ $&/;
Chris@69 196 s/\bGBLL\b/@ $&/;
Chris@69 197 s/\bGBLA\b/@ $&/;
Chris@69 198 s/^\W+OPT\b/@ $&/;
Chris@69 199 s/:OR:/|/g;
Chris@69 200 s/:SHL:/<</g;
Chris@69 201 s/:SHR:/>>/g;
Chris@69 202 s/:AND:/&/g;
Chris@69 203 s/:LAND:/&&/g;
Chris@69 204 s/CPSR/cpsr/;
Chris@69 205 s/SPSR/spsr/;
Chris@69 206 s/ALIGN$/.balign 4/;
Chris@69 207 s/ALIGN\s+([0-9x]+)$/.balign $1/;
Chris@69 208 s/psr_cxsf/psr_all/;
Chris@69 209 s/LTORG/.ltorg/;
Chris@69 210 s/^([A-Za-z_]\w*)[ \t]+EQU/ .set $1,/;
Chris@69 211 s/^([A-Za-z_]\w*)[ \t]+SETL/ .set $1,/;
Chris@69 212 s/^([A-Za-z_]\w*)[ \t]+SETA/ .set $1,/;
Chris@69 213 s/^([A-Za-z_]\w*)[ \t]+\*/ .set $1,/;
Chris@69 214
Chris@69 215 # {PC} + 0xdeadfeed --> . + 0xdeadfeed
Chris@69 216 s/\{PC\} \+/ \. +/;
Chris@69 217
Chris@69 218 # Single hex constant on the line !
Chris@69 219 #
Chris@69 220 # >>> NOTE <<<
Chris@69 221 # Double-precision floats in gcc are always mixed-endian, which means
Chris@69 222 # bytes in two words are little-endian, but words are big-endian.
Chris@69 223 # So, 0x0000deadfeed0000 would be stored as 0x0000dead at low address
Chris@69 224 # and 0xfeed0000 at high address.
Chris@69 225 #
Chris@69 226 s/\bDCFD\b[ \t]+0x([a-fA-F0-9]{8})([a-fA-F0-9]{8})/.long 0x$1, 0x$2/;
Chris@69 227 # Only decimal constants on the line, no hex !
Chris@69 228 s/\bDCFD\b[ \t]+([0-9\.\-]+)/.double $1/;
Chris@69 229
Chris@69 230 # Single hex constant on the line !
Chris@69 231 # s/\bDCFS\b[ \t]+0x([a-f0-9]{8})([a-f0-9]{8})/.long 0x$1, 0x$2/;
Chris@69 232 # Only decimal constants on the line, no hex !
Chris@69 233 # s/\bDCFS\b[ \t]+([0-9\.\-]+)/.double $1/;
Chris@69 234 s/\bDCFS[ \t]+0x/.word 0x/;
Chris@69 235 s/\bDCFS\b/.float/;
Chris@69 236
Chris@69 237 s/^([A-Za-z_]\w*)[ \t]+DCD/$1 .word/;
Chris@69 238 s/\bDCD\b/.word/;
Chris@69 239 s/^([A-Za-z_]\w*)[ \t]+DCW/$1 .short/;
Chris@69 240 s/\bDCW\b/.short/;
Chris@69 241 s/^([A-Za-z_]\w*)[ \t]+DCB/$1 .byte/;
Chris@69 242 s/\bDCB\b/.byte/;
Chris@69 243 s/^([A-Za-z_]\w*)[ \t]+\%/.comm $1,/;
Chris@69 244 s/^[A-Za-z_\.]\w+/$&:/;
Chris@69 245 s/^(\d+)/$1:/;
Chris@69 246 s/\%(\d+)/$1b_or_f/;
Chris@69 247 s/\%[Bb](\d+)/$1b/;
Chris@69 248 s/\%[Ff](\d+)/$1f/;
Chris@69 249 s/\%[Ff][Tt](\d+)/$1f/;
Chris@69 250 s/&([\dA-Fa-f]+)/0x$1/;
Chris@69 251 if ( /\b2_[01]+\b/ ) {
Chris@69 252 s/\b2_([01]+)\b/conv$1&&&&/g;
Chris@69 253 while ( /[01][01][01][01]&&&&/ ) {
Chris@69 254 s/0000&&&&/&&&&0/g;
Chris@69 255 s/0001&&&&/&&&&1/g;
Chris@69 256 s/0010&&&&/&&&&2/g;
Chris@69 257 s/0011&&&&/&&&&3/g;
Chris@69 258 s/0100&&&&/&&&&4/g;
Chris@69 259 s/0101&&&&/&&&&5/g;
Chris@69 260 s/0110&&&&/&&&&6/g;
Chris@69 261 s/0111&&&&/&&&&7/g;
Chris@69 262 s/1000&&&&/&&&&8/g;
Chris@69 263 s/1001&&&&/&&&&9/g;
Chris@69 264 s/1010&&&&/&&&&A/g;
Chris@69 265 s/1011&&&&/&&&&B/g;
Chris@69 266 s/1100&&&&/&&&&C/g;
Chris@69 267 s/1101&&&&/&&&&D/g;
Chris@69 268 s/1110&&&&/&&&&E/g;
Chris@69 269 s/1111&&&&/&&&&F/g;
Chris@69 270 }
Chris@69 271 s/000&&&&/&&&&0/g;
Chris@69 272 s/001&&&&/&&&&1/g;
Chris@69 273 s/010&&&&/&&&&2/g;
Chris@69 274 s/011&&&&/&&&&3/g;
Chris@69 275 s/100&&&&/&&&&4/g;
Chris@69 276 s/101&&&&/&&&&5/g;
Chris@69 277 s/110&&&&/&&&&6/g;
Chris@69 278 s/111&&&&/&&&&7/g;
Chris@69 279 s/00&&&&/&&&&0/g;
Chris@69 280 s/01&&&&/&&&&1/g;
Chris@69 281 s/10&&&&/&&&&2/g;
Chris@69 282 s/11&&&&/&&&&3/g;
Chris@69 283 s/0&&&&/&&&&0/g;
Chris@69 284 s/1&&&&/&&&&1/g;
Chris@69 285 s/conv&&&&/0x/g;
Chris@69 286 }
Chris@69 287
Chris@69 288 if ( /commandline/)
Chris@69 289 {
Chris@69 290 if( /-bigend/)
Chris@69 291 {
Chris@69 292 $bigend=1;
Chris@69 293 }
Chris@69 294 }
Chris@69 295
Chris@69 296 if ( /\bDCDU\b/ )
Chris@69 297 {
Chris@69 298 my $cmd=$_;
Chris@69 299 my $value;
Chris@69 300 my $prefix;
Chris@69 301 my $w1;
Chris@69 302 my $w2;
Chris@69 303 my $w3;
Chris@69 304 my $w4;
Chris@69 305
Chris@69 306 s/\s+DCDU\b/@ $&/;
Chris@69 307
Chris@69 308 $cmd =~ /\bDCDU\b\s+0x(\d+)/;
Chris@69 309 $value = $1;
Chris@69 310 $value =~ /(\w\w)(\w\w)(\w\w)(\w\w)/;
Chris@69 311 $w1 = $1;
Chris@69 312 $w2 = $2;
Chris@69 313 $w3 = $3;
Chris@69 314 $w4 = $4;
Chris@69 315
Chris@69 316 if( $bigend ne "")
Chris@69 317 {
Chris@69 318 # big endian
Chris@69 319 $prefix = "\t.byte\t0x".$w1.";".
Chris@69 320 "\t.byte\t0x".$w2.";".
Chris@69 321 "\t.byte\t0x".$w3.";".
Chris@69 322 "\t.byte\t0x".$w4."; ";
Chris@69 323 }
Chris@69 324 else
Chris@69 325 {
Chris@69 326 # little endian
Chris@69 327 $prefix = "\t.byte\t0x".$w4.";".
Chris@69 328 "\t.byte\t0x".$w3.";".
Chris@69 329 "\t.byte\t0x".$w2.";".
Chris@69 330 "\t.byte\t0x".$w1."; ";
Chris@69 331 }
Chris@69 332 $_=$prefix.$_;
Chris@69 333 }
Chris@69 334
Chris@69 335 if ( /\badrl\b/i )
Chris@69 336 {
Chris@69 337 s/\badrl\s+(\w+)\s*,\s*(\w+)/ldr $1,=$2/i;
Chris@69 338 $addPadding = 1;
Chris@69 339 }
Chris@69 340 s/\bEND\b/@ END/;
Chris@69 341 } continue {
Chris@69 342 printf ("%s", $_) if $printit;
Chris@69 343 if ($addPadding != 0)
Chris@69 344 {
Chris@69 345 printf (" mov r0,r0\n");
Chris@69 346 $addPadding = 0;
Chris@69 347 }
Chris@69 348 }
Chris@69 349 #If we had a code section, mark that this object doesn't need an executable
Chris@69 350 # stack.
Chris@69 351 if ($nxstack && !$apple) {
Chris@69 352 printf (" .section\t.note.GNU-stack,\"\",\%\%progbits\n");
Chris@69 353 }