mirror of https://github.com/llvm/circt.git
[OM] Add AnyType C API and Python bindings. (#7488)
We want to expose this type through the Python bindings for isinstance queries, etc., so add the necessary boilerplate.
This commit is contained in:
parent
a6028eea60
commit
61d2719269
|
@ -25,6 +25,12 @@ MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(OM, om);
|
||||||
// Type API.
|
// Type API.
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
/// Is the Type an AnyType.
|
||||||
|
MLIR_CAPI_EXPORTED bool omTypeIsAAnyType(MlirType type);
|
||||||
|
|
||||||
|
/// Get the TypeID for an AnyType.
|
||||||
|
MLIR_CAPI_EXPORTED MlirTypeID omAnyTypeGetTypeID(void);
|
||||||
|
|
||||||
/// Is the Type a ClassType.
|
/// Is the Type a ClassType.
|
||||||
MLIR_CAPI_EXPORTED bool omTypeIsAClassType(MlirType type);
|
MLIR_CAPI_EXPORTED bool omTypeIsAClassType(MlirType type);
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
import circt
|
import circt
|
||||||
from circt.dialects import om
|
from circt.dialects import om
|
||||||
from circt.ir import Context, InsertionPoint, Location, Module, IntegerAttr, IntegerType
|
from circt.ir import Context, InsertionPoint, Location, Module, IntegerAttr, IntegerType, Type
|
||||||
from circt.support import var_to_attribute
|
from circt.support import var_to_attribute
|
||||||
|
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
@ -307,3 +307,7 @@ with Context() as ctx:
|
||||||
IntegerAttr.get(IntegerType.get_unsigned(64), -42))
|
IntegerAttr.get(IntegerType.get_unsigned(64), -42))
|
||||||
# CHECK: 18446744073709551574
|
# CHECK: 18446744073709551574
|
||||||
print(str(int_attr6))
|
print(str(int_attr6))
|
||||||
|
|
||||||
|
# Test AnyType
|
||||||
|
any_type = Type.parse("!om.any")
|
||||||
|
assert isinstance(any_type, om.AnyType)
|
||||||
|
|
|
@ -612,6 +612,9 @@ void circt::python::populateDialectOMSubmodule(py::module &m) {
|
||||||
.def("__len__", &omMapAttrGetNumElements);
|
.def("__len__", &omMapAttrGetNumElements);
|
||||||
PyMapAttrIterator::bind(m);
|
PyMapAttrIterator::bind(m);
|
||||||
|
|
||||||
|
// Add the AnyType class definition.
|
||||||
|
mlir_type_subclass(m, "AnyType", omTypeIsAAnyType, omAnyTypeGetTypeID);
|
||||||
|
|
||||||
// Add the ClassType class definition.
|
// Add the ClassType class definition.
|
||||||
mlir_type_subclass(m, "ClassType", omTypeIsAClassType, omClassTypeGetTypeID)
|
mlir_type_subclass(m, "ClassType", omTypeIsAClassType, omClassTypeGetTypeID)
|
||||||
.def_property_readonly("name", [](MlirType type) {
|
.def_property_readonly("name", [](MlirType type) {
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from ._om_ops_gen import *
|
from ._om_ops_gen import *
|
||||||
from .._mlir_libs._circt._om import 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, MapAttr, OMIntegerAttr
|
||||||
|
|
||||||
from ..ir import Attribute, Diagnostic, DiagnosticSeverity, Module, StringAttr, IntegerAttr, IntegerType
|
from ..ir import Attribute, Diagnostic, DiagnosticSeverity, Module, StringAttr, IntegerAttr, IntegerType
|
||||||
from ..support import attribute_to_var, var_to_attribute
|
from ..support import attribute_to_var, var_to_attribute
|
||||||
|
|
|
@ -29,6 +29,12 @@ MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(OM, om, OMDialect)
|
||||||
// Type API.
|
// Type API.
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
/// Is the Type an AnyType.
|
||||||
|
bool omTypeIsAAnyType(MlirType type) { return isa<AnyType>(unwrap(type)); }
|
||||||
|
|
||||||
|
/// Get the TypeID for an AnyType.
|
||||||
|
MlirTypeID omAnyTypeGetTypeID(void) { return wrap(AnyType::getTypeID()); }
|
||||||
|
|
||||||
/// Is the Type a ClassType.
|
/// Is the Type a ClassType.
|
||||||
bool omTypeIsAClassType(MlirType type) { return isa<ClassType>(unwrap(type)); }
|
bool omTypeIsAClassType(MlirType type) { return isa<ClassType>(unwrap(type)); }
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue