Skip to content

Commit 897373d

Browse files
committed
Add slang to check systemverilog syntax of generated files
1 parent c024ce7 commit 897373d

3 files changed

Lines changed: 53 additions & 11 deletions

File tree

Makefile

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,6 @@ endif
55

66
XSD_DIR = schema1.5
77

8-
UNAME := $(shell uname)
9-
ifeq ($(UNAME), Linux)
10-
SVPARSER := ./tools/linux/depmapDebug
11-
else
12-
SVPARSER := ./tools/osx/slang-depmap
13-
endif
14-
15-
16-
178
all: gen
189

1910
gen:
@@ -81,7 +72,7 @@ compile_icarus:
8172
iverilog -g2012 -o foo example/output/*.sv
8273

8374
parse_systemverilog:
84-
$(SVPARSER) example/output/
75+
python ipxact2systemverilog/slang.py example/output/*.sv
8576

8677
.PHONY: whole_library example/output
8778

ipxact2systemverilog/slang.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/env python3
2+
3+
import sys
4+
import os
5+
import pyslang
6+
7+
8+
def check_file(file_path):
9+
if not (file_path.endswith(".sv") or file_path.endswith(".svh")):
10+
print(f"⏭️ Skipping {file_path}: not an .sv or .svh file")
11+
return False
12+
13+
if not os.path.isfile(file_path):
14+
print(f"❌ Error: File '{file_path}' does not exist.")
15+
return False
16+
17+
print(f"\n🔍 Checking {file_path}...")
18+
19+
tree = pyslang.SyntaxTree.fromFile(file_path)
20+
diagnostics = tree.diagnostics
21+
22+
if diagnostics:
23+
print(f"❌ Syntax errors in {file_path}:")
24+
for diag in diagnostics:
25+
print(f" - {diag}")
26+
return False
27+
28+
print(f"✅ {file_path} is syntactically valid.")
29+
30+
return True
31+
32+
33+
def main():
34+
if len(sys.argv) < 2:
35+
print("Usage: check_sv_syntax.py <file1.sv> [file2.svh ...]")
36+
sys.exit(1)
37+
38+
files = sys.argv[1:]
39+
all_passed = True
40+
41+
for file_path in files:
42+
if not check_file(file_path):
43+
all_passed = False
44+
45+
if not all_passed:
46+
sys.exit(1)
47+
48+
49+
if __name__ == "__main__":
50+
main()

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
[project]
22
description = "Generate VHDL, SystemVerilog, html, rst, md, pdf, c headers from an IPXACT description"
33
readme = "README.md"
4-
version = "1.0.25"
4+
version = "1.0.26"
55
name = "ipxact2systemverilog"
66
authors = [
77
{name = "oddball"},
88
]
99
keywords = ["ipxact2systemverilog", "ipxact2vhdl", "VHDL", "SystemVerilog", "html", "rst", "md", "pdf", "IPXACT"]
1010
requires-python = ">= 3"
1111
dependencies = [
12+
"pyslang",
1213
"docutils",
1314
"lxml",
1415
"mdutils",

0 commit comments

Comments
 (0)