[libav-devel] [PATCH 04/20] Fix handling of mixed .rept/.irp/.if/.macro

Janne Grunau janne-libav at jannau.net
Mon Mar 24 15:29:41 CET 2014


On 2014-03-24 14:37:55 +0200, Martin Storsjö wrote:
> Instead of handling macros and repetitions in two passes, with
> .if handling spread out over the two, handle both at the same
> time.
> ---
>  gas-preprocessor.pl | 171 ++++++++++++++++++++++++++--------------------------
>  test.S              |   4 ++
>  2 files changed, 88 insertions(+), 87 deletions(-)
> 
> diff --git a/gas-preprocessor.pl b/gas-preprocessor.pl
> index d6779cd..5a048ec 100755
> --- a/gas-preprocessor.pl
> +++ b/gas-preprocessor.pl
> @@ -216,6 +216,12 @@ my $macro_count = 0;
>  my $altmacro = 0;
>  my $in_irp = 0;
>  
> +my $num_repts;
> +my @rept_lines;
> +
> +my @irp_args;
> +my $irp_param;
> +
>  my @pass1_lines;
>  my @ifstack;
>  
> @@ -327,27 +333,27 @@ sub parse_line {
>  
>      return if (parse_if_line($line));
>  
> -    if (/\.macro/) {
> -        $macro_level++;
> -        if ($macro_level > 1 && !$current_macro) {
> -            die "nested macros but we don't have master macro";
> -        }
> -    } elsif (/\.endm/) {
> -        $macro_level--;
> -        if ($macro_level < 0) {
> -            die "unmatched .endm";
> -        } elsif ($macro_level == 0) {
> -            $current_macro = '';
> -            return;
> +    if (scalar(@rept_lines) == 0) {
> +        if (/\.macro/) {
> +            $macro_level++;
> +            if ($macro_level > 1 && !$current_macro) {
> +                die "nested macros but we don't have master macro";
> +            }
> +        } elsif (/\.endm/) {
> +            $macro_level--;
> +            if ($macro_level < 0) {
> +                die "unmatched .endm";
> +            } elsif ($macro_level == 0) {
> +                $current_macro = '';
> +                return;
> +            }
>          }
> -    } elsif (/\.irp/ or /\.rept/) {
> -        $in_irp = 1;
> -    } elsif (/.endr/) {
> -        $in_irp = 0;
>      }
>  
>      if ($macro_level > 1) {
>          push(@{$macro_lines{$current_macro}}, $line);
> +    } elsif (scalar(@rept_lines) and $line !~ /\.endr/) {
> +        push(@rept_lines, $line);
>      } elsif ($macro_level == 0) {
>          expand_macros($line);
>      } else {
> @@ -390,7 +396,7 @@ sub expand_macros {
>  
>      # handle .if directives; apple's assembler doesn't support important non-basic ones
>      # evaluating them is also needed to handle recursive macros
> -    if (!$in_irp && handle_if($line)) {
> +    if (handle_if($line)) {
>          return;
>      }
>  
> @@ -415,7 +421,65 @@ sub expand_macros {
>  
>      handle_set($line);
>  
> -    if ($line =~ /(\S+:|)\s*([\w\d\.]+)\s*(.*)/ && exists $macro_lines{$2}) {
> +    if ($line =~ /\.rept\s+(.*)/) {
> +        $num_repts = $1;
> +        @rept_lines = ("\n");
> +
> +        # handle the possibility of repeating another directive on the same line
> +        # .endr on the same line is not valid, I don't know if a non-directive is
> +        if ($num_repts =~ s/(\.\w+.*)//) {
> +            push(@rept_lines, "$1\n");
> +        }
> +        $num_repts = eval_expr($num_repts);

x264 has '.rept 16 .byte 0xff', I'm too unsure if this is allowed but gas
seems to handle it fine.

seems fine

Janne


More information about the libav-devel mailing list