hdl.ir: collect source location for Instance.

This commit is contained in:
Wanda 2024-01-13 13:00:40 +01:00 committed by Catherine
parent 7f76914b74
commit eb1c55859e
4 changed files with 11 additions and 3 deletions

View file

@ -888,8 +888,13 @@ def _convert_fragment(builder, fragment, name_map, hierarchy):
if len(value) > 0 or sub_type == "$mem_v2": if len(value) > 0 or sub_type == "$mem_v2":
sub_ports[port] = rhs_compiler(value) sub_ports[port] = rhs_compiler(value)
if isinstance(subfragment, ir.Instance):
src = _src(subfragment.src_loc)
else:
src = ""
module.cell(sub_type, name=sub_name, ports=sub_ports, params=sub_params, module.cell(sub_type, name=sub_name, ports=sub_ports, params=sub_params,
attrs=subfragment.attrs) attrs=subfragment.attrs, src=src)
# If we emit all of our combinatorial logic into a single RTLIL process, Verilog # If we emit all of our combinatorial logic into a single RTLIL process, Verilog
# simulators will break horribly, because Yosys write_verilog transforms RTLIL processes # simulators will break horribly, because Yosys write_verilog transforms RTLIL processes

View file

@ -3,6 +3,7 @@ from collections import defaultdict, OrderedDict
from functools import reduce from functools import reduce
import warnings import warnings
from .. import tracer
from .._utils import * from .._utils import *
from .._unused import * from .._unused import *
from .ast import * from .ast import *
@ -617,12 +618,13 @@ class Fragment:
class Instance(Fragment): class Instance(Fragment):
def __init__(self, type, *args, **kwargs): def __init__(self, type, *args, src_loc=None, src_loc_at=0, **kwargs):
super().__init__() super().__init__()
self.type = type self.type = type
self.parameters = OrderedDict() self.parameters = OrderedDict()
self.named_ports = OrderedDict() self.named_ports = OrderedDict()
self.src_loc = src_loc or tracer.get_src_loc(src_loc_at)
for (kind, name, value) in args: for (kind, name, value) in args:
if kind == "a": if kind == "a":

View file

@ -166,6 +166,7 @@ class Memory(Elaboratable):
i_WR_EN=Cat(Cat(en_bit.replicate(port.granularity) for en_bit in port.en) for port in self._write_ports), i_WR_EN=Cat(Cat(en_bit.replicate(port.granularity) for en_bit in port.en) for port in self._write_ports),
i_WR_ADDR=Cat(port.addr for port in self._write_ports), i_WR_ADDR=Cat(port.addr for port in self._write_ports),
i_WR_DATA=Cat(port.data for port in self._write_ports), i_WR_DATA=Cat(port.data for port in self._write_ports),
src_loc=self.src_loc,
) )
for port in self._read_ports: for port in self._read_ports:
port._MustUse__used = True port._MustUse__used = True

View file

@ -263,7 +263,7 @@ class FragmentTransformer:
def on_fragment(self, fragment): def on_fragment(self, fragment):
if isinstance(fragment, Instance): if isinstance(fragment, Instance):
new_fragment = Instance(fragment.type) new_fragment = Instance(fragment.type, src_loc=fragment.src_loc)
new_fragment.parameters = OrderedDict(fragment.parameters) new_fragment.parameters = OrderedDict(fragment.parameters)
self.map_named_ports(fragment, new_fragment) self.map_named_ports(fragment, new_fragment)
else: else: