Iain Sandoe <[email protected]> writes:
> This introduces threee customisation points into the function body scans
> code.  This allows targets to consume regexes that are written for ABIs and
> asm syntax that is reasonably compatibile with that used by the target.
>
> The initial use-case here is to map from regexes specified in terms of
> ELF syntax and Linux ABIs, but to be consumed by Darwin ABI and mach-o
> binary format.
>
> gcc/testsuite/ChangeLog:
>
>       * lib/scanasm.exp (target_regex_skip_line,
>       target_regex_verbatim_line, target_substitute_func_regex): New.
>       (check-function-bodies): use the customisation points.
>       (configure_check-function-bodies): Populate the new customisation
>       points for Darwin/Mach-O.
>       * lib/target-supports.exp
>       (add_options_for_check_function_bodies): Add Darwin criteria.
>
> Signed-off-by: Iain Sandoe <[email protected]>
> ---
>  gcc/testsuite/lib/scanasm.exp         | 107 ++++++++++++++++++++++++--
>  gcc/testsuite/lib/target-supports.exp |   4 +
>  2 files changed, 103 insertions(+), 8 deletions(-)
>
> diff --git a/gcc/testsuite/lib/scanasm.exp b/gcc/testsuite/lib/scanasm.exp
> index 08dbf1a8118..9e7a5896475 100644
> --- a/gcc/testsuite/lib/scanasm.exp
> +++ b/gcc/testsuite/lib/scanasm.exp
> @@ -921,7 +921,7 @@ proc configure_check-function-bodies { config } {
>      } elseif { [istarget *-*-darwin*] } {
>       set up_config(start) {
>           {^_([a-zA-Z_]\S*):$}
> -         {^LFB[0-9]+:}
> +         {^LFS?B[0-9]+:$}
>       }
>      } else {
>       set up_config(start) {{^([a-zA-Z_]\S*):$}}
> @@ -931,7 +931,7 @@ proc configure_check-function-bodies { config } {
>      if { [istarget nvptx*-*-*] } {
>       set up_config(end) {^\}$}
>      } elseif { [istarget *-*-darwin*] } {
> -     set up_config(end) {^LFE[0-9]+}
> +     set up_config(end) {^LFE[0-9]+:$}
>      } elseif { [istarget *-*-mingw32] } {
>       set up_config(end) {seh_endproc}
>      } else {
> @@ -944,7 +944,7 @@ proc configure_check-function-bodies { config } {
>       # example).
>       set up_config(fluff) {^\s*(?://)}
>      } elseif { [istarget *-*-darwin*] } {
> -     set up_config(fluff) {^\s*(?:\.|//|@)|^L[0-9ABCESV]}
> +     set up_config(fluff) {^\s*(?:\.|//|@|#)|^L[ABCESV]}
>      } elseif { [istarget s390*-*-*] } {
>       # Additionally to the defaults skip lines beginning with a # resulting
>       # from inline asm.
> @@ -967,6 +967,92 @@ proc configure_check-function-bodies { config } {
>      } else {
>       set up_config(line_prefix) {\t}
>      }
> +
> +    # Set up regex lines that should be skipped for a given object format
> +    set up_config(skip_regex_cases) ""
> +    if { [istarget *-*-darwin*] } {
> +        # Darwin already matches .LF* as part of start/end.
> +        # Currently, .cfi_xxx instructions are not used.
> +     set up_config(skip_regex_cases) {
> +         {^\.LF.*$}
> +         {^.*\.cfi_.*$}
> +     }
> +    }
> +
> +    # Set up regex lines that should be copied verbatim for a given object
> +    # format
> +    if { [istarget *-*-darwin*] } {
> +        # Lines starting with a label, for Darwin we accept ELF local labels
> +        # (starting with .L) and Mach-O (starting with L).  We also accept
> +        # numeric assembler labels.
> +     set up_config(verbatim_regex_cases) {
> +         {^\.?L\[?[0-9].*:$}
> +         {^[0-9]+:.*$}
> +     }
> +    } else {
> +        # Lines starting with a local code label ".L" (which are usually the
> +        # only entries on a line -  or numeric assembler labels, which are
> +        # often followed by some instruction.
> +        set up_config(verbatim_regex_cases) {
> +         {^\.L.*$}
> +         {^[0-9]+:.*$}

The comment led me to expect :$ for the .L case.  Is not having the
: deliberate?  .*$ might as well be dropped, as in the original regexp.

This is admittedly partly pre-existing, but: here and in the
substitutions below, I think it'd be worth allowing an optional "\"
before the ".", to handle cases where the check-function-bodies regexp
itself escapes the ".".  I suppose that would make it:

   (?:\\)?\.

(untested).

> +     }
> +    }
> +
> +    set up_config(regex_substitutions) ""
> +    if { [istarget *-*-darwin*] } {
> +        # Setup substitution pairs for body regexes
> +        # the first entry is what should be matched, the second is what 
> should
> +        # replace it.
> +     set up_config(regex_substitutions) {
> +         { {\.LC} {[lL]C} }
> +         { {\.L} "L" }
> +     }
> +    }
> +
> +}
> +
> +# Sometimes the function match regex might include directives that are not
> +# used by a given binary format.  Allow these to be skipped.
> +proc target_regex_skip_line { config line } {
> +    upvar $config up_config
> +    set item 0
> +    while { $item < [llength $up_config(skip_regex_cases)] } {
> +        if { [regexp [lindex $up_config(skip_regex_cases) $item] $line] } {
> +            return 1
> +        }
> +        incr item
> +    }
> +    return 0

This loop would be simpler with foreach.  Same for the functions below.

LGTM otherwise.

Thanks,
Richard

> +}
> +
> +# Some regex lines (mostly ones starting with a label) should be copied
> +# verbatim (i.e. without prepending config(line_prefix)).
> +
> +proc target_regex_verbatim_line { config line } {
> +    upvar $config up_config
> +    set item 0
> +    while { $item < [llength $up_config(verbatim_regex_cases)] } {
> +        if { [regexp [lindex $up_config(verbatim_regex_cases) $item] $line] 
> } {
> +            return 1
> +        }
> +        incr item
> +    }
> +    return 0
> +}
> +
> +# Apply global substitutions to the function body regex as needed by the
> +# target ABI / assembler syntax.
> +
> +proc target_substitute_func_regex { config func_regex } {
> +    upvar $config up_config
> +    upvar $func_regex up_func_regex
> +    set item 0
> +    while { $item < [llength $up_config(regex_substitutions)] } {
> +        set subs [lindex $up_config(regex_substitutions) $item]
> +        regsub -all [lindex $subs 0] $up_func_regex [lindex $subs 1] 
> up_func_regex
> +        incr item
> +    }
>  }
>  
>  # Per CONFIG, read assembly file FILENAME and store a mapping from function
> @@ -1002,7 +1088,7 @@ proc parse_function_bodies { config filename result } {
>               set function_name $maybe_function_name
>               set in_function 1
>           } elseif { [regexp $up_config(end) $line] } {
> -             verbose "parse_function_bodies: $function_name:\n$function_body"
> +             verbose "parse_function_bodies: found end marker for 
> $function_name:\n$function_body"
>               set up_result($function_name) $function_body
>               set in_function 0
>           } elseif { $up_config(matched) ne "" \
> @@ -1188,14 +1274,19 @@ proc check-function-bodies { args } {
>               append function_regexp ")"
>           } elseif { [string equal $line "..."] } {
>               append function_regexp ".*"
> -         } elseif { [regexp {^\.L} $line] } {
> -             append function_regexp $line "\n"
> -         } elseif { [regexp {^[0-9]+:} $line] } {
> -             append function_regexp $line "\n"
> +         } elseif { [target_regex_skip_line config $line] } {
> +             # Drop this line.
> +             continue
> +         } elseif { [target_regex_verbatim_line config $line] } {
> +             # Copy this through.
> +             append function_regexp $line "\n"
>           } else {
> +             # Copy but with a prefix (typically \t).
>               append function_regexp $config(line_prefix) $line "\n"
>           }
>       } elseif { [string equal -length $terminator_len $line $terminator] } {
> +         # Do any global substitutions the target ABI/asm syntax needs.
> +         target_substitute_func_regex config function_regexp
>           if { ![string equal $selector "N"] } {
>               if { $xfail_all || [string equal $selector "F"] } {
>                   setup_xfail "*-*-*"
> diff --git a/gcc/testsuite/lib/target-supports.exp 
> b/gcc/testsuite/lib/target-supports.exp
> index cba178b937f..e212cfa9165 100644
> --- a/gcc/testsuite/lib/target-supports.exp
> +++ b/gcc/testsuite/lib/target-supports.exp
> @@ -982,6 +982,10 @@ proc add_options_for_check_function_bodies { flags } {
>       # off on Solaris/x86 with as and ld.  Similarly it also expects
>       # the .LFB/.LFE labels, which aren't emitted for 32-bit.
>       return "-fdwarf2-cfi-asm -fasynchronous-unwind-tables $flags "
> +    } elseif { [istarget i?86-*-darwin*] || [istarget x86_64-*-darwin*]  } {
> +        # Darwin does not currently use .cfi_ instructions and also requires
> +        # unwind tables to be forced on for 32bit.
> +     return "-fno-dwarf2-cfi-asm -fasynchronous-unwind-tables $flags "
>      }
>      return $flags
>  }

Reply via email to