mirror of
https://github.com/YosysHQ/yosys
synced 2026-05-25 19:36:21 +00:00
60 lines
1.7 KiB
CMake
60 lines
1.7 KiB
CMake
# Syntax:
|
|
#
|
|
# pmgen_command(<output>
|
|
# [<input>...]
|
|
# [PREFIX <prefix>]
|
|
# [DEBUG]
|
|
# )
|
|
#
|
|
# Builds `<output>_pm.h` in the current binary directory from pmgen source files `<input>`, which must have
|
|
# the `*.pmg` extension. If `<input>...` contains more than one file, `<prefix>` must be provided.
|
|
#
|
|
# Defines the following variables:
|
|
# - `PMGEN_<output>_DEFINED`: Boolean indicating whether this command was successfully invoked.
|
|
# - `PMGEN_<output>_OUTPUT`: The header file generated by `pmgen`.
|
|
#
|
|
# Usage example:
|
|
#
|
|
# pmgen_command(my_dsp
|
|
# my_dsp.pmg
|
|
# )
|
|
# yosys_pass(my_dsp
|
|
# my_dsp.cc
|
|
# ${PMGEN_my_dsp_OUTPUT}
|
|
# )
|
|
#
|
|
# Usage example with multiple files:
|
|
#
|
|
# pmgen_command(my_dsp
|
|
# my_dsp_macc.pmg
|
|
# my_dsp_carry.pmg
|
|
# PREFIX
|
|
# my_dsp
|
|
# )
|
|
#
|
|
function(pmgen_command arg_NAME)
|
|
cmake_parse_arguments(PARSE_ARGV 1 arg "DEBUG" "PREFIX" "")
|
|
set(arg_INPUTS ${arg_UNPARSED_ARGUMENTS})
|
|
|
|
set(pmgen_script ${CMAKE_SOURCE_DIR}/passes/pmgen/pmgen.py)
|
|
set(pmgen_output ${CMAKE_CURRENT_BINARY_DIR}/${arg_NAME}_pm.h)
|
|
cmake_path(RELATIVE_PATH pmgen_output BASE_DIRECTORY ${CMAKE_BINARY_DIR} OUTPUT_VARIABLE pmgen_output_rel)
|
|
add_custom_command(
|
|
DEPENDS ${pmgen_script} ${arg_INPUTS}
|
|
OUTPUT ${pmgen_output}
|
|
COMMAND ${Python3_EXECUTABLE}
|
|
${pmgen_script}
|
|
"$<$<BOOL:${arg_DEBUG}>:-g>"
|
|
"$<$<BOOL:${arg_PREFIX}>:-p;${arg_PREFIX}>"
|
|
-o ${pmgen_output}
|
|
${arg_INPUTS}
|
|
COMMAND_EXPAND_LISTS
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
|
VERBATIM
|
|
COMMENT "Compiling pattern matcher ${pmgen_output_rel}"
|
|
)
|
|
|
|
# The usage of this command is somewhat inspired by `flex_target()` and `bison_target()`.
|
|
set(PMGEN_${arg_NAME}_DEFINED TRUE)
|
|
set(PMGEN_${arg_NAME}_OUTPUT ${pmgen_output} PARENT_SCOPE)
|
|
endfunction()
|