[FIRRTL][CAPI] add LayerConvention Enum and Attr

This commit is contained in:
Jiuyang Liu 2025-01-13 10:31:36 +08:00 committed by Asuna
parent bf9f0dc583
commit fab24cbd8a
2 changed files with 27 additions and 0 deletions

View File

@ -29,6 +29,13 @@ typedef enum FIRRTLConvention {
FIRRTL_CONVENTION_SCALARIZED,
} FIRRTLConvention;
/// Layer lowering conventions.
// NOLINTNEXTLINE(modernize-use-using)
typedef enum FIRRTLLayerConvention {
FIRRTL_LAYER_CONVENTION_BIND,
FIRRTL_LAYER_CONVENTION_INLINE,
} FIRRTLLayerConvention;
/// Port direction.
// NOLINTNEXTLINE(modernize-use-using)
typedef enum FIRRTLDirection {
@ -266,6 +273,10 @@ MLIR_CAPI_EXPORTED MlirType firrtlTypeGetMaskType(MlirType type);
MLIR_CAPI_EXPORTED MlirAttribute
firrtlAttrGetConvention(MlirContext ctx, FIRRTLConvention convention);
/// Creates a LayerConventionAttr with the specified value.
MLIR_CAPI_EXPORTED MlirAttribute
firrtlAttrGetLayerConvention(MlirContext ctx, FIRRTLLayerConvention convention);
/// Creates a DenseBoolArrayAttr with the specified port directions.
MLIR_CAPI_EXPORTED MlirAttribute firrtlAttrGetPortDirs(
MlirContext ctx, size_t count, const FIRRTLDirection *dirs);

View File

@ -291,6 +291,22 @@ MlirAttribute firrtlAttrGetConvention(MlirContext ctx,
return wrap(ConventionAttr::get(unwrap(ctx), value));
}
MlirAttribute firrtlAttrGetLayerConvention(MlirContext ctx,
FIRRTLLayerConvention convention) {
LayerConvention value;
switch (convention) {
case FIRRTL_LAYER_CONVENTION_BIND:
value = LayerConvention::Bind;
break;
case FIRRTL_LAYER_CONVENTION_INLINE:
value = LayerConvention::Inline;
break;
}
return wrap(LayerConventionAttr::get(unwrap(ctx), value));
}
MlirAttribute firrtlAttrGetPortDirs(MlirContext ctx, size_t count,
const FIRRTLDirection *dirs) {
static_assert(FIRRTL_DIRECTION_IN ==