From 6826c1cdfba855513786d9e3d606681316453398 Mon Sep 17 00:00:00 2001 From: Devin Matthews Date: Mon, 25 Jul 2022 18:21:05 -0500 Subject: [PATCH] Add `#line` directives to flattened `blis.h`. (#643) Details: - Modified flatten-headers.py so that #line directives are inserted into the flattened blis.h file. This facilitates easier debugging when something is amiss in the flattened blis.h because the compiler will be able to refer to the line number within the original constituent header file (which is where the fix would go) rather than the line number within the flattened header (which is not as helpful). --- build/flatten-headers.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/build/flatten-headers.py b/build/flatten-headers.py index 563725a7e..40fc2a450 100755 --- a/build/flatten-headers.py +++ b/build/flatten-headers.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -# BLIS +# BLIS # An object-based framework for developing high-performance BLAS-like # libraries. # @@ -215,9 +215,19 @@ def flatten_header( inputfile, header_dirpaths, cursp ): # Open the input file to process. ifile = open( inputfile, "r" ) + # A counter to track the line number being parsed within the current file. + # This counter, when selectively encoded into the flattened header via #line + # directives, facilitates easier debugging. (When the compiler finds an + # issue, it will be able to refer to the line number within the constituent + # header file rather than the flattened one.) + lineno = 0 + # Iterate over the lines in the file. while True: + # Increment the line number. + lineno += 1 + # Read a line in the file. line = ifile.readline() @@ -268,12 +278,14 @@ def flatten_header( inputfile, header_dirpaths, cursp ): # Mark the beginning of the header being inserted. ostring += "%s%s%c" % ( beginstr, header, '\n' ) + ostring += "#line %d \"%s\"%c\n" % ( 1, header_path, '\n' ) # Recurse on the header, accumulating the string. ostring += flatten_header( header_path, header_dirpaths, cursp + " " ) # Mark the end of the header being inserted. ostring += "%s%s%c" % ( endstr, header, '\n' ) + ostring += "#line %d \"%s\"%c\n" % ( lineno+1, inputfile, '\n' ) echov2( "%sheader file '%s' fully processed." \ % ( cursp, header_path ) ) @@ -300,7 +312,7 @@ def flatten_header( inputfile, header_dirpaths, cursp ): # endif # endwhile - + # Close the input file. ifile.close() @@ -330,7 +342,6 @@ def find_header_dirs( dirpath ): #endfor return header_dirpaths - # ------------------------------------------------------------------------------