Skip to content

Commit

Permalink
hdl.mem: add synthesis attribute support.
Browse files Browse the repository at this point in the history
Fixes #291.
  • Loading branch information
whitequark committed Feb 6, 2020
1 parent f7abe36 commit 31cd72c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion nmigen/back/rtlil.py
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ def _convert_fragment(builder, fragment, name_map, hierarchy):
memory = param_value
if memory not in memories:
memories[memory] = module.memory(width=memory.width, size=memory.depth,
name=memory.name)
name=memory.name, attrs=memory.attrs)
addr_bits = bits_for(memory.depth)
data_parts = []
data_mask = (1 << memory.width) - 1
Expand Down
7 changes: 6 additions & 1 deletion nmigen/hdl/mem.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import operator
from collections import OrderedDict

from .. import tracer
from .ast import *
Expand All @@ -24,14 +25,17 @@ class Memory:
name : str
Name hint for this memory. If ``None`` (default) the name is inferred from the variable
name this ``Signal`` is assigned to.
attrs : dict
Dictionary of synthesis attributes.
Attributes
----------
width : int
depth : int
init : list of int
attrs : dict
"""
def __init__(self, *, width, depth, init=None, name=None, simulate=True):
def __init__(self, *, width, depth, init=None, name=None, attrs=None, simulate=True):
if not isinstance(width, int) or width < 0:
raise TypeError("Memory width must be a non-negative integer, not {!r}"
.format(width))
Expand All @@ -44,6 +48,7 @@ def __init__(self, *, width, depth, init=None, name=None, simulate=True):

self.width = width
self.depth = depth
self.attrs = OrderedDict(() if attrs is None else attrs)

# Array of signals for simulation.
self._array = Array()
Expand Down
6 changes: 6 additions & 0 deletions nmigen/test/test_hdl_mem.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ def test_init_wrong_type(self):
"'str' object cannot be interpreted as an integer"):
m = Memory(width=8, depth=4, init=[1, "0"])

def test_attrs(self):
m1 = Memory(width=8, depth=4)
self.assertEqual(m1.attrs, {})
m2 = Memory(width=8, depth=4, attrs={"ram_block": True})
self.assertEqual(m2.attrs, {"ram_block": True})

def test_read_port_transparent(self):
mem = Memory(width=8, depth=4)
rdport = mem.read_port()
Expand Down

0 comments on commit 31cd72c

Please sign in to comment.