Skip to content

Commit

Permalink
Refactor simulator functions to allow separate compile and run target…
Browse files Browse the repository at this point in the history
…s, which allows adding tests with CTest
  • Loading branch information
Risto97 committed Dec 2, 2024
1 parent e249ca2 commit 5212b1f
Show file tree
Hide file tree
Showing 5 changed files with 364 additions and 170 deletions.
4 changes: 2 additions & 2 deletions SoCMakeConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ include("${CMAKE_CURRENT_LIST_DIR}/cmake/sim/iverilog/iverilog.cmake")
# ----- xcelium ------
include("${CMAKE_CURRENT_LIST_DIR}/cmake/sim/cadence/xcelium.cmake")

# ----- modelsim ------
include("${CMAKE_CURRENT_LIST_DIR}/cmake/sim/modelsim/modelsim.cmake")
# ----- siemens ------
include("${CMAKE_CURRENT_LIST_DIR}/cmake/sim/siemens/modelsim.cmake")

# ----- vcs ------
include("${CMAKE_CURRENT_LIST_DIR}/cmake/sim/synopsys/vcs.cmake")
Expand Down
185 changes: 163 additions & 22 deletions cmake/sim/cadence/xcelium.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
include_guard(GLOBAL)

function(xcelium IP_LIB)
cmake_parse_arguments(ARG "GUI" "" "ARGS" ${ARGN})
cmake_parse_arguments(ARG "TARGET_PER_IP;NO_RUN_TARGET;GUI" "RUN_TARGET_NAME" "XMVLOG_ARGS;XMVHDL_ARGS;XMELAB_ARGS;RUN_ARGS" ${ARGN})
if(ARG_UNPARSED_ARGUMENTS)
message(FATAL_ERROR "${CMAKE_CURRENT_FUNCTION} passed unrecognized argument " "${ARG_UNPARSED_ARGUMENTS}")
endif()
Expand All @@ -28,17 +28,15 @@ function(xcelium IP_LIB)
alias_dereference(IP_LIB ${IP_LIB})
get_target_property(BINARY_DIR ${IP_LIB} BINARY_DIR)

get_ip_sources(SOURCES ${IP_LIB} SYSTEMVERILOG VERILOG VHDL)
get_ip_include_directories(INC_DIRS ${IP_LIB} SYSTEMVERILOG VERILOG VHDL)
# get_target_property(LIBRARY ${IP_LIB} LIBRARY)
# if(NOT LIBRARY)
set(LIBRARY worklib)
# endif()

foreach(dir ${INC_DIRS})
list(APPEND ARG_INCDIRS -incdir ${dir})
endforeach()

get_ip_compile_definitions(COMP_DEFS ${IP_LIB} SYSTEMVERILOG VERILOG VHDL)
foreach(def ${COMP_DEFS})
list(APPEND CMP_DEFS_ARG -define ${def})
endforeach()
if(NOT ARG_TOP_MODULE)
get_target_property(IP_NAME ${IP_LIB} IP_NAME)
set(ARG_TOP_MODULE ${IP_NAME})
endif()

get_ip_links(IPS_LIST ${IP_LIB})

Expand All @@ -50,21 +48,164 @@ function(xcelium IP_LIB)
endif()
endforeach()

