-
Notifications
You must be signed in to change notification settings - Fork 281
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] Get the field names from an Object #5402
Changes from all commits
e733868
325bcd1
fdc1887
155abcb
f4e877d
82834c8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
#include "mlir-c/BuiltinAttributes.h" | ||
#include "mlir-c/IR.h" | ||
#include "mlir/Bindings/Python/PybindAdaptors.h" | ||
#include "mlir/CAPI/IR.h" | ||
#include <pybind11/pybind11.h> | ||
#include <pybind11/stl.h> | ||
namespace py = pybind11; | ||
|
@@ -55,6 +56,18 @@ struct Object { | |
return omEvaluatorObjectValueGetPrimitive(result); | ||
} | ||
|
||
// Get a list with the names of all the fields in the Object. | ||
std::vector<std::string> getFieldNames() { | ||
ArrayAttr fieldNames = | ||
cast<ArrayAttr>(unwrap(omEvaluatorObjectGetFieldNames(object))); | ||
|
||
std::vector<std::string> slots; | ||
for (auto fieldName : fieldNames.getAsRange<StringAttr>()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh sorry, didn't realize that, will create a new PR to fix it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @prithayan no worries, it was my bad, and fixed in 80531eb |
||
slots.push_back(fieldName.str()); | ||
|
||
return slots; | ||
} | ||
|
||
private: | ||
// The underlying CAPI OMObject. | ||
OMObject object; | ||
|
@@ -108,6 +121,8 @@ void circt::python::populateDialectOMSubmodule(py::module &m) { | |
.def(py::init<Object>(), py::arg("object")) | ||
.def("__getattr__", &Object::getField, "Get a field from an Object", | ||
py::arg("name")) | ||
.def_property_readonly("field_names", &Object::getFieldNames, | ||
"Get field names from an Object") | ||
.def_property_readonly("type", &Object::getType, | ||
"The Type of the Object"); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You cannot use
ArrayAttr
in pybind11 code. You must use the CAPI for interacting with MLIR objects/classes... 'cause linking issues.