media/libopus/celt/arm/arm2gnu.pl

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/media/libopus/celt/arm/arm2gnu.pl	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,316 @@
     1.4 +#!/usr/bin/perl
     1.5 +
     1.6 +my $bigend;  # little/big endian
     1.7 +my $nxstack;
     1.8 +
     1.9 +$nxstack = 0;
    1.10 +
    1.11 +eval 'exec /usr/local/bin/perl -S $0 ${1+"$@"}'
    1.12 +    if $running_under_some_shell;
    1.13 +
    1.14 +while ($ARGV[0] =~ /^-/) {
    1.15 +    $_ = shift;
    1.16 +  last if /^--/;
    1.17 +    if (/^-n/) {
    1.18 +    $nflag++;
    1.19 +    next;
    1.20 +    }
    1.21 +    die "I don't recognize this switch: $_\\n";
    1.22 +}
    1.23 +$printit++ unless $nflag;
    1.24 +
    1.25 +$\ = "\n";      # automatically add newline on print
    1.26 +$n=0;
    1.27 +
    1.28 +$thumb = 0;     # ARM mode by default, not Thumb.
    1.29 +@proc_stack = ();
    1.30 +
    1.31 +LINE:
    1.32 +while (<>) {
    1.33 +
    1.34 +    # For ADRLs we need to add a new line after the substituted one.
    1.35 +    $addPadding = 0;
    1.36 +
    1.37 +    # First, we do not dare to touch *anything* inside double quotes, do we?
    1.38 +    # Second, if you want a dollar character in the string,
    1.39 +    # insert two of them -- that's how ARM C and assembler treat strings.
    1.40 +    s/^([A-Za-z_]\w*)[ \t]+DCB[ \t]*\"/$1:   .ascii \"/   && do { s/\$\$/\$/g; next };
    1.41 +    s/\bDCB\b[ \t]*\"/.ascii \"/                          && do { s/\$\$/\$/g; next };
    1.42 +    s/^(\S+)\s+RN\s+(\S+)/$1 .req r$2/                    && do { s/\$\$/\$/g; next };
    1.43 +    # If there's nothing on a line but a comment, don't try to apply any further
    1.44 +    #  substitutions (this is a cheap hack to avoid mucking up the license header)
    1.45 +    s/^([ \t]*);/$1@/                                     && do { s/\$\$/\$/g; next };
    1.46 +    # If substituted -- leave immediately !
    1.47 +
    1.48 +    s/@/,:/;
    1.49 +    s/;/@/;
    1.50 +    while ( /@.*'/ ) {
    1.51 +      s/(@.*)'/$1/g;
    1.52 +    }
    1.53 +    s/\{FALSE\}/0/g;
    1.54 +    s/\{TRUE\}/1/g;
    1.55 +    s/\{(\w\w\w\w+)\}/$1/g;
    1.56 +    s/\bINCLUDE[ \t]*([^ \t\n]+)/.include \"$1\"/;
    1.57 +    s/\bGET[ \t]*([^ \t\n]+)/.include \"${ my $x=$1; $x =~ s|\.s|-gnu.S|; \$x }\"/;
    1.58 +    s/\bIMPORT\b/.extern/;
    1.59 +    s/\bEXPORT\b/.global/;
    1.60 +    s/^(\s+)\[/$1IF/;
    1.61 +    s/^(\s+)\|/$1ELSE/;
    1.62 +    s/^(\s+)\]/$1ENDIF/;
    1.63 +    s/IF *:DEF:/ .ifdef/;
    1.64 +    s/IF *:LNOT: *:DEF:/ .ifndef/;
    1.65 +    s/ELSE/ .else/;
    1.66 +    s/ENDIF/ .endif/;
    1.67 +
    1.68 +    if( /\bIF\b/ ) {
    1.69 +      s/\bIF\b/ .if/;
    1.70 +      s/=/==/;
    1.71 +    }
    1.72 +    if ( $n == 2) {
    1.73 +        s/\$/\\/g;
    1.74 +    }
    1.75 +    if ($n == 1) {
    1.76 +        s/\$//g;
    1.77 +        s/label//g;
    1.78 +    $n = 2;
    1.79 +      }
    1.80 +    if ( /MACRO/ ) {
    1.81 +      s/MACRO *\n/.macro/;
    1.82 +      $n=1;
    1.83 +    }
    1.84 +    if ( /\bMEND\b/ ) {
    1.85 +      s/\bMEND\b/.endm/;
    1.86 +      $n=0;
    1.87 +    }
    1.88 +
    1.89 +    # ".rdata" doesn't work in 'as' version 2.13.2, as it is ".rodata" there.
    1.90 +    #
    1.91 +    if ( /\bAREA\b/ ) {
    1.92 +        my $align;
    1.93 +        $align = "2";
    1.94 +        if ( /ALIGN=(\d+)/ ) {
    1.95 +            $align = $1;
    1.96 +        }
    1.97 +        if ( /CODE/ ) {
    1.98 +            $nxstack = 1;
    1.99 +        }
   1.100 +        s/^(.+)CODE(.+)READONLY(.*)/    .text/;
   1.101 +        s/^(.+)DATA(.+)READONLY(.*)/    .section .rdata/;
   1.102 +        s/^(.+)\|\|\.data\|\|(.+)/    .data/;
   1.103 +        s/^(.+)\|\|\.bss\|\|(.+)/    .bss/;
   1.104 +        s/$/;   .p2align $align/;
   1.105 +        # Enable NEON instructions but don't produce a binary that requires
   1.106 +        # ARMv7. RVCT does not have equivalent directives, so we just do this
   1.107 +        # for all CODE areas.
   1.108 +        if ( /.text/ ) {
   1.109 +            # Separating .arch, .fpu, etc., by semicolons does not work (gas
   1.110 +            # thinks the semicolon is part of the arch name, even when there's
   1.111 +            # whitespace separating them). Sadly this means our line numbers
   1.112 +            # won't match the original source file (we could use the .line
   1.113 +            # directive, which is documented to be obsolete, but then gdb will
   1.114 +            # show the wrong line in the translated source file).
   1.115 +            s/$/;   .arch armv7-a\n   .fpu neon\n   .object_arch armv4t/;
   1.116 +        }
   1.117 +    }
   1.118 +
   1.119 +    s/\|\|\.constdata\$(\d+)\|\|/.L_CONST$1/;       # ||.constdata$3||
   1.120 +    s/\|\|\.bss\$(\d+)\|\|/.L_BSS$1/;               # ||.bss$2||
   1.121 +    s/\|\|\.data\$(\d+)\|\|/.L_DATA$1/;             # ||.data$2||
   1.122 +    s/\|\|([a-zA-Z0-9_]+)\@([a-zA-Z0-9_]+)\|\|/@ $&/;
   1.123 +    s/^(\s+)\%(\s)/    .space $1/;
   1.124 +
   1.125 +    s/\|(.+)\.(\d+)\|/\.$1_$2/;                     # |L80.123| -> .L80_123
   1.126 +    s/\bCODE32\b/.code 32/ && do {$thumb = 0};
   1.127 +    s/\bCODE16\b/.code 16/ && do {$thumb = 1};
   1.128 +    if (/\bPROC\b/)
   1.129 +    {
   1.130 +        my $prefix;
   1.131 +        my $proc;
   1.132 +        /^([A-Za-z_\.]\w+)\b/;
   1.133 +        $proc = $1;
   1.134 +        $prefix = "";
   1.135 +        if ($proc)
   1.136 +        {
   1.137 +            $prefix = $prefix.sprintf("\t.type\t%s, %%function; ",$proc);
   1.138 +            push(@proc_stack, $proc);
   1.139 +            s/^[A-Za-z_\.]\w+/$&:/;
   1.140 +        }
   1.141 +        $prefix = $prefix."\t.thumb_func; " if ($thumb);
   1.142 +        s/\bPROC\b/@ $&/;
   1.143 +        $_ = $prefix.$_;
   1.144 +    }
   1.145 +    s/^(\s*)(S|Q|SH|U|UQ|UH)ASX\b/$1$2ADDSUBX/;
   1.146 +    s/^(\s*)(S|Q|SH|U|UQ|UH)SAX\b/$1$2SUBADDX/;
   1.147 +    if (/\bENDP\b/)
   1.148 +    {
   1.149 +        my $proc;
   1.150 +        s/\bENDP\b/@ $&/;
   1.151 +        $proc = pop(@proc_stack);
   1.152 +        $_ = "\t.size $proc, .-$proc".$_ if ($proc);
   1.153 +    }
   1.154 +    s/\bSUBT\b/@ $&/;
   1.155 +    s/\bDATA\b/@ $&/;   # DATA directive is deprecated -- Asm guide, p.7-25
   1.156 +    s/\bKEEP\b/@ $&/;
   1.157 +    s/\bEXPORTAS\b/@ $&/;
   1.158 +    s/\|\|(.)+\bEQU\b/@ $&/;
   1.159 +    s/\|\|([\w\$]+)\|\|/$1/;
   1.160 +    s/\bENTRY\b/@ $&/;
   1.161 +    s/\bASSERT\b/@ $&/;
   1.162 +    s/\bGBLL\b/@ $&/;
   1.163 +    s/\bGBLA\b/@ $&/;
   1.164 +    s/^\W+OPT\b/@ $&/;
   1.165 +    s/:OR:/|/g;
   1.166 +    s/:SHL:/<</g;
   1.167 +    s/:SHR:/>>/g;
   1.168 +    s/:AND:/&/g;
   1.169 +    s/:LAND:/&&/g;
   1.170 +    s/CPSR/cpsr/;
   1.171 +    s/SPSR/spsr/;
   1.172 +    s/ALIGN$/.balign 4/;
   1.173 +    s/ALIGN\s+([0-9x]+)$/.balign $1/;
   1.174 +    s/psr_cxsf/psr_all/;
   1.175 +    s/LTORG/.ltorg/;
   1.176 +    s/^([A-Za-z_]\w*)[ \t]+EQU/ .set $1,/;
   1.177 +    s/^([A-Za-z_]\w*)[ \t]+SETL/ .set $1,/;
   1.178 +    s/^([A-Za-z_]\w*)[ \t]+SETA/ .set $1,/;
   1.179 +    s/^([A-Za-z_]\w*)[ \t]+\*/ .set $1,/;
   1.180 +
   1.181 +    #  {PC} + 0xdeadfeed  -->  . + 0xdeadfeed
   1.182 +    s/\{PC\} \+/ \. +/;
   1.183 +
   1.184 +    # Single hex constant on the line !
   1.185 +    #
   1.186 +    # >>> NOTE <<<
   1.187 +    #   Double-precision floats in gcc are always mixed-endian, which means
   1.188 +    #   bytes in two words are little-endian, but words are big-endian.
   1.189 +    #   So, 0x0000deadfeed0000 would be stored as 0x0000dead at low address
   1.190 +    #   and 0xfeed0000 at high address.
   1.191 +    #
   1.192 +    s/\bDCFD\b[ \t]+0x([a-fA-F0-9]{8})([a-fA-F0-9]{8})/.long 0x$1, 0x$2/;
   1.193 +    # Only decimal constants on the line, no hex !
   1.194 +    s/\bDCFD\b[ \t]+([0-9\.\-]+)/.double $1/;
   1.195 +
   1.196 +    # Single hex constant on the line !
   1.197 +#    s/\bDCFS\b[ \t]+0x([a-f0-9]{8})([a-f0-9]{8})/.long 0x$1, 0x$2/;
   1.198 +    # Only decimal constants on the line, no hex !
   1.199 +#    s/\bDCFS\b[ \t]+([0-9\.\-]+)/.double $1/;
   1.200 +    s/\bDCFS[ \t]+0x/.word 0x/;
   1.201 +    s/\bDCFS\b/.float/;
   1.202 +
   1.203 +    s/^([A-Za-z_]\w*)[ \t]+DCD/$1 .word/;
   1.204 +    s/\bDCD\b/.word/;
   1.205 +    s/^([A-Za-z_]\w*)[ \t]+DCW/$1 .short/;
   1.206 +    s/\bDCW\b/.short/;
   1.207 +    s/^([A-Za-z_]\w*)[ \t]+DCB/$1 .byte/;
   1.208 +    s/\bDCB\b/.byte/;
   1.209 +    s/^([A-Za-z_]\w*)[ \t]+\%/.comm $1,/;
   1.210 +    s/^[A-Za-z_\.]\w+/$&:/;
   1.211 +    s/^(\d+)/$1:/;
   1.212 +    s/\%(\d+)/$1b_or_f/;
   1.213 +    s/\%[Bb](\d+)/$1b/;
   1.214 +    s/\%[Ff](\d+)/$1f/;
   1.215 +    s/\%[Ff][Tt](\d+)/$1f/;
   1.216 +    s/&([\dA-Fa-f]+)/0x$1/;
   1.217 +    if ( /\b2_[01]+\b/ ) {
   1.218 +      s/\b2_([01]+)\b/conv$1&&&&/g;
   1.219 +      while ( /[01][01][01][01]&&&&/ ) {
   1.220 +        s/0000&&&&/&&&&0/g;
   1.221 +        s/0001&&&&/&&&&1/g;
   1.222 +        s/0010&&&&/&&&&2/g;
   1.223 +        s/0011&&&&/&&&&3/g;
   1.224 +        s/0100&&&&/&&&&4/g;
   1.225 +        s/0101&&&&/&&&&5/g;
   1.226 +        s/0110&&&&/&&&&6/g;
   1.227 +        s/0111&&&&/&&&&7/g;
   1.228 +        s/1000&&&&/&&&&8/g;
   1.229 +        s/1001&&&&/&&&&9/g;
   1.230 +        s/1010&&&&/&&&&A/g;
   1.231 +        s/1011&&&&/&&&&B/g;
   1.232 +        s/1100&&&&/&&&&C/g;
   1.233 +        s/1101&&&&/&&&&D/g;
   1.234 +        s/1110&&&&/&&&&E/g;
   1.235 +        s/1111&&&&/&&&&F/g;
   1.236 +      }
   1.237 +      s/000&&&&/&&&&0/g;
   1.238 +      s/001&&&&/&&&&1/g;
   1.239 +      s/010&&&&/&&&&2/g;
   1.240 +      s/011&&&&/&&&&3/g;
   1.241 +      s/100&&&&/&&&&4/g;
   1.242 +      s/101&&&&/&&&&5/g;
   1.243 +      s/110&&&&/&&&&6/g;
   1.244 +      s/111&&&&/&&&&7/g;
   1.245 +      s/00&&&&/&&&&0/g;
   1.246 +      s/01&&&&/&&&&1/g;
   1.247 +      s/10&&&&/&&&&2/g;
   1.248 +      s/11&&&&/&&&&3/g;
   1.249 +      s/0&&&&/&&&&0/g;
   1.250 +      s/1&&&&/&&&&1/g;
   1.251 +      s/conv&&&&/0x/g;
   1.252 +    }
   1.253 +
   1.254 +    if ( /commandline/)
   1.255 +    {
   1.256 +        if( /-bigend/)
   1.257 +        {
   1.258 +            $bigend=1;
   1.259 +        }
   1.260 +    }
   1.261 +
   1.262 +    if ( /\bDCDU\b/ )
   1.263 +    {
   1.264 +        my $cmd=$_;
   1.265 +        my $value;
   1.266 +        my $prefix;
   1.267 +        my $w1;
   1.268 +        my $w2;
   1.269 +        my $w3;
   1.270 +        my $w4;
   1.271 +
   1.272 +        s/\s+DCDU\b/@ $&/;
   1.273 +
   1.274 +        $cmd =~ /\bDCDU\b\s+0x(\d+)/;
   1.275 +        $value = $1;
   1.276 +        $value =~ /(\w\w)(\w\w)(\w\w)(\w\w)/;
   1.277 +        $w1 = $1;
   1.278 +        $w2 = $2;
   1.279 +        $w3 = $3;
   1.280 +        $w4 = $4;
   1.281 +
   1.282 +        if( $bigend ne "")
   1.283 +        {
   1.284 +            # big endian
   1.285 +            $prefix = "\t.byte\t0x".$w1.";".
   1.286 +                      "\t.byte\t0x".$w2.";".
   1.287 +                      "\t.byte\t0x".$w3.";".
   1.288 +                      "\t.byte\t0x".$w4."; ";
   1.289 +        }
   1.290 +        else
   1.291 +        {
   1.292 +            # little endian
   1.293 +            $prefix = "\t.byte\t0x".$w4.";".
   1.294 +                      "\t.byte\t0x".$w3.";".
   1.295 +                      "\t.byte\t0x".$w2.";".
   1.296 +                      "\t.byte\t0x".$w1."; ";
   1.297 +        }
   1.298 +        $_=$prefix.$_;
   1.299 +    }
   1.300 +
   1.301 +    if ( /\badrl\b/i )
   1.302 +    {
   1.303 +        s/\badrl\s+(\w+)\s*,\s*(\w+)/ldr $1,=$2/i;
   1.304 +        $addPadding = 1;
   1.305 +    }
   1.306 +    s/\bEND\b/@ END/;
   1.307 +} continue {
   1.308 +    printf ("%s", $_) if $printit;
   1.309 +    if ($addPadding != 0)
   1.310 +    {
   1.311 +        printf ("   mov r0,r0\n");
   1.312 +        $addPadding = 0;
   1.313 +    }
   1.314 +}
   1.315 +#If we had a code section, mark that this object doesn't need an executable
   1.316 +# stack.
   1.317 +if ($nxstack) {
   1.318 +    printf ("    .section\t.note.GNU-stack,\"\",\%\%progbits\n");
   1.319 +}

mercurial