Skip to content
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

[OM] Add AnyType C API and Python bindings. #7488

Merged
merged 1 commit into from
Aug 9, 2024
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
6 changes: 6 additions & 0 deletions include/circt-c/Dialect/OM.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(OM, om);
// 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.
MLIR_CAPI_EXPORTED bool omTypeIsAClassType(MlirType type);

Expand Down
6 changes: 5 additions & 1 deletion integration_test/Bindings/Python/dialects/om.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import circt
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 dataclasses import dataclass
Expand Down Expand Up @@ -307,3 +307,7 @@
IntegerAttr.get(IntegerType.get_unsigned(64), -42))
# CHECK: 18446744073709551574
print(str(int_attr6))

# Test AnyType
any_type = Type.parse("!om.any")
assert isinstance(any_type, om.AnyType)
3 changes: 3 additions & 0 deletions lib/Bindings/Python/OMModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,9 @@ void circt::python::populateDialectOMSubmodule(py::module &m) {
.def("__len__", &omMapAttrGetNumElements);
PyMapAttrIterator::bind(m);

// Add the AnyType class definition.
mlir_type_subclass(m, "AnyType", omTypeIsAAnyType, omAnyTypeGetTypeID);

// Add the ClassType class definition.
mlir_type_subclass(m, "ClassType", omTypeIsAClassType, omClassTypeGetTypeID)
.def_property_readonly("name", [](MlirType type) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Bindings/Python/dialects/om.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from __future__ import annotations

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 ..support import attribute_to_var, var_to_attribute
Expand Down
6 changes: 6 additions & 0 deletions lib/CAPI/Dialect/OM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(OM, om, OMDialect)
// 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.
bool omTypeIsAClassType(MlirType type) { return isa<ClassType>(unwrap(type)); }

Expand Down
Loading