Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions include/circt-c/Dialect/ESI.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(ESI, esi);
MLIR_CAPI_EXPORTED void registerESIPasses(void);

MLIR_CAPI_EXPORTED bool circtESITypeIsAChannelType(MlirType type);
MLIR_CAPI_EXPORTED MlirTypeID circtESIChannelTypeGetTypeID(void);
MLIR_CAPI_EXPORTED MlirType circtESIChannelTypeGet(MlirType inner,
uint32_t signaling,
uint64_t dataDelay);
Expand All @@ -27,9 +28,11 @@ MLIR_CAPI_EXPORTED uint32_t circtESIChannelGetSignaling(MlirType channelType);
MLIR_CAPI_EXPORTED uint64_t circtESIChannelGetDataDelay(MlirType channelType);

MLIR_CAPI_EXPORTED bool circtESITypeIsAnAnyType(MlirType type);
MLIR_CAPI_EXPORTED MlirTypeID circtESIAnyTypeGetTypeID(void);
MLIR_CAPI_EXPORTED MlirType circtESIAnyTypeGet(MlirContext);

MLIR_CAPI_EXPORTED bool circtESITypeIsAListType(MlirType type);
MLIR_CAPI_EXPORTED MlirTypeID circtESIListTypeGetTypeID(void);
MLIR_CAPI_EXPORTED MlirType circtESIListTypeGet(MlirType inner);
MLIR_CAPI_EXPORTED MlirType
circtESIListTypeGetElementType(MlirType channelType);
Expand All @@ -53,6 +56,7 @@ typedef struct {
} CirctESIBundleTypeBundleChannel;

MLIR_CAPI_EXPORTED bool circtESITypeIsABundleType(MlirType type);
MLIR_CAPI_EXPORTED MlirTypeID circtESIBundleTypeGetTypeID(void);
MLIR_CAPI_EXPORTED MlirType circtESIBundleTypeGet(
MlirContext, size_t numChannels,
const CirctESIBundleTypeBundleChannel *channels, bool resettable);
Expand All @@ -66,6 +70,7 @@ circtESIBundleTypeGetChannel(MlirType bundle, size_t idx);
//===----------------------------------------------------------------------===//

