From 4a605e0a8b869bf41a225df3843f332bed48d51f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Risto=20Peja=C5=A1inovi=C4=87?= Date: Sun, 22 Dec 2024 00:19:57 +0100 Subject: [PATCH] Add VCS support Legacy VCS support is removed, it was focused around SystemC. SystemC support in VCS is currently removed, and will be added at a later stage --- cmake/sim/synopsys/vcs.cmake | 379 +++++++++++++------------ cmake/sim/synopsys/vcs_toolchain.cmake | 32 --- 2 files changed, 190 insertions(+), 221 deletions(-) delete mode 100644 cmake/sim/synopsys/vcs_toolchain.cmake diff --git a/cmake/sim/synopsys/vcs.cmake b/cmake/sim/synopsys/vcs.cmake index 43ded43..a86393f 100644 --- a/cmake/sim/synopsys/vcs.cmake +++ b/cmake/sim/synopsys/vcs.cmake @@ -1,12 +1,7 @@ include_guard(GLOBAL) -set(__VCS__CMAKE__CURRENT_LIST_DIR ${CMAKE_CURRENT_LIST_DIR} CACHE INTERNAL "") -macro(vcs_init) - set(CMAKE_TOOLCHAIN_FILE ${__VCS__CMAKE__CURRENT_LIST_DIR}/vcs_toolchain.cmake) -endmacro() - -function(vcs_vlogan IP_LIB) - cmake_parse_arguments(ARG "" "TOP_MODULE;OUTDIR" "" ${ARGN}) +function(vcs IP_LIB) + cmake_parse_arguments(ARG "TARGET_PER_IP;NO_RUN_TARGET;GUI" "EXECUTABLE_NAME;RUN_TARGET_NAME" "VLOGAN_ARGS;VHDLAN_ARGS;VCS_ARGS;RUN_ARGS" ${ARGN}) if(ARG_UNPARSED_ARGUMENTS) message(FATAL_ERROR "${CMAKE_CURRENT_FUNCTION} passed unrecognized argument " "${ARG_UNPARSED_ARGUMENTS}") endif() @@ -16,204 +11,210 @@ function(vcs_vlogan 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) + if(NOT ARG_OUTDIR) + set(OUTDIR ${BINARY_DIR}/${IP_LIB}_vcs) + else() + set(OUTDIR ${ARG_OUTDIR}) + endif() + file(MAKE_DIRECTORY ${OUTDIR}) - get_ip_include_directories(INC_DIRS ${IP_LIB} SYSTEMVERILOG VERILOG VHDL) + # get_target_property(LIBRARY ${IP_LIB} LIBRARY) + # if(NOT LIBRARY) + set(LIBRARY work) + # endif() - foreach(dir ${INC_DIRS}) - list(APPEND ARG_INCDIRS -incdir ${dir}) - endforeach() + if(NOT ARG_TOP_MODULE) + get_target_property(IP_NAME ${IP_LIB} IP_NAME) + set(ARG_TOP_MODULE ${IP_NAME}) + endif() - get_ip_compile_definitions(COMP_DEFS ${IP_LIB} SYSTEMVERILOG VERILOG VHDL) - foreach(def ${COMP_DEFS}) - list(APPEND CMP_DEFS_ARG -D${def}) + if(ARG_VLOGAN_ARGS) + set(ARG_VLOGAN_ARGS VLOGAN_ARGS ${ARG_VLOGAN_ARGS}) + endif() + if(ARG_VHDLAN_ARGS) + set(ARG_VHDLAN_ARGS VHDLAN_ARGS ${ARG_VHDLAN_ARGS}) + endif() + if(ARG_VCS_ARGS) + set(ARG_VCS_ARGS VCS_ARGS ${ARG_VCS_ARGS}) + endif() + + get_ip_links(IPS_LIST ${IP_LIB}) + + unset(__lib_args) + foreach(ip ${IPS_LIST}) + get_target_property(ip_type ${ip} TYPE) + if(ip_type STREQUAL "SHARED_LIBRARY" OR ip_type STREQUAL "STATIC_LIBRARY") + list(APPEND __lib_args $) + endif() endforeach() - if(ARG_TOP_MODULE) - set(ARG_TOP_MODULE ${ARG_TOP_MODULE}) + 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() - get_target_property(ARG_TOP_MODULE ${IP_LIB} IP_NAME) + 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 + __vcs_compile_lib(${ip} ${__no_deps_arg} + OUTDIR ${OUTDIR} + ${ARG_VLOGAN_ARGS} + ${ARG_VHDLAN_ARGS} + ${ARG_VCS_ARGS} + ) + list(APPEND __comp_tgts ${ip}_vcs_complib) + endif() + endforeach() + + if(NOT ARG_EXECUTABLE_NAME) + set(ARG_EXECUTABLE_NAME ${IP_LIB}_vcs_exec) + endif() + set(SIM_EXEC_PATH ${OUTDIR}/${ARG_EXECUTABLE_NAME}) + + ## VCS command for compiling executable + set(__vcs_cmd vcs + -full64 + -q + ${__lib_args} + -o ${SIM_EXEC_PATH} + ${ARG_VCS_ARGS} + ${LIBRARY}.${ARG_TOP_MODULE} + # $<$:-gui> + ) + set(DESCRIPTION "Compile testbench ${IP_LIB} with ${CMAKE_CURRENT_FUNCTION}") + set(STAMP_FILE "${BINARY_DIR}/${IP_LIB}_vcs.stamp") + add_custom_command( + OUTPUT ${SIM_EXEC_PATH} ${STAMP_FILE} + COMMAND ${__vcs_cmd} + COMMAND touch ${STAMP_FILE} + COMMENT ${DESCRIPTION} + BYPRODUCTS ${OUTDIR}/csrc ${OUTDIR}/${ARG_EXECUTABLE_NAME}.daidir + WORKING_DIRECTORY ${OUTDIR} + DEPENDS ${__comp_tgts} ${VCS_COMPLIB_STAMP_FILE} + ) + + add_custom_target(${IP_LIB}_vcs + DEPENDS ${STAMP_FILE} ${IP_LIB} + ) + set_property(TARGET ${IP_LIB}_vcs PROPERTY DESCRIPTION ${DESCRIPTION}) + + set(__vcsrun_cmd ${SIM_EXEC_PATH} ${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 simulation on ${IP_LIB} with ${CMAKE_CURRENT_FUNCTION}") + add_custom_target(${ARG_RUN_TARGET_NAME} + COMMAND ${__vcsrun_cmd} + COMMENT ${DESCRIPTION} + WORKING_DIRECTORY ${OUTDIR} + DEPENDS ${IP_LIB}_vcs + ) + set_property(TARGET ${ARG_RUN_TARGET_NAME} PROPERTY DESCRIPTION ${DESCRIPTION}) + endif() + set(SIM_RUN_CMD ${__vcsrun_cmd} PARENT_SCOPE) + +endfunction() + +function(__vcs_compile_lib IP_LIB) + cmake_parse_arguments(ARG "NO_DEPS" "OUTDIR;TOP_MODULE" "VLOGAN_ARGS;VHDLAN_ARGS;VCS_ARGS" ${ARGN}) + # Check for any unrecognized arguments + if(ARG_UNPARSED_ARGUMENTS) + message(FATAL_ERROR "${CMAKE_CURRENT_FUNCTION} passed unrecognized argument " "${ARG_UNPARSED_ARGUMENTS}") endif() - if(ARG_OUTDIR) + 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 work) + # endif() + + if(NOT ARG_OUTDIR) + set(OUTDIR ${BINARY_DIR}/${IP_LIB}_vcs) + else() set(OUTDIR ${ARG_OUTDIR}) + endif() + file(MAKE_DIRECTORY ${OUTDIR}) + + if(NOT ARG_TOP_MODULE) + get_target_property(IP_NAME ${IP_LIB} IP_NAME) + set(ARG_TOP_MODULE ${IP_NAME}) + endif() + + if(ARG_NO_DEPS) + set(ARG_NO_DEPS NO_DEPS) else() - set(OUTDIR ${BINARY_DIR}) + unset(ARG_NO_DEPS) endif() - file(MAKE_DIRECTORY ${OUTDIR}/csrc/sysc/include) - find_program(VLOGAN_EXECUTABLE vlogan REQUIRED - HINTS ${VCS_HOME} $ENV{VCS_HOME} - ) + # 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 vcs vlogan in library ${LIBRARY}") + set(__vlogan_cmd COMMAND vlogan + -full64 + -q + -sverilog + ${ARG_VLOGAN_ARGS} + ${SV_ARG_INCDIRS} + ${SV_CMP_DEFS_ARG} + ${SV_SOURCES} + # -work ${OUTDIR}/${LIBRARY} + ) + endif() - set(STAMP_FILE "${OUTDIR}/${IP_LIB}_${CMAKE_CURRENT_FUNCTION}.stamp") - add_custom_command( - OUTPUT ${STAMP_FILE} - WORKING_DIRECTORY ${OUTDIR} - COMMAND ${VLOGAN_EXECUTABLE} - -full64 -nc -sverilog - -sc_model ${ARG_TOP_MODULE} - ${SOURCES} - ${COMP_DEFS} + # VHDL files and arguments + get_ip_sources(VHDL_SOURCES ${IP_LIB} VHDL ${ARG_NO_DEPS}) + if(VHDL_SOURCES) + set(__vhdlan_cmd COMMAND vhdlan + -full64 + -q + ${ARG_VHDLAN_ARGS} + ${VHDL_SOURCES} + # -work ${OUTDIR}/${LIBRARY} + ) + endif() - COMMAND touch ${STAMP_FILE} - DEPENDS ${SOURCES} - COMMENT "Running ${CMAKE_CURRENT_FUNCTION} on ${IP_LIB}" + if(NOT TARGET ${IP_LIB}_vcs_complib) + set(DESCRIPTION "Compile VHDL, SV, and Verilog files for ${IP_LIB} with vcs in library ${LIBRARY}") + set(STAMP_FILE "${BINARY_DIR}/${IP_LIB}_${CMAKE_CURRENT_FUNCTION}.stamp") + add_custom_command( + OUTPUT ${STAMP_FILE} + ${__vlogan_cmd} + ${__vhdlan_cmd} + COMMAND touch ${STAMP_FILE} + WORKING_DIRECTORY ${OUTDIR} + BYPRODUCTS ${OUTDIR}/64 ${OUTDIR}/AN.DB + DEPENDS ${SV_SOURCES} ${VHDL_SOURCES} + COMMENT ${DESCRIPTION} ) - add_custom_target( - ${IP_LIB}_${CMAKE_CURRENT_FUNCTION} - DEPENDS ${STAMP_FILE} + add_custom_target( + ${IP_LIB}_vcs_complib + DEPENDS ${STAMP_FILE} ${STAMP_FILE_VHDL} ${IP_LIB} ) + set_property(TARGET ${IP_LIB}_vcs_complib PROPERTY + DESCRIPTION "Compile VHDL, SV, and Verilog files for ${IP_LIB} with vcs in library ${LIBRARY}") + set(VCS_COMPLIB_STAMP_FILE ${STAMP_FILE} PARENT_SCOPE) + endif() - set(__VCS_LIB ${IP_LIB}__vcs) - add_library(${__VCS_LIB} OBJECT IMPORTED) - add_dependencies(${__VCS_LIB} ${IP_LIB}_${CMAKE_CURRENT_FUNCTION}) - target_include_directories(${__VCS_LIB} INTERFACE - ${OUTDIR}/csrc/sysc/include) - #target_link_libraries(${__VCS_LIB} INTERFACE -lpthread) - - string(REPLACE "__" "::" ALIAS_NAME "${__VCS_LIB}") - add_library(${ALIAS_NAME} ALIAS ${__VCS_LIB}) - - # add_dependencies(${IP_LIB}_${CMAKE_CURRENT_FUNCTION} ${IP_LIB}) endfunction() - -# syscan -full64 -sysc=scv20 sc_main.cpp - -#function(vcs EXEC) -# cmake_parse_arguments(ARG "" "OUTDIR" "DEPENDS" ${ARGN}) -# 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") -# -# get_target_property(BINARY_DIR ${EXEC} BINARY_DIR) -# -# safe_get_target_property(INTERFACE_SOURCES ${EXEC} INTERFACE_SOURCES "") -# safe_get_target_property(SOURCES ${EXEC} SOURCES "") -# list(APPEND SOURCES ${INTERFACE_SOURCES}) -# message("SOURCES: ${SOURCES}") -# -# if(NOT ARG_OUTDIR) -# set(OUTDIR "${BINARY_DIR}/${EXEC}_vcs") -# else() -# set(OUTDIR ${ARG_OUTDIR}) -# endif() -# file(MAKE_DIRECTORY ${OUTDIR}) -# -# ###################################### -# ##### Get libraries from EXEC ######## -# ###################################### -# -# safe_get_target_property(INTERFACE_LINK_LIBRARIES ${EXEC} INTERFACE_LINK_LIBRARIES "") -# safe_get_target_property(LINK_LIBRARIES ${EXEC} LINK_LIBRARIES "") -# list(APPEND LINK_LIBRARIES ${INTERFACE_LINK_LIBRARIES}) -# list(REMOVE_DUPLICATES LINK_LIBRARIES) -# message("====== LINK_LIBRARIES: ${LINK_LIBRARIES}") -# -# unset(VCS_LDFLAG_RPATH) -# unset(VCS_LDFLAGS_LIBS) -# string(APPEND VCS_LDFLAG_RPATH "-LDFLAGS -Wl,-rpath,") -# foreach(lib ${LINK_LIBRARIES}) -# if(TARGET ${lib}) -# get_target_property(IMPORTED_LOCATION ${lib} IMPORTED_LOCATION) -# if(IMPORTED_LOCATION) -# set(lib ${IMPORTED_LOCATION}) -# cmake_path(GET lib PARENT_PATH lib_dir) -# string(APPEND VCS_LDFLAG_RPATH ${lib_dir}:) -# list(APPEND VCS_LDFLAGS_LIBS -LDFLAGS ${lib}) -# else() -# get_target_property(BINARY_DIR ${lib} BINARY_DIR) -# set(lib_dir ${BINARY_DIR}) -# string(APPEND VCS_LDFLAG_RPATH ${lib_dir}:) -# message("------ ADDING LIB: ${lib}") -# list(APPEND VCS_LIBS_ARG -LDFLAGS -L${lib_dir} -l${lib}) -# endif() -# endif() -# endforeach() -# -# # string (REPLACE ";" " " VCS_LDFLAG_RPATH "${VCS_LDFLAG_RPATH}") -# message("LIBS: ${VCS_LDFLAG_RPATH}") -# -# ###################################### -# ##### Get Include Directories ######## -# ###################################### -# -# safe_get_target_property(INTERFACE_INCLUDE_DIRECTORIES ${EXEC} INTERFACE_INCLUDE_DIRECTORIES "") -# safe_get_target_property(INCLUDE_DIRECTORIES ${EXEC} INCLUDE_DIRECTORIES "") -# message("INCLUDE: ${INCLUDE_DIRECTORIES}, INTF_INC: ${INTERFACE_INCLUDE_DIRECTORIES}") -# foreach(incdir ${INCLUDE_DIRECTORIES} ${INTERFACE_INCLUDE_DIRECTORIES}) -# list(APPEND _VCS_CFLAGS -CFLAGS -I${incdir}) -# endforeach() -# -# foreach(lib ${LINK_LIBRARIES}) -# if(TARGET ${lib}) -# safe_get_target_property(intf_inc_dirs ${lib} INTERFACE_INCLUDE_DIRECTORIES "") -# safe_get_target_property(inc_dirs ${lib} INCLUDE_DIRECTORIES "") -# message("LIB: ${lib} DIR: ${intf_inc_dirs} inc_dirs: ${inc_dirs}") -# foreach(incdir ${inc_dirs} ${intf_inc_dirs}) -# list(APPEND _VCS_CFLAGS -CFLAGS -I${incdir}) -# endforeach() -# endif() -# endforeach() -# -# -# set(CMAKE_FIND_DEBUG_MODE TRUE) -# find_program(_SYSCAN_EXECUTABLE syscan REQUIRED -# HINTS ${VCS_HOME} $ENV{VCS_HOME} -# ) -# set(CMAKE_FIND_DEBUG_MODE FALSE) -# -# set(STAMP_FILE "${OUTDIR}/${EXEC}_syscan.stamp") -# add_custom_command( -# OUTPUT ${STAMP_FILE} -# WORKING_DIRECTORY ${OUTDIR} -# COMMAND ${_SYSCAN_EXECUTABLE} -# -full64 -sysc=scv20 -# ${_VCS_CFLAGS} -# ${SOURCES} -# -# COMMAND touch ${STAMP_FILE} -# DEPENDS ${SOURCES} ${ARG_DEPENDS} -# COMMENT "Running ${CMAKE_CURRENT_FUNCTION} on ${EXEC}" -# ) -# -# add_custom_target( -# ${EXEC}_syscan -# DEPENDS ${STAMP_FILE} -# ) -# -## vcs -V -full64 -nc -j16 -sverilog -sysc=scv20 sc_main -timescale=1ns/1ps -# -# find_program(_VCS_EXECUTABLE vcs REQUIRED -# HINTS ${VCS_HOME} $ENV{VCS_HOME} -# ) -# -# message("DEPENDS: ${ARG_DEPENDS}") -# set(STAMP_FILE "${OUTDIR}/${EXEC}_vcs.stamp") -# add_custom_command( -# OUTPUT ${STAMP_FILE} ${PROJECT_BINARY_DIR}/${EXEC} -# WORKING_DIRECTORY ${OUTDIR} -# COMMAND ${_VCS_EXECUTABLE} -# -full64 -nc -sysc=scv20 -# sc_main -# -timescale=1ns/1ps -# ${VCS_LDFLAG_RPATH} -# ${VCS_LDFLAGS_LIBS} -# ${VCS_LIBS_ARG} -# -o ${PROJECT_BINARY_DIR}/${EXEC} -# -# COMMAND touch ${STAMP_FILE} -# DEPENDS ${SOURCES} ${EXEC}_syscan ${ARG_DEPENDS} ${LINK_LIBRARIES} -# COMMENT "Running ${CMAKE_CURRENT_FUNCTION} on ${EXEC}" -# ) -# -# add_custom_target( -# ${EXEC}_vcs -# DEPENDS ${STAMP_FILE} -# ) -# -# # add_dependencies(${IP_LIB}_${CMAKE_CURRENT_FUNCTION} ${IP_LIB}) -#endfunction() diff --git a/cmake/sim/synopsys/vcs_toolchain.cmake b/cmake/sim/synopsys/vcs_toolchain.cmake deleted file mode 100644 index d40bea1..0000000 --- a/cmake/sim/synopsys/vcs_toolchain.cmake +++ /dev/null @@ -1,32 +0,0 @@ -set(CMAKE_LINKER ${VCS_HOME}/gnu/linux64/binutils-64/bin/ld) -set(CMAKE_C_COMPILER ${VCS_HOME}/gnu/linux64/gcc-64/bin/gcc) -set(CMAKE_CXX_COMPILER ${VCS_HOME}/gnu/linux64/gcc-64/bin/g++) - -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -L${VCS_HOME}/gnu/linux64/gcc-64/lib64/ ") -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -L${VCS_HOME}/gnu/linux64/gcc-64/lib64/ ") - - -if(NOT TARGET vcs__libs) - add_library(vcs__libs INTERFACE) - add_library(vcs::libs ALIAS vcs__libs) - - target_include_directories(vcs__libs INTERFACE - ${VCS_HOME}/etc/systemc/accellera_install/systemc233-gcc9/include - ${VCS_HOME}/include/systemc233 - ${VCS_HOME}/include/scv-2.0 - ${VCS_HOME}/lib - ${VCS_HOME}/include - ${VCS_HOME}/include/cosim/bf - ) -endif() - -find_program(VCS_EXECUTABLE vcs REQUIRED - HINTS ${VCS_HOME} $ENV{VCS_HOME} - ) - -set(CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLAG "-LDFLAGS -Wl,-rpath,") -set(CMAKE_CXX_LINK_EXECUTABLE "${VCS_EXECUTABLE} -full64 -nc -sysc=scv20 sc_main -timescale=1ns/1ps -o ") - -unset(CMAKE_CXX_COMPILER_WORKS CACHE) -set(CMAKE_CXX_COMPILER_WORKS TRUE) -