Skip to content

Commit

Permalink
[Python] Add bindings for hw::ParamVerbatimAttr. (llvm#2051)
Browse files Browse the repository at this point in the history
This just needs to be plumbed up to Python.
  • Loading branch information
mikeurbach committed Oct 28, 2021
1 parent bbdcddd commit c5bda61
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
3 changes: 3 additions & 0 deletions include/circt-c/Dialect/HW.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion integration_test/Bindings/Python/dialects/hw.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
5 changes: 5 additions & 0 deletions lib/Bindings/Python/HWModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
});
}
10 changes: 10 additions & 0 deletions lib/CAPI/Dialect/HW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,13 @@ MLIR_CAPI_EXPORTED MlirAttribute hwParamDeclAttrGetType(MlirAttribute decl) {
MLIR_CAPI_EXPORTED MlirAttribute hwParamDeclAttrGetValue(MlirAttribute decl) {
return wrap(unwrap(decl).cast<ParamDeclAttr>().getValue());
}

MLIR_CAPI_EXPORTED bool hwAttrIsAParamVerbatimAttr(MlirAttribute attr) {
return unwrap(attr).isa<ParamVerbatimAttr>();
}
MLIR_CAPI_EXPORTED MlirAttribute hwParamVerbatimAttrGet(MlirAttribute text) {
auto textAttr = unwrap(text).cast<StringAttr>();
MLIRContext *ctx = textAttr.getContext();
auto type = NoneType::get(ctx);
return wrap(ParamVerbatimAttr::get(ctx, textAttr, type));
}

0 comments on commit c5bda61

Please sign in to comment.