diff --git a/include/circt-c/Dialect/HW.h b/include/circt-c/Dialect/HW.h index 1e812837ca3d..1474c17a3c18 100644 --- a/include/circt-c/Dialect/HW.h +++ b/include/circt-c/Dialect/HW.h @@ -116,6 +116,9 @@ MLIR_CAPI_EXPORTED MlirStringRef hwParamDeclAttrGetName(MlirAttribute decl); MLIR_CAPI_EXPORTED MlirAttribute hwParamDeclAttrGetType(MlirAttribute decl); MLIR_CAPI_EXPORTED MlirAttribute hwParamDeclAttrGetValue(MlirAttribute decl); +MLIR_CAPI_EXPORTED bool hwAttrIsAParamVerbatimAttr(MlirAttribute); +MLIR_CAPI_EXPORTED MlirAttribute hwParamVerbatimAttrGet(MlirAttribute text); + #ifdef __cplusplus } #endif diff --git a/integration_test/Bindings/Python/dialects/hw.py b/integration_test/Bindings/Python/dialects/hw.py index 12fcdd2b3ce2..0c622dde306f 100644 --- a/integration_test/Bindings/Python/dialects/hw.py +++ b/integration_test/Bindings/Python/dialects/hw.py @@ -5,7 +5,7 @@ from circt.dialects import hw from mlir.ir import (Context, Location, InsertionPoint, IntegerType, - IntegerAttr, Module, TypeAttr) + IntegerAttr, Module, StringAttr, TypeAttr) with Context() as ctx, Location.unknown(): circt.register_dialects(ctx) @@ -73,3 +73,7 @@ def build(module): pdecl = hw.ParamDeclAttr.get_nodefault("param2", TypeAttr.get(i32)) # CHECK: #hw.param.decl<"param2": i32> print(pdecl) + + pverbatim = hw.ParamVerbatimAttr.get(StringAttr.get("this is verbatim")) + # CHECK: #hw.param.verbatim<"this is verbatim"> + print(pverbatim) diff --git a/lib/Bindings/Python/HWModule.cpp b/lib/Bindings/Python/HWModule.cpp index 07e1b84afb16..33b99b205990 100644 --- a/lib/Bindings/Python/HWModule.cpp +++ b/lib/Bindings/Python/HWModule.cpp @@ -130,4 +130,9 @@ void circt::python::populateDialectHWSubmodule(py::module &m) { MlirStringRef cStr = hwParamDeclAttrGetName(self); return std::string(cStr.data, cStr.length); }); + + mlir_attribute_subclass(m, "ParamVerbatimAttr", hwAttrIsAParamVerbatimAttr) + .def_classmethod("get", [](py::object cls, MlirAttribute text) { + return cls(hwParamVerbatimAttrGet(text)); + }); } diff --git a/lib/CAPI/Dialect/HW.cpp b/lib/CAPI/Dialect/HW.cpp index 1612c7fc0391..56e2f0a74655 100644 --- a/lib/CAPI/Dialect/HW.cpp +++ b/lib/CAPI/Dialect/HW.cpp @@ -154,3 +154,13 @@ MLIR_CAPI_EXPORTED MlirAttribute hwParamDeclAttrGetType(MlirAttribute decl) { MLIR_CAPI_EXPORTED MlirAttribute hwParamDeclAttrGetValue(MlirAttribute decl) { return wrap(unwrap(decl).cast().getValue()); } + +MLIR_CAPI_EXPORTED bool hwAttrIsAParamVerbatimAttr(MlirAttribute attr) { + return unwrap(attr).isa(); +} +MLIR_CAPI_EXPORTED MlirAttribute hwParamVerbatimAttrGet(MlirAttribute text) { + auto textAttr = unwrap(text).cast(); + MLIRContext *ctx = textAttr.getContext(); + auto type = NoneType::get(ctx); + return wrap(ParamVerbatimAttr::get(ctx, textAttr, type)); +}