bitfield_gen: comment for original source file

Add a `--form_file <file>` option to the bitfield generator for
printing a `/* generated from <file> */` message in a comment.

Use this option in cmake to provide the original source .bf file before
preprocessing so it's easier to find out where the corresponding
definitions are.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
This commit is contained in:
Gerwin Klein
2023-04-06 13:19:55 +10:00
committed by Kent McLeod
parent ec170f4c21
commit 57c46bc8d0
4 changed files with 8 additions and 1 deletions

View File

@@ -2851,6 +2851,8 @@ if __name__ == '__main__':
parser.add_option('--skip_modifies', action='store_true', default=False)
parser.add_option('--showclasses', action='store_true', default=False)
parser.add_option('--debug', action='store_true', default=False)
parser.add_option('--from_file', action='store', default=None,
help="Original source file before preprocessing.")
options, args = parser.parse_args()
DEBUG = options.debug
@@ -3057,6 +3059,8 @@ if __name__ == '__main__':
print("end", file=out_file)
else:
if options.from_file:
print(f"/* generated from {options.from_file} */\n", file=out_file)
print("#pragma once\n", file=out_file)
print('\n'.join(map(lambda x: '#include <%s>' % x,
INCLUDES[options.environment])), file=out_file)

View File

@@ -132,7 +132,7 @@ endfunction(GenBFTarget)
# environment is empty for kernel generation and "libsel4" for generating non kernel headers
# prunes is an optional list of files that will be passed as --prune options to the bitfield
# generator
function(GenHBFTarget environment target_name target_file pbf_path pbf_target prunes deps)
function(GenHBFTarget environment target_name target_file pbf_path pbf_target prunes deps orig_file)
set(args "")
if(NOT "${environment}" STREQUAL "")
list(APPEND args --environment "${environment}")
@@ -141,6 +141,7 @@ function(GenHBFTarget environment target_name target_file pbf_path pbf_target pr
get_absolute_source_or_binary(prune_absolute "${prune}")
list(APPEND args "--prune" "${prune_absolute}")
endforeach()
list(APPEND args --from_file "${orig_file}")
list(APPEND deps ${prunes})
GenBFTarget("${args}" "${target_name}" "${target_file}" "${pbf_path}" "${pbf_target}" "${deps}")
endfunction(GenHBFTarget)