13 #include "mlir/CAPI/Registration.h"
14 #include "mlir/CAPI/Wrap.h"
15 #include "mlir/IR/Location.h"
16 #include "llvm/ADT/Hashing.h"
17 #include "llvm/Support/Casting.h"
46 return wrap(cast<ClassType>(
unwrap(type)).getClassName().getAttr());
51 return isa<FrozenBasePathType>(
unwrap(type));
61 return isa<FrozenPathType>(
unwrap(type));
77 return wrap(cast<ListType>(
unwrap(type)).getElementType());
82 return isa<StringType>(
unwrap(type));
92 return wrap(cast<MapType>(
unwrap(type)).getKeyType());
130 MlirAttribute className,
131 intptr_t nActualParams,
137 StringAttr cppClassName = cast<StringAttr>(
unwrap(className));
140 SmallVector<std::shared_ptr<evaluator::EvaluatorValue>> cppActualParams;
141 for (
unsigned i = 0; i < nActualParams; i++)
142 cppActualParams.push_back(
unwrap(actualParams[i]));
145 auto result = cppEvaluator->
instantiate(cppClassName, cppActualParams);
153 return wrap(result.value());
174 return wrap(llvm::cast<Object>(
unwrap(
object).
get())->getType());
184 return llvm::cast<Object>(
unwrap(
object).
get()) ==
190 return wrap(llvm::cast<Object>(
unwrap(
object).
get())->getFieldNames());
194 return wrap(llvm::cast<evaluator::MapValue>(
unwrap(value).
get())->getType());
199 return wrap(llvm::cast<evaluator::MapValue>(
unwrap(
object).
get())->getKeys());
204 MlirAttribute name) {
207 FailureOr<EvaluatorValuePtr> result =
209 ->getField(cast<StringAttr>(
unwrap(name)));
225 return wrap(
unwrap(evaluatorValue)->getContext());
230 return wrap(
unwrap(evaluatorValue)->getLoc());
236 return !evaluatorValue.
ptr;
242 return isa<evaluator::ObjectValue>(
unwrap(evaluatorValue).
get());
248 return isa<evaluator::AttributeValue>(
unwrap(evaluatorValue).
get());
256 llvm::cast<evaluator::AttributeValue>(
unwrap(evaluatorValue).
get())
263 return wrap(std::make_shared<evaluator::AttributeValue>(
unwrap(primitive)));
268 return isa<evaluator::ListValue>(
unwrap(evaluatorValue).
get());
276 return evaluatorValue;
281 return cast<evaluator::ListValue>(
unwrap(evaluatorValue).
get())
289 return wrap(cast<evaluator::ListValue>(
unwrap(evaluatorValue).
get())
290 ->getElements()[pos]);
295 return isa<evaluator::TupleValue>(
unwrap(evaluatorValue).
get());
300 return cast<evaluator::TupleValue>(
unwrap(evaluatorValue).
get())
308 return wrap(cast<evaluator::TupleValue>(
unwrap(evaluatorValue).
get())
309 ->getElements()[pos]);
314 MlirAttribute attr) {
315 const auto &elements =
316 cast<evaluator::MapValue>(
unwrap(evaluatorValue).
get())->getElements();
317 const auto &it = elements.find(
unwrap(attr));
318 if (it != elements.end())
319 return wrap(it->second);
325 return isa<evaluator::MapValue>(
unwrap(evaluatorValue).
get());
329 return isa<evaluator::BasePathValue>(
unwrap(evaluatorValue).
get());
333 return wrap(std::make_shared<evaluator::BasePathValue>(
unwrap(context)));
337 return isa<evaluator::PathValue>(
unwrap(evaluatorValue).
get());
341 const auto *path = cast<evaluator::PathValue>(
unwrap(evaluatorValue).
get());
342 return wrap((Attribute)path->getAsString());
347 return isa<evaluator::ReferenceValue>(
unwrap(evaluatorValue).
get());
359 llvm::cast<evaluator::ReferenceValue>(
unwrap(evaluatorValue).
get())
360 ->getStrippedValue();
367 return wrap(result.value());
375 return isa<ReferenceAttr>(
unwrap(attr));
380 (Attribute)cast<ReferenceAttr>(
unwrap(referenceAttr)).getInnerRef());
388 return isa<circt::om::IntegerAttr>(
unwrap(attr));
392 return wrap(cast<circt::om::IntegerAttr>(
unwrap(attr)).getValue());
396 auto integerAttr = cast<mlir::IntegerAttr>(
unwrap(attr));
403 mlir::IntegerAttr integerAttr =
404 cast<circt::om::IntegerAttr>(
unwrap(attr)).getValue();
405 SmallVector<char> str;
406 integerAttr.getValue().toString(
407 str, 10, integerAttr.getType().isSignedInteger());
416 return isa<ListAttr>(
unwrap(attr));
420 auto listAttr = llvm::cast<ListAttr>(
unwrap(attr));
421 return static_cast<intptr_t
>(listAttr.getElements().size());
425 auto listAttr = llvm::cast<ListAttr>(
unwrap(attr));
426 return wrap(listAttr.getElements()[pos]);
436 auto mapAttr = llvm::cast<MapAttr>(
unwrap(attr));
437 return static_cast<intptr_t
>(mapAttr.getElements().size());
441 auto mapAttr = llvm::cast<MapAttr>(
unwrap(attr));
442 return wrap(mapAttr.getElements().getValue()[pos].getName());
446 auto mapAttr = llvm::cast<MapAttr>(
unwrap(attr));
447 return wrap(mapAttr.getElements().getValue()[pos].getValue());
assert(baseType &&"element must be base type")
MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(CHIRRTL, chirrtl, circt::chirrtl::CHIRRTLDialect) MlirType chirrtlTypeGetCMemory(MlirContext ctx
bool omTypeIsAFrozenBasePathType(MlirType type)
Is the Type a FrozenBasePathType.
bool omEvaluatorValueIsABasePath(OMEvaluatorValue evaluatorValue)
Query if the EvaluatorValue is a BasePath.
MlirAttribute omMapAttrGetElementValue(MlirAttribute attr, intptr_t pos)
bool omEvaluatorValueIsNull(OMEvaluatorValue evaluatorValue)
MlirContext omEvaluatorValueGetContext(OMEvaluatorValue evaluatorValue)
MlirAttribute omReferenceAttrGetInnerRef(MlirAttribute referenceAttr)
bool omTypeIsAStringType(MlirType type)
Is the Type a StringType.
static OMEvaluatorValue wrap(EvaluatorValuePtr object)
Define our own wrap and unwrap instead of using the usual macro.
MlirAttribute omEvaluatorPathGetAsString(OMEvaluatorValue evaluatorValue)
Get a string representation of a Path.
bool omEvaluatorValueIsAPath(OMEvaluatorValue evaluatorValue)
Query if the EvaluatorValue is a Path.
MlirIdentifier omMapAttrGetElementKey(MlirAttribute attr, intptr_t pos)
bool omAttrIsAListAttr(MlirAttribute attr)
OMEvaluatorValue omEvaluatorListGetElement(OMEvaluatorValue evaluatorValue, intptr_t pos)
Get an element of the List.
OMEvaluatorValue omEvaluatorValueFromPrimitive(MlirAttribute primitive)
Get the Primitive from an EvaluatorValue, which must contain a Primitive.
MlirStringRef omIntegerAttrToString(MlirAttribute attr)
Get a string representation of an om::IntegerAttr.
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.
MlirType omEvaluatorMapGetType(OMEvaluatorValue value)
Get the Type from a Map, which will be a MapType.
intptr_t omListAttrGetNumElements(MlirAttribute attr)
MlirAttribute omEvaluatorObjectGetFieldNames(OMEvaluatorValue object)
Get an ArrayAttr with the names of the fields in an Object.
bool omAttrIsAIntegerAttr(MlirAttribute attr)
OMEvaluatorValue omEvaluatorObjectGetField(OMEvaluatorValue object, MlirAttribute name)
Get a field from an Object, which must contain a field of that name.
MlirLocation omEvaluatorValueGetLoc(OMEvaluatorValue evaluatorValue)
bool omEvaluatorValueIsAMap(OMEvaluatorValue evaluatorValue)
Query if the EvaluatorValue is a map.
MlirTypeID omListTypeGetTypeID(void)
Get the TypeID for a ListType.
MlirType omMapTypeGetKeyType(MlirType type)
Return a key type of a map.
MlirTypeID omFrozenBasePathTypeGetTypeID(void)
Get the TypeID for a FrozenBasePathType.
MlirType omStringTypeGet(MlirContext ctx)
Get a StringType.
bool omTypeIsAClassType(MlirType type)
Is the Type a ClassType.
OMEvaluatorValue omEvaluatorTupleGetElement(OMEvaluatorValue evaluatorValue, intptr_t pos)
Get an element of the Tuple.
MlirIdentifier omClassTypeGetName(MlirType type)
Get the name for a ClassType.
OMEvaluatorValue omEvaluatorValueGetReferenceValue(OMEvaluatorValue evaluatorValue)
Dereference a Reference EvaluatorValue.
bool omTypeIsAListType(MlirType type)
Is the Type a ListType.
intptr_t omEvaluatorListGetNumElements(OMEvaluatorValue evaluatorValue)
Get the length of the List.
MlirAttribute omEvaluatorValueGetPrimitive(OMEvaluatorValue evaluatorValue)
Get the Primitive from an EvaluatorValue, which must contain a Primitive.
MlirAttribute omEvaluatorMapGetKeys(OMEvaluatorValue object)
Get an ArrayAttr with the keys in a Map.
MlirAttribute omIntegerAttrGetInt(MlirAttribute attr)
Given an om::IntegerAttr, return the mlir::IntegerAttr.
bool omEvaluatorValueIsAList(OMEvaluatorValue evaluatorValue)
Query if the EvaluatorValue is a List.
bool omTypeIsAFrozenPathType(MlirType type)
Is the Type a FrozenPathType.
bool omAttrIsAMapAttr(MlirAttribute attr)
OMEvaluatorValue omEvaluatorMapGetElement(OMEvaluatorValue evaluatorValue, MlirAttribute attr)
Get an element of the Map.
bool omEvaluatorValueIsAPrimitive(OMEvaluatorValue evaluatorValue)
Query if the EvaluatorValue is a Primitive.
bool omEvaluatorValueIsATuple(OMEvaluatorValue evaluatorValue)
Query if the EvaluatorValue is a Tuple.
bool omEvaluatorObjectIsNull(OMEvaluatorValue object)
Query if the Object is null.
MlirModule omEvaluatorGetModule(OMEvaluator evaluator)
Get the Module the Evaluator is built from.
OMEvaluator omEvaluatorNew(MlirModule mod)
Construct an Evaluator with an IR module.
OMEvaluatorValue omEvaluatorBasePathGetEmpty(MlirContext context)
Create an empty BasePath.
MlirAttribute omListAttrGetElement(MlirAttribute attr, intptr_t pos)
bool omTypeIsAAnyType(MlirType type)
Is the Type an AnyType.
MlirTypeID omAnyTypeGetTypeID(void)
Get the TypeID for an AnyType.
MlirTypeID omFrozenPathTypeGetTypeID(void)
Get the TypeID for a FrozenPathType.
intptr_t omMapAttrGetNumElements(MlirAttribute attr)
MlirType omEvaluatorObjectGetType(OMEvaluatorValue object)
Get the Type from an Object, which will be a ClassType.
intptr_t omEvaluatorTupleGetNumElements(OMEvaluatorValue evaluatorValue)
Get the length of the Tuple.
bool omAttrIsAReferenceAttr(MlirAttribute attr)
static EvaluatorValuePtr unwrap(OMEvaluatorValue c)
MlirAttribute omIntegerAttrGet(MlirAttribute attr)
Get an om::IntegerAttr from mlir::IntegerAttr.
OMEvaluatorValue omEvaluatorValueGetList(OMEvaluatorValue evaluatorValue)
Get the List from an EvaluatorValue, which must contain a List.
bool omEvaluatorValueIsAObject(OMEvaluatorValue evaluatorValue)
Query if the EvaluatorValue is an Object.
MlirType omListTypeGetElementType(MlirType type)
MlirTypeID omClassTypeGetTypeID()
Get the TypeID for a ClassType.
bool omEvaluatorValueIsAReference(OMEvaluatorValue evaluatorValue)
Query if the EvaluatorValue is a Reference.
unsigned omEvaluatorObjectGetHash(OMEvaluatorValue object)
Get the hash for the object.
bool omEvaluatorObjectIsEq(OMEvaluatorValue object, OMEvaluatorValue other)
Check if two objects are same.
struct OMEvaluatorValue OMEvaluatorValue
Direction get(bool isOutput)
Returns an output direction if isOutput is true, otherwise returns an input direction.
StringAttr getTypeID(Type t)
llvm::hash_code hash_value(const BundledChannel channel)
std::shared_ptr< EvaluatorValue > EvaluatorValuePtr
A value of an object in memory.
evaluator::EvaluatorValuePtr EvaluatorValuePtr
A value type for use in C APIs that just wraps a pointer to an Object.
A value type for use in C APIs that just wraps a pointer to an Evaluator.
An Evaluator, which is constructed with an IR module and can instantiate Objects.
FailureOr< evaluator::EvaluatorValuePtr > instantiate(StringAttr className, ArrayRef< EvaluatorValuePtr > actualParams)
Instantiate an Object with its class name and actual parameters.
Base class for evaluator runtime values.