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"
45 return isa<FrozenBasePathType>(
unwrap(type));
55 return isa<FrozenPathType>(
unwrap(type));
65 return isa<StringType>(
unwrap(type));
75 return wrap(cast<MapType>(
unwrap(type)).getKeyType());
113 MlirAttribute className,
114 intptr_t nActualParams,
120 StringAttr cppClassName = cast<StringAttr>(
unwrap(className));
123 SmallVector<std::shared_ptr<evaluator::EvaluatorValue>> cppActualParams;
124 for (
unsigned i = 0; i < nActualParams; i++)
125 cppActualParams.push_back(
unwrap(actualParams[i]));
128 auto result = cppEvaluator->
instantiate(cppClassName, cppActualParams);
136 return wrap(result.value());
157 return wrap(llvm::cast<Object>(
unwrap(
object).
get())->getType());
167 return llvm::cast<Object>(
unwrap(
object).
get()) ==
173 return wrap(llvm::cast<Object>(
unwrap(
object).
get())->getFieldNames());
177 return wrap(llvm::cast<evaluator::MapValue>(
unwrap(value).
get())->getType());
182 return wrap(llvm::cast<evaluator::MapValue>(
unwrap(
object).
get())->getKeys());
187 MlirAttribute name) {
192 ->getField(cast<StringAttr>(
unwrap(name)));
208 return wrap(
unwrap(evaluatorValue)->getContext());
213 return wrap(
unwrap(evaluatorValue)->getLoc());
219 return !evaluatorValue.
ptr;
225 return isa<evaluator::ObjectValue>(
unwrap(evaluatorValue).
get());
231 return isa<evaluator::AttributeValue>(
unwrap(evaluatorValue).
get());
239 llvm::cast<evaluator::AttributeValue>(
unwrap(evaluatorValue).
get())
246 return wrap(std::make_shared<evaluator::AttributeValue>(
unwrap(primitive)));
251 return isa<evaluator::ListValue>(
unwrap(evaluatorValue).
get());
259 return evaluatorValue;
264 return cast<evaluator::ListValue>(
unwrap(evaluatorValue).
get())
272 return wrap(cast<evaluator::ListValue>(
unwrap(evaluatorValue).
get())
273 ->getElements()[pos]);
278 return isa<evaluator::TupleValue>(
unwrap(evaluatorValue).
get());
283 return cast<evaluator::TupleValue>(
unwrap(evaluatorValue).
get())
291 return wrap(cast<evaluator::TupleValue>(
unwrap(evaluatorValue).
get())
292 ->getElements()[pos]);
297 MlirAttribute attr) {
298 const auto &elements =
299 cast<evaluator::MapValue>(
unwrap(evaluatorValue).
get())->getElements();
300 const auto &it = elements.find(
unwrap(attr));
301 if (it != elements.end())
302 return wrap(it->second);
308 return isa<evaluator::MapValue>(
unwrap(evaluatorValue).
get());
312 return isa<evaluator::BasePathValue>(
unwrap(evaluatorValue).
get());
316 return wrap(std::make_shared<evaluator::BasePathValue>(
unwrap(context)));
320 return isa<evaluator::PathValue>(
unwrap(evaluatorValue).
get());
324 const auto *path = cast<evaluator::PathValue>(
unwrap(evaluatorValue).
get());
325 return wrap((Attribute)path->getAsString());
330 return isa<evaluator::ReferenceValue>(
unwrap(evaluatorValue).
get());
342 llvm::cast<evaluator::ReferenceValue>(
unwrap(evaluatorValue).
get())
343 ->getStrippedValue();
350 return wrap(result.value());
358 return isa<ReferenceAttr>(
unwrap(attr));
363 (Attribute)cast<ReferenceAttr>(
unwrap(referenceAttr)).getInnerRef());
371 return isa<circt::om::IntegerAttr>(
unwrap(attr));
375 return wrap(cast<circt::om::IntegerAttr>(
unwrap(attr)).getValue());
379 auto integerAttr = cast<mlir::IntegerAttr>(
unwrap(attr));
386 mlir::IntegerAttr integerAttr =
387 cast<circt::om::IntegerAttr>(
unwrap(attr)).getValue();
388 SmallVector<char> str;
389 integerAttr.getValue().toString(
390 str, 10, integerAttr.getType().isSignedInteger());
399 return isa<ListAttr>(
unwrap(attr));
403 auto listAttr = llvm::cast<ListAttr>(
unwrap(attr));
404 return static_cast<intptr_t
>(listAttr.getElements().size());
408 auto listAttr = llvm::cast<ListAttr>(
unwrap(attr));
409 return wrap(listAttr.getElements()[pos]);
419 auto mapAttr = llvm::cast<MapAttr>(
unwrap(attr));
420 return static_cast<intptr_t
>(mapAttr.getElements().size());
424 auto mapAttr = llvm::cast<MapAttr>(
unwrap(attr));
425 return wrap(mapAttr.getElements().getValue()[pos].getName());
429 auto mapAttr = llvm::cast<MapAttr>(
unwrap(attr));
430 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
static Attribute getAttr(ArrayRef< NamedAttribute > attrs, StringRef name)
Get an attribute by name from a list of named attributes.
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.
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.
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)
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.
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.