Skip to content

Commit 2bcf95c

Browse files
committed
refactor(generate_sources_list): replace Python script with direct slang invocation in CMake
It follows @Risto97 feedback in the MR [1] - Remove generate_sources_list.py and its invocation - Integrate slang command directly into CMake function - Add checks for slang executable and improve error messages - Use add_custom_command and add_custom_target for output generation - Update argument handling for top module and synthesis options [1] #198 (comment)
1 parent ceb38e2 commit 2bcf95c

2 files changed

Lines changed: 62 additions & 105 deletions

File tree

cmake/utils/generate_sources_list/generate_sources_list.cmake

Lines changed: 62 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -22,63 +22,77 @@
2222
# :type TOP_MODULE: string
2323
#]]
2424
function(generate_sources_list IP_LIB)
25-
cmake_parse_arguments(ARG "SYNTHESIS" "OUTDIR;TOP_MODULE" "" ${ARGN})
26-
if(ARG_UNPARSED_ARGUMENTS)
27-
message(FATAL_ERROR "${CMAKE_CURRENT_FUNCTION} passed unrecognized argument " "${ARG_UNPARSED_ARGUMENTS}")
28-
endif()
25+
cmake_parse_arguments(ARG "SYNTHESIS" "OUTDIR;TOP_MODULE" "" ${ARGN})
26+
if(ARG_UNPARSED_ARGUMENTS)
27+
message(FATAL_ERROR "${CMAKE_CURRENT_FUNCTION} passed unrecognized argument " "${ARG_UNPARSED_ARGUMENTS}")
28+
endif()
2929

30-
# Initialize variables
31-
set(INCDIR_ARG "")
32-
set(TOP_MODULE_ARG "")
33-
set(SYNTHESIS_ARG "")
30+
# Find slang executable
31+
find_program(SLANG_EXECUTABLE slang)
32+
if(NOT SLANG_EXECUTABLE)
33+
message(FATAL_ERROR "slang executable not found! Please install slang or set SLANG_EXECUTABLE.")
34+
endif()
3435

35-
# Check if the Python script exists
36-
if(NOT EXISTS "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/generate_sources_list.py")
37-
message(FATAL_ERROR "generate_sources_list.py not found!")
38-
endif()
36+
# Initialize variables
37+
set(INCDIR_ARG "")
38+
set(TOP_MODULE_ARG "")
39+
set(SYNTHESIS_ARG "")
3940

40-
include("${CMAKE_CURRENT_FUNCTION_LIST_DIR}/../../hwip.cmake")
41+
include("${CMAKE_CURRENT_FUNCTION_LIST_DIR}/../../hwip.cmake")
42+
alias_dereference(IP_LIB ${IP_LIB})
4143

42-
alias_dereference(IP_LIB ${IP_LIB})
44+
if(NOT ARG_OUTDIR)
45+
set(OUTDIR ${CMAKE_BINARY_DIR}/ip_sources)
46+
else()
47+
set(OUTDIR ${ARG_OUTDIR})
48+
endif()
4349

44-
if(NOT ARG_OUTDIR)
45-
set(OUTDIR ${CMAKE_BINARY_DIR}/ip_sources)
46-
else()
47-
set(OUTDIR ${ARG_OUTDIR})
48-
endif()
50+
# If a top module is provided, only modules in its hierarchy are included.
51+
if(ARG_TOP_MODULE)
52+
list(APPEND TOP_MODULE_ARG --top ${ARG_TOP_MODULE})
53+
endif()
4954

50-
# If a top module is provided, only modules in its hierarchy are included.
51-
if(ARG_TOP_MODULE)
52-
set(TOP_MODULE_ARG --top-module ${ARG_TOP_MODULE})
53-
endif()
55+
# Get the list of RTL sources
56+
get_ip_sources(RTL_SOURCES ${IP_LIB} SYSTEMVERILOG VERILOG)
57+
get_ip_include_directories(RTL_INCDIRS ${IP_LIB} SYSTEMVERILOG)
58+
foreach(_i ${RTL_INCDIRS})
59+
list(APPEND INCDIR_ARG -I${_i})
60+
endforeach()
5461

55-
# Get the list of RTL sources
56-
get_ip_sources(RTL_SOURCES ${IP_LIB} SYSTEMVERILOG VERILOG)
57-
get_ip_include_directories(RTL_INCDIRS ${IP_LIB} SYSTEMVERILOG)
58-
foreach(_i ${RTL_INCDIRS})
59-
set(INCDIR_ARG ${INCDIR_ARG} --include ${_i})
60-
endforeach()
62+
if(ARG_SYNTHESIS)
63+
list(APPEND SYNTHESIS_ARGS -DSYNTHESIS)
64+
endif()
6165

62-
if(ARG_SYNTHESIS)
63-
set(SYNTHESIS_ARG --synthesis)
64-
endif()
66+
set(RTL_FILE ${OUTDIR}/rtl_sources.f)
67+
set(INCLUDE_FILE ${OUTDIR}/include_sources.f)
68+
file(MAKE_DIRECTORY ${OUTDIR})
6569

66-
find_python3()
67-
set(__CMD ${Python3_EXECUTABLE} ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/generate_sources_list.py
68-
${TOP_MODULE_ARG} ${SYNTHESIS_ARG}
69-
${INCDIR_ARG}
70-
--outdir ${OUTDIR}
71-
${RTL_SOURCES}
72-
)
70+
set(SLANG_CMD
71+
${SLANG_EXECUTABLE}
72+
--depfile-trim --Mmodule ${RTL_FILE} --Minclude ${INCLUDE_FILE}
73+
${TOP_MODULE_ARG}
74+
${SYNTHESIS_ARG}
75+
${INCDIR_ARG}
76+
${RTL_SOURCES}
77+
)
7378

74-
# Create a target to run the custom command
75-
add_custom_target(
76-
${IP_LIB}_source_list
77-
ALL # This forces the target to be run every time as outputs are not known in advance
78-
COMMAND ${__CMD}
79-
COMMENT "Generating list of the RTL source files in ${OUTDIR}"
80-
DEPENDS ${IP_LIB}
81-
VERBATIM
82-
)
79+
get_ip_links(DEPENDENT_TARGETS ${IP_LIB})
80+
81+
add_custom_command(
82+
OUTPUT ${RTL_FILE} ${INCLUDE_FILE}
83+
COMMAND ${SLANG_CMD}
84+
DEPENDS ${DEPENDENT_TARGETS} ${RTL_SOURCES}
85+
COMMENT "Generating list of the RTL source files in ${OUTDIR}"
86+
VERBATIM
87+
)
88+
89+
add_custom_target(
90+
${IP_LIB}_source_list
91+
DEPENDS ${RTL_FILE} ${INCLUDE_FILE}
92+
COMMENT "Target for generating filtered RTL source list for ${IP_LIB}"
93+
VERBATIM
94+
)
95+
96+
message(STATUS "To generate RTL source list for ${IP_LIB}, build the target: ${IP_LIB}_source_list")
8397

8498
endfunction()

cmake/utils/generate_sources_list/generate_sources_list.py

Lines changed: 0 additions & 57 deletions
This file was deleted.

0 commit comments

Comments
 (0)