Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

hdl.ir: collect source location for Instance. #1032

Merged
merged 1 commit into from
Jan 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion amaranth/back/rtlil.py
Original file line number Diff line number Diff line change
Expand Up @@ -888,8 +888,13 @@ def _convert_fragment(builder, fragment, name_map, hierarchy):
if len(value) > 0 or sub_type == "$mem_v2":
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,
attrs=subfragment.attrs)
attrs=subfragment.attrs, src=src)

# 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
Expand Down
4 changes: 3 additions & 1 deletion amaranth/hdl/ir.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from functools import reduce
import warnings

from .. import tracer
from .._utils import *
from .._unused import *
from .ast import *
Expand Down Expand Up @@ -617,12 +618,13 @@ def _assign_names_to_fragments(self, hierarchy=("top",), *, _names=None):


class Instance(Fragment):
def __init__(self, type, *args, **kwargs):
def __init__(self, type, *args, src_loc=None, src_loc_at=0, **kwargs):
super().__init__()

self.type = type
self.parameters = OrderedDict()
self.named_ports = OrderedDict()
self.src_loc = src_loc or tracer.get_src_loc(src_loc_at)

for (kind, name, value) in args:
if kind == "a":
Expand Down
1 change: 1 addition & 0 deletions amaranth/hdl/mem.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ def elaborate(self, platform):
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_DATA=Cat(port.data for port in self._write_ports),
src_loc=self.src_loc,
)
for port in self._read_ports:
port._MustUse__used = True
Expand Down
2 changes: 1 addition & 1 deletion amaranth/hdl/xfrm.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def map_drivers(self, fragment, new_fragment):

def on_fragment(self, fragment):
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)
self.map_named_ports(fragment, new_fragment)
else:
Expand Down