From 31e75fdf1e277bbf961287706b06eab8136c6cd0 Mon Sep 17 00:00:00 2001 From: Dan Liew Date: Wed, 24 May 2017 17:38:12 +0100 Subject: Refactor file opening code out of `main.cpp` and into `klee_open_output_file()` function so that it can be used by the Z3Solver. --- lib/Support/CMakeLists.txt | 1 + lib/Support/FileHandling.cpp | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 lib/Support/FileHandling.cpp (limited to 'lib/Support') diff --git a/lib/Support/CMakeLists.txt b/lib/Support/CMakeLists.txt index 4e44fbc6..7145930f 100644 --- a/lib/Support/CMakeLists.txt +++ b/lib/Support/CMakeLists.txt @@ -9,6 +9,7 @@ klee_add_component(kleeSupport CompressionStream.cpp ErrorHandling.cpp + FileHandling.cpp MemoryUsage.cpp PrintVersion.cpp RNG.cpp diff --git a/lib/Support/FileHandling.cpp b/lib/Support/FileHandling.cpp new file mode 100644 index 00000000..092a1af0 --- /dev/null +++ b/lib/Support/FileHandling.cpp @@ -0,0 +1,43 @@ +//===-- FileHandling.cpp --------------------------------------------------===// +// +// The KLEE Symbolic Virtual Machine +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +#include "klee/Internal/Support/FileHandling.h" +#include "klee/Config/Version.h" +#include "klee/Config/config.h" +#include "klee/Internal/Support/ErrorHandling.h" + +#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 5) +#include "llvm/Support/FileSystem.h" +#endif + +namespace klee { + +llvm::raw_fd_ostream *klee_open_output_file(std::string &path, + std::string &error) { + llvm::raw_fd_ostream *f; +#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6) + std::error_code ec; + f = new llvm::raw_fd_ostream(path.c_str(), ec, llvm::sys::fs::F_None); + if (ec) + error = ec.message(); +#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 5) + f = new llvm::raw_fd_ostream(path.c_str(), error, llvm::sys::fs::F_None); +#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 4) + f = new llvm::raw_fd_ostream(path.c_str(), error, llvm::sys::fs::F_Binary); +#else + f = new llvm::raw_fd_ostream(path.c_str(), error, + llvm::raw_fd_ostream::F_Binary); +#endif + if (!error.empty()) { + if (f) + delete f; + f = NULL; + } + return f; +} +} -- cgit 1.4.1