summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlejandro Soto <alejandro@34project.org>2024-06-02 11:39:56 -0600
committerAlejandro Soto <alejandro@34project.org>2024-06-02 12:19:36 -0600
commit3ca4cd68d70a32bd20380dc21ae9d9866f6c0866 (patch)
tree143b10f0c1291d82a0187a39f5facf6d2a72372d
parent3794b707ebec4f91bd3f9922572bb154a8ac910a (diff)
mk/cocotb: implement pydoc generation
-rw-r--r--mk/cocotb.mk44
-rw-r--r--mk/tools.mk1
-rw-r--r--tb/gfx_shader_bind/mod.mk4
3 files changed, 38 insertions, 11 deletions
diff --git a/mk/cocotb.mk b/mk/cocotb.mk
index 7187773..240d808 100644
--- a/mk/cocotb.mk
+++ b/mk/cocotb.mk
@@ -1,17 +1,38 @@
-targets += test
+targets += pydoc test
target/test/prepare = $(prepare_verilator_target)
cocotb_modules = $(call per_target,cocotb_modules)
+pydoc_modules = $(call per_target,pydoc_modules)
-define target/test/setup
- $(setup_verilator_target)
+cocotb_pythonpath_decl = PYTHONPATH="$(subst $(space),:,$(strip $(cocotb_pythonpath)) $$PYTHONPATH)"
+
+cocotb_pythonpath = \
+ $(addprefix $(src)/, \
+ $(foreach dep,$(dep_tree/$(rule_top)), \
+ $(call core_paths,$(dep),cocotb_paths)))
+define cocotb_setup_common
$$(call target_var,cocotb_modules) := $$(strip $$(core_info/$$(rule_top)/cocotb_modules))
ifeq (,$$(cocotb_modules))
$$(error core '$$(rule_top)' has no cocotb test modules)
endif
+endef
+
+define target/pydoc/setup
+ $(cocotb_setup_common)
+
+ $$(call target_var,pydoc_modules) := $$(strip $$(core_info/$$(rule_top)/pydoc_modules))
+
+ ifeq (,$$(pydoc_modules))
+ $$(error core '$$(rule_top)' has no modules for pydoc to cover)
+ endif
+endef
+
+define target/test/setup
+ $(setup_verilator_target)
+ $(cocotb_setup_common)
$$(call target_var,vl_main) = $$(cocotb_share)/lib/verilator/verilator.cpp
$$(call target_var,vl_flags) += --vpi --public-flat-rw
@@ -20,6 +41,15 @@ define target/test/setup
-lcocotbvpi_verilator -lgpi -lcocotb -lgpilog -lcocotbutils $$(cocotb_libpython)
endef
+define target/pydoc/rules
+ .PHONY: $$(rule_top_path)/pydoc
+
+ $$(rule_top_path)/pydoc: | $$(obj)
+ $$(call run,PYDOC) cd $$(obj) && $$(cocotb_pythonpath_decl) $$(PYDOC3) -w $$(pydoc_modules)
+
+ $(call target_entrypoint,$$(rule_top_path)/pydoc)
+endef
+
define target/test/rules
$(verilator_target_rules)
@@ -28,14 +58,8 @@ define target/test/rules
$$(rule_top_path)/test &: $$(vtop_exe) $$(call core_objs,$$(rule_top),obj_deps) | $$(obj)
$$(call run_no_err,COCOTB) cd $$(obj) && rm -f log.txt results.xml && \
LIBPYTHON_LOC=$$(cocotb_libpython) COCOTB_RESULTS_FILE=results.xml \
- PYTHONPATH="$$(subst $$(space),:,$$(strip $$(cocotb_pythonpath) $$$$PYTHONPATH))" \
- MODULE=$$(subst $$(space),$$(comma),$$(cocotb_modules)) \
+ $$(cocotb_pythonpath_decl) MODULE=$$(subst $$(space),$$(comma),$$(cocotb_modules)) \
$$(src)/$$< | tee log.txt
$(call target_entrypoint,$$(rule_top_path)/test)
endef
-
-cocotb_pythonpath = \
- $(addprefix $(src)/, \
- $(foreach dep,$(dep_tree/$(rule_top)), \
- $(call core_paths,$(dep),cocotb_paths)))
diff --git a/mk/tools.mk b/mk/tools.mk
index c01c2de..177b956 100644
--- a/mk/tools.mk
+++ b/mk/tools.mk
@@ -5,6 +5,7 @@ define find_tools_lazy
$(call find_command_lazy,ninja,NINJA)
$(call find_command_lazy,peakrdl,PEAKRDL)
$(call find_command_lazy,pkg-config,PKG_CONFIG)
+ $(call find_command_lazy,pydoc3,PYDOC3)
$(call find_command_lazy,python3,PYTHON3)
$(call find_command_lazy,qsys-generate,QSYS_GENERATE)
$(call find_command_lazy,quartus,QUARTUS)
diff --git a/tb/gfx_shader_bind/mod.mk b/tb/gfx_shader_bind/mod.mk
index e031f52..af16a04 100644
--- a/tb/gfx_shader_bind/mod.mk
+++ b/tb/gfx_shader_bind/mod.mk
@@ -1,10 +1,12 @@
define core
$(this)/deps := gfx
- $(this)/targets := test
+ $(this)/targets := pydoc test
$(this)/rtl_top := dut
$(this)/rtl_files := dut.sv
$(this)/cocotb_paths := .
$(this)/cocotb_modules := testbench.main
+
+ $(this)/pydoc_modules := testbench
endef