[lld] r321146 - [WebAssembly] Improve toString(OutputSection). NFC.
Sam Clegg via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 19 21:14:48 PST 2017
Author: sbc
Date: Tue Dec 19 21:14:48 2017
New Revision: 321146
URL: http://llvm.org/viewvc/llvm-project?rev=321146&view=rev
Log:
[WebAssembly] Improve toString(OutputSection). NFC.
Modified:
lld/trunk/wasm/OutputSections.cpp
lld/trunk/wasm/OutputSections.h
lld/trunk/wasm/Writer.cpp
Modified: lld/trunk/wasm/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/OutputSections.cpp?rev=321146&r1=321145&r2=321146&view=diff
==============================================================================
--- lld/trunk/wasm/OutputSections.cpp (original)
+++ lld/trunk/wasm/OutputSections.cpp Tue Dec 19 21:14:48 2017
@@ -63,10 +63,10 @@ static StringRef sectionTypeToString(uin
}
}
-std::string lld::toString(OutputSection *Section) {
- std::string rtn = sectionTypeToString(Section->Type);
- if (!Section->Name.empty())
- rtn += "(" + Section->Name + ")";
+std::string lld::toString(const OutputSection &Section) {
+ std::string rtn = Section.getSectionName();
+ if (!Section.Name.empty())
+ rtn += "(" + Section.Name + ")";
return rtn;
}
@@ -177,11 +177,11 @@ static void calcRelocations(const ObjFil
}
}
-std::string OutputSection::getSectionName() {
+std::string OutputSection::getSectionName() const {
return sectionTypeToString(Type);
}
-std::string SubSection::getSectionName() {
+std::string SubSection::getSectionName() const {
return std::string("subsection <type=") + std::to_string(Type) + ">";
}
@@ -191,7 +191,7 @@ void OutputSection::createHeader(size_t
writeUleb128(OS, Type, nullptr);
writeUleb128(OS, BodySize, "section size");
OS.flush();
- log("createHeader: " + toString(this) + " body=" + Twine(BodySize) +
+ log("createHeader: " + toString(*this) + " body=" + Twine(BodySize) +
" total=" + Twine(getSize()));
}
@@ -222,7 +222,7 @@ CodeSection::CodeSection(uint32_t NumFun
}
void CodeSection::writeTo(uint8_t *Buf) {
- log("writing " + toString(this));
+ log("writing " + toString(*this));
log(" size=" + Twine(getSize()));
Buf += Offset;
@@ -303,7 +303,7 @@ DataSection::DataSection(ArrayRef<Output
}
void DataSection::writeTo(uint8_t *Buf) {
- log("writing " + toString(this) + " size=" + Twine(getSize()) +
+ log("writing " + toString(*this) + " size=" + Twine(getSize()) +
" body=" + Twine(BodySize));
Buf += Offset;
Modified: lld/trunk/wasm/OutputSections.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/OutputSections.h?rev=321146&r1=321145&r2=321146&view=diff
==============================================================================
--- lld/trunk/wasm/OutputSections.h (original)
+++ lld/trunk/wasm/OutputSections.h Tue Dec 19 21:14:48 2017
@@ -23,7 +23,7 @@ namespace lld {
namespace wasm {
class OutputSection;
}
-std::string toString(wasm::OutputSection *Section);
+std::string toString(const wasm::OutputSection &Section);
namespace wasm {
@@ -34,28 +34,24 @@ class OutputSection {
public:
OutputSection(uint32_t Type, std::string Name = "")
: Type(Type), Name(Name) {}
-
virtual ~OutputSection() = default;
- std::string getSectionName();
-
+ std::string getSectionName() const;
void setOffset(size_t NewOffset) {
- log("setOffset: " + toString(this) + " -> " + Twine(NewOffset));
+ log("setOffset: " + toString(*this) + ": " + Twine(NewOffset));
Offset = NewOffset;
}
-
void createHeader(size_t BodySize);
virtual size_t getSize() const = 0;
virtual void writeTo(uint8_t *Buf) = 0;
virtual void finalizeContents() {}
+ virtual uint32_t numRelocations() const { return 0; }
+ virtual void writeRelocations(raw_ostream &OS) const {}
std::string Header;
uint32_t Type;
std::string Name;
- virtual uint32_t numRelocations() const { return 0; }
- virtual void writeRelocations(raw_ostream &OS) const {}
-
protected:
size_t Offset = 0;
};
@@ -70,7 +66,7 @@ public:
void writeTo(uint8_t *Buf) override {
assert(Offset);
- log("writing " + toString(this));
+ log("writing " + toString(*this));
memcpy(Buf + Offset, Header.data(), Header.size());
memcpy(Buf + Offset + Header.size(), Body.data(), Body.size());
}
@@ -99,8 +95,7 @@ class SubSection : public SyntheticSecti
public:
explicit SubSection(uint32_t Type) : SyntheticSection(Type) {}
- std::string getSectionName();
-
+ std::string getSectionName() const;
void writeToStream(raw_ostream &OS) {
writeBytes(OS, Header.data(), Header.size());
writeBytes(OS, Body.data(), Body.size());
Modified: lld/trunk/wasm/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/Writer.cpp?rev=321146&r1=321145&r2=321146&view=diff
==============================================================================
--- lld/trunk/wasm/Writer.cpp (original)
+++ lld/trunk/wasm/Writer.cpp Tue Dec 19 21:14:48 2017
@@ -522,7 +522,7 @@ void Writer::layoutMemory() {
SyntheticSection *Writer::createSyntheticSection(uint32_t Type,
std::string Name) {
auto Sec = make<SyntheticSection>(Type, Name);
- log("createSection: " + toString(Sec));
+ log("createSection: " + toString(*Sec));
OutputSections.push_back(Sec);
return Sec;
}
More information about the llvm-commits
mailing list