[WebAssembly] Improve toString(OutputSection). NFC.

llvm-svn: 321146
This commit is contained in:
Sam Clegg
2017-12-20 05:14:48 +00:00
parent cdb5240287
commit ab2ac29066
3 changed files with 17 additions and 22 deletions

View File

@@ -63,10 +63,10 @@ static StringRef sectionTypeToString(uint32_t SectionType) {
}
}
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 ObjFile &File,
}
}
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 BodySize) {
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 NumFunctions, ArrayRef<ObjFile *> Objs)
}
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<OutputSegment *> Segments)
}
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;

View File

@@ -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 SyntheticSection {
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());

View File

@@ -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;
}