Skip to content

[HW][CAPI] Add a function for getting port info from module #8491

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

Merged
merged 1 commit into from
May 31, 2025
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
5 changes: 5 additions & 0 deletions include/circt-c/Dialect/HW.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ MLIR_CAPI_EXPORTED MlirType hwModuleTypeGetOutputType(MlirType type,
/// Get an HW module type's output name at a specific index.
MLIR_CAPI_EXPORTED MlirStringRef hwModuleTypeGetOutputName(MlirType type,
intptr_t index);

/// Get an HW module type's port info at a specific index.
MLIR_CAPI_EXPORTED void hwModuleTypeGetPort(MlirType type, intptr_t index,
HWModulePort *ret);

/// Creates an HW struct type in the context associated with the elements.
MLIR_CAPI_EXPORTED MlirType hwStructTypeGet(MlirContext ctx,
intptr_t numElements,
Expand Down
23 changes: 23 additions & 0 deletions lib/CAPI/Dialect/HW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,29 @@ MlirStringRef hwModuleTypeGetOutputName(MlirType type, intptr_t index) {
return wrap(cast<ModuleType>(unwrap(type)).getOutputName(index));
}

void hwModuleTypeGetPort(MlirType type, intptr_t index, HWModulePort *ret) {
auto port = cast<ModuleType>(unwrap(type)).getPorts()[index];

HWModulePortDirection dir;
switch (port.dir) {
case ModulePort::Direction::Input:
dir = HWModulePortDirection::Input;
break;
case ModulePort::Direction::Output:
dir = HWModulePortDirection::Output;
break;
case ModulePort::Direction::InOut:
dir = HWModulePortDirection::InOut;
break;
default:
llvm_unreachable("unknown ModulePort::Direction");
}

ret->name = wrap(static_cast<Attribute>(port.name));
ret->type = wrap(port.type);
ret->dir = dir;
}

bool hwTypeIsAStructType(MlirType type) {
return isa<StructType>(unwrap(type));
}
Expand Down