[Mlir-commits] [mlir] [mlir] Python: write bytecode to a file path (PR #127118)
Nikhil Kalra
llvmlistbot at llvm.org
Mon Feb 24 11:34:03 PST 2025
================
@@ -1351,6 +1352,27 @@ void PyOperationBase::writeBytecode(const nb::object &fileObject,
.c_str());
}
+void PyOperationBase::writeBytecode(const nb::object &fileObject,
+ std::optional<int64_t> bytecodeVersion) {
+ PyOperation &operation = getOperation();
+ operation.checkValid();
+
+ std::string filePath;
+ if (nb::try_cast<std::string>(fileObject, filePath)) {
+ std::error_code ec;
+ llvm::raw_fd_ostream ostream(filePath, ec);
+ if (ec) {
+ throw nb::value_error("Unable to open file for writing");
+ }
+
+ OstreamAccumulator accum(ostream);
+ writeBytecodeForOperation(accum, operation, bytecodeVersion);
+ } else {
+ PyFileAccumulator accum(fileObject, /*binary=*/true);
+ writeBytecodeForOperation(accum, operation, bytecodeVersion);
----------------
nikalra wrote:
Sure -- done!
https://github.com/llvm/llvm-project/pull/127118
More information about the Mlir-commits
mailing list