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 ListType C API and Python bindings. #7490

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
9 changes: 9 additions & 0 deletions include/circt-c/Dialect/OM.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
5 changes: 5 additions & 0 deletions integration_test/Bindings/Python/dialects/om.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,3 +311,8 @@
# 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)
4 changes: 4 additions & 0 deletions lib/Bindings/Python/OMModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
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 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
Expand Down
11 changes: 11 additions & 0 deletions lib/CAPI/Dialect/OM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Loading