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

This commit is contained in:
Asuna 2025-05-31 16:34:43 +08:00 committed by GitHub
parent c4c4964cbd
commit 31aeba1846
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 28 additions and 0 deletions

View File

@ -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,

View File

@ -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));
}