FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
siliconcompiler/scripts/class_hierarchy.py at main · ECASLab/siliconcompiler · GitHub
ECASLab
/
siliconcompiler
Public
forked from
siliconcompiler/siliconcompiler
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
siliconcompiler
/
scripts
/
class_hierarchy.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
128 lines (110 loc) · 5.23 KB
Breadcrumbs
siliconcompiler
/
scripts
/
class_hierarchy.py
Copy path
File metadata and controls
128 lines (110 loc) · 5.23 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/usr/bin/env python3
import
inspect
import
importlib
from
argparse
import
ArgumentParser
try
:
import
graphviz
_has_graphviz
=
True
except
ModuleNotFoundError
:
_has_graphviz
=
False
# Import all the classes
from
siliconcompiler
import
(
Project
,
ASIC
,
FPGA
,
Lint
,
Sim
,
Design
,
PDK
,
Flowgraph
,
Checklist
,
StdCellLibrary
,
FPGADevice
,
Task
,
ShowTask
,
ScreenshotTask
,
Schematic
)
from
siliconcompiler
.
asic
import
ASICTask
from
siliconcompiler
.
constraints
import
(
ASICTimingConstraintSchema
,
ASICAreaConstraint
,
ASICComponentConstraints
,
ASICPinConstraints
,
FPGAComponentConstraints
,
FPGAPinConstraints
,
FPGATimingConstraintSchema
)
from
siliconcompiler
.
schema_support
import
metric
,
record
,
option
from
siliconcompiler
.
library
import
ToolLibrarySchema
def
generate_class_hierarchy
(
classes
,
output_file
=
"class_hierarchy"
):
"""
Generates a class inheritance graph using graphviz.
"""
if
not
_has_graphviz
:
raise
RuntimeError
(
"Graphviz is not installed."
" Please install it to generate class hierarchy graphs."
)
dot
=
graphviz
.
Digraph
(
'SiliconCompiler Class Hierarchy'
,
comment
=
'SiliconCompiler Class Hierarchy'
)
dot
.
attr
(
'graph'
,
rankdir
=
'RL'
,
concentrate
=
'true'
)
dot
.
attr
(
'node'
,
shape
=
'box'
,
style
=
'rounded,filled'
)
SCHEMA_COLOR
=
"#fff8dc"
# cornsilk
SCHEMA_SUPPORT_COLOR
=
"#add8e6"
# lightblue
DEFAULT_COLOR
=
"#d3d3d3"
# lightgrey
# Classes exposed at the top-level of the siliconcompiler package
TOP_LEVEL_CLASSES
=
{
'Project'
,
'ASIC'
,
'FPGA'
,
'Lint'
,
'Sim'
,
'Design'
,
'PDK'
,
'Flowgraph'
,
'Checklist'
,
'StdCellLibrary'
,
'FPGADevice'
,
'Task'
,
'ShowTask'
,
'ScreenshotTask'
,
'Schematic'
}
added_nodes
=
set
()
all_mro_classes
=
set
()
for
cls
in
classes
:
mro
=
[
c
for
c
in
inspect
.
getmro
(
cls
)
if
'siliconcompiler'
in
c
.
__module__
or
c
is
cls
]
all_mro_classes
.
update
(
mro
)
# Create a subgraph for top-level classes to cluster them
with
dot
.
subgraph
(
name
=
'cluster_api'
)
as
c
:
c
.
attr
(
label
=
'SiliconCompiler API'
,
style
=
'filled'
,
color
=
'#f0f0f0'
,
fontcolor
=
'black'
)
for
cls
in
all_mro_classes
:
if
cls
.
__name__
not
in
added_nodes
:
module_name
=
cls
.
__module__
if
module_name
.
startswith
(
'siliconcompiler.schema.'
):
color
=
SCHEMA_COLOR
elif
module_name
.
startswith
(
'siliconcompiler.schema_support.'
):
color
=
SCHEMA_SUPPORT_COLOR
else
:
color
=
DEFAULT_COLOR
# Add node to the cluster or the main graph
if
cls
.
__name__
in
TOP_LEVEL_CLASSES
:
c
.
node
(
cls
.
__name__
,
fillcolor
=
color
)
else
:
dot
.
node
(
cls
.
__name__
,
fillcolor
=
color
)
added_nodes
.
add
(
cls
.
__name__
)
edges
=
[]
for
cls
in
all_mro_classes
:
for
base
in
cls
.
__bases__
:
if
'siliconcompiler'
not
in
base
.
__module__
:
continue
if
(
base
.
__name__
,
cls
.
__name__
)
in
edges
:
continue
edges
.
append
((
base
.
__name__
,
cls
.
__name__
))
# Add edge
dot
.
edge
(
f"
{
base
.
__name__
}
:w"
,
f"
{
cls
.
__name__
}
:e"
)
# Save the dot file and render a PNG
try
:
dot
.
render
(
output_file
,
view
=
False
,
format
=
'png'
,
cleanup
=
True
)
print
(
f"Generated class hierarchy graph at
{
output_file
}
.png"
)
except
graphviz
.
ExecutableNotFound
:
print
(
"Graphviz executable not found. Please install it and add it to your PATH."
)
print
(
"On Debian/Ubuntu: sudo apt-get install graphviz"
)
print
(
"On macOS (with Homebrew): brew install graphviz"
)
with
open
(
f"
{
output_file
}
.dot"
,
'w'
)
as
f
:
f
.
write
(
dot
.
source
)
print
(
f"Generated dot file at
{
output_file
}
.dot"
)
if
__name__
==
"__main__"
:
parser
=
ArgumentParser
(
description
=
"Generate a class inheritance graph for SiliconCompiler classes."
)
parser
.
add_argument
(
"cls"
,
nargs
=
"?"
,
help
=
"A specific class to graph in module/ClassName format "
"(e.g., siliconcompiler/Project)."
)
parser
.
add_argument
(
"--output"
,
default
=
"class_hierarchy"
,
help
=
"Output file name without extension."
)
args
=
parser
.
parse_args
()
if
args
.
cls
:
module
,
cls_name
=
args
.
cls
.
split
(
"/"
)
classes_to_graph
=
[
getattr
(
importlib
.
import_module
(
module
),
cls_name
)]
else
:
# The list of classes from methods.py
classes_to_graph
=
[
Project
,
ASIC
,
FPGA
,
Lint
,
Sim
,
Design
,
PDK
,
Flowgraph
,
Checklist
,
StdCellLibrary
,
FPGADevice
,
Schematic
,
Task
,
ShowTask
,
ScreenshotTask
,
ASICTask
,
ASICTimingConstraintSchema
,
ASICAreaConstraint
,
ASICComponentConstraints
,
ASICPinConstraints
,
FPGAComponentConstraints
,
FPGAPinConstraints
,
FPGATimingConstraintSchema
,
metric
.
MetricSchema
,
record
.
RecordSchema
,
option
.
OptionSchema
,
ToolLibrarySchema
]
generate_class_hierarchy
(
classes_to_graph
,
args
.
output
)
Back
|
FazBrowse Home
|
New Git URL