17 #include "mlir/CAPI/Registration.h"
18 #include "mlir/CAPI/Wrap.h"
19 #include "mlir/IR/Location.h"
20 #include "llvm/ADT/Hashing.h"
21 #include "llvm/Support/Casting.h"
49 return isa<FrozenBasePathType>(
unwrap(type));
59 return isa<FrozenPathType>(
unwrap(type));
69 return unwrap(type).isa<StringType>();
79 return wrap(
unwrap(type).cast<MapType>().getKeyType());
117 MlirAttribute className,
118 intptr_t nActualParams,
124 StringAttr cppClassName =
unwrap(className).cast<StringAttr>();
127 SmallVector<std::shared_ptr<evaluator::EvaluatorValue>> cppActualParams;
128 for (
unsigned i = 0; i < nActualParams; i++)
129 cppActualParams.push_back(
unwrap(actualParams[i]));
132 auto result = cppEvaluator->
instantiate(cppClassName, cppActualParams);
140 return wrap(result.value());
161 return wrap(llvm::cast<Object>(
unwrap(
object).
get())->getType());
171 return llvm::cast<Object>(
unwrap(
object).
get()) ==
177 return wrap(llvm::cast<Object>(
unwrap(
object).
get())->getFieldNames());
186 return wrap(llvm::cast<evaluator::MapValue>(
unwrap(
object).
get())->getKeys());
191 MlirAttribute name) {
196 ->getField(
unwrap(name).cast<StringAttr>());
212 return wrap(
unwrap(evaluatorValue)->getContext());
217 return wrap(
unwrap(evaluatorValue)->getLoc());
223 return !evaluatorValue.
ptr;
229 return isa<evaluator::ObjectValue>(
unwrap(evaluatorValue).
get());
235 return isa<evaluator::AttributeValue>(
unwrap(evaluatorValue).
get());
243 llvm::cast<evaluator::AttributeValue>(
unwrap(evaluatorValue).
get())
250 return wrap(std::make_shared<evaluator::AttributeValue>(
unwrap(primitive)));
255 return isa<evaluator::ListValue>(
unwrap(evaluatorValue).
get());
263 return evaluatorValue;
268 return cast<evaluator::ListValue>(
unwrap(evaluatorValue).
get())
276 return wrap(cast<evaluator::ListValue>(
unwrap(evaluatorValue).
get())
277 ->getElements()[pos]);
282 return isa<evaluator::TupleValue>(
unwrap(evaluatorValue).
get());
287 return cast<evaluator::TupleValue>(
unwrap(evaluatorValue).
get())
295 return wrap(cast<evaluator::TupleValue>(
unwrap(evaluatorValue).
get())
296 ->getElements()[pos]);
301 MlirAttribute attr) {
302 const auto &elements =
303 cast<evaluator::MapValue>(
unwrap(evaluatorValue).
get())->getElements();
304 const auto &it = elements.find(
unwrap(attr));
305 if (it != elements.end())
306 return wrap(it->second);
312 return isa<evaluator::MapValue>(
unwrap(evaluatorValue).
get());
316 return isa<evaluator::BasePathValue>(
unwrap(evaluatorValue).
get());
320 return wrap(std::make_shared<evaluator::BasePathValue>(
unwrap(context)));
324 return isa<evaluator::PathValue>(
unwrap(evaluatorValue).
get());
328 const auto *path = cast<evaluator::PathValue>(
unwrap(evaluatorValue).
get());
329 return wrap((Attribute)path->getAsString());
337 return unwrap(attr).isa<ReferenceAttr>();
342 (Attribute)
unwrap(referenceAttr).cast<ReferenceAttr>().getInnerRef());
350 return unwrap(attr).isa<circt::om::IntegerAttr>();
354 return wrap(cast<circt::om::IntegerAttr>(
unwrap(attr)).getValue());
358 auto integerAttr = cast<mlir::IntegerAttr>(
unwrap(attr));
368 return unwrap(attr).isa<ListAttr>();
372 auto listAttr = llvm::cast<ListAttr>(
unwrap(attr));
373 return static_cast<intptr_t
>(listAttr.getElements().size());
377 auto listAttr = llvm::cast<ListAttr>(
unwrap(attr));
378 return wrap(listAttr.getElements()[pos]);
386 return unwrap(attr).isa<MapAttr>();
390 auto mapAttr = llvm::cast<MapAttr>(
unwrap(attr));
391 return static_cast<intptr_t
>(mapAttr.getElements().size());
395 auto mapAttr = llvm::cast<MapAttr>(
unwrap(attr));
396 return wrap(mapAttr.getElements().getValue()[pos].getName());
400 auto mapAttr = llvm::cast<MapAttr>(
unwrap(attr));
401 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.
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.
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.
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.