Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SMT][python] enable python bindings #8071

Merged
merged 3 commits into from
Jan 13, 2025
Merged
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
24 changes: 24 additions & 0 deletions include/circt-c/Dialect/SMT.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//===- SMT.h - C interface for the SMT dialect --------------------*- C -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef CIRCT_C_DIALECT_SMT_H
#define CIRCT_C_DIALECT_SMT_H

#include "mlir-c/IR.h"

#ifdef __cplusplus
extern "C" {
#endif

MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(SMT, smt);

#ifdef __cplusplus
}
#endif

#endif // CIRCT_C_DIALECT_SMT_H
17 changes: 17 additions & 0 deletions integration_test/Bindings/Python/dialects/smt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# REQUIRES: bindings_python
# RUN: %PYTHON% %s | FileCheck %s

import circt

from circt.dialects import smt
from circt.ir import Context, Location, Module, InsertionPoint

with Context() as ctx, Location.unknown():
circt.register_dialects(ctx)
m = Module.create()
with InsertionPoint(m.body):
true = smt.constant(True)
false = smt.constant(False)
# CHECK: smt.constant true
# CHECK: smt.constant false
print(m)
5 changes: 5 additions & 0 deletions lib/Bindings/Python/CIRCTModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#ifdef CIRCT_INCLUDE_TESTS
#include "circt-c/Dialect/RTGTest.h"
#endif
#include "circt-c/Dialect/SMT.h"
#include "circt-c/Dialect/SV.h"
#include "circt-c/Dialect/Seq.h"
#include "circt-c/Dialect/Verif.h"
Expand Down Expand Up @@ -135,6 +136,10 @@ PYBIND11_MODULE(_circt, m) {
MlirDialectHandle verif = mlirGetDialectHandle__verif__();
mlirDialectHandleRegisterDialect(verif, context);
mlirDialectHandleLoadDialect(verif, context);

MlirDialectHandle smt = mlirGetDialectHandle__smt__();
mlirDialectHandleRegisterDialect(smt, context);
mlirDialectHandleLoadDialect(smt, context);
},
"Register CIRCT dialects on a PyMlirContext.");

Expand Down
9 changes: 9 additions & 0 deletions lib/Bindings/Python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ set(PYTHON_BINDINGS_LINK_LIBS
CIRCTCAPIRTG
CIRCTCAPIRtgTool
CIRCTCAPISeq
CIRCTCAPISMT
CIRCTCAPISV
CIRCTCAPIVerif
MLIRCAPITransforms
Expand Down Expand Up @@ -212,6 +213,14 @@ declare_mlir_dialect_python_bindings(
dialects/verif.py
DIALECT_NAME verif)

declare_mlir_dialect_python_bindings(
ADD_TO_PARENT CIRCTBindingsPythonSources.Dialects
ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}"
TD_FILE dialects/SMTOps.td
SOURCES
dialects/smt.py
DIALECT_NAME smt)

declare_mlir_dialect_python_bindings(
ADD_TO_PARENT CIRCTBindingsPythonSources.Dialects
ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}"
Expand Down
14 changes: 14 additions & 0 deletions lib/Bindings/Python/dialects/SMTOps.td
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//===- SMTOps.td - Entry point for SMT bindings ------------*- tablegen -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef BINDINGS_PYTHON_SMT_OPS
#define BINDINGS_PYTHON_SMT_OPS

include "circt/Dialect/SMT/SMT.td"

#endif // BINDINGS_PYTHON_SMT_OPS
5 changes: 5 additions & 0 deletions lib/Bindings/Python/dialects/smt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

from ._smt_ops_gen import *
9 changes: 9 additions & 0 deletions lib/CAPI/Dialect/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ set(LLVM_OPTIONAL_SOURCES
RTGTest.cpp
SV.cpp
Seq.cpp
SMT.cpp
Verif.cpp
)

Expand Down Expand Up @@ -224,3 +225,11 @@ add_circt_public_c_api_library(CIRCTCAPIEmit
MLIRCAPIIR
CIRCTEmit
)

add_circt_public_c_api_library(CIRCTCAPISMT
SMT.cpp

LINK_LIBS PUBLIC
MLIRCAPIIR
CIRCTSMT
)
14 changes: 14 additions & 0 deletions lib/CAPI/Dialect/SMT.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//===- SMT.cpp - C interface for the SMT dialect --------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "circt-c/Dialect/SMT.h"
#include "circt/Dialect/SMT/SMTDialect.h"

#include "mlir/CAPI/Registration.h"

MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(SMT, smt, circt::smt::SMTDialect)
Loading