From 7be0e6ab237d6ef96e1364de7ec275153aa58be6 Mon Sep 17 00:00:00 2001 From: Pietro Fezzardi Date: Tue, 9 Mar 2021 16:25:58 +0100 Subject: [PATCH] Drop redundant functions dumpToString They have been substituted with `print` methods, that are more general. The `dumpToString` is emitted automatically with a template in a revng header, for those classes that already have the `print` method anyway. --- lib/Decompiler/DLATypeSystem.cpp | 34 ++++++++++++-------------------- lib/Decompiler/DLATypeSystem.h | 12 +++++++---- 2 files changed, 21 insertions(+), 25 deletions(-) diff --git a/lib/Decompiler/DLATypeSystem.cpp b/lib/Decompiler/DLATypeSystem.cpp index 454c98a84..872210ffc 100644 --- a/lib/Decompiler/DLATypeSystem.cpp +++ b/lib/Decompiler/DLATypeSystem.cpp @@ -24,31 +24,24 @@ using namespace llvm; -std::string dumpToString(const dla::LayoutTypeSystemNode *N) { - std::string Result = "LTSN ID: " + std::to_string(N->ID); - return Result; -} +namespace dla { -std::string dumpToString(const dla::OffsetExpression &OE) { - std::string Result; - Result += "Off: " + std::to_string(OE.Offset); - auto NStrides = OE.Strides.size(); - revng_assert(NStrides == OE.TripCounts.size()); - if (not OE.Strides.empty()) { +void OffsetExpression::print(llvm::raw_ostream &OS) const { + OS << "Off: " << Offset; + auto NStrides = Strides.size(); + revng_assert(NStrides == TripCounts.size()); + if (not Strides.empty()) { for (decltype(NStrides) N = 0; N < NStrides; ++N) { - Result += ", {" + std::to_string(OE.Strides[N]) + ','; - if (OE.TripCounts[N].has_value()) - Result += std::to_string(OE.TripCounts[N].value()); + OS << ", {" << Strides[N] << ','; + if (TripCounts[N].has_value()) + OS << TripCounts[N].value(); else - Result += "none"; - Result += '}'; + OS << "none"; + OS << '}'; } } - return Result; } -namespace dla { - void LayoutTypePtr::print(raw_ostream &Out) const { Out << '{'; Out << "0x"; @@ -69,9 +62,8 @@ void LayoutTypePtr::print(raw_ostream &Out) const { Out << '}'; } -void LayoutTypeSystemNode::printAsOperand(llvm::raw_ostream &OS, - bool /* unused */) { - OS << ID; +void LayoutTypeSystemNode::print(llvm::raw_ostream &OS) const { + OS << "LTSN ID: " << ID; } namespace { diff --git a/lib/Decompiler/DLATypeSystem.h b/lib/Decompiler/DLATypeSystem.h index 5385b0fbd..f0e8bd113 100644 --- a/lib/Decompiler/DLATypeSystem.h +++ b/lib/Decompiler/DLATypeSystem.h @@ -17,6 +17,7 @@ #include "llvm/ADT/SmallSet.h" #include "llvm/ADT/SmallVector.h" #include "llvm/IR/Value.h" +#include "llvm/Support/raw_ostream.h" #include "revng/ADT/FilteredGraphTraits.h" #include "revng/Support/Assert.h" @@ -38,6 +39,8 @@ struct OffsetExpression { std::strong_ordering operator<=>(const OffsetExpression &Other) const = default; + + void print(llvm::raw_ostream &OS) const; }; // end class OffsetExpression class TypeLinkTag { @@ -132,7 +135,11 @@ public: return nullptr; } - void printAsOperand(llvm::raw_ostream &OS, bool /* unused */); + void print(llvm::raw_ostream &OS) const; + + void printAsOperand(llvm::raw_ostream &OS, bool /* unused */) const { + print(OS); + } }; inline bool hasValidLayout(const LayoutTypeSystemNode *N) { @@ -549,6 +556,3 @@ inline bool isInstanceRoot(const LayoutTypeSystemNode *N) { return isRoot(N); } } // end namespace dla - -std::string dumpToString(const dla::OffsetExpression &OE); -std::string dumpToString(const dla::LayoutTypeSystemNode *N);