Skip to content

Commit

Permalink
Add passthrough API
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardt committed Aug 20, 2024
1 parent 306a076 commit 34619f9
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
12 changes: 12 additions & 0 deletions include/circt/Dialect/OM/OMOpInterfaces.td
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,18 @@ def ClassLike : OpInterface<"ClassLike"> {
/*methodBody=*/[{}],
/*defaultImplementation=*/[{
return mlir::cast<ClassFieldsLike>($_op.getBodyBlock()->getTerminator());
}]>,
InterfaceMethod<"Get the class-like field type",
"std::optional<mlir::Type>", "getFieldType", (ins "mlir::StringAttr":$field),
/*methodBody=*/[{}],
/*defaultImplementation=*/[{
return $_op.getFieldsOp().getFieldType(field);
}]>,
InterfaceMethod<"Get the class-like field names",
"llvm::SmallVector<mlir::StringAttr>", "getFieldNames", (ins),
/*methodBody=*/[{}],
/*defaultImplementation=*/[{
return $_op.getFieldsOp().getFieldNames();
}]>
];
}
Expand Down
10 changes: 4 additions & 6 deletions lib/Dialect/OM/OMOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -456,16 +456,14 @@ void circt::om::ClassExternOp::addFields(

auto *ctx = builder.getContext();
llvm::SmallVector<NamedAttribute> typeAttrs;
llvm::SmallVector<Attribute> fieldAttrs;
llvm::SmallVector<NamedAttribute> fieldIdxs;
unsigned i = 0;
for (auto [name, type] : llvm::zip(fieldNames, fieldTypes)) {
typeAttrs.push_back(makeFieldType(name, type));
fieldAttrs.push_back(cast<Attribute>(name));
for (unsigned i = 0; i < fieldNames.size(); i++) {
auto name = fieldNames[i];
typeAttrs.push_back(makeFieldType(name, fieldTypes[i]));
fieldIdxs.push_back(makeFieldIdx(ctx, name, i));
}
addFieldAttrs(
ctx, fieldAttrs, fieldIdxs, typeAttrs,
ctx, {fieldNames.begin(), fieldNames.end()}, fieldIdxs, typeAttrs,
[&](StringRef field, Attribute attr) { op->setAttr(field, attr); });
}

Expand Down
8 changes: 3 additions & 5 deletions lib/Dialect/OM/Transforms/LinkModules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,16 +190,14 @@ static FailureOr<bool> resolveClasses(StringAttr name,
// Check declared fields.
llvm::DenseSet<StringAttr> declaredFields;

auto classOpFieldsOp = classOp.getFieldsOp();

for (auto name : op.getFieldsOp().getFieldNames()) {
std::optional<Type> opTypeOpt = op.getFieldsOp().getFieldType(name);
std::optional<Type> opTypeOpt = op.getFieldType(name);

if (!opTypeOpt.has_value())
return emitError(op) << " no type for field " << name;
Type opType = opTypeOpt.value();

std::optional<Type> classTypeOpt = classOpFieldsOp.getFieldType(name);
std::optional<Type> classTypeOpt = classOp.getFieldType(name);

// Field not found in its definition.
if (!classTypeOpt.has_value())
Expand All @@ -214,7 +212,7 @@ static FailureOr<bool> resolveClasses(StringAttr name,
declaredFields.insert(name);
}

for (auto fieldName : classOpFieldsOp.getFieldNames())
for (auto fieldName : classOp.getFieldNames())
if (!declaredFields.count(fieldName))
return emitError(op) << "definition has a field " << fieldName
<< " but not found in this declaration";
Expand Down
2 changes: 1 addition & 1 deletion lib/Dialect/OM/Transforms/VerifyObjectFields.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void VerifyObjectFieldsPass::runOnOperation() {
// Verify the field exists on the ClassOp.
auto field = fields[i];
std::optional<Type> fieldTypeOpt =
classDef.getFieldsOp().getFieldType(field.getAttr());
classDef.getFieldType(field.getAttr());

if (!fieldTypeOpt.has_value()) {
auto error =
Expand Down

0 comments on commit 34619f9

Please sign in to comment.