-
Notifications
You must be signed in to change notification settings - Fork 1.4k
applications: sdp: Add asm_gen target #17638
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| /* | ||
| * Copyright (c) 2024 Nordic Semiconductor ASA | ||
| * | ||
| * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause | ||
| */ | ||
|
|
||
| #include <hal/nrf_vpr_csr_vio.h> | ||
|
|
||
| void set_direction(void) | ||
| { | ||
| nrf_vpr_csr_vio_dir_set(0xA); | ||
| nrf_vpr_csr_vio_dir_set(0xB); | ||
| nrf_vpr_csr_vio_dir_set(0xC); | ||
| } | ||
|
|
||
| void set_output(void) | ||
| { | ||
| nrf_vpr_csr_vio_out_set(0xA); | ||
| nrf_vpr_csr_vio_dir_set(0xB); | ||
| nrf_vpr_csr_vio_dir_set(0xC); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| # | ||
| # Copyright (c) 2024 Nordic Semiconductor ASA | ||
| # | ||
| # SPDX-License-Identifier: LicenseRef-Nordic-5-Clause | ||
| # | ||
|
|
||
| function(sdp_assembly_generate hrt_srcs) | ||
| set(hrt_msg "Generating ASM files for Hard Real Time files.") | ||
| set(hrt_opts -g0 -fno-ident -fno-verbose-asm) | ||
|
|
||
| # Compiler does not know how to build for this platform so we export | ||
| # all the flags used in this zephyr build to the external build system. | ||
| zephyr_get_compile_options_for_lang(C options) | ||
| zephyr_get_compile_definitions_for_lang(C defines) | ||
| zephyr_get_include_directories_for_lang(C includes) | ||
| zephyr_get_system_include_directories_for_lang(C sys_includes) | ||
| # Replace "-I" with "-isystem" to treat all Zephyr headers as system headers | ||
| # that do not trigger -Werror. | ||
| string(REPLACE "-I" "-isystem" includes "${includes}") | ||
|
|
||
| set(compiler_options ${defines} ${options} ${includes} ${sys_includes}) | ||
|
|
||
| if(TARGET asm_gen) | ||
| message(FATAL_ERROR "sdp_assembly_generate() already called, please note that | ||
| sdp_assembly_generate() must be called only once with a list of all source files." | ||
| ) | ||
| endif() | ||
|
|
||
| # Define the asm_gen target that depends on all generated assembly files | ||
| add_custom_target(asm_gen | ||
| COMMENT ${hrt_msg} | ||
| ) | ||
|
|
||
| foreach(hrt_src ${hrt_srcs}) | ||
| if(IS_DIRECTORY ${hrt_src}) | ||
| message(FATAL_ERROR "sdp_assembly_generate() was called on a directory") | ||
| endif() | ||
| get_filename_component(src_filename ${hrt_src} NAME_WE) # filename without extension | ||
| add_custom_command(TARGET asm_gen | ||
| BYPRODUCTS ${src_filename}-temp.s | ||
| COMMAND ${CMAKE_C_COMPILER} ${compiler_options} ${hrt_opts} -S ${hrt_src} -o ${src_filename}-temp.s | ||
| COMMAND ${PYTHON_EXECUTABLE} ${ZEPHYR_NRF_MODULE_DIR}/scripts/sdp/remove_comments.py ${src_filename}-temp.s | ||
| DEPENDS ${hrt_src} | ||
| COMMAND_EXPAND_LISTS | ||
| COMMENT "Generating ASM file for ${hrt_src}" | ||
| ) | ||
| endforeach() | ||
|
|
||
| add_dependencies(asm_gen syscall_list_h_target) | ||
|
|
||
| endfunction() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| #!/usr/bin/env python3 | ||
| # | ||
| # Copyright (c) 2024 Nordic Semiconductor ASA | ||
| # | ||
| # SPDX-License-Identifier: LicenseRef-Nordic-5-Clause | ||
| # | ||
|
|
||
| import os | ||
| import sys | ||
|
|
||
| def remove_comments_from_assembly_file(input_file): | ||
| """Cleans an assembly file by removing lines starting with # and saves the changes in the same file.""" | ||
| with open(input_file, 'r') as infile: | ||
| lines = infile.readlines() | ||
|
|
||
| # Filter out lines starting with # | ||
| cleaned_lines = [line for line in lines if not line.startswith('#')] | ||
|
Comment on lines
+16
to
+17
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note, gcc may use |
||
|
|
||
| # Save the cleaned file in the same file | ||
| with open(input_file, 'w') as outfile: | ||
| outfile.writelines(cleaned_lines) | ||
|
|
||
| print(f"File {input_file} has been cleaned of comments.") | ||
|
|
||
| def process_directory(directory): | ||
| """Processes all .s files in the directory.""" | ||
| for root, _, files in os.walk(directory): # '_' instead of 'dirs' to ignore unused variable | ||
| for file in files: | ||
| if file.endswith('.s'): | ||
| input_file = os.path.join(root, file) | ||
| remove_comments_from_assembly_file(input_file) | ||
|
|
||
| def main(path): | ||
| """Checks if given path is a file or a directory and processes it accordingly.""" | ||
| if os.path.isfile(path) and path.endswith('.s'): | ||
| # If a single .s file is provided | ||
| remove_comments_from_assembly_file(path) | ||
| elif os.path.isdir(path): | ||
| # If a directory is provided | ||
| process_directory(path) | ||
| else: | ||
| print("The provided path is neither a .s file nor a directory.") | ||
|
|
||
| if __name__ == "__main__": | ||
| if len(sys.argv) != 2: | ||
| print("Usage: python clean_asm.py <file.or.directory>") | ||
| else: | ||
| main(sys.argv[1]) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will be a problem if the
sdp_assembly_generate()function is called multiple times, for example like this:because there can only be a single
asm_gentarget created.This might be an acceptable limitation for now, but could you please make this check and provide a use-ful error to the user, for example a check like this:
Note, line length not checked in above example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The message with
FATAL_ERRORhas been added.