|
|
|
@ -123,6 +123,9 @@ class VerilogTransformer(Transformer):
@@ -123,6 +123,9 @@ class VerilogTransformer(Transformer):
|
|
|
|
|
assignments = [] |
|
|
|
|
for stmt in args[2:]: # pass 1: instantiate cells and driven signals |
|
|
|
|
if isinstance(stmt, Instantiation): |
|
|
|
|
if stmt.type not in self.tlib.cells: |
|
|
|
|
log.warn(f'Ignoring cell of unknown kind "{stmt.type}"') |
|
|
|
|
continue |
|
|
|
|
n = Node(c, stmt.name, kind=stmt.type) |
|
|
|
|
for p, s in stmt.pins.items(): |
|
|
|
|
if self.tlib.pin_is_output(n.kind, p): |
|
|
|
@ -141,35 +144,41 @@ class VerilogTransformer(Transformer):
@@ -141,35 +144,41 @@ class VerilogTransformer(Transformer):
|
|
|
|
|
c.io_nodes[positions[name]] = n |
|
|
|
|
if sd.kind == 'input': |
|
|
|
|
Line(c, n, Node(c, name)) |
|
|
|
|
for target, source in assignments: # pass 1.5: process signal assignments |
|
|
|
|
target_sigs = [] |
|
|
|
|
if not isinstance(target, list): target = [target] |
|
|
|
|
for s in target: |
|
|
|
|
if s in sig_decls: |
|
|
|
|
target_sigs += sig_decls[s].names |
|
|
|
|
else: |
|
|
|
|
target_sigs.append(s) |
|
|
|
|
source_sigs = [] |
|
|
|
|
if not isinstance(source, list): source = [source] |
|
|
|
|
for s in source: |
|
|
|
|
if s in sig_decls: |
|
|
|
|
source_sigs += sig_decls[s].names |
|
|
|
|
else: |
|
|
|
|
source_sigs.append(s) |
|
|
|
|
for t, s in zip(target_sigs, source_sigs): |
|
|
|
|
if t in c.forks: |
|
|
|
|
assert s not in c.forks, 'assignment between two driven signals' |
|
|
|
|
Line(c, c.forks[t], Node(c, s)) |
|
|
|
|
elif s in c.forks: |
|
|
|
|
assert t not in c.forks, 'assignment between two driven signals' |
|
|
|
|
Line(c, c.forks[s], Node(c, t)) |
|
|
|
|
elif s.startswith("1'b"): |
|
|
|
|
cnode = Node(c, f'__const{s[3]}_{const_count}__', f'__const{s[3]}__') |
|
|
|
|
const_count += 1 |
|
|
|
|
Line(c, cnode, Node(c, t)) |
|
|
|
|
while len(assignments) > 0: |
|
|
|
|
more_assignments = [] |
|
|
|
|
for target, source in assignments: # pass 1.5: process signal assignments |
|
|
|
|
target_sigs = [] |
|
|
|
|
if not isinstance(target, list): target = [target] |
|
|
|
|
for s in target: |
|
|
|
|
if s in sig_decls: |
|
|
|
|
target_sigs += sig_decls[s].names |
|
|
|
|
else: |
|
|
|
|
target_sigs.append(s) |
|
|
|
|
source_sigs = [] |
|
|
|
|
if not isinstance(source, list): source = [source] |
|
|
|
|
for s in source: |
|
|
|
|
if s in sig_decls: |
|
|
|
|
source_sigs += sig_decls[s].names |
|
|
|
|
else: |
|
|
|
|
source_sigs.append(s) |
|
|
|
|
for t, s in zip(target_sigs, source_sigs): |
|
|
|
|
if t in c.forks: |
|
|
|
|
assert s not in c.forks, 'assignment between two driven signals' |
|
|
|
|
Line(c, c.forks[t], Node(c, s)) |
|
|
|
|
elif s in c.forks: |
|
|
|
|
assert t not in c.forks, 'assignment between two driven signals' |
|
|
|
|
Line(c, c.forks[s], Node(c, t)) |
|
|
|
|
elif s.startswith("1'b"): |
|
|
|
|
cnode = Node(c, f'__const{s[3]}_{const_count}__', f'__const{s[3]}__') |
|
|
|
|
const_count += 1 |
|
|
|
|
Line(c, cnode, Node(c, t)) |
|
|
|
|
else: |
|
|
|
|
more_assignments.append((target, source)) |
|
|
|
|
assignments = more_assignments |
|
|
|
|
for stmt in args[2:]: # pass 2: connect signals to readers |
|
|
|
|
if isinstance(stmt, Instantiation): |
|
|
|
|
for p, s in stmt.pins.items(): |
|
|
|
|
if stmt.name not in c.cells: continue |
|
|
|
|
n = c.cells[stmt.name] |
|
|
|
|
if self.tlib.pin_is_output(n.kind, p): continue |
|
|
|
|
if s.startswith("1'b"): |
|
|
|
|