Skip to content

Commit

Permalink
[HW] Fix ModuleType::getInputType to return InOutType for InOut port (#…
Browse files Browse the repository at this point in the history
…6162)

`ModuleType::getInputTypes` returns inout types for inout ports but `getInputType` doesn't wrap with inout. This is inconsistent and python API `module_type.input_types` returns a wrong type for this.
  • Loading branch information
uenoku authored Sep 21, 2023
1 parent 77630d5 commit 960195f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
9 changes: 5 additions & 4 deletions integration_test/Bindings/Python/dialects/hw.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,17 @@ def build(module):
ports = [
hw.ModulePort(StringAttr.get("out"), i1, hw.ModulePortDirection.OUTPUT),
hw.ModulePort(StringAttr.get("in1"), i2, hw.ModulePortDirection.INPUT),
hw.ModulePort(StringAttr.get("in2"), i32, hw.ModulePortDirection.INPUT)
hw.ModulePort(StringAttr.get("in2"), i32, hw.ModulePortDirection.INPUT),
hw.ModulePort(StringAttr.get("in3"), i32, hw.ModulePortDirection.INOUT)
]
module_type = hw.ModuleType.get(ports)
# CHECK: !hw.modty<output out : i1, input in1 : i2, input in2 : i32>
# CHECK: !hw.modty<output out : i1, input in1 : i2, input in2 : i32, inout in3 : i32>
print(module_type)
# CHECK-NEXT: [IntegerType(i2), IntegerType(i32)]
# CHECK-NEXT: [IntegerType(i2), IntegerType(i32), Type(!hw.inout<i32>)]
print(module_type.input_types)
# CHECK-NEXT: [IntegerType(i1)]
print(module_type.output_types)
# CHECK-NEXT: ['in1', 'in2']
# CHECK-NEXT: ['in1', 'in2', 'in3']
print(module_type.input_names)
# CHECK-NEXT: ['out']
print(module_type.output_names)
5 changes: 4 additions & 1 deletion lib/Dialect/HW/HWTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,10 @@ SmallVector<Type> ModuleType::getPortTypes() {
}

Type ModuleType::getInputType(size_t idx) {
return getPorts()[getPortIdForInputId(idx)].type;
const auto &portInfo = getPorts()[getPortIdForInputId(idx)];
if (portInfo.dir != ModulePort::InOut)
return portInfo.type;
return InOutType::get(portInfo.type);
}

Type ModuleType::getOutputType(size_t idx) {
Expand Down

0 comments on commit 960195f

Please sign in to comment.