media/libvpx/build/make/ads2gas.pl

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/media/libvpx/build/make/ads2gas.pl	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,236 @@
     1.4 +#!/usr/bin/perl
     1.5 +##
     1.6 +##  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
     1.7 +##
     1.8 +##  Use of this source code is governed by a BSD-style license
     1.9 +##  that can be found in the LICENSE file in the root of the source
    1.10 +##  tree. An additional intellectual property rights grant can be found
    1.11 +##  in the file PATENTS.  All contributing project authors may
    1.12 +##  be found in the AUTHORS file in the root of the source tree.
    1.13 +##
    1.14 +
    1.15 +
    1.16 +# ads2gas.pl
    1.17 +# Author: Eric Fung (efung (at) acm.org)
    1.18 +#
    1.19 +# Convert ARM Developer Suite 1.0.1 syntax assembly source to GNU as format
    1.20 +#
    1.21 +# Usage: cat inputfile | perl ads2gas.pl > outputfile
    1.22 +#
    1.23 +
    1.24 +use FindBin;
    1.25 +use lib $FindBin::Bin;
    1.26 +use thumb;
    1.27 +
    1.28 +my $thumb = 0;
    1.29 +
    1.30 +foreach my $arg (@ARGV) {
    1.31 +    $thumb = 1 if ($arg eq "-thumb");
    1.32 +}
    1.33 +
    1.34 +print "@ This file was created from a .asm file\n";
    1.35 +print "@  using the ads2gas.pl script.\n";
    1.36 +print "\t.equ DO1STROUNDING, 0\n";
    1.37 +if ($thumb) {
    1.38 +    print "\t.syntax unified\n";
    1.39 +    print "\t.thumb\n";
    1.40 +}
    1.41 +
    1.42 +# Stack of procedure names.
    1.43 +@proc_stack = ();
    1.44 +
    1.45 +while (<STDIN>)
    1.46 +{
    1.47 +    undef $comment;
    1.48 +    undef $line;
    1.49 +    $comment_char = ";";
    1.50 +    $comment_sub = "@";
    1.51 +
    1.52 +    # Handle comments.
    1.53 +    if (/$comment_char/)
    1.54 +    {
    1.55 +      $comment = "";
    1.56 +      ($line, $comment) = /(.*?)$comment_char(.*)/;
    1.57 +      $_ = $line;
    1.58 +    }
    1.59 +
    1.60 +    # Load and store alignment
    1.61 +    s/@/,:/g;
    1.62 +
    1.63 +    # Hexadecimal constants prefaced by 0x
    1.64 +    s/#&/#0x/g;
    1.65 +
    1.66 +    # Convert :OR: to |
    1.67 +    s/:OR:/ | /g;
    1.68 +
    1.69 +    # Convert :AND: to &
    1.70 +    s/:AND:/ & /g;
    1.71 +
    1.72 +    # Convert :NOT: to ~
    1.73 +    s/:NOT:/ ~ /g;
    1.74 +
    1.75 +    # Convert :SHL: to <<
    1.76 +    s/:SHL:/ << /g;
    1.77 +
    1.78 +    # Convert :SHR: to >>
    1.79 +    s/:SHR:/ >> /g;
    1.80 +
    1.81 +    # Convert ELSE to .else
    1.82 +    s/\bELSE\b/.else/g;
    1.83 +
    1.84 +    # Convert ENDIF to .endif
    1.85 +    s/\bENDIF\b/.endif/g;
    1.86 +
    1.87 +    # Convert ELSEIF to .elseif
    1.88 +    s/\bELSEIF\b/.elseif/g;
    1.89 +
    1.90 +    # Convert LTORG to .ltorg
    1.91 +    s/\bLTORG\b/.ltorg/g;
    1.92 +
    1.93 +    # Convert endfunc to nothing.
    1.94 +    s/\bendfunc\b//ig;
    1.95 +
    1.96 +    # Convert FUNCTION to nothing.
    1.97 +    s/\bFUNCTION\b//g;
    1.98 +    s/\bfunction\b//g;
    1.99 +
   1.100 +    s/\bENTRY\b//g;
   1.101 +    s/\bMSARMASM\b/0/g;
   1.102 +    s/^\s+end\s+$//g;
   1.103 +
   1.104 +    # Convert IF :DEF:to .if
   1.105 +    # gcc doesn't have the ability to do a conditional
   1.106 +    # if defined variable that is set by IF :DEF: on
   1.107 +    # armasm, so convert it to a normal .if and then
   1.108 +    # make sure to define a value elesewhere
   1.109 +    if (s/\bIF :DEF:\b/.if /g)
   1.110 +    {
   1.111 +        s/=/==/g;
   1.112 +    }
   1.113 +
   1.114 +    # Convert IF to .if
   1.115 +    if (s/\bIF\b/.if/g)
   1.116 +    {
   1.117 +        s/=+/==/g;
   1.118 +    }
   1.119 +
   1.120 +    # Convert INCLUDE to .INCLUDE "file"
   1.121 +    s/INCLUDE(\s*)(.*)$/.include $1\"$2\"/;
   1.122 +
   1.123 +    # Code directive (ARM vs Thumb)
   1.124 +    s/CODE([0-9][0-9])/.code $1/;
   1.125 +
   1.126 +    # No AREA required
   1.127 +    # But ALIGNs in AREA must be obeyed
   1.128 +    s/^\s*AREA.*ALIGN=([0-9])$/.text\n.p2align $1/;
   1.129 +    # If no ALIGN, strip the AREA and align to 4 bytes
   1.130 +    s/^\s*AREA.*$/.text\n.p2align 2/;
   1.131 +
   1.132 +    # DCD to .word
   1.133 +    # This one is for incoming symbols
   1.134 +    s/DCD\s+\|(\w*)\|/.long $1/;
   1.135 +
   1.136 +    # DCW to .short
   1.137 +    s/DCW\s+\|(\w*)\|/.short $1/;
   1.138 +    s/DCW(.*)/.short $1/;
   1.139 +
   1.140 +    # Constants defined in scope
   1.141 +    s/DCD(.*)/.long $1/;
   1.142 +    s/DCB(.*)/.byte $1/;
   1.143 +
   1.144 +    # RN to .req
   1.145 +    if (s/RN\s+([Rr]\d+|lr)/.req $1/)
   1.146 +    {
   1.147 +        print;
   1.148 +        print "$comment_sub$comment\n" if defined $comment;
   1.149 +        next;
   1.150 +    }
   1.151 +
   1.152 +    # Make function visible to linker, and make additional symbol with
   1.153 +    # prepended underscore
   1.154 +    s/EXPORT\s+\|([\$\w]*)\|/.global $1 \n\t.type $1, function/;
   1.155 +    s/IMPORT\s+\|([\$\w]*)\|/.global $1/;
   1.156 +
   1.157 +    s/EXPORT\s+([\$\w]*)/.global $1/;
   1.158 +    s/export\s+([\$\w]*)/.global $1/;
   1.159 +
   1.160 +    # No vertical bars required; make additional symbol with prepended
   1.161 +    # underscore
   1.162 +    s/^\|(\$?\w+)\|/_$1\n\t$1:/g;
   1.163 +
   1.164 +    # Labels need trailing colon
   1.165 +#   s/^(\w+)/$1:/ if !/EQU/;
   1.166 +    # put the colon at the end of the line in the macro
   1.167 +    s/^([a-zA-Z_0-9\$]+)/$1:/ if !/EQU/;
   1.168 +
   1.169 +    # ALIGN directive
   1.170 +    s/\bALIGN\b/.balign/g;
   1.171 +
   1.172 +    if ($thumb) {
   1.173 +        # ARM code - we force everything to thumb with the declaration in the header
   1.174 +        s/\sARM//g;
   1.175 +    } else {
   1.176 +        # ARM code
   1.177 +        s/\sARM/.arm/g;
   1.178 +    }
   1.179 +
   1.180 +    # push/pop
   1.181 +    s/(push\s+)(r\d+)/stmdb sp\!, \{$2\}/g;
   1.182 +    s/(pop\s+)(r\d+)/ldmia sp\!, \{$2\}/g;
   1.183 +
   1.184 +    # NEON code
   1.185 +    s/(vld1.\d+\s+)(q\d+)/$1\{$2\}/g;
   1.186 +    s/(vtbl.\d+\s+[^,]+),([^,]+)/$1,\{$2\}/g;
   1.187 +
   1.188 +    if ($thumb) {
   1.189 +        thumb::FixThumbInstructions($_, 0);
   1.190 +    }
   1.191 +
   1.192 +    # eabi_attributes numerical equivalents can be found in the
   1.193 +    # "ARM IHI 0045C" document.
   1.194 +
   1.195 +    # REQUIRE8 Stack is required to be 8-byte aligned
   1.196 +    s/\sREQUIRE8/.eabi_attribute 24, 1 \@Tag_ABI_align_needed/g;
   1.197 +
   1.198 +    # PRESERVE8 Stack 8-byte align is preserved
   1.199 +    s/\sPRESERVE8/.eabi_attribute 25, 1 \@Tag_ABI_align_preserved/g;
   1.200 +
   1.201 +    # Use PROC and ENDP to give the symbols a .size directive.
   1.202 +    # This makes them show up properly in debugging tools like gdb and valgrind.
   1.203 +    if (/\bPROC\b/)
   1.204 +    {
   1.205 +        my $proc;
   1.206 +        /^_([\.0-9A-Z_a-z]\w+)\b/;
   1.207 +        $proc = $1;
   1.208 +        push(@proc_stack, $proc) if ($proc);
   1.209 +        s/\bPROC\b/@ $&/;
   1.210 +    }
   1.211 +    if (/\bENDP\b/)
   1.212 +    {
   1.213 +        my $proc;
   1.214 +        s/\bENDP\b/@ $&/;
   1.215 +        $proc = pop(@proc_stack);
   1.216 +        $_ = "\t.size $proc, .-$proc".$_ if ($proc);
   1.217 +    }
   1.218 +
   1.219 +    # EQU directive
   1.220 +    s/(\S+\s+)EQU(\s+\S+)/.equ $1, $2/;
   1.221 +
   1.222 +    # Begin macro definition
   1.223 +    if (/\bMACRO\b/) {
   1.224 +        $_ = <STDIN>;
   1.225 +        s/^/.macro/;
   1.226 +        s/\$//g;                # remove formal param reference
   1.227 +        s/;/@/g;                # change comment characters
   1.228 +    }
   1.229 +
   1.230 +    # For macros, use \ to reference formal params
   1.231 +    s/\$/\\/g;                  # End macro definition
   1.232 +    s/\bMEND\b/.endm/;              # No need to tell it where to stop assembling
   1.233 +    next if /^\s*END\s*$/;
   1.234 +    print;
   1.235 +    print "$comment_sub$comment\n" if defined $comment;
   1.236 +}
   1.237 +
   1.238 +# Mark that this object doesn't need an executable stack.
   1.239 +printf ("\t.section\t.note.GNU-stack,\"\",\%\%progbits\n");

mercurial