forked from litaotju/netlistx
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnetlist_rules.py
More file actions
74 lines (66 loc) · 2.34 KB
/
netlist_rules.py
File metadata and controls
74 lines (66 loc) · 2.34 KB
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
# -*- coding:utf-8 -*-
from netlistx.exception import *
from netlistx.netlist import Netlist
def check(nt, check_clk = True, check_reset = True):
'''
'''
check_ports = ['C','R','S','CLR','PRE']
specials = _get_fd_specport( nt, check_ports)
clks = specials['C']
sync_resets = specials['R'].keys() + specials['S'].keys()
async_resets = specials['CLR'].keys() + specials['PRE'].keys()
if check_clk:
_clk_check(nt, clks)
if check_reset:
_reset_check( nt, sync_resets + async_resets)
def _get_fd_specport(nt, port_names ):
'''@param: nt, a Netlist obj
@return: specs, a dict, {port_name:{signal_id : [fd list]} }
'''
assert isinstance(nt, Netlist)
fds = [prim for prim in nt.primitives if prim.m_type == 'FD']
specs = {name:{} for name in port_names }
for fd in fds:
for port in fd.port_list:
name = port.port_name
if name in port_names:
signal_id = port.port_assign.string
if not specs[name].has_key( signal_id ):
specs[name][ signal_id ] = [fd]
else:
specs[name][ signal_id ].append( fd )
return specs
def _clk_check(nt, clks):
if len(clks) > 1:
errmsg = "Netlist has %s CLK domain.They are: %s" % ( len(clks), clks.keys() )
raise CrgraphError, errmsg
elif len(clks) == 0:
print "Info: no clks in this netlist"
return None
clkname = clks.keys()[0]
clkflag = False
single_inports = []
for port in nt.ports:
if port.port_type == "input":
single_inports += port.split()
for port in single_inports:
if port.port_assign.string == clkname:
clkflag = True
break
else: continue
if not clkflag:
errmsg = "CLK: %s do not connected to any pi" % clkname
raise CrgraphError, errmsg
def _reset_check(nt, resets):
single_inports = []
for port in nt.ports:
if port.port_type == "input":
single_inports += port.split()
strings = [port.port_assign.string for port in single_inports]
internal_resets = []
for reset in resets:
if reset not in strings:
internal_resets.append( reset)
if internal_resets:
errmsg = "Internal Resets: %s" % internal_resets
raise CrgraphError, errmsg