Skip to content

Commit

Permalink
rename verilate -> verilator, add description, refactor examples, add…
Browse files Browse the repository at this point in the history
… vhier description
  • Loading branch information
Risto97 committed Sep 15, 2024
1 parent 9f2e9cd commit 3d6b93d
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 15 deletions.
2 changes: 1 addition & 1 deletion SoCMakeConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ include("${CMAKE_CURRENT_LIST_DIR}/cmake/utils/copy_rtl_files/vhier.cmake")
# ====================================

# ----- Verilator ------
include("${CMAKE_CURRENT_LIST_DIR}/cmake/sim/verilator/verilate.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/cmake/sim/verilator/verilator.cmake")

# ----- iverilog ------
include("${CMAKE_CURRENT_LIST_DIR}/cmake/sim/iverilog/iverilog.cmake")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function(verilate IP_LIB)
function(verilator IP_LIB)
set(OPTIONS "COVERAGE;TRACE;TRACE_FST;SYSTEMC;TRACE_STRUCTS;MAIN")
set(ONE_PARAM_ARGS "PREFIX;TOP_MODULE;THREADS;TRACE_THREADS;DIRECTORY;EXECUTABLE_NAME")
set(MULTI_PARAM_ARGS "VERILATOR_ARGS;OPT_SLOW;OPT_FAST;OPT_GLOBAL")
Expand All @@ -21,7 +21,7 @@ function(verilate IP_LIB)
get_target_property(BINARY_DIR ${IP_LIB} BINARY_DIR)

if(NOT ARG_DIRECTORY)
set(DIRECTORY "${BINARY_DIR}/${IP_LIB}_verilate")
set(DIRECTORY "${BINARY_DIR}/${IP_LIB}_verilator")
else()
set(DIRECTORY ${ARG_DIRECTORY})
endif()
Expand Down Expand Up @@ -58,8 +58,10 @@ function(verilate IP_LIB)
set(PREFIX V${ARG_TOP_MODULE})
endif()

## TODO deprecate
get_ip_property(VERILATOR_ARGS ${IP_LIB} VERILATOR_ARGS)
list(APPEND ARG_VERILATOR_ARGS ${VERILATOR_ARGS})
##

get_ip_compile_definitions(COMP_DEFS ${IP_LIB} SYSTEMVERILOG VERILOG)
foreach(def ${COMP_DEFS})
Expand All @@ -76,7 +78,7 @@ function(verilate IP_LIB)
if(ARG_MAIN)
list(APPEND ARG_VERILATOR_ARGS --main)
if(NOT ARG_EXECUTABLE_NAME)
set(ARG_EXECUTABLE_NAME ${IP_LIB}_verilator_tb)
set(ARG_EXECUTABLE_NAME ${IP_LIB}_verilator_exec)
endif()
set(EXECUTABLE_PATH ${BINARY_DIR}/${ARG_EXECUTABLE_NAME})
unset(ARG_MAIN)
Expand Down Expand Up @@ -111,7 +113,6 @@ function(verilate IP_LIB)
endforeach()
string(REPLACE ";" "|" ARGUMENTS_LIST "${ARGUMENTS_LIST}")


if(ARG_SYSTEMC)
if(NOT SYSTEMC_HOME)
find_package(SystemCLanguage REQUIRED
Expand All @@ -125,6 +126,17 @@ function(verilate IP_LIB)
set(ARG_CMAKE_CXX_STANDARD "-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}")
endif()

##################################
## Prepare help message ##########
##################################
if(EXECUTABLE_PATH)
set(OUTPUT_TYPE "EXECUTABLE")
else()
set(OUTPUT_TYPE "STATIC_LIBRARY")
endif()
set(DESCRIPTION "Compiling ${IP_LIB} with verilator as ${OUTPUT_TYPE}")
###

set(VERILATE_TARGET ${IP_LIB}_verilate)
include(ExternalProject)
ExternalProject_Add(${VERILATE_TARGET}
Expand Down Expand Up @@ -152,6 +164,7 @@ function(verilate IP_LIB)
INSTALL_COMMAND ""
DEPENDS ${IP_LIB}
EXCLUDE_FROM_ALL 1
COMMENT ${DESCRIPTION}
)

set_property(
Expand All @@ -160,6 +173,7 @@ function(verilate IP_LIB)
${DIRECTORY}
${EXECUTABLE_PATH}
)
set_property(TARGET ${VERILATE_TARGET} PROPERTY DESCRIPTION ${DESCRIPTION})

set(VLT_STATIC_LIB "${DIRECTORY}/lib${ARG_TOP_MODULE}.a")
set(INC_DIR ${DIRECTORY})
Expand All @@ -181,4 +195,16 @@ function(verilate IP_LIB)

string(REPLACE "__" "::" ALIAS_NAME "${VERILATED_LIB}")
add_library(${ALIAS_NAME} ALIAS ${VERILATED_LIB})

if(EXECUTABLE_PATH)
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 ${EXECUTABLE_PATH}
DEPENDS ${EXECUTABLE_PATH} ${STAMP_FILE} ${VERILATE_TARGET}
COMMENT ${DESCRIPTION}
)
set_property(TARGET run_${IP_LIB}_${CMAKE_CURRENT_FUNCTION} PROPERTY DESCRIPTION ${DESCRIPTION})
endif()
endfunction()
6 changes: 5 additions & 1 deletion cmake/utils/copy_rtl_files/vhier.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,23 @@ function(vhier IP_LIB)
$<$<BOOL:${ARG_FOREST}>:--forest>
)