add_custom_target( run_${IP_LIB}_${CMAKE_CURRENT_FUNCTION}
COMMAND xrun
# Enable parameters without default value
-setenv CADENCE_ENABLE_AVSREQ_44905_PHASE_1=1 -setenv CADENCE_ENABLE_AVSREQ_63188_PHASE_1=1
-define COMMON_CELLS_ASSERTS_OFF
${SOURCES}
${ARG_INCDIRS}
${CMP_DEFS_ARG}
if(ARG_TARGET_PER_IP) # In case TARGET_PER_IP is passed, a compile target is created per IP block
set(list_comp_libs ${IPS_LIST})
set(__no_deps_arg NO_DEPS)
else()
set(list_comp_libs ${IP_LIB})
unset(__no_deps_arg)
endif()

unset(__comp_tgts)
foreach(ip ${list_comp_libs})
get_target_property(ip_name ${ip} IP_NAME)
if(ip_name) # If IP_NAME IS set, its SoCMake's IP_LIBRARY
__xcelium_compile_lib(${ip} ${__no_deps_arg}
# OUTDIR ${OUTDIR}
${ARG_XMVLOG_ARGS}
${ARG_XMVHDL_ARGS}
${ARG_XMELAB_ARGS}
)
list(APPEND __comp_tgts ${ip}_xcelium_complib)
endif()
endforeach()


## XMSIM command for running simulation
set(__xmsim_cmd xmsim
${__lib_args}
${ARG_RUN_ARGS}
${LIBRARY}.${ARG_TOP_MODULE}
$<$<BOOL:${ARG_GUI}>:-gui>
${ARG_ARGS}
COMMENT "Running ${CMAKE_CURRENT_FUNCTION} on ${IP_LIB}"
DEPENDS ${SOURCES} ${IP_LIB}

# $<$<BOOL:${ARG_QUIET}>:-quiet>
)
if(NOT ARG_NO_RUN_TARGET)
if(NOT ARG_RUN_TARGET_NAME)
set(ARG_RUN_TARGET_NAME run_${IP_LIB}_${CMAKE_CURRENT_FUNCTION})
endif()
set(DESCRIPTION "Run simulation on ${IP_LIB} with ${CMAKE_CURRENT_FUNCTION}")
add_custom_target(${ARG_RUN_TARGET_NAME}
COMMAND ${__xmsim_cmd}
COMMENT ${DESCRIPTION}
DEPENDS ${__comp_tgts}
)
set_property(TARGET ${ARG_RUN_TARGET_NAME} PROPERTY DESCRIPTION ${DESCRIPTION})
endif()
set(SIM_RUN_CMD ${__xmsim_cmd} PARENT_SCOPE)

endfunction()

function(__xcelium_compile_lib IP_LIB)
cmake_parse_arguments(ARG "NO_DEPS" "OUTDIR;TOP_MODULE;XMVLOG_ARGS;XMVHDL_ARGS;XMELAB_ARGS" "" ${ARGN})
# Check for any unrecognized arguments
if(ARG_UNPARSED_ARGUMENTS)
message(FATAL_ERROR "${CMAKE_CURRENT_FUNCTION} passed unrecognized argument " "${ARG_UNPARSED_ARGUMENTS}")
endif()

include("${CMAKE_CURRENT_FUNCTION_LIST_DIR}/../../hwip.cmake")

alias_dereference(IP_LIB ${IP_LIB})
get_target_property(BINARY_DIR ${IP_LIB} BINARY_DIR)

# get_target_property(LIBRARY ${IP_LIB} LIBRARY)
# if(NOT LIBRARY)
set(LIBRARY worklib)
# endif()

if(NOT ARG_TOP_MODULE)
get_target_property(IP_NAME ${IP_LIB} IP_NAME)
set(ARG_TOP_MODULE ${IP_NAME})
endif()

# if(NOT ARG_OUTDIR)
# set(OUTDIR ${BINARY_DIR}/${IP_LIB}_xcelium)
# else()
# set(OUTDIR ${ARG_OUTDIR})
# endif()

if(ARG_NO_DEPS)
set(ARG_NO_DEPS NO_DEPS)
else()
unset(ARG_NO_DEPS)
endif()

# SystemVerilog and Verilog files and arguments
get_ip_sources(SV_SOURCES ${IP_LIB} SYSTEMVERILOG VERILOG ${ARG_NO_DEPS})
if(SV_SOURCES)
get_ip_include_directories(SV_INC_DIRS ${IP_LIB} SYSTEMVERILOG VERILOG)
get_ip_compile_definitions(SV_COMP_DEFS ${IP_LIB} SYSTEMVERILOG VERILOG)

foreach(dir ${SV_INC_DIRS})
list(APPEND SV_ARG_INCDIRS -INCDIR ${dir})
endforeach()

foreach(def ${SV_COMP_DEFS})
list(APPEND SV_CMP_DEFS_ARG -DEFINE ${def})
endforeach()

set(DESCRIPTION "Compile Verilog and SV files of ${IP_LIB} with xcelium xmvlog in library ${LIBRARY}")
set(__xmvlog_cmd COMMAND xmvlog
-sv
${ARG_XMVLOG_ARGS}
${SV_ARG_INCDIRS}
${SV_CMP_DEFS_ARG}
${SV_SOURCES}
# -work ${OUTDIR}/${LIBRARY}
)
endif()

# VHDL files and arguments
get_ip_sources(VHDL_SOURCES ${IP_LIB} VHDL ${ARG_NO_DEPS})
if(VHDL_SOURCES)
get_ip_include_directories(VHDL_INC_DIRS ${IP_LIB} VHDL)
get_ip_compile_definitions(VHDL_COMP_DEFS ${IP_LIB} VHDL)

foreach(dir ${VHDL_INC_DIRS})
list(APPEND VHDL_ARG_INCDIRS -INCDIR ${dir})
endforeach()

foreach(def ${VHDL_COMP_DEFS})
list(APPEND VHDL_CMP_DEFS_ARG -DEFINE ${def})
endforeach()

set(__xmvhdl_cmd COMMAND xmvhdl
${ARG_XMVHDL_ARGS}
${VHDL_ARG_INCDIRS}
${VHDL_CMP_DEFS_ARG}
${VHDL_SOURCES}
# -work ${OUTDIR}/${LIBRARY}
)
endif()

set(__xmelab_cmd COMMAND xmelab
${ARG_XMELAB_ARGS}
worklib.${IP_NAME}
# -work ${OUTDIR}/${LIBRARY}
)

if(NOT TARGET ${IP_LIB}_xcelium_complib)
set(DESCRIPTION "Compile VHDL, SV, and Verilog files for ${IP_LIB} with xcelium in library ${LIBRARY}")
set(STAMP_FILE "${BINARY_DIR}/${IP_LIB}_${CMAKE_CURRENT_FUNCTION}.stamp")
add_custom_command(
OUTPUT ${STAMP_FILE} #${OUTDIR}/${LIBRARY}
# COMMAND ${CMAKE_COMMAND} -E make_directory ${OUTDIR}
${__xmvlog_cmd}
${__xmvhdl_cmd}
${__xmelab_cmd}
COMMAND touch ${STAMP_FILE}
DEPENDS ${SV_SOURCES} ${VHDL_SOURCES}
COMMENT ${DESCRIPTION}
)

add_custom_target(
${IP_LIB}_xcelium_complib
DEPENDS ${STAMP_FILE} ${STAMP_FILE_VHDL} ${IP_LIB}
)
set_property(TARGET ${IP_LIB}_xcelium_complib PROPERTY
DESCRIPTION "Compile VHDL, SV, and Verilog files for ${IP_LIB} with xcelium in library ${LIBRARY}")
endif()

# set(__XCELIUM_IP_LIB_DIR ${OUTDIR} PARENT_SCOPE)
# set(__XCELIUM_IP_LIB_NAME ${LIBRARY} PARENT_SCOPE)
endfunction()
74 changes: 43 additions & 31 deletions cmake/sim/iverilog/iverilog.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ include_guard(GLOBAL)
# ]]]
function(iverilog IP_LIB)
# Parse the function arguments
cmake_parse_arguments(ARG "" "TOP_MODULE;OUTDIR;EXECUTABLE;CLI_FLAGS" "" ${ARGN})
cmake_parse_arguments(ARG "NO_RUN_TARGET" "TOP_MODULE;OUTDIR;EXECUTABLE;RUN_TARGET_NAME" ";IVERILOG_ARGS;RUN_ARGS" ${ARGN})
# Check for any unrecognized arguments
if(ARG_UNPARSED_ARGUMENTS)
message(FATAL_ERROR "${CMAKE_CURRENT_FUNCTION} passed unrecognized argument " "${ARG_UNPARSED_ARGUMENTS}")
Expand Down Expand Up @@ -57,38 +57,50 @@ function(iverilog IP_LIB)
set(STAMP_FILE "${BINARY_DIR}/${IP_LIB}_${CMAKE_CURRENT_FUNCTION}.stamp")
set(DESCRIPTION "Compile ${IP_LIB} with ${CMAKE_CURRENT_FUNCTION}")

# Add a custom command to run iverilog
add_custom_command(
OUTPUT ${ARG_EXECUTABLE} ${STAMP_FILE}
COMMAND ${CMAKE_COMMAND} -E make_directory ${OUTDIR}
COMMAND iverilog
$<$<BOOL:${ARG_TOP_MODULE}>:-s${ARG_TOP_MODULE}>
${ARG_INCDIRS}
${CMP_DEFS_ARG}
${ARG_CLI_FLAGS}
-o ${ARG_EXECUTABLE}
${SOURCES}
COMMAND touch ${STAMP_FILE}
DEPENDS ${SOURCES}
COMMENT ${DESCRIPTION}
)
if(NOT TARGET ${IP_LIB}_${CMAKE_CURRENT_FUNCTION})
# Add a custom command to run iverilog
add_custom_command(
OUTPUT ${ARG_EXECUTABLE} ${STAMP_FILE}
COMMAND ${CMAKE_COMMAND} -E make_directory ${OUTDIR}
COMMAND iverilog
$<$<BOOL:${ARG_TOP_MODULE}>:-s${ARG_TOP_MODULE}>
${ARG_INCDIRS}
${CMP_DEFS_ARG}
${ARG_IVERILOG_ARGS}
-o ${ARG_EXECUTABLE}
${SOURCES}
COMMAND touch ${STAMP_FILE}
DEPENDS ${SOURCES}
COMMENT ${DESCRIPTION}
)

# Add a custom target that depends on the executable and stamp file
add_custom_target(
${IP_LIB}_${CMAKE_CURRENT_FUNCTION}
DEPENDS ${ARG_EXECUTABLE} ${STAMP_FILE} ${IP_LIB}
)
set_property(TARGET ${IP_LIB}_${CMAKE_CURRENT_FUNCTION} PROPERTY DESCRIPTION ${DESCRIPTION})
# Add a custom target that depends on the executable and stamp file
add_custom_target(
${IP_LIB}_${CMAKE_CURRENT_FUNCTION}
DEPENDS ${ARG_EXECUTABLE} ${STAMP_FILE} ${IP_LIB}
)
set_property(TARGET ${IP_LIB}_${CMAKE_CURRENT_FUNCTION} PROPERTY DESCRIPTION ${DESCRIPTION})
endif()

set(DESCRIPTION "Run ${CMAKE_CURRENT_FUNCTION} testbench compiled from ${IP_LIB}")
# Add a custom target to run the generated executable
add_custom_target(
run_${IP_LIB}_${CMAKE_CURRENT_FUNCTION}
COMMAND ${ARG_EXECUTABLE}
DEPENDS ${ARG_EXECUTABLE} ${STAMP_FILE} ${SOURCES} ${IP_LIB}_${CMAKE_CURRENT_FUNCTION}
COMMENT ${DESCRIPTION}
)
set_property(TARGET run_${IP_LIB}_${CMAKE_CURRENT_FUNCTION} PROPERTY DESCRIPTION ${DESCRIPTION})
set(__sim_run_cmd
vvp ${ARG_EXECUTABLE}
${ARG_RUN_ARGS}
)
if(NOT ${ARG_NO_RUN_TARGET})
if(NOT ARG_RUN_TARGET_NAME)
set(ARG_RUN_TARGET_NAME run_${IP_LIB}_${CMAKE_CURRENT_FUNCTION})
endif()
set(DESCRIPTION "Run ${CMAKE_CURRENT_FUNCTION} testbench compiled from ${IP_LIB}")
# Add a custom target to run the generated executable
add_custom_target(
${ARG_RUN_TARGET_NAME}
COMMAND ${__sim_run_cmd}
DEPENDS ${ARG_EXECUTABLE} ${STAMP_FILE} ${SOURCES} ${IP_LIB}_${CMAKE_CURRENT_FUNCTION}
COMMENT ${DESCRIPTION}
)
set_property(TARGET ${ARG_RUN_TARGET_NAME} PROPERTY DESCRIPTION ${DESCRIPTION})
endif()
set(SIM_RUN_CMD ${__sim_run_cmd} PARENT_SCOPE)

endfunction()

Loading

0 comments on commit 5212b1f

Please sign in to comment.