Skip to content

fixing verilog placeholder pass #277

New issue

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

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

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: pymtl4.0-dev
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions pymtl3/datatypes/PythonBits.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ def __getitem__( self, idx ):
raise IndexError( "Index cannot contain step" )
try:
start, stop = int(idx.start or 0), int(idx.stop or self._nbits)
if start is None: start = 0
if stop is None: stop = self._nbits
assert 0 <= start < stop <= self._nbits
except:
raise IndexError( f"Invalid access: [{idx.start}:{idx.stop}] in a Bits{self._nbits} instance" )
Expand Down
6 changes: 6 additions & 0 deletions pymtl3/datatypes/test/bits_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,12 @@ def test_slice_bits():
with pytest.raises( IndexError ):
assert data[x:x] == 0b1

def test_slice_bits_int():
data = Bits(8, 0b1101)
assert data[:2] == 0b01
assert data[2:] == 0b11


def test_clone():
a = Bits(4,3)
b = a.clone()
Expand Down
6 changes: 2 additions & 4 deletions pymtl3/dsl/AstHelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ def _get_full_name_up_to_py38( self, input_node ):
if x in self.globals: up = (False, x)
elif x in self.closure: up = (True, x)

if low is not None and up is not None:
slices.append( slice(low, up) )
slices.append( slice(low, up) )
# FIXME
# else:

Expand Down Expand Up @@ -160,8 +159,7 @@ def _get_full_name_starting_py39( self, input_node ):
if x in self.globals: up = (False, x)
elif x in self.closure: up = (True, x)

if low is not None and up is not None:
slices.append( slice(low, up) )
slices.append( slice(low, up) )
# FIXME
# else:

Expand Down
2 changes: 2 additions & 0 deletions pymtl3/dsl/Connectable.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@ def __getitem__( s, idx ):
start, stop = idx, idx + 1
elif isinstance( idx, slice ):
start, stop = idx.start, idx.stop
if start is None: start = 0
if stop is None: stop = s._dsl.Type.nbits
else: assert False, f"The slice {idx} is invalid"

if s._dsl.slice is None:
Expand Down
21 changes: 18 additions & 3 deletions pymtl3/dsl/test/Slicing_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,7 @@ def up_wr_30_31():
def up_rd_A():
print(s.A[0:17])

m = Top()
m.elaborate()
simple_sim_pass( m, 0x123 )
_test_model( Top )

# assert len(m._all_constraints) == 2
# _, x = list(m._all_constraints)[0]
Expand Down Expand Up @@ -165,6 +163,23 @@ def up_rd_A():
return
raise Exception("Should've thrown MultiWriterError.")

# test slicing without specified width
def test_write_two_slices_and_bit_without_specifying_width():

class Top( ComponentLevel3 ):
def construct( s ):
s.A = Wire( Bits32 )

@update
def up_wr_0_16():
s.A[:16] @= 0xff

@update
def up_wr_16_32():
s.A[16:] @= 0xff

_test_model(Top)

# write a slice and there are two reader
def test_multiple_readers():

Expand Down
11 changes: 11 additions & 0 deletions pymtl3/passes/backends/verilog/VerilogPlaceholderConfigs.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ class VerilogPlaceholderConfigs( PlaceholderConfigs ):

# The separator used for name mangling
"separator" : '__',

# The name of the clock signal
"clk_name" : "clk",

# The name of the reset signal
"reset_name" : "rst",
}

VerilogCheckers = {
Expand All @@ -65,6 +71,11 @@ class VerilogPlaceholderConfigs( PlaceholderConfigs ):

"v_include": Checker( lambda v: isinstance(v, list) and all(os.path.isdir(expand(p)) for p in v),
"expects a list of paths to directory"),

"has_clk": Checker( lambda v: isinstance(v, bool), "expects a bool" ),
"has_reset": Checker( lambda v: isinstance(v, bool), "expects a bool" ),
"clk_name": Checker( lambda v: isinstance(v, str) and v, "expects a non-empty string" ),
"reset_name": Checker( lambda v: isinstance(v, str) and v, "expects a non-empty string" ),
}

Pass = VerilogPlaceholderPass
Expand Down
23 changes: 21 additions & 2 deletions pymtl3/passes/backends/verilog/VerilogPlaceholderPass.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,18 @@ class VerilogPlaceholderPass( PlaceholderPass ):
#: Default value: ``'_'``
separator = MetadataKey(str)

#: has clk
has_clk = MetadataKey(bool)

#: has reset
has_reset = MetadataKey(bool)

#: clk name
clk_name = MetadataKey(str)

#: reset name
reset_name = MetadataKey(str)

@staticmethod
def get_placeholder_config():
from pymtl3.passes.backends.verilog.VerilogPlaceholderConfigs import (
Expand Down Expand Up @@ -338,10 +350,17 @@ def _gen_verilog_wrapper( s, m, cfg, irepr ):
]

# Connections between top module and inner module
connect_ports = [
connect_ports = []
if s.has_clk:
connect_ports.append(f" .{cfg.clk_name}( clk )," )

if s.has_reset:
connect_ports.append(f" .{cfg.reset_name}( reset )," )
connect_ports.extend([
f" .{name}( {name} ){'' if idx == len(rtlir_ports)-1 else ','}"\
for idx, (_, name, p, _) in enumerate(rtlir_ports) if name
]
])


lines = [
f"module {cfg.pickled_top_module}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ def create_cc_cmd( s ):
if not s.is_default("c_flags"):
c_flags += f" {expand(s.c_flags)}"

c_flags += f" -fPIC -shared -std=c++11 -pthread"
c_flags += f" -fPIC -shared -std=c++14 -pthread"

c_include_path = " ".join("-I"+p for p in s._get_all_includes() if p)
out_file = s.get_shared_lib_path()
Expand Down