Skip to content
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

Fix bugs in InOut logic #384

Merged
merged 3 commits into from
Apr 27, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 19 additions & 12 deletions magma/backend/coreir_.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,15 @@ def to_string(k):
_type = self.context.named_types[("coreir", "arst")]
else:
_type = self.context.Bit()
else:
elif port.isoutput():
if isinstance(port, (ClockType, ClockKind)):
_type = self.context.named_types[("coreir", "clkIn")]
elif isinstance(port, (AsyncResetType, AsyncResetKind)):
_type = self.context.named_types[("coreir", "arstIn")]
else:
_type = self.context.BitIn()
else:
_type = self.context.BitInOut()
return _type

coreirNamedTypeToPortDict = {
Expand Down Expand Up @@ -274,21 +276,23 @@ def compile_definition_to_module_definition(self, definition, module_definition)

for instance in definition.instances:
for name, port in instance.interface.ports.items():
self.connect_input(module_definition, port, non_input_ports)
self.connect_non_outputs(module_definition, port,
non_input_ports)

for port in definition.interface.ports.values():
self.connect_input(module_definition, port,
non_input_ports)
self.connect_non_outputs(module_definition, port, non_input_ports)

def connect_input(self, module_definition, port,
def connect_non_outputs(self, module_definition, port,
non_input_ports):
if not port.isinput():
if isinstance(port, (TupleType, ArrayType)):
for elem in port:
self.connect_input(module_definition, elem,
non_input_ports)
return
self.connect(module_definition, port, port.value(), non_input_ports)
# Recurse into non input types that may contain inout children
if isinstance(port, TupleType) and not port.isinput() or \
isinstance(port, ArrayType) and not port.T.isinput():
for elem in port:
self.connect_non_outputs(module_definition, elem,
non_input_ports)
elif not port.isoutput():
self.connect(module_definition, port, port.value(),
non_input_ports)

def compile_definition(self, definition):
logger.debug(f"Compiling definition {definition}")
Expand Down Expand Up @@ -333,6 +337,9 @@ def is_clock_or_nested_clock(p):
if value is None and is_clock_or_nested_clock(port):
return
elif value is None:
if port.isinout():
# Skip inouts because they might be connected as an input
return
raise Exception(f"Got None for port '{port.debug_name}', is it "
"connected to anything?")
elif isinstance(value, coreir.Wireable):
Expand Down
6 changes: 3 additions & 3 deletions tests/test_verilog/gold/test_pad.v
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module PRWDWUWSWCDGH_V (
input I,
input IE,
input OEN,
output PAD,
inout PAD,
input PD,
input PU,
input RTE,
Expand All @@ -26,7 +26,7 @@ endmodule // PRWDWUWSWCDGH_V

*/
module Top (
output pad
inout pad
);


Expand Down Expand Up @@ -76,7 +76,7 @@ module Top (

assign PRWDWUWSWCDGH_V_inst0__OEN = bit_const_0_None__out;

assign pad = PRWDWUWSWCDGH_V_inst0__PAD;
assign PRWDWUWSWCDGH_V_inst0__PAD = pad;

assign PRWDWUWSWCDGH_V_inst0__PD = bit_const_0_None__out;

Expand Down
4 changes: 2 additions & 2 deletions tests/test_verilog/test_from_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ def test_from_sv():
"test_pe.sv")


def test_from_pad():
def test_from_pad_inout():
file_path = os.path.dirname(__file__)
Pad = m.DeclareFromVerilogFile(os.path.join(file_path, "pad.v"))[0]

class Top(m.Circuit):
IO = ["pad", m.Out(m.Bit)]
IO = ["pad", m.InOut(m.Bit)]
@classmethod
def definition(io):
pad = Pad()
Expand Down