[Python] Add debug dialect bindings (#6471)

Add basic Python bindings for the debug dialect.
This commit is contained in:
Fabian Schuiki 2023-11-29 15:02:59 -08:00 committed by GitHub
parent a9c43bc407
commit 878303a1fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 97 additions and 0 deletions

View File

@ -0,0 +1,24 @@
//===- Debug.h - C interface for the for Debug 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_DEBUG_H
#define CIRCT_C_DIALECT_DEBUG_H
#include "mlir-c/IR.h"
#ifdef __cplusplus
extern "C" {
#endif
MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(Debug, debug);
#ifdef __cplusplus
}
#endif
#endif // CIRCT_C_DIALECT_DEBUG_H

View File

@ -0,0 +1,17 @@
# REQUIRES: bindings_python
# RUN: %PYTHON% %s | FileCheck %s
import circt
from circt.dialects import hw, debug
from circt.ir import Context, Location, Module, InsertionPoint, IntegerAttr, IntegerType
with Context() as ctx, Location.unknown():
circt.register_dialects(ctx)
m = Module.create()
with InsertionPoint(m.body):
i1 = IntegerType.get_signless(1)
true = hw.ConstantOp(IntegerAttr.get(i1, 1))
op = debug.VariableOp("foo", true)
# CHECK: dbg.variable "foo", %true : i1
print(op)

View File

@ -10,6 +10,7 @@
#include "circt-c/Conversion.h"
#include "circt-c/Dialect/Comb.h"
#include "circt-c/Dialect/Debug.h"
#include "circt-c/Dialect/ESI.h"
#include "circt-c/Dialect/FSM.h"
#include "circt-c/Dialect/HW.h"
@ -62,6 +63,10 @@ PYBIND11_MODULE(_circt, m) {
mlirDialectHandleRegisterDialect(comb, context);
mlirDialectHandleLoadDialect(comb, context);
MlirDialectHandle debug = mlirGetDialectHandle__debug__();
mlirDialectHandleRegisterDialect(debug, context);
mlirDialectHandleLoadDialect(debug, context);
MlirDialectHandle esi = mlirGetDialectHandle__esi__();
mlirDialectHandleRegisterDialect(esi, context);
mlirDialectHandleLoadDialect(esi, context);

View File

@ -23,6 +23,7 @@ declare_mlir_python_extension(CIRCTBindingsPythonExtension
SVModule.cpp
EMBED_CAPI_LINK_LIBS
CIRCTCAPIComb
CIRCTCAPIDebug
CIRCTCAPIESI
CIRCTCAPIExportVerilog
CIRCTCAPIFSM
@ -73,6 +74,14 @@ declare_mlir_dialect_python_bindings(
dialects/comb.py
DIALECT_NAME comb)
declare_mlir_dialect_python_bindings(
ADD_TO_PARENT CIRCTBindingsPythonSources.Dialects
ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}"
TD_FILE dialects/DebugOps.td
SOURCES
dialects/debug.py
DIALECT_NAME dbg)
declare_mlir_dialect_python_bindings(
ADD_TO_PARENT CIRCTBindingsPythonSources.Dialects
ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}"

View File

@ -0,0 +1,14 @@
//===- DebugOps.td - Entry point for Debug 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_DEBUG_OPS
#define BINDINGS_PYTHON_DEBUG_OPS
include "circt/Dialect/Debug/Debug.td"
#endif

View File

@ -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 ._dbg_ops_gen import *

View File

@ -2,6 +2,7 @@
set(LLVM_OPTIONAL_SOURCES
CHIRRTL.cpp
Comb.cpp
Debug.cpp
ESI.cpp
FIRRTL.cpp
FSM.cpp
@ -26,6 +27,14 @@ add_mlir_public_c_api_library(CIRCTCAPIComb
CIRCTComb
)
add_mlir_public_c_api_library(CIRCTCAPIDebug
Debug.cpp
LINK_LIBS PUBLIC
MLIRCAPIIR
CIRCTDebug
)
add_mlir_public_c_api_library(CIRCTCAPIESI
ESI.cpp

View File

@ -0,0 +1,14 @@
//===- Debug.cpp - C interface for the Debug 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/Debug.h"
#include "circt/Dialect/Debug/DebugDialect.h"
#include "mlir/CAPI/Registration.h"
MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(Debug, debug, circt::debug::DebugDialect)