Skip to content
Draft
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
4 changes: 2 additions & 2 deletions cmake/ExternalDependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ endif()
# Fetch jeff-mlir
FetchContent_Declare(
jeff-mlir
GIT_REPOSITORY https://github.com/PennyLaneAI/jeff-mlir.git
GIT_TAG v0.3.0)
GIT_REPOSITORY https://github.com/denialhaag/jeff-mlir.git
GIT_TAG 198d2eb7c17c7625fc9f41fac3601832647302a9)
# Cap'n Proto, which is fetched transitively by jeff-mlir, uses the generic BUILD_TESTING option and
# defines a global `check` target when it is enabled. Do not let an embedding project's test setting
# leak into this third-party dependency.
Expand Down
22 changes: 5 additions & 17 deletions mlir/lib/Compiler/Programs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@
#include <cstdint>
#include <cstring>
#include <filesystem>
#include <fstream>
#include <ios>
#include <memory>
#include <optional>
#include <span>
Expand Down Expand Up @@ -231,8 +229,7 @@ bool OpenQASMProgram::write(const std::filesystem::path& path) const {
stream << source_;
stream.flush();
if (stream.has_error()) {
llvm::errs() << "failed to write OpenQASM output file '" << path.string()
<< "'\n";
llvm::errs() << "failed to write OpenQASM file '" << path.string() << "'\n";
return false;
}
return true;
Expand Down Expand Up @@ -528,17 +525,8 @@ std::vector<std::byte> JeffProgram::toBytes() const {
}

bool JeffProgram::write(const std::filesystem::path& path) const {
const auto bytes = toBytes();
std::ofstream output(path, std::ios::binary);
if (!output) {
mod().emitError() << "failed to open output file '" << path.string() << "'";
return false;
}
output.write(reinterpret_cast<const char*>(bytes.data()),
static_cast<std::streamsize>(bytes.size()));
if (!output) {
mod().emitError() << "failed to write output file '" << path.string()
<< "'";
if (failed(serializeToFile(mod(), path.string()))) {
mod().emitError() << "failed to write jeff file '" << path.string() << "'";
return false;
}
return true;
Expand Down Expand Up @@ -626,8 +614,8 @@ bool QIRProgram::writeBitcode(const std::filesystem::path& path) const {
llvm::WriteBitcodeToFile(*llvmModule, stream);
stream.flush();
if (stream.has_error()) {
mod().emitError() << "failed to write bitcode output file '"
<< path.string() << "'";
mod().emitError() << "failed to write bitcode file '" << path.string()
<< "'";
return false;
}
return true;
Expand Down
11 changes: 10 additions & 1 deletion mlir/tools/mqt-cc/mqt-cc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,15 @@ static ParsedProgram loadJeffFile(const StringRef filename,
* @brief Write serialized `jeff` bytes to an output file or standard output.
*/
static LogicalResult writeJeffOutput(ModuleOp mod, const StringRef filename) {
if (filename != "-") {
if (failed(serializeToFile(mod, filename))) {
llvm::errs() << "Failed to write jeff file '" << filename << "'.\n";
return failure();
}
return success();
}

// `serializeToFile` takes a path, so standard output is served from a buffer.
std::string errorMessage;
const auto output = openOutputFile(filename, &errorMessage);
if (!output) {
Expand All @@ -333,7 +342,7 @@ static LogicalResult writeJeffOutput(ModuleOp mod, const StringRef filename) {
bytes.size());
output->os().flush();
if (output->os().has_error()) {
llvm::errs() << "I/O error while writing output file: " << filename << "\n";
llvm::errs() << "I/O error while writing to standard output\n";
return failure();
}

Expand Down
Loading