diff --git a/lib/Module/CMakeLists.txt b/lib/Module/CMakeLists.txt index 06d5861701..dcb4f59292 100644 --- a/lib/Module/CMakeLists.txt +++ b/lib/Module/CMakeLists.txt @@ -25,7 +25,6 @@ set(KLEE_MODULE_COMPONENT_SRCS RaiseAsm.cpp ReturnSplitter.cpp SarifReport.cpp - StreamWithLine.cpp Target.cpp TargetHash.cpp TargetForest.cpp diff --git a/lib/Module/InstructionInfoTable.cpp b/lib/Module/InstructionInfoTable.cpp index 321f97556c..33b35a10b7 100644 --- a/lib/Module/InstructionInfoTable.cpp +++ b/lib/Module/InstructionInfoTable.cpp @@ -10,7 +10,6 @@ #include "klee/Module/InstructionInfoTable.h" #include "klee/Config/Version.h" -#include "StreamWithLine.h" #include "llvm/Analysis/ValueTracking.h" #include "llvm/IR/AssemblyAnnotationWriter.h" #include "llvm/IR/DebugInfo.h" @@ -35,30 +34,35 @@ using namespace klee; class InstructionToLineAnnotator : public llvm::AssemblyAnnotationWriter { +private: + std::unordered_map mapping = {}; + public: void emitInstructionAnnot(const llvm::Instruction *i, llvm::formatted_raw_ostream &os) override { - os << "%%%" + std::to_string(reinterpret_cast(i)); + os.flush(); + mapping.emplace(reinterpret_cast(i), os.getLine() + 1); } void emitFunctionAnnot(const llvm::Function *f, llvm::formatted_raw_ostream &os) override { - os << "%%%" + std::to_string(reinterpret_cast(f)); + os.flush(); + mapping.emplace(reinterpret_cast(f), os.getLine() + 1); } + + std::unordered_map getMapping() const { return mapping; } }; static std::unordered_map buildInstructionToLineMap(const llvm::Module &m, std::unique_ptr assemblyFS) { - std::unordered_map mapping; InstructionToLineAnnotator a; - StreamWithLine os(std::move(assemblyFS)); - m.print(os, &a); - os.flush(); + m.print(*assemblyFS, &a); + assemblyFS->flush(); - return os.getMapping(); + return a.getMapping(); } class DebugInfoExtractor { diff --git a/lib/Module/StreamWithLine.cpp b/lib/Module/StreamWithLine.cpp deleted file mode 100644 index ae7f26c22b..0000000000 --- a/lib/Module/StreamWithLine.cpp +++ /dev/null @@ -1,85 +0,0 @@ -#include "StreamWithLine.h" - -StreamWithLine::StreamWithLine(std::unique_ptr assemblyFS) - : assemblyFS(std::move(assemblyFS)), value(), state(State::NewLine) {} - -void StreamWithLine::write_impl(const char *Ptr, size_t Size) { - const char *start = Ptr; - const char *end = Ptr + Size; - for (const char *ch = Ptr; ch < end; ++ch) { - switch (state) { - case State::NewLine: - if (*ch == '%') { - assemblyFS->write(start, ch - start); - start = ch; - state = State::FirstP; - continue; - } - break; - case State::FirstP: - if (*ch == '%') { - state = State::SecondP; - continue; - } - assemblyFS->write("%", 1); - start = ch; - break; - case State::SecondP: - if (*ch == '%') { - state = State::ThirdP; - continue; - } - assemblyFS->write("%%", 2); - start = ch; - break; - case State::ThirdP: - if (isdigit(*ch)) { - value = *ch; - state = State::Num; - continue; - } - assemblyFS->write("%%%", 3); - start = ch; - break; - case State::Num: - if (isdigit(*ch)) { - value += *ch; - state = State::Num; - continue; - } - start = ch; - mapping.emplace(stoull(value), line); - break; - case State::Another: - break; - } - - if (*ch == '\n') { - state = State::NewLine; - line++; - continue; - } - state = State::Another; - } - - switch (state) { - case State::NewLine: - assemblyFS->write(start, end - start); - case State::Another: - assemblyFS->write(start, end - start); - break; - case State::FirstP: - case State::SecondP: - case State::ThirdP: - case State::Num: - break; - } - - curPos += Size; -} - -uint64_t StreamWithLine::current_pos() const { return curPos; } - -std::unordered_map StreamWithLine::getMapping() const { - return mapping; -} diff --git a/lib/Module/StreamWithLine.h b/lib/Module/StreamWithLine.h deleted file mode 100644 index 0bd3d42ad6..0000000000 --- a/lib/Module/StreamWithLine.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef KLEE_STREAMWITHLINE_H -#define KLEE_STREAMWITHLINE_H - -#include -#include - -class StreamWithLine : public llvm::raw_ostream { - std::unique_ptr assemblyFS; - - uint64_t line = 0; - uint64_t curPos = 0; - std::string value; - std::unordered_map mapping = {}; - enum State { NewLine, FirstP, SecondP, ThirdP, Num, Another } state; - - void write_impl(const char *Ptr, size_t Size) override; - uint64_t current_pos() const override; - -public: - explicit StreamWithLine(std::unique_ptr assemblyFS); - - std::unordered_map getMapping() const; -}; - -#endif // KLEE_STREAMWITHLINE_H