CIRCT  19.0.0git
OMModule.cpp
Go to the documentation of this file.
1 //===- OMModule.cpp - OM API pybind module --------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "DialectModules.h"
10 #include "circt-c/Dialect/OM.h"
11 #include "mlir-c/BuiltinAttributes.h"
12 #include "mlir-c/BuiltinTypes.h"
13 #include "mlir-c/IR.h"
14 #include "mlir/Bindings/Python/PybindAdaptors.h"
15 #include <pybind11/pybind11.h>
16 #include <pybind11/stl.h>
17 namespace py = pybind11;
18 
19 using namespace mlir;
20 using namespace mlir::python;
21 using namespace mlir::python::adaptors;
22 
23 namespace {
24 
25 struct List;
26 struct Object;
27 struct Tuple;
28 struct Map;
29 struct BasePath;
30 struct Path;
31 
32 /// None is used to by pybind when default initializing a PythonValue. The order
33 /// of types in the variant matters here, and we want pybind to try casting to
34 /// the Python classes defined in this file first, before MlirAttribute and the
35 /// upstream MLIR type casters. If the MlirAttribute is tried first, then we
36 /// can hit an assert inside the MLIR codebase.
37 struct None {};
38 using PythonValue =
39  std::variant<None, Object, List, Tuple, Map, BasePath, Path, MlirAttribute>;
40 
41 /// Map an opaque OMEvaluatorValue into a python value.
42 PythonValue omEvaluatorValueToPythonValue(OMEvaluatorValue result);
43 OMEvaluatorValue pythonValueToOMEvaluatorValue(PythonValue result);
44 
45 /// Provides a List class by simply wrapping the OMObject CAPI.
46 struct List {
47  // Instantiate a List with a reference to the underlying OMEvaluatorValue.
48  List(OMEvaluatorValue value) : value(value) {}
49 
50  /// Return the number of elements.
51  intptr_t getNumElements() { return omEvaluatorListGetNumElements(value); }
52 
53  PythonValue getElement(intptr_t i);
54  OMEvaluatorValue getValue() const { return value; }
55 
56 private:
57  // The underlying CAPI value.
58  OMEvaluatorValue value;
59 };
60 
61 struct Tuple {
62  // Instantiate a Tuple with a reference to the underlying OMEvaluatorValue.
63  Tuple(OMEvaluatorValue value) : value(value) {}
64 
65  /// Return the number of elements.
66  intptr_t getNumElements() { return omEvaluatorTupleGetNumElements(value); }
67 
68  PythonValue getElement(intptr_t i);
69  OMEvaluatorValue getValue() const { return value; }
70 
71 private:
72  // The underlying CAPI value.
73  OMEvaluatorValue value;
74 };
75 
76 /// Provides a Map class by simply wrapping the OMObject CAPI.
77 struct Map {
78  // Instantiate a Map with a reference to the underlying OMEvaluatorValue.
79  Map(OMEvaluatorValue value) : value(value) {}
80 
81  /// Return the keys.
82  std::vector<MlirAttribute> getKeys() {
83  auto attr = omEvaluatorMapGetKeys(value);
84  intptr_t numFieldNames = mlirArrayAttrGetNumElements(attr);
85 
86  std::vector<MlirAttribute> pyFieldNames;
87  for (intptr_t i = 0; i < numFieldNames; ++i)
88  pyFieldNames.emplace_back(mlirArrayAttrGetElement(attr, i));
89 
90  return pyFieldNames;
91  }
92 
93  /// Look up the value. A key is an integer, string or attribute.
94  PythonValue dunderGetItemAttr(MlirAttribute key);
95  PythonValue dunderGetItemNamed(const std::string &key);
96  PythonValue dunderGetItemIndexed(intptr_t key);
97  PythonValue
98  dunderGetItem(std::variant<intptr_t, std::string, MlirAttribute> key);
99 
100  /// Return a context from an underlying value.
101  MlirContext getContext() const { return omEvaluatorValueGetContext(value); }
102 
103  OMEvaluatorValue getValue() const { return value; }
104  MlirType getType() { return omEvaluatorMapGetType(value); }
105 
106 private:
107  // The underlying CAPI value.
108  OMEvaluatorValue value;
109 };
110 
111 /// Provides a BasePath class by simply wrapping the OMObject CAPI.
112 struct BasePath {
113  /// Instantiate a BasePath with a reference to the underlying
114  /// OMEvaluatorValue.
115  BasePath(OMEvaluatorValue value) : value(value) {}
116 
117  static BasePath getEmpty(MlirContext context) {
118  return BasePath(omEvaluatorBasePathGetEmpty(context));
119  }
120 
121  /// Return a context from an underlying value.
122  MlirContext getContext() const { return omEvaluatorValueGetContext(value); }
123 
124  OMEvaluatorValue getValue() const { return value; }
125 
126 private:
127  // The underlying CAPI value.
128  OMEvaluatorValue value;
129 };
130 
131 /// Provides a Path class by simply wrapping the OMObject CAPI.
132 struct Path {
133  /// Instantiate a Path with a reference to the underlying OMEvaluatorValue.
134  Path(OMEvaluatorValue value) : value(value) {}
135 
136  /// Return a context from an underlying value.
137  MlirContext getContext() const { return omEvaluatorValueGetContext(value); }
138 
139  OMEvaluatorValue getValue() const { return value; }
140 
141  std::string dunderStr() {
142  auto ref = mlirStringAttrGetValue(omEvaluatorPathGetAsString(getValue()));
143  return std::string(ref.data, ref.length);
144  }
145 
146 private:
147  // The underlying CAPI value.
148  OMEvaluatorValue value;
149 };
150 
151 /// Provides an Object class by simply wrapping the OMObject CAPI.
152 struct Object {
153  // Instantiate an Object with a reference to the underlying OMObject.
154  Object(OMEvaluatorValue value) : value(value) {}
155 
156  /// Get the Type from an Object, which will be a ClassType.
157  MlirType getType() { return omEvaluatorObjectGetType(value); }
158 
159  /// Get the Location from an Object, which will be an MlirLocation.
160  MlirLocation getLocation() { return omEvaluatorValueGetLoc(value); }
161 
162  // Get the field location info.
163  MlirLocation getFieldLoc(const std::string &name) {
164  // Wrap the requested field name in an attribute.
165  MlirContext context = mlirTypeGetContext(omEvaluatorObjectGetType(value));
166  MlirStringRef cName = mlirStringRefCreateFromCString(name.c_str());
167  MlirAttribute nameAttr = mlirStringAttrGet(context, cName);
168 
169  // Get the field's ObjectValue via the CAPI.
170  OMEvaluatorValue result = omEvaluatorObjectGetField(value, nameAttr);
171 
172  return omEvaluatorValueGetLoc(result);
173  }
174 
175  // Get a field from the Object, using pybind's support for variant to return a
176  // Python object that is either an Object or Attribute.
177  PythonValue getField(const std::string &name) {
178  // Wrap the requested field name in an attribute.
179  MlirContext context = mlirTypeGetContext(omEvaluatorObjectGetType(value));
180  MlirStringRef cName = mlirStringRefCreateFromCString(name.c_str());
181  MlirAttribute nameAttr = mlirStringAttrGet(context, cName);
182 
183  // Get the field's ObjectValue via the CAPI.
184  OMEvaluatorValue result = omEvaluatorObjectGetField(value, nameAttr);
185 
186  return omEvaluatorValueToPythonValue(result);
187  }
188 
189  // Get a list with the names of all the fields in the Object.
190  std::vector<std::string> getFieldNames() {
191  MlirAttribute fieldNames = omEvaluatorObjectGetFieldNames(value);
192  intptr_t numFieldNames = mlirArrayAttrGetNumElements(fieldNames);
193 
194  std::vector<std::string> pyFieldNames;
195  for (intptr_t i = 0; i < numFieldNames; ++i) {
196  MlirAttribute fieldName = mlirArrayAttrGetElement(fieldNames, i);
197  MlirStringRef fieldNameStr = mlirStringAttrGetValue(fieldName);
198  pyFieldNames.emplace_back(fieldNameStr.data, fieldNameStr.length);
199  }
200 
201  return pyFieldNames;
202  }
203 
204  // Get the hash of the object
205  unsigned getHash() { return omEvaluatorObjectGetHash(value); }
206 
207  // Check the equality of the underlying values.
208  bool eq(Object &other) { return omEvaluatorObjectIsEq(value, other.value); }
209 
210  OMEvaluatorValue getValue() const { return value; }
211 
212 private:
213  // The underlying CAPI OMObject.
214  OMEvaluatorValue value;
215 };
216 
217 /// Provides an Evaluator class by simply wrapping the OMEvaluator CAPI.
218 struct Evaluator {
219  // Instantiate an Evaluator with a reference to the underlying OMEvaluator.
220  Evaluator(MlirModule mod) : evaluator(omEvaluatorNew(mod)) {}
221 
222  // Instantiate an Object.
223  Object instantiate(MlirAttribute className,
224  std::vector<PythonValue> actualParams) {
225  std::vector<OMEvaluatorValue> values;
226  for (auto &param : actualParams)
227  values.push_back(pythonValueToOMEvaluatorValue(param));
228 
229  // Instantiate the Object via the CAPI.
231  evaluator, className, values.size(), values.data());
232 
233  // If the Object is null, something failed. Diagnostic handling is
234  // implemented in pure Python, so nothing to do here besides throwing an
235  // error to halt execution.
236  if (omEvaluatorObjectIsNull(result))
237  throw py::value_error(
238  "unable to instantiate object, see previous error(s)");
239 
240  // Return a new Object.
241  return Object(result);
242  }
243 
244  // Get the Module the Evaluator is built from.
245  MlirModule getModule() { return omEvaluatorGetModule(evaluator); }
246 
247 private:
248  // The underlying CAPI OMEvaluator.
249  OMEvaluator evaluator;
250 };
251 
252 class PyListAttrIterator {
253 public:
254  PyListAttrIterator(MlirAttribute attr) : attr(std::move(attr)) {}
255 
256  PyListAttrIterator &dunderIter() { return *this; }
257 
258  MlirAttribute dunderNext() {
259  if (nextIndex >= omListAttrGetNumElements(attr))
260  throw py::stop_iteration();
261  return omListAttrGetElement(attr, nextIndex++);
262  }
263 
264  static void bind(py::module &m) {
265  py::class_<PyListAttrIterator>(m, "ListAttributeIterator",
266  py::module_local())
267  .def("__iter__", &PyListAttrIterator::dunderIter)
268  .def("__next__", &PyListAttrIterator::dunderNext);
269  }
270 
271 private:
272  MlirAttribute attr;
273  intptr_t nextIndex = 0;
274 };
275 
276 PythonValue List::getElement(intptr_t i) {
277  return omEvaluatorValueToPythonValue(omEvaluatorListGetElement(value, i));
278 }
279 
280 class PyMapAttrIterator {
281 public:
282  PyMapAttrIterator(MlirAttribute attr) : attr(std::move(attr)) {}
283 
284  PyMapAttrIterator &dunderIter() { return *this; }
285 
286  py::tuple dunderNext() {
287  if (nextIndex >= omMapAttrGetNumElements(attr))
288  throw py::stop_iteration();
289 
290  MlirIdentifier key = omMapAttrGetElementKey(attr, nextIndex);
291  MlirAttribute value = omMapAttrGetElementValue(attr, nextIndex);
292  nextIndex++;
293 
294  auto keyName = mlirIdentifierStr(key);
295  std::string keyStr(keyName.data, keyName.length);
296  return py::make_tuple(keyStr, value);
297  }
298 
299  static void bind(py::module &m) {
300  py::class_<PyMapAttrIterator>(m, "MapAttributeIterator", py::module_local())
301  .def("__iter__", &PyMapAttrIterator::dunderIter)
302  .def("__next__", &PyMapAttrIterator::dunderNext);
303  }
304 
305 private:
306  MlirAttribute attr;
307  intptr_t nextIndex = 0;
308 };
309 
310 PythonValue Tuple::getElement(intptr_t i) {
311  if (i < 0 || i >= omEvaluatorTupleGetNumElements(value))
312  throw std::out_of_range("tuple index out of range");
313 
314  return omEvaluatorValueToPythonValue(omEvaluatorTupleGetElement(value, i));
315 }
316 
317 PythonValue Map::dunderGetItemNamed(const std::string &key) {
318  MlirType type = omMapTypeGetKeyType(omEvaluatorMapGetType(value));
319  if (!omTypeIsAStringType(type))
320  throw pybind11::key_error("key is not string");
321  MlirAttribute attr =
322  mlirStringAttrTypedGet(type, mlirStringRefCreateFromCString(key.c_str()));
323  return dunderGetItemAttr(attr);
324 }
325 
326 PythonValue Map::dunderGetItemIndexed(intptr_t i) {
327  MlirType type = omMapTypeGetKeyType(omEvaluatorMapGetType(value));
328  if (!mlirTypeIsAInteger(type))
329  throw pybind11::key_error("key is not integer");
330  MlirAttribute attr = mlirIntegerAttrGet(type, i);
331  return dunderGetItemAttr(attr);
332 }
333 
334 PythonValue Map::dunderGetItemAttr(MlirAttribute key) {
335  OMEvaluatorValue result = omEvaluatorMapGetElement(value, key);
336 
337  if (omEvaluatorValueIsNull(result))
338  throw pybind11::key_error("key not found");
339 
340  return omEvaluatorValueToPythonValue(result);
341 }
342 
343 PythonValue
344 Map::dunderGetItem(std::variant<intptr_t, std::string, MlirAttribute> key) {
345  if (auto *i = std::get_if<intptr_t>(&key))
346  return dunderGetItemIndexed(*i);
347  else if (auto *str = std::get_if<std::string>(&key))
348  return dunderGetItemNamed(*str);
349  return dunderGetItemAttr(std::get<MlirAttribute>(key));
350 }
351 
352 PythonValue omEvaluatorValueToPythonValue(OMEvaluatorValue result) {
353  // If the result is null, something failed. Diagnostic handling is
354  // implemented in pure Python, so nothing to do here besides throwing an
355  // error to halt execution.
356  if (omEvaluatorValueIsNull(result))
357  throw py::value_error("unable to get field, see previous error(s)");
358 
359  // If the field was an Object, return a new Object.
360  if (omEvaluatorValueIsAObject(result))
361  return Object(result);
362 
363  // If the field was a list, return a new List.
364  if (omEvaluatorValueIsAList(result))
365  return List(result);
366 
367  // If the field was a tuple, return a new Tuple.
368  if (omEvaluatorValueIsATuple(result))
369  return Tuple(result);
370 
371  // If the field was a map, return a new Map.
372  if (omEvaluatorValueIsAMap(result))
373  return Map(result);
374 
375  // If the field was a base path, return a new BasePath.
376  if (omEvaluatorValueIsABasePath(result))
377  return BasePath(result);
378 
379  // If the field was a path, return a new Path.
380  if (omEvaluatorValueIsAPath(result))
381  return Path(result);
382 
383  if (omEvaluatorValueIsAReference(result))
384  return omEvaluatorValueToPythonValue(
386 
387  // If the field was a primitive, return the Attribute.
389  return omEvaluatorValueGetPrimitive(result);
390 }
391 
392 OMEvaluatorValue pythonValueToOMEvaluatorValue(PythonValue result) {
393  if (auto *attr = std::get_if<MlirAttribute>(&result))
394  return omEvaluatorValueFromPrimitive(*attr);
395 
396  if (auto *list = std::get_if<List>(&result))
397  return list->getValue();
398 
399  if (auto *tuple = std::get_if<Tuple>(&result))
400  return tuple->getValue();
401 
402  if (auto *map = std::get_if<Map>(&result))
403  return map->getValue();
404 
405  if (auto *basePath = std::get_if<BasePath>(&result))
406  return basePath->getValue();
407 
408  if (auto *path = std::get_if<Path>(&result))
409  return path->getValue();
410 
411  return std::get<Object>(result).getValue();
412 }
413 
414 } // namespace
415 
416 /// Populate the OM Python module.
417 void circt::python::populateDialectOMSubmodule(py::module &m) {
418  m.doc() = "OM dialect Python native extension";
419 
420  // Add the Evaluator class definition.
421  py::class_<Evaluator>(m, "Evaluator")
422  .def(py::init<MlirModule>(), py::arg("module"))
423  .def("instantiate", &Evaluator::instantiate, "Instantiate an Object",
424  py::arg("class_name"), py::arg("actual_params"))
425  .def_property_readonly("module", &Evaluator::getModule,
426  "The Module the Evaluator is built from");
427 
428  // Add the List class definition.
429  py::class_<List>(m, "List")
430  .def(py::init<List>(), py::arg("list"))
431  .def("__getitem__", &List::getElement)
432  .def("__len__", &List::getNumElements);
433 
434  py::class_<Tuple>(m, "Tuple")
435  .def(py::init<Tuple>(), py::arg("tuple"))
436  .def("__getitem__", &Tuple::getElement)
437  .def("__len__", &Tuple::getNumElements);
438 
439  // Add the Map class definition.
440  py::class_<Map>(m, "Map")
441  .def(py::init<Map>(), py::arg("map"))
442  .def("__getitem__", &Map::dunderGetItem)
443  .def("keys", &Map::getKeys)
444  .def_property_readonly("type", &Map::getType, "The Type of the Map");
445 
446  // Add the BasePath class definition.
447  py::class_<BasePath>(m, "BasePath")
448  .def(py::init<BasePath>(), py::arg("basepath"))
449  .def_static("get_empty", &BasePath::getEmpty,
450  py::arg("context") = py::none());
451 
452  // Add the Path class definition.
453  py::class_<Path>(m, "Path")
454  .def(py::init<Path>(), py::arg("path"))
455  .def("__str__", &Path::dunderStr);
456 
457  // Add the Object class definition.
458  py::class_<Object>(m, "Object")
459  .def(py::init<Object>(), py::arg("object"))
460  .def("__getattr__", &Object::getField, "Get a field from an Object",
461  py::arg("name"))
462  .def("get_field_loc", &Object::getFieldLoc,
463  "Get the location of a field from an Object", py::arg("name"))
464  .def_property_readonly("field_names", &Object::getFieldNames,
465  "Get field names from an Object")
466  .def_property_readonly("type", &Object::getType, "The Type of the Object")
467  .def_property_readonly("loc", &Object::getLocation,
468  "The Location of the Object")
469  .def("__hash__", &Object::getHash, "Get object hash")
470  .def("__eq__", &Object::eq, "Check if two objects are same");
471 
472  // Add the ReferenceAttr definition
473  mlir_attribute_subclass(m, "ReferenceAttr", omAttrIsAReferenceAttr)
474  .def_property_readonly("inner_ref", [](MlirAttribute self) {
475  return omReferenceAttrGetInnerRef(self);
476  });
477 
478  // Add the IntegerAttr definition
479  mlir_attribute_subclass(m, "OMIntegerAttr", omAttrIsAIntegerAttr)
480  .def_classmethod("get",
481  [](py::object cls, MlirAttribute intVal) {
482  return cls(omIntegerAttrGet(intVal));
483  })
484  .def_property_readonly(
485  "integer",
486  [](MlirAttribute self) { return omIntegerAttrGetInt(self); })
487  .def("__str__", [](MlirAttribute self) {
488  MlirStringRef str = omIntegerAttrToString(self);
489  return std::string(str.data, str.length);
490  });
491 
492  // Add the OMListAttr definition
493  mlir_attribute_subclass(m, "ListAttr", omAttrIsAListAttr)
494  .def("__getitem__", &omListAttrGetElement)
495  .def("__len__", &omListAttrGetNumElements)
496  .def("__iter__",
497  [](MlirAttribute arr) { return PyListAttrIterator(arr); });
498  PyListAttrIterator::bind(m);
499 
500  // Add the MapAttr definition
501  mlir_attribute_subclass(m, "MapAttr", omAttrIsAMapAttr)
502  .def("__iter__", [](MlirAttribute arr) { return PyMapAttrIterator(arr); })
503  .def("__len__", &omMapAttrGetNumElements);
504  PyMapAttrIterator::bind(m);
505 
506  // Add the ClassType class definition.
507  mlir_type_subclass(m, "ClassType", omTypeIsAClassType, omClassTypeGetTypeID)
508  .def_property_readonly("name", [](MlirType type) {
509  MlirStringRef name = mlirIdentifierStr(omClassTypeGetName(type));
510  return std::string(name.data, name.length);
511  });
512 
513  // Add the BasePathType class definition.
514  mlir_type_subclass(m, "BasePathType", omTypeIsAFrozenBasePathType,
516 
517  // Add the PathType class definition.
518  mlir_type_subclass(m, "PathType", omTypeIsAFrozenPathType,
520 }
assert(baseType &&"element must be base type")
MLIR_CAPI_EXPORTED bool omEvaluatorObjectIsEq(OMEvaluatorValue object, OMEvaluatorValue other)
Check equality of two objects.
Definition: OM.cpp:166
MLIR_CAPI_EXPORTED intptr_t omListAttrGetNumElements(MlirAttribute attr)
Definition: OM.cpp:402
MLIR_CAPI_EXPORTED unsigned omEvaluatorObjectGetHash(OMEvaluatorValue object)
Get the object hash.
Definition: OM.cpp:161
MLIR_CAPI_EXPORTED bool omTypeIsAFrozenBasePathType(MlirType type)
Is the Type a FrozenBasePathType.
Definition: OM.cpp:44
MLIR_CAPI_EXPORTED bool omAttrIsAListAttr(MlirAttribute attr)
Definition: OM.cpp:398
MLIR_CAPI_EXPORTED MlirTypeID omFrozenPathTypeGetTypeID(void)
Get the TypeID for a FrozenPathType.
Definition: OM.cpp:59
MLIR_CAPI_EXPORTED bool omEvaluatorValueIsABasePath(OMEvaluatorValue evaluatorValue)
Query if the EvaluatorValue is a BasePath.
Definition: OM.cpp:311
MLIR_CAPI_EXPORTED bool omEvaluatorValueIsNull(OMEvaluatorValue evaluatorValue)
Definition: OM.cpp:217
MLIR_CAPI_EXPORTED MlirAttribute omMapAttrGetElementValue(MlirAttribute attr, intptr_t pos)
Definition: OM.cpp:428
MLIR_CAPI_EXPORTED intptr_t omEvaluatorTupleGetNumElements(OMEvaluatorValue evaluatorValue)
Get the size of the tuple.
Definition: OM.cpp:282
MLIR_CAPI_EXPORTED OMEvaluator omEvaluatorNew(MlirModule mod)
Construct an Evaluator with an IR module.
Definition: OM.cpp:105
MLIR_CAPI_EXPORTED OMEvaluatorValue omEvaluatorValueGetReferenceValue(OMEvaluatorValue evaluatorValue)
Dereference a Reference EvaluatorValue.
Definition: OM.cpp:336
MLIR_CAPI_EXPORTED MlirLocation omEvaluatorValueGetLoc(OMEvaluatorValue evaluatorValue)
Definition: OM.cpp:212
MLIR_CAPI_EXPORTED MlirAttribute omEvaluatorValueGetPrimitive(OMEvaluatorValue evaluatorValue)
Get the Primitive from an EvaluatorValue, which must contain a Primitive.
Definition: OM.cpp:235
MLIR_CAPI_EXPORTED OMEvaluatorValue omEvaluatorBasePathGetEmpty(MlirContext context)
Create an empty BasePath.
Definition: OM.cpp:315
MLIR_CAPI_EXPORTED bool omEvaluatorValueIsAPath(OMEvaluatorValue evaluatorValue)
Query if the EvaluatorValue is a Path.
Definition: OM.cpp:319
MLIR_CAPI_EXPORTED bool omEvaluatorValueIsAMap(OMEvaluatorValue evaluatorValue)
Query if the EvaluatorValue is a Map.
Definition: OM.cpp:307
MLIR_CAPI_EXPORTED MlirTypeID omFrozenBasePathTypeGetTypeID(void)
Get the TypeID for a FrozenBasePathType.
Definition: OM.cpp:49
MLIR_CAPI_EXPORTED MlirModule omEvaluatorGetModule(OMEvaluator evaluator)
Get the Module the Evaluator is built from.
Definition: OM.cpp:140
MLIR_CAPI_EXPORTED MlirType omMapTypeGetKeyType(MlirType type)
Return a key type of a map.
Definition: OM.cpp:74
MLIR_CAPI_EXPORTED OMEvaluatorValue omEvaluatorInstantiate(OMEvaluator evaluator, MlirAttribute className, intptr_t nActualParams, OMEvaluatorValue *actualParams)
Use the Evaluator to Instantiate an Object from its class name and actual parameters.
Definition: OM.cpp:112
MLIR_CAPI_EXPORTED MlirTypeID omClassTypeGetTypeID(void)
Get the TypeID for a ClassType.
Definition: OM.cpp:36
MLIR_CAPI_EXPORTED OMEvaluatorValue omEvaluatorMapGetElement(OMEvaluatorValue evaluatorValue, MlirAttribute attr)
Get an element of the map.
Definition: OM.cpp:296
MLIR_CAPI_EXPORTED intptr_t omEvaluatorListGetNumElements(OMEvaluatorValue evaluatorValue)
Get the length of the list.
Definition: OM.cpp:263
MLIR_CAPI_EXPORTED MlirIdentifier omClassTypeGetName(MlirType type)
Get the name for a ClassType.
Definition: OM.cpp:39
MLIR_CAPI_EXPORTED bool omAttrIsAReferenceAttr(MlirAttribute attr)
Definition: OM.cpp:357
MLIR_CAPI_EXPORTED OMEvaluatorValue omEvaluatorTupleGetElement(OMEvaluatorValue evaluatorValue, intptr_t pos)
Get an element of the tuple.
Definition: OM.cpp:289
MLIR_CAPI_EXPORTED bool omEvaluatorValueIsAList(OMEvaluatorValue evaluatorValue)
Query if the EvaluatorValue is an Object.
Definition: OM.cpp:250
MLIR_CAPI_EXPORTED bool omEvaluatorValueIsATuple(OMEvaluatorValue evaluatorValue)
Query if the EvaluatorValue is a Tuple.
Definition: OM.cpp:277
MLIR_CAPI_EXPORTED MlirType omEvaluatorMapGetType(OMEvaluatorValue evaluatorValue)
Get the Type from a Map, which will be a MapType.
Definition: OM.cpp:176
MLIR_CAPI_EXPORTED bool omTypeIsAFrozenPathType(MlirType type)
Is the Type a FrozenPathType.
Definition: OM.cpp:54
MLIR_CAPI_EXPORTED MlirType omEvaluatorObjectGetType(OMEvaluatorValue object)
Get the Type from an Object, which will be a ClassType.
Definition: OM.cpp:156
MLIR_CAPI_EXPORTED bool omAttrIsAIntegerAttr(MlirAttribute attr)
Definition: OM.cpp:370
MLIR_CAPI_EXPORTED bool omTypeIsAStringType(MlirType type)
Is the Type a StringType.
Definition: OM.cpp:64
MLIR_CAPI_EXPORTED OMEvaluatorValue omEvaluatorListGetElement(OMEvaluatorValue evaluatorValue, intptr_t pos)
Get an element of the list.
Definition: OM.cpp:270
MLIR_CAPI_EXPORTED bool omTypeIsAClassType(MlirType type)
Is the Type a ClassType.
Definition: OM.cpp:33
MLIR_CAPI_EXPORTED bool omEvaluatorObjectIsNull(OMEvaluatorValue object)
Query if the Object is null.
Definition: OM.cpp:150
MLIR_CAPI_EXPORTED intptr_t omMapAttrGetNumElements(MlirAttribute attr)
Definition: OM.cpp:418
MLIR_CAPI_EXPORTED MlirStringRef omIntegerAttrToString(MlirAttribute attr)
Get a string representation of an om::IntegerAttr.
Definition: OM.cpp:385
MLIR_CAPI_EXPORTED MlirIdentifier omMapAttrGetElementKey(MlirAttribute attr, intptr_t pos)
Definition: OM.cpp:423
MLIR_CAPI_EXPORTED OMEvaluatorValue omEvaluatorValueFromPrimitive(MlirAttribute primitive)
Get the EvaluatorValue from a Primitive value.
Definition: OM.cpp:244
MLIR_CAPI_EXPORTED MlirAttribute omIntegerAttrGet(MlirAttribute attr)
Get an om::IntegerAttr from mlir::IntegerAttr.
Definition: OM.cpp:378
MLIR_CAPI_EXPORTED bool omEvaluatorValueIsAObject(OMEvaluatorValue evaluatorValue)
Query if the EvaluatorValue is an Object.
Definition: OM.cpp:223
MLIR_CAPI_EXPORTED MlirAttribute omListAttrGetElement(MlirAttribute attr, intptr_t pos)
Definition: OM.cpp:407
MLIR_CAPI_EXPORTED bool omEvaluatorValueIsAPrimitive(OMEvaluatorValue evaluatorValue)
Query if the EvaluatorValue is a Primitive.
Definition: OM.cpp:229
MLIR_CAPI_EXPORTED OMEvaluatorValue omEvaluatorObjectGetField(OMEvaluatorValue object, MlirAttribute name)
Get a field from an Object, which must contain a field of that name.
Definition: OM.cpp:186
MLIR_CAPI_EXPORTED MlirAttribute omEvaluatorMapGetKeys(OMEvaluatorValue object)
Get an ArrayAttr with the keys in a Map.
Definition: OM.cpp:181
MLIR_CAPI_EXPORTED MlirContext omEvaluatorValueGetContext(OMEvaluatorValue evaluatorValue)
Definition: OM.cpp:207
MLIR_CAPI_EXPORTED MlirAttribute omEvaluatorObjectGetFieldNames(OMEvaluatorValue object)
Get all the field names from an Object, can be empty if object has no fields.
Definition: OM.cpp:172
MLIR_CAPI_EXPORTED bool omAttrIsAMapAttr(MlirAttribute attr)
Definition: OM.cpp:416
MLIR_CAPI_EXPORTED bool omEvaluatorValueIsAReference(OMEvaluatorValue evaluatorValue)
Query if the EvaluatorValue is a Reference.
Definition: OM.cpp:329
MLIR_CAPI_EXPORTED MlirAttribute omEvaluatorPathGetAsString(OMEvaluatorValue evaluatorValue)
Get a string representation of a Path.
Definition: OM.cpp:323
MLIR_CAPI_EXPORTED MlirAttribute omReferenceAttrGetInnerRef(MlirAttribute attr)
Definition: OM.cpp:361
MLIR_CAPI_EXPORTED MlirAttribute omIntegerAttrGetInt(MlirAttribute attr)
Given an om::IntegerAttr, return the mlir::IntegerAttr.
Definition: OM.cpp:374
evaluator::ObjectValue Object
Definition: Evaluator.h:411
void populateDialectOMSubmodule(pybind11::module &m)
A value type for use in C APIs that just wraps a pointer to an Object.
Definition: OM.h:75
A value type for use in C APIs that just wraps a pointer to an Evaluator.
Definition: OM.h:64