On 2014-03-12 23:02:38 +0200, Martin Storsjö wrote:
> This syntax is supported by the official arm tools and
> by Microsoft's assembler.
> 
> This currently only supports microsoft's assembler, the
> armasm assembler in RVCT requires a few more tweaks to
> be able to build libav.
> 
> The preprocessing is done by invoking cpp (do we need to
> be able to override this?).
> 
> The converted output is written to a file instead of using
> a pipe, since Microsoft's armasm can't read the input from
> a pipe.
> ---
> Moved conversion of .arm/.thumb to a later stage, after interpreting
> them for setting the thumb flag, and moved a few more conversions
> into =~ /^-apple/ instead of checking for not gas, not armasm.
> ---
>  gas-preprocessor.pl | 280 
> ++++++++++++++++++++++++++++++++++++++++++++++------
>  1 file changed, 250 insertions(+), 30 deletions(-)
> 
> diff --git a/gas-preprocessor.pl b/gas-preprocessor.pl
> index ec326f9..f6f3699 100755
> --- a/gas-preprocessor.pl
> +++ b/gas-preprocessor.pl
> @@ -40,7 +40,7 @@ command. Following options are currently supported:
>  
>      -help         - this usage text
>      -arch         - target architecture
> -    -as-type      - one value out of {,apple-}{gas,clang}
> +    -as-type      - one value out of {{,apple-}{gas,clang},armasm}
>      -fix-unreq
>      -no-fix-unreq
>  ";
> @@ -79,7 +79,7 @@ while (@options) {
>          die "unknown arch: '$arch'\n" if not exists $comments{$arch};
>      } elsif ($opt eq "-as-type") {
>          $as_type = shift @options;
> -        die "unknown as type: '$as_type'\n" if $as_type !~ 
> /^(apple-)?(gas|clang)$/;
> +        die "unknown as type: '$as_type'\n" if $as_type !~ 
> /^((apple-)?(gas|clang)|armasm)$/;
>      } elsif ($opt eq "-help") {
>          usage();
>          exit 0;
> @@ -103,6 +103,25 @@ if (grep /\.c$/, @gcc_cmd) {
>  } else {
>      die "Unrecognized input filetype";
>  }
> +if ($as_type eq "armasm") {
> +
> +    $preprocess_c_cmd[0] = "cpp";
> +
> +    @preprocess_c_cmd = grep ! /^-nologo$/, @preprocess_c_cmd;
> +    # Remove -ignore XX parameter pairs from preprocess_c_cmd
> +    my $index = 1;
> +    while ($index < $#preprocess_c_cmd) {
> +        if ($preprocess_c_cmd[$index] eq "-ignore" and $index + 1 < 
> $#preprocess_c_cmd) {
> +            splice(@preprocess_c_cmd, $index, 2);
> +            next;
> +        }
> +        $index++;
> +    }
> +    if (grep /^-MM$/, @preprocess_c_cmd) {
> +        system(@preprocess_c_cmd) == 0 or die "Error running preprocessor";
> +        exit 0;
> +    }
> +}
>  
>  # if compiling, avoid creating an output file named '-.o'
>  if ((grep /^-c$/, @gcc_cmd) && !(grep /^-o/, @gcc_cmd)) {
> @@ -116,8 +135,27 @@ if ((grep /^-c$/, @gcc_cmd) && !(grep /^-o/, @gcc_cmd)) {
>          }
>      }
>  }
> -@gcc_cmd = map { /\.[csS]$/ ? qw(-x assembler -) : $_ } @gcc_cmd;
>  @preprocess_c_cmd = map { /\.o$/ ? "-" : $_ } @preprocess_c_cmd;
> +my $tempfile;
> +if ($as_type ne "armasm") {
> +    @gcc_cmd = map { /\.[csS]$/ ? qw(-x assembler -) : $_ } @gcc_cmd;
> +} else {
> +    @preprocess_c_cmd = grep ! /^-c$/, @preprocess_c_cmd;
> +    @preprocess_c_cmd = grep ! /^-m/, @preprocess_c_cmd;
> +
> +    my @outfiles = grep /\.o$/, @gcc_cmd;
> +    $tempfile = $outfiles[0].".asm";
> +
> +    # Remove most parameters from gcc_cmd, which actually is the armasm 
> command,
> +    # which doesn't support any of the common compiler/preprocessor options.
> +    @gcc_cmd = grep ! /^-D/, @gcc_cmd;
> +    @gcc_cmd = grep ! /^-U/, @gcc_cmd;
> +    @gcc_cmd = grep ! /^-m/, @gcc_cmd;
> +    @gcc_cmd = grep ! /^-M/, @gcc_cmd;
> +    @gcc_cmd = grep ! /^-c$/, @gcc_cmd;
> +    @gcc_cmd = grep ! /^-I/, @gcc_cmd;
> +    @gcc_cmd = map { /\.S$/ ? $tempfile : $_ } @gcc_cmd;
> +}
>  
>  # detect architecture from gcc binary name
>  if (!$arch) {
> @@ -167,23 +205,52 @@ my %symbols;
>  while (<ASMFILE>) {
>      # remove all comments (to avoid interfering with evaluating directives)
>      s/(?<!\\)$comm.*//x;
> +    # Strip out windows linefeeds
> +    s/\r$//;
> +    # Strip out line number comments - armasm can handle them in a separate
> +    # syntax, but since the line numbers are off they are only misleading.
> +    s/^#\s+(\d+).*//          if $as_type =~ /armasm/;
>  
>      # comment out unsupported directives
> -    s/\.type/$comm$&/x        if $as_type =~ /^apple-/;
> +    s/\.type/$comm$&/x        if $as_type =~ /^(apple-|armasm)/;
>      s/\.func/$comm$&/x        if $as_type =~ /^(apple-|clang)/;
>      s/\.endfunc/$comm$&/x     if $as_type =~ /^(apple-|clang)/;
> -    s/\.ltorg/$comm$&/x       if $as_type =~ /^(apple-|clang)/;
> -    s/\.size/$comm$&/x        if $as_type =~ /^apple-/;
> -    s/\.fpu/$comm$&/x         if $as_type =~ /^apple-/;
> -    s/\.arch/$comm$&/x        if $as_type =~ /^(apple-|clang)/;
> -    s/\.object_arch/$comm$&/x if $as_type =~ /^apple-/;
> -
> -    # the syntax for these is a little different
> -    s/\.global/.globl/x       if $as_type =~ /apple-/;
> -    # also catch .section .rodata since the equivalent to .const_data is 
> .section __DATA,__const
> -    s/(.*)\.rodata/.const_data/x if $as_type =~ /apple-/;
> -    s/\.int/.long/x;
> -    s/\.float/.single/x;
> +    s/\.endfunc/ENDP/x        if $as_type =~ /armasm/;
> +    s/\.ltorg/$comm$&/x       if $as_type =~ /^(apple-|clang|armasm)/;
> +    s/\.size/$comm$&/x        if $as_type =~ /^(apple-|armasm)/;
> +    s/\.fpu/$comm$&/x         if $as_type =~ /^(apple-|armasm)/;
> +    s/\.arch/$comm$&/x        if $as_type =~ /^(apple-|clang|armasm)/;
> +    s/\.object_arch/$comm$&/x if $as_type =~ /^(apple-|armasm)/;
> +
> +    s/\.syntax/$comm$&/x      if $as_type =~ /armasm/;
> +    # armasm uses a different comment character. We don't want to change
> +    # $comm originally since that matches what the input source uses.
> +    s/$comm/;/                if $as_type =~ /armasm/;
> +
> +    if ($as_type =~ /^apple-/) {
> +        # the syntax for these is a little different
> +        s/\.global/.globl/x       if $as_type =~ /apple-/;
> +        # also catch .section .rodata since the equivalent to .const_data is 
> .section __DATA,__const
> +        s/(.*)\.rodata/.const_data/x if $as_type =~ /apple-/;

the 'if $as_type =~ /apple-/' inside this block are always true,

ok with those removed

Janne
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to