[OM] Add ListType C API and Python bindings. (#7490)

We want to expose this type through the Python bindings for isinstance
queries, etc., so add the necessary boilerplate.
This commit is contained in:
Mike Urbach 2024-08-09 13:53:25 -06:00 committed by GitHub
parent 61d2719269
commit 36a3a424fc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 30 additions and 1 deletions

View File

@ -52,6 +52,15 @@ MLIR_CAPI_EXPORTED bool omTypeIsAFrozenPathType(MlirType type);
/// Get the TypeID for a FrozenPathType.
MLIR_CAPI_EXPORTED MlirTypeID omFrozenPathTypeGetTypeID(void);
/// Is the Type a ListType.
MLIR_CAPI_EXPORTED bool omTypeIsAListType(MlirType type);
/// Get the TypeID for a ListType.
MLIR_CAPI_EXPORTED MlirTypeID omListTypeGetTypeID(void);
// Return a element type of a ListType.
MLIR_CAPI_EXPORTED MlirType omListTypeGetElementType(MlirType type);
/// Is the Type a MapType.
MLIR_CAPI_EXPORTED bool omTypeIsAMapType(MlirType type);

View File

@ -311,3 +311,8 @@ with Context() as ctx:
# Test AnyType
any_type = Type.parse("!om.any")
assert isinstance(any_type, om.AnyType)
# Test ListType
list_type = Type.parse("!om.list<!om.any>")
assert isinstance(list_type, om.ListType)
assert isinstance(list_type.element_type, om.AnyType)

View File

@ -626,6 +626,10 @@ void circt::python::populateDialectOMSubmodule(py::module &m) {
mlir_type_subclass(m, "BasePathType", omTypeIsAFrozenBasePathType,
omFrozenBasePathTypeGetTypeID);
// Add the ListType class definition.
mlir_type_subclass(m, "ListType", omTypeIsAListType, omListTypeGetTypeID)
.def_property_readonly("element_type", omListTypeGetElementType);
// Add the PathType class definition.
mlir_type_subclass(m, "PathType", omTypeIsAFrozenPathType,
omFrozenPathTypeGetTypeID);

View File

@ -5,7 +5,7 @@
from __future__ import annotations
from ._om_ops_gen import *
from .._mlir_libs._circt._om import AnyType, Evaluator as BaseEvaluator, Object as BaseObject, List as BaseList, Tuple as BaseTuple, Map as BaseMap, BasePath as BaseBasePath, BasePathType, Path, PathType, ClassType, ReferenceAttr, ListAttr, MapAttr, OMIntegerAttr
from .._mlir_libs._circt._om import AnyType, Evaluator as BaseEvaluator, Object as BaseObject, List as BaseList, Tuple as BaseTuple, Map as BaseMap, BasePath as BaseBasePath, BasePathType, Path, PathType, ClassType, ReferenceAttr, ListAttr, ListType, MapAttr, OMIntegerAttr
from ..ir import Attribute, Diagnostic, DiagnosticSeverity, Module, StringAttr, IntegerAttr, IntegerType
from ..support import attribute_to_var, var_to_attribute

View File

@ -66,6 +66,17 @@ MlirTypeID omFrozenPathTypeGetTypeID(void) {
return wrap(FrozenPathType::getTypeID());
}
/// Is the Type a ListType.
bool omTypeIsAListType(MlirType type) { return isa<ListType>(unwrap(type)); }
/// Get the TypeID for a ListType.
MlirTypeID omListTypeGetTypeID(void) { return wrap(ListType::getTypeID()); }
// Return a element type of a ListType.
MlirType omListTypeGetElementType(MlirType type) {
return wrap(cast<ListType>(unwrap(type)).getElementType());
}
/// Is the Type a StringType.
bool omTypeIsAStringType(MlirType type) {
return isa<StringType>(unwrap(type));