mirror of https://github.com/llvm/circt.git
[ESI] [Python] Move functionality through the C API (#1595)
Necessary to avoid linking issues on Windows.
This commit is contained in:
parent
18b5b57e1e
commit
f537e0faba
|
@ -32,6 +32,11 @@ MLIR_CAPI_EXPORTED MlirOperation circtESIWrapModule(MlirOperation cModOp,
|
|||
long numPorts,
|
||||
const MlirStringRef *ports);
|
||||
|
||||
MLIR_CAPI_EXPORTED void circtESIAppendMlirFile(MlirModule,
|
||||
MlirStringRef fileName);
|
||||
MLIR_CAPI_EXPORTED MlirOperation circtESILookup(MlirModule,
|
||||
MlirStringRef symbol);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -9,17 +9,11 @@
|
|||
#include "DialectModules.h"
|
||||
|
||||
#include "circt-c/Dialect/ESI.h"
|
||||
#include "circt/Dialect/ESI/ESIDialect.h"
|
||||
#include "circt/Dialect/ESI/ESITypes.h"
|
||||
#include "circt/Support/LLVM.h"
|
||||
#include "mlir-c/Bindings/Python/Interop.h"
|
||||
|
||||
#include "mlir/Bindings/Python/PybindAdaptors.h"
|
||||
#include "mlir/CAPI/IR.h"
|
||||
#include "mlir/CAPI/Support.h"
|
||||
#include "mlir/IR/Builders.h"
|
||||
#include "mlir/Parser.h"
|
||||
#include "mlir/Support/FileUtilities.h"
|
||||
|
||||
#include "llvm/ADT/SmallVector.h"
|
||||
|
||||
|
@ -28,9 +22,6 @@
|
|||
#include <pybind11/stl.h>
|
||||
namespace py = pybind11;
|
||||
|
||||
using namespace circt;
|
||||
using namespace circt::esi;
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// The main entry point into the ESI Assembly API.
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
@ -45,21 +36,13 @@ public:
|
|||
|
||||
/// Load the contents of an MLIR asm file into the system module.
|
||||
void loadMlir(std::string filename) {
|
||||
auto loadedMod = mlir::parseSourceFile(filename, ctxt());
|
||||
Block *loadedBlock = loadedMod->getBody();
|
||||
ModuleOp modOp = mod();
|
||||
assert(!modOp->getRegions().empty());
|
||||
if (modOp.body().empty()) {
|
||||
modOp.body().push_back(loadedBlock);
|
||||
return;
|
||||
}
|
||||
auto &ops = modOp.getBody()->getOperations();
|
||||
ops.splice(ops.end(), loadedBlock->getOperations());
|
||||
circtESIAppendMlirFile(cModuleOp,
|
||||
mlirStringRefCreateFromCString(filename.c_str()));
|
||||
}
|
||||
|
||||
MlirOperation lookup(std::string symbol) {
|
||||
Operation *found = SymbolTable::lookupSymbolIn(mod(), symbol);
|
||||
return wrap(found);
|
||||
return circtESILookup(cModuleOp,
|
||||
mlirStringRefCreateFromCString(symbol.c_str()));
|
||||
}
|
||||
|
||||
void printCapnpSchema(py::object fileObject) {
|
||||
|
@ -70,9 +53,6 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
MLIRContext *ctxt() { return unwrap(cCtxt); }
|
||||
ModuleOp mod() { return unwrap(cModuleOp); }
|
||||
|
||||
MlirContext cCtxt;
|
||||
MlirModule cModuleOp;
|
||||
};
|
||||
|
|
|
@ -9,8 +9,12 @@
|
|||
#include "mlir/CAPI/Support.h"
|
||||
#include "mlir/CAPI/Utils.h"
|
||||
#include "mlir/IR/Builders.h"
|
||||
#include "mlir/IR/SymbolTable.h"
|
||||
#include "mlir/Parser.h"
|
||||
#include "mlir/Support/FileUtilities.h"
|
||||
|
||||
using namespace circt::esi;
|
||||
using namespace mlir;
|
||||
|
||||
MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(ESI, esi, circt::esi::ESIDialect)
|
||||
|
||||
|
@ -48,3 +52,19 @@ MlirOperation circtESIWrapModule(MlirOperation cModOp, long numPorts,
|
|||
mlir::Operation *wrapper = buildESIWrapper(b, modOp, portTriples);
|
||||
return wrap(wrapper);
|
||||
}
|
||||
|
||||
void circtESIAppendMlirFile(MlirModule cMod, MlirStringRef filename) {
|
||||
ModuleOp modOp = unwrap(cMod);
|
||||
auto loadedMod = parseSourceFile(unwrap(filename), modOp.getContext());
|
||||
Block *loadedBlock = loadedMod->getBody();
|
||||
assert(!modOp->getRegions().empty());
|
||||
if (modOp.body().empty()) {
|
||||
modOp.body().push_back(loadedBlock);
|
||||
return;
|
||||
}
|
||||
auto &ops = modOp.getBody()->getOperations();
|
||||
ops.splice(ops.end(), loadedBlock->getOperations());
|
||||
}
|
||||
MlirOperation circtESILookup(MlirModule mod, MlirStringRef symbol) {
|
||||
return wrap(SymbolTable::lookupSymbolIn(unwrap(mod), unwrap(symbol)));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue