|
| 1 | +# Makefile for Verilator simulation with coverage |
| 2 | +VERILATOR = verilator |
| 3 | +VERILATOR_FLAGS = -Wall -Wno-fatal |
| 4 | +VERILATOR_COV_FLAGS = --coverage --coverage-line --coverage-toggle --coverage-user |
| 5 | + |
| 6 | +# Directories |
| 7 | +SRC_DIR = . |
| 8 | +BUILD_DIR = obj_dir |
| 9 | +COV_DIR = coverage |
| 10 | + |
| 11 | +# Source files |
| 12 | +SV_SOURCES = counter.sv counter_tb.sv |
| 13 | + |
| 14 | +# Top module |
| 15 | +TOP_MODULE = counter_tb |
| 16 | + |
| 17 | +# Verilator build target |
| 18 | +.PHONY: all |
| 19 | +all: build |
| 20 | + |
| 21 | +# Build the simulation with coverage using --binary flag |
| 22 | +.PHONY: build |
| 23 | +build: |
| 24 | + @echo "Building Verilator simulation with coverage..." |
| 25 | + $(VERILATOR) $(VERILATOR_FLAGS) $(VERILATOR_COV_FLAGS) \ |
| 26 | + --binary -j 0 \ |
| 27 | + --top-module $(TOP_MODULE) \ |
| 28 | + $(SV_SOURCES) |
| 29 | + @echo "Build complete!" |
| 30 | + |
| 31 | +# Run the simulation |
| 32 | +.PHONY: run |
| 33 | +run: build |
| 34 | + @echo "Running simulation..." |
| 35 | + @mkdir -p $(COV_DIR) |
| 36 | + ./$(BUILD_DIR)/V$(TOP_MODULE) |
| 37 | + @echo "Simulation complete!" |
| 38 | + @echo "Coverage data saved to: coverage.dat" |
| 39 | + |
| 40 | +# Convert Verilator coverage to UCIS SQLite format |
| 41 | +.PHONY: convert |
| 42 | +convert: run |
| 43 | + @echo "Converting Verilator coverage to UCIS SQLite format..." |
| 44 | + PYTHONPATH=$(shell cd ../.. && pwd)/src pyucis convert \ |
| 45 | + --input-format vltcov --output-format sqlite \ |
| 46 | + coverage.dat -o $(COV_DIR)/coverage.cdb |
| 47 | + @echo "Conversion complete! UCIS database: $(COV_DIR)/coverage.cdb" |
| 48 | + |
| 49 | +# View the coverage database with PyUCIS TUI |
| 50 | +.PHONY: view |
| 51 | +view: convert |
| 52 | + @echo "Launching PyUCIS TUI..." |
| 53 | + pyucis view --input-format sqlite $(COV_DIR)/coverage.cdb |
| 54 | + |
| 55 | +# Generate coverage report |
| 56 | +.PHONY: report |
| 57 | +report: convert |
| 58 | + @echo "Generating coverage report..." |
| 59 | + pyucis show summary --input-format sqlite $(COV_DIR)/coverage.cdb |
| 60 | + @echo "" |
| 61 | + @echo "Coverage hierarchy:" |
| 62 | + pyucis show hierarchy --input-format sqlite $(COV_DIR)/coverage.cdb |
| 63 | + |
| 64 | +# Clean build artifacts |
| 65 | +.PHONY: clean |
| 66 | +clean: |
| 67 | + @echo "Cleaning build artifacts..." |
| 68 | + rm -rf $(BUILD_DIR) coverage.dat logs |
| 69 | + @echo "Clean complete!" |
| 70 | + |
| 71 | +# Clean everything including coverage database |
| 72 | +.PHONY: distclean |
| 73 | +distclean: clean |
| 74 | + @echo "Cleaning coverage database..." |
| 75 | + rm -rf $(COV_DIR) |
| 76 | + @echo "Distclean complete!" |
| 77 | + |
| 78 | +# Help |
| 79 | +.PHONY: help |
| 80 | +help: |
| 81 | + @echo "Verilator Coverage Example - Makefile Targets" |
| 82 | + @echo "==============================================" |
| 83 | + @echo " make build - Build Verilator simulation with coverage" |
| 84 | + @echo " make run - Run simulation and generate coverage.dat" |
| 85 | + @echo " make convert - Convert coverage.dat to UCIS SQLite (.cdb)" |
| 86 | + @echo " make view - Launch PyUCIS TUI to view coverage" |
| 87 | + @echo " make report - Generate text coverage reports" |
| 88 | + @echo " make clean - Remove build artifacts" |
| 89 | + @echo " make distclean- Remove everything including coverage DB" |
| 90 | + @echo " make all - Build (default target)" |
| 91 | + @echo "" |
| 92 | + @echo "Quick start: make run && make convert && make view" |
0 commit comments