MLIR_CAPI_EXPORTED bool circtESITypeIsAWindowType(MlirType type);
MLIR_CAPI_EXPORTED MlirTypeID circtESIWindowTypeGetTypeID(void);
MLIR_CAPI_EXPORTED MlirType circtESIWindowTypeGet(MlirContext cctxt,
MlirAttribute name,
MlirType into,
Expand All @@ -79,6 +84,7 @@ MLIR_CAPI_EXPORTED MlirType circtESIWindowTypeGetFrame(MlirType window,
MLIR_CAPI_EXPORTED MlirType circtESIWindowTypeGetLoweredType(MlirType window);

MLIR_CAPI_EXPORTED bool circtESITypeIsAWindowFrameType(MlirType type);
MLIR_CAPI_EXPORTED MlirTypeID circtESIWindowFrameTypeGetTypeID(void);
MLIR_CAPI_EXPORTED MlirType circtESIWindowFrameTypeGet(MlirContext cctxt,
MlirAttribute name,
size_t numMembers,
Expand All @@ -89,6 +95,7 @@ MLIR_CAPI_EXPORTED MlirType circtESIWindowFrameTypeGetMember(MlirType frame,
size_t idx);

MLIR_CAPI_EXPORTED bool circtESITypeIsAWindowFieldType(MlirType type);
MLIR_CAPI_EXPORTED MlirTypeID circtESIWindowFieldTypeGetTypeID(void);
MLIR_CAPI_EXPORTED MlirType circtESIWindowFieldTypeGet(MlirContext cctxt,
MlirAttribute fieldName,
uint64_t numItems,
Expand Down
18 changes: 15 additions & 3 deletions include/circt-c/Dialect/HW.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,26 +73,32 @@ MLIR_CAPI_EXPORTED int64_t hwGetBitWidth(MlirType);
/// dialects.
MLIR_CAPI_EXPORTED bool hwTypeIsAValueType(MlirType);

MLIR_CAPI_EXPORTED bool hwTypeIsAIntType(MlirType);
MLIR_CAPI_EXPORTED MlirTypeID hwIntTypeGetTypeID(void);

/// If the type is an HW array
MLIR_CAPI_EXPORTED bool hwTypeIsAArrayType(MlirType);
MLIR_CAPI_EXPORTED MlirTypeID hwArrayTypeGetTypeID(void);

/// If the type is an HW inout.
MLIR_CAPI_EXPORTED bool hwTypeIsAInOut(MlirType type);
MLIR_CAPI_EXPORTED MlirTypeID hwInOutTypeGetTypeID(void);

/// If the type is an HW module type.
MLIR_CAPI_EXPORTED bool hwTypeIsAModuleType(MlirType type);
MLIR_CAPI_EXPORTED MlirTypeID hwModuleTypeGetTypeID(void);

/// If the type is an HW struct.
MLIR_CAPI_EXPORTED bool hwTypeIsAStructType(MlirType);
MLIR_CAPI_EXPORTED MlirTypeID hwStructTypeGetTypeID(void);

/// If the type is an HW union.
MLIR_CAPI_EXPORTED bool hwTypeIsAUnionType(MlirType);
MLIR_CAPI_EXPORTED MlirTypeID hwUnionTypeGetTypeID(void);

/// If the type is an HW type alias.
MLIR_CAPI_EXPORTED bool hwTypeIsATypeAliasType(MlirType);

/// If the type is an HW int.
MLIR_CAPI_EXPORTED bool hwTypeIsAIntType(MlirType);
MLIR_CAPI_EXPORTED MlirTypeID hwTypeAliasTypeGetTypeID(void);

/// Creates a fixed-size HW array type in the context associated with element
MLIR_CAPI_EXPORTED MlirType hwArrayTypeGet(MlirType element, size_t size);
Expand Down Expand Up @@ -192,17 +198,20 @@ MLIR_CAPI_EXPORTED MlirStringRef hwTypeAliasTypeGetScope(MlirType typeAlias);
//===----------------------------------------------------------------------===//

MLIR_CAPI_EXPORTED bool hwAttrIsAInnerSymAttr(MlirAttribute);
MLIR_CAPI_EXPORTED MlirTypeID hwInnerSymAttrGetTypeID(void);
MLIR_CAPI_EXPORTED MlirAttribute hwInnerSymAttrGet(MlirAttribute symName);
MLIR_CAPI_EXPORTED MlirAttribute hwInnerSymAttrGetEmpty(MlirContext ctx);
MLIR_CAPI_EXPORTED MlirAttribute hwInnerSymAttrGetSymName(MlirAttribute);

MLIR_CAPI_EXPORTED bool hwAttrIsAInnerRefAttr(MlirAttribute);
MLIR_CAPI_EXPORTED MlirTypeID hwInnerRefAttrGetTypeID(void);
MLIR_CAPI_EXPORTED MlirAttribute hwInnerRefAttrGet(MlirAttribute moduleName,
MlirAttribute innerSym);
MLIR_CAPI_EXPORTED MlirAttribute hwInnerRefAttrGetName(MlirAttribute);
MLIR_CAPI_EXPORTED MlirAttribute hwInnerRefAttrGetModule(MlirAttribute);

MLIR_CAPI_EXPORTED bool hwAttrIsAParamDeclAttr(MlirAttribute);
MLIR_CAPI_EXPORTED MlirTypeID hwParamDeclAttrGetTypeID(void);
MLIR_CAPI_EXPORTED MlirAttribute hwParamDeclAttrGet(MlirStringRef name,
MlirType type,
MlirAttribute value);
Expand All @@ -211,15 +220,18 @@ MLIR_CAPI_EXPORTED MlirType hwParamDeclAttrGetType(MlirAttribute decl);
MLIR_CAPI_EXPORTED MlirAttribute hwParamDeclAttrGetValue(MlirAttribute decl);

MLIR_CAPI_EXPORTED bool hwAttrIsAParamDeclRefAttr(MlirAttribute);
MLIR_CAPI_EXPORTED MlirTypeID hwParamDeclRefAttrGetTypeID(void);
MLIR_CAPI_EXPORTED MlirAttribute hwParamDeclRefAttrGet(MlirContext ctx,
MlirStringRef cName);
MLIR_CAPI_EXPORTED MlirStringRef hwParamDeclRefAttrGetName(MlirAttribute decl);
MLIR_CAPI_EXPORTED MlirType hwParamDeclRefAttrGetType(MlirAttribute decl);

MLIR_CAPI_EXPORTED bool hwAttrIsAParamVerbatimAttr(MlirAttribute);
MLIR_CAPI_EXPORTED MlirTypeID hwParamVerbatimAttrGetTypeID(void);
MLIR_CAPI_EXPORTED MlirAttribute hwParamVerbatimAttrGet(MlirAttribute text);

MLIR_CAPI_EXPORTED bool hwAttrIsAOutputFileAttr(MlirAttribute);
MLIR_CAPI_EXPORTED MlirTypeID hwOutputFileAttrGetTypeID(void);
MLIR_CAPI_EXPORTED MlirAttribute hwOutputFileGetFromFileName(
MlirAttribute text, bool excludeFromFileList, bool includeReplicatedOp);
MLIR_CAPI_EXPORTED MlirStringRef
Expand Down
3 changes: 3 additions & 0 deletions include/circt-c/Dialect/Seq.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ MLIR_CAPI_EXPORTED void registerSeqPasses(void);
/// If the type is an clock type
MLIR_CAPI_EXPORTED bool seqTypeIsAClock(MlirType type);

/// Get the TypeID is an clock type
MLIR_CAPI_EXPORTED MlirTypeID seqClockTypeGetTypeID(void);

/// Creates an seq clock type
MLIR_CAPI_EXPORTED MlirType seqClockTypeGet(MlirContext ctx);

Expand Down
2 changes: 1 addition & 1 deletion integration_test/Bindings/Python/dialects/esi.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
assert (not bundle_type.resettable)
for bchan in bundle_type.channels:
print(bchan)
# CHECK: ('i16chan', ChannelDirection.TO, Type(!esi.channel<i16>))
# CHECK: ('i16chan', ChannelDirection.TO, ChannelType(!esi.channel<i16>))
print()

bundle_type = esi.BundleType.get(
Expand Down
2 changes: 1 addition & 1 deletion integration_test/Bindings/Python/dialects/hw.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def build(module):
module_type = hw.ModuleType.get(ports)
# CHECK: !hw.modty<output out : i1, input in1 : i2, input in2 : i32, inout in3 : i32>
print(module_type)
# CHECK-NEXT: [IntegerType(i2), IntegerType(i32), Type(!hw.inout<i32>)]
# CHECK-NEXT: [IntegerType(i2), IntegerType(i32), InOutType(!hw.inout<i32>)]
print(module_type.input_types)
# CHECK-NEXT: [IntegerType(i1)]
print(module_type.output_types)
Expand Down
1 change: 1 addition & 0 deletions lib/Bindings/Python/CIRCTModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ static void registerPasses() {
}

NB_MODULE(_circt, m) {
nb::module_::import_(MAKE_MLIR_PYTHON_QUALNAME("ir"));
m.doc() = "CIRCT Python Native Extension";
registerPasses();
llvm::sys::PrintStackTraceOnErrorSignal(/*argv=*/"");
Expand Down
21 changes: 14 additions & 7 deletions lib/Bindings/Python/ESIModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ void circt::python::populateDialectESISubmodule(nb::module_ &m) {
"Register a service generator for a given service name.",
nb::arg("impl_type"), nb::arg("generator"));

mlir_type_subclass(m, "ChannelType", circtESITypeIsAChannelType)
mlir_type_subclass(m, "ChannelType", circtESITypeIsAChannelType,
circtESIChannelTypeGetTypeID)
.def_classmethod(
"get",
[](nb::object cls, MlirType inner, uint32_t signaling = 0,
Expand All @@ -126,15 +127,17 @@ void circt::python::populateDialectESISubmodule(nb::module_ &m) {
return circtESIChannelGetDataDelay(self);
});

mlir_type_subclass(m, "AnyType", circtESITypeIsAnAnyType)
mlir_type_subclass(m, "AnyType", circtESITypeIsAnAnyType,
circtESIAnyTypeGetTypeID)
.def_classmethod(
"get",
[](nb::object cls, MlirContext ctxt) {
return cls(circtESIAnyTypeGet(ctxt));
},
nb::arg("self"), nb::arg("ctxt") = nullptr);

mlir_type_subclass(m, "ListType", circtESITypeIsAListType)
mlir_type_subclass(m, "ListType", circtESITypeIsAListType,
circtESIListTypeGetTypeID)
.def_classmethod(
"get",
[](nb::object cls, MlirType inner) {
Expand All @@ -148,7 +151,8 @@ void circt::python::populateDialectESISubmodule(nb::module_ &m) {
nb::enum_<ChannelDirection>(m, "ChannelDirection")
.value("TO", ChannelDirection::to)
.value("FROM", ChannelDirection::from);
mlir_type_subclass(m, "BundleType", circtESITypeIsABundleType)
mlir_type_subclass(m, "BundleType", circtESITypeIsABundleType,
circtESIBundleTypeGetTypeID)
.def_classmethod(
"get",
[](nb::object cls, std::vector<nb::tuple> channelTuples,
Expand Down Expand Up @@ -182,7 +186,8 @@ void circt::python::populateDialectESISubmodule(nb::module_ &m) {
return channels;
});

mlir_type_subclass(m, "WindowType", circtESITypeIsAWindowType)
mlir_type_subclass(m, "WindowType", circtESITypeIsAWindowType,
circtESIWindowTypeGetTypeID)
.def_classmethod(
"get",
[](nb::object cls, MlirAttribute name, MlirType into,
Expand Down Expand Up @@ -216,7 +221,8 @@ void circt::python::populateDialectESISubmodule(nb::module_ &m) {
})
.def("get_lowered_type", &circtESIWindowTypeGetLoweredType);

mlir_type_subclass(m, "WindowFrameType", circtESITypeIsAWindowFrameType)
mlir_type_subclass(m, "WindowFrameType", circtESITypeIsAWindowFrameType,
circtESIWindowFrameTypeGetTypeID)
.def_classmethod(
"get",
[](nb::object cls, MlirAttribute name, std::vector<MlirType> members,
Expand All @@ -241,7 +247,8 @@ void circt::python::populateDialectESISubmodule(nb::module_ &m) {
return members;
});

mlir_type_subclass(m, "WindowFieldType", circtESITypeIsAWindowFieldType)
mlir_type_subclass(m, "WindowFieldType", circtESITypeIsAWindowFieldType,
circtESIWindowFieldTypeGetTypeID)
.def_classmethod(
"get",
[](nb::object cls, MlirAttribute fieldName, uint64_t numItems,
Expand Down
35 changes: 22 additions & 13 deletions lib/Bindings/Python/HWModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void circt::python::populateDialectHWSubmodule(nb::module_ &m) {

m.def("get_bitwidth", &hwGetBitWidth);

mlir_type_subclass(m, "InOutType", hwTypeIsAInOut)
mlir_type_subclass(m, "InOutType", hwTypeIsAInOut, hwInOutTypeGetTypeID)
.def_classmethod("get",
[](nb::object cls, MlirType innerType) {
return cls(hwInOutTypeGet(innerType));
Expand All @@ -42,7 +42,7 @@ void circt::python::populateDialectHWSubmodule(nb::module_ &m) {
return hwInOutTypeGetElementType(self);
});

mlir_type_subclass(m, "ArrayType", hwTypeIsAArrayType)
mlir_type_subclass(m, "ArrayType", hwTypeIsAArrayType, hwArrayTypeGetTypeID)
.def_classmethod("get",
[](nb::object cls, MlirType elementType, intptr_t size) {
return cls(hwArrayTypeGet(elementType, size));
Expand All @@ -62,7 +62,8 @@ void circt::python::populateDialectHWSubmodule(nb::module_ &m) {
nb::class_<HWModulePort>(m, "ModulePort")
.def(nb::init<MlirAttribute, MlirType, HWModulePortDirection>());

mlir_type_subclass(m, "ModuleType", hwTypeIsAModuleType)
mlir_type_subclass(m, "ModuleType", hwTypeIsAModuleType,
hwModuleTypeGetTypeID)
.def_classmethod(
"get",
[](nb::object cls, nb::list pyModulePorts, MlirContext ctx) {
Expand Down Expand Up @@ -113,7 +114,7 @@ void circt::python::populateDialectHWSubmodule(nb::module_ &m) {
return outputNames;
});

mlir_type_subclass(m, "ParamIntType", hwTypeIsAIntType)
mlir_type_subclass(m, "ParamIntType", hwTypeIsAIntType, hwIntTypeGetTypeID)
.def_classmethod(
"get_from_param",
[](nb::object cls, MlirContext ctx, MlirAttribute param) {
Expand All @@ -123,7 +124,8 @@ void circt::python::populateDialectHWSubmodule(nb::module_ &m) {
return hwParamIntTypeGetWidthAttr(self);
});

mlir_type_subclass(m, "StructType", hwTypeIsAStructType)
mlir_type_subclass(m, "StructType", hwTypeIsAStructType,
hwStructTypeGetTypeID)
.def_classmethod(
"get",
[](nb::object cls, nb::list pyFieldInfos,
Expand Down Expand Up @@ -177,7 +179,7 @@ void circt::python::populateDialectHWSubmodule(nb::module_ &m) {
return fields;
});

mlir_type_subclass(m, "UnionType", hwTypeIsAUnionType)
mlir_type_subclass(m, "UnionType", hwTypeIsAUnionType, hwUnionTypeGetTypeID)
.def_classmethod(
"get",
[](nb::object cls, nb::list pyFieldInfos) {
Expand Down Expand Up @@ -227,7 +229,8 @@ void circt::python::populateDialectHWSubmodule(nb::module_ &m) {
return fields;
});

mlir_type_subclass(m, "TypeAliasType", hwTypeIsATypeAliasType)
mlir_type_subclass(m, "TypeAliasType", hwTypeIsATypeAliasType,
hwTypeAliasTypeGetTypeID)
.def_classmethod("get",
[](nb::object cls, std::string scope, std::string name,
MlirType innerType) {
Expand All @@ -253,7 +256,8 @@ void circt::python::populateDialectHWSubmodule(nb::module_ &m) {
return std::string(cStr.data, cStr.length);
});

mlir_attribute_subclass(m, "ParamDeclAttr", hwAttrIsAParamDeclAttr)
mlir_attribute_subclass(m, "ParamDeclAttr", hwAttrIsAParamDeclAttr,
hwParamDeclAttrGetTypeID)
.def_classmethod(
"get",
[](nb::object cls, std::string name, MlirType type,
Expand All @@ -278,7 +282,8 @@ void circt::python::populateDialectHWSubmodule(nb::module_ &m) {
return std::string(cStr.data, cStr.length);
});

mlir_attribute_subclass(m, "ParamDeclRefAttr", hwAttrIsAParamDeclRefAttr)
mlir_attribute_subclass(m, "ParamDeclRefAttr", hwAttrIsAParamDeclRefAttr,
hwParamDeclRefAttrGetTypeID)
.def_classmethod(
"get",
[](nb::object cls, MlirContext ctx, std::string name) {
Expand All @@ -293,12 +298,14 @@ void circt::python::populateDialectHWSubmodule(nb::module_ &m) {
return std::string(cStr.data, cStr.length);
});

mlir_attribute_subclass(m, "ParamVerbatimAttr", hwAttrIsAParamVerbatimAttr)
mlir_attribute_subclass(m, "ParamVerbatimAttr", hwAttrIsAParamVerbatimAttr,
hwParamVerbatimAttrGetTypeID)
.def_classmethod("get", [](nb::object cls, MlirAttribute text) {
return cls(hwParamVerbatimAttrGet(text));
});

mlir_attribute_subclass(m, "OutputFileAttr", hwAttrIsAOutputFileAttr)
mlir_attribute_subclass(m, "OutputFileAttr", hwAttrIsAOutputFileAttr,
hwOutputFileAttrGetTypeID)
.def_classmethod(
"get_from_filename",
[](nb::object cls, MlirAttribute fileName, bool excludeFromFileList,
Expand All @@ -311,7 +318,8 @@ void circt::python::populateDialectHWSubmodule(nb::module_ &m) {
return std::string(cStr.data, cStr.length);
});

mlir_attribute_subclass(m, "InnerSymAttr", hwAttrIsAInnerSymAttr)
mlir_attribute_subclass(m, "InnerSymAttr", hwAttrIsAInnerSymAttr,
hwInnerSymAttrGetTypeID)
.def_classmethod("get",
[](nb::object cls, MlirAttribute symName) {
return cls(hwInnerSymAttrGet(symName));
Expand All @@ -320,7 +328,8 @@ void circt::python::populateDialectHWSubmodule(nb::module_ &m) {
return hwInnerSymAttrGetSymName(self);
});

mlir_attribute_subclass(m, "InnerRefAttr", hwAttrIsAInnerRefAttr)
mlir_attribute_subclass(m, "InnerRefAttr", hwAttrIsAInnerRefAttr,
hwInnerRefAttrGetTypeID)
.def_classmethod(
"get",
[](nb::object cls, MlirAttribute moduleName, MlirAttribute innerSym) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Bindings/Python/SeqModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ using namespace mlir::python::nanobind_adaptors;
void circt::python::populateDialectSeqSubmodule(nb::module_ &m) {
m.doc() = "Seq dialect Python native extension";

mlir_type_subclass(m, "ClockType", seqTypeIsAClock)
mlir_type_subclass(m, "ClockType", seqTypeIsAClock, seqClockTypeGetTypeID)
.def_classmethod(
"get",
[](nb::object cls, MlirContext ctx) {
Expand Down
Loading