Skip to content

Commit

Permalink
sed_wor dedicated function (#48)
Browse files Browse the repository at this point in the history
Co-authored-by: Anvesh Nookala <[email protected]>
Co-authored-by: Benoît Denkinger <[email protected]>
Co-authored-by: Benoit Denkinger <[email protected]>
  • Loading branch information
4 people authored Sep 16, 2024
1 parent 24ae41e commit acef140
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 46 deletions.
52 changes: 7 additions & 45 deletions cmake/sim/verilator/verilate.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -72,51 +72,13 @@ function(verilate IP_LIB)

get_ip_rtl_sources(SOURCES ${IP_LIB})

# String replace "wor " with "wire " in TMR files, since Verilator does not support "wor"
# TODO: Remove this if Verilator ever supports "wor"
if(ARG_SED_WOR)
file(MAKE_DIRECTORY ${BINARY_DIR}/sed_wor)
set(MODIFIED_SOURCES "")

foreach(source ${SOURCES})
get_filename_component(source_name ${source} NAME)
if(source_name MATCHES "TMR")
set(output_file "${BINARY_DIR}/sed_wor/${source_name}")
list(APPEND MODIFIED_SOURCES ${output_file})

add_custom_command(
OUTPUT ${output_file}
COMMAND sed "s/wor /wire /g" ${source} > ${output_file}
DEPENDS ${source}
COMMENT "Replacing wor with wire in ${source_name}."
)
else()
list(APPEND MODIFIED_SOURCES ${source})
endif()
endforeach()

# Update sources to use modified sources
set(SOURCES ${MODIFIED_SOURCES})

# Create stamp file for sed command
set(STAMP_FILE "${BINARY_DIR}/sed_wor/${IP_LIB}_sed_wor.stamp")

add_custom_command(
OUTPUT ${STAMP_FILE}
COMMAND /bin/sh -c date > ${STAMP_FILE}
DEPENDS ${MODIFIED_SOURCES}
COMMENT "Generating stamp file after sed commands."
)

add_custom_target(
${IP_LIB}_sed_wor ALL
DEPENDS ${STAMP_FILE}
)

add_dependencies(${IP_LIB} ${IP_LIB}_sed_wor)
include(${CMAKE_CURRENT_FUNCTION_LIST_DIR}/../../utils/sed_wor/sed_wor.cmake)
sed_wor(${IP_LIB} ${BINARY_DIR} "${SOURCES}")
set(SOURCES ${SED_WOR_SOURCES})
# unset, so argument is not further passed to verilator bin
unset(ARG_SED_WOR)
endif()
endif()

get_ip_sim_only_sources(SIM_SOURCES ${IP_LIB})
list(PREPEND SOURCES ${SIM_SOURCES})
Expand Down Expand Up @@ -208,7 +170,7 @@ function(verilate IP_LIB)
INSTALL_COMMAND ""
DEPENDS ${IP_LIB}
EXCLUDE_FROM_ALL 1
)
)

set_property(
TARGET ${VERILATE_TARGET}
Expand All @@ -221,8 +183,8 @@ function(verilate IP_LIB)
set(INC_DIR ${DIRECTORY})

# TODO: Remove this if Verilator ever supports "wor"
if(TARGET ${IP_LIB}__sed_wor)
add_dependencies(${VERILATE_TARGET} ${IP_LIB}__sed_wor)
if(TARGET ${IP_LIB}_sed_wor)
add_dependencies(${VERILATE_TARGET} ${IP_LIB}_sed_wor)
endif()

set(VERILATED_LIB ${IP_LIB}__vlt)
Expand Down
1 change: 0 additions & 1 deletion cmake/tmrg/tmrg/tmrg.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ function(tmrg IP_LIB)
add_custom_command(
OUTPUT ${TRMG_GEN} ${STAMP_FILE}
COMMAND ${TMRG_COMMAND}
${SED_COMMAND}
COMMAND /bin/sh -c date > ${STAMP_FILE}
DEPENDS ${IP_TMRG_SRC} ${SCR_DEPS_STRIPPED}
COMMENT "Running ${CMAKE_CURRENT_FUNCTION} on ${IP_LIB}"
Expand Down
45 changes: 45 additions & 0 deletions cmake/utils/sed_wor/sed_wor.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# sed_wor.cmake
# String replace "wor" with "wire" in TMR files.
# This is a workaround for a Verilator not supporting "wor" and similar keywords...
function(sed_wor IP_LIB BINARY_DIR SOURCES)
file(MAKE_DIRECTORY ${BINARY_DIR}/sed_wor)
set(MODIFIED_SOURCES "")

foreach(source ${SOURCES})
get_filename_component(source_name ${source} NAME)
if(source_name MATCHES "TMR")
set(output_file "${BINARY_DIR}/sed_wor/${source_name}")
list(APPEND MODIFIED_SOURCES ${output_file})

add_custom_command(
OUTPUT ${output_file}
# space after wor is important to avoid replacing words like "word"!
COMMAND sed "s/wor /wire /g" ${source} > ${output_file}
DEPENDS ${source}
COMMENT "Replacing wor with wire in ${source_name}."
)
else()
list(APPEND MODIFIED_SOURCES ${source})
endif()
endforeach()

# Create stamp file for sed command
set(STAMP_FILE "${BINARY_DIR}/sed_wor/${IP_LIB}_sed_wor.stamp")

add_custom_command(
OUTPUT ${STAMP_FILE}
COMMAND /bin/sh -c date > ${STAMP_FILE}
DEPENDS ${MODIFIED_SOURCES}
COMMENT "Generating stamp file after sed commands."
)

add_custom_target(
${IP_LIB}_sed_wor
DEPENDS ${STAMP_FILE}
)

add_dependencies(${IP_LIB}_sed_wor ${IP_LIB})

# Return modified sources
set(SED_WOR_SOURCES ${MODIFIED_SOURCES} PARENT_SCOPE)
endfunction()

0 comments on commit acef140

Please sign in to comment.