[MSFT] [Python] Export tcl API call (#939)

* [MSFT] [Python] Export tcl API call

* clang-format
This commit is contained in:
John Demme 2021-04-21 10:50:24 -07:00 committed by GitHub
parent 9e4202991c
commit 8183b7a961
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 33 additions and 0 deletions

View File

@ -19,6 +19,11 @@ extern "C" {
MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(MSFT, msft);
/// Emits tcl for the specified module using the provided callback and user
/// data
MlirLogicalResult mlirMSFTExportTcl(MlirModule, MlirStringCallback,
void *userData);
#ifdef __cplusplus
}
#endif

View File

@ -6,6 +6,7 @@ from circt import msft
from circt.dialects import rtl
from mlir.ir import *
import sys
with Context() as ctx, Location.unknown():
circt.register_dialects(ctx)
@ -33,3 +34,10 @@ with Context() as ctx, Location.unknown():
# CHECK: rtl.instance "widget" @MyWidget() {"loc:mem" = #msft.physloc<M20K, 50, 100, 1>, parameters = {}} : () -> ()
m.operation.print()
# CHECK-LABEL: === tcl ===
print("=== tcl ===")
# CHECK: proc top_config { parent } {
# CHECK: set_location_assignment M20K_X50_Y100_N1 -to $parent|widget|mem
msft.export_tcl(m, sys.stdout)

View File

@ -8,6 +8,7 @@
#include "DialectModules.h"
#include "circt-c/Dialect/MSFT.h"
#include "circt/Dialect/MSFT/MSFTAttributes.h"
#include "circt/Support/LLVM.h"
@ -50,4 +51,10 @@ void circt::python::populateDialectMSFTSubmodule(py::module &m) {
.value("M20K", DeviceType::M20K)
.value("DSP", DeviceType::DSP)
.export_values();
m.def("export_tcl", [](MlirModule mod, py::object fileObject) {
circt::python::PyFileAccumulator accum(fileObject, false);
py::gil_scoped_release();
mlirMSFTExportTcl(mod, accum.getCallback(), accum.getUserData());
});
}

View File

@ -41,6 +41,7 @@ add_circt_library(CIRCTCAPIMSFT
LINK_LIBS PUBLIC
MLIRCAPIIR
CIRCTMSFT
CIRCTMSFTExportTcl
)
add_circt_library(CIRCTCAPIRTL

View File

@ -3,9 +3,21 @@
//===----------------------------------------------------------------------===//
#include "circt-c/Dialect/MSFT.h"
#include "circt/Dialect/MSFT/ExportTcl.h"
#include "circt/Dialect/MSFT/MSFTDialect.h"
#include "mlir/CAPI/IR.h"
#include "mlir/CAPI/Registration.h"
#include "mlir/CAPI/Support.h"
#include "mlir/CAPI/Utils.h"
#include "llvm/Support/raw_ostream.h"
MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(MSFT, msft, circt::msft::MSFTDialect)
using namespace circt::msft;
MlirLogicalResult mlirMSFTExportTcl(MlirModule module,
MlirStringCallback callback,
void *userData) {
mlir::detail::CallbackOstream stream(callback, userData);
return wrap(exportQuartusTcl(unwrap(module), stream));
}