set(DESCRIPTION "Extract verilog hierarchy of ${IP_LIB} with ${CMAKE_CURRENT_FUNCTION}")

set(OUT_FILE ${CMAKE_BINARY_DIR}/${IP_LIB}_${CMAKE_CURRENT_FUNCTION}.$<IF:$<BOOL:${ARG_XML}>,xml,txt>)
set(STAMP_FILE "${CMAKE_BINARY_DIR}/${IP_LIB}_${CMAKE_CURRENT_FUNCTION}.stamp")
add_custom_command(
OUTPUT ${STAMP_FILE} ${OUT_FILE}
COMMAND touch ${STAMP_FILE}
COMMAND ${__CMD} | tee ${OUT_FILE}
DEPENDS ${RTL_SOURCES} ${IP_LIB}
COMMENT "Printing verilog hierarchy of ${IP_LIB} with ${CMAKE_CURRENT_FUNCTION}"
COMMENT ${DESCRIPTION}
)

add_custom_target(
${IP_LIB}_${CMAKE_CURRENT_FUNCTION}
DEPENDS ${IP_LIB} ${STAMP_FILE} ${OUT_FILE}
)

set_property(TARGET ${IP_LIB}_${CMAKE_CURRENT_FUNCTION} PROPERTY DESCRIPTION ${DESCRIPTION})
endfunction()

2 changes: 1 addition & 1 deletion examples/sim_example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ip_sources(${IP} VERILOG # Add source files to the VERILOG file set

iverilog(${IP})

verilate(${IP} # Create verilate target
verilator(${IP} # Create verilate target
MAIN) # Let Verilator create a main.cpp testbench

help()
2 changes: 1 addition & 1 deletion examples/sim_example/deps/deps.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ include(${CMAKE_CURRENT_LIST_DIR}/CPM.cmake) # Include the CPM.cmake downloader

CPMAddPackage( # Add SoCMake as a package
NAME SoCMake
GIT_TAG master # You can define GIT_TAG or VERSION for versioning
GIT_TAG develop # You can define GIT_TAG or VERSION for versioning
GIT_REPOSITORY "https://github.com/HEP-SoC/SoCMake.git" # GIT_REPOSITORY or URL
)
2 changes: 1 addition & 1 deletion examples/sim_example/tb.v
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module tb;
initial begin
$display("Simulated with Iverilog, from SoCMake build system\n");
$display("Hello world, from SoCMake build system\n");
$finish();
end
endmodule
4 changes: 3 additions & 1 deletion examples/verilator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ project(example CXX C)
include("deps/deps.cmake")
add_subdirectory(adder)

verilate(cern::ip::adder::0.0.1 TRACE)
verilator(cern::ip::adder::0.0.1 TRACE)

add_executable(testbench main.cpp)

target_link_libraries(testbench cern::ip::adder::0.0.1::vlt)

help()
6 changes: 2 additions & 4 deletions examples/verilator/adder/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
cmake_minimum_required(VERSION 3.25)
project(adder NONE)

add_ip(adder
VENDOR cern
LIBRARY ip
VERSION 0.0.1
add_ip(cern::ip::adder::0.0.1
DESCRIPTION "Just a simple adder"
)

ip_sources(adder VERILOG
Expand Down
2 changes: 1 addition & 1 deletion examples/verilator/deps/deps.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ include(${CMAKE_CURRENT_LIST_DIR}/CPM.cmake) # Include the CPM.cmake downloader

CPMAddPackage( # Add SoCMake as a package
NAME SoCMake
GIT_TAG master # You can define GIT_TAG or VERSION for versioning
GIT_TAG develop # You can define GIT_TAG or VERSION for versioning
GIT_REPOSITORY "https://github.com/HEP-SoC/SoCMake.git" # GIT_REPOSITORY or URL
)

0 comments on commit 3d6b93d

Please sign in to comment.