Skip to content

Commit ab2ac29

Browse files
committed
[WebAssembly] Improve toString(OutputSection). NFC.
llvm-svn: 321146
1 parent cdb5240 commit ab2ac29

File tree

3 files changed

+17
-22
lines changed

3 files changed

+17
-22
lines changed

lld/wasm/OutputSections.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ static StringRef sectionTypeToString(uint32_t SectionType) {
6363
}
6464
}
6565

66-
std::string lld::toString(OutputSection *Section) {
67-
std::string rtn = sectionTypeToString(Section->Type);
68-
if (!Section->Name.empty())
69-
rtn += "(" + Section->Name + ")";
66+
std::string lld::toString(const OutputSection &Section) {
67+
std::string rtn = Section.getSectionName();
68+
if (!Section.Name.empty())
69+
rtn += "(" + Section.Name + ")";
7070
return rtn;
7171
}
7272

@@ -177,11 +177,11 @@ static void calcRelocations(const ObjFile &File,
177177
}
178178
}
179179

180-
std::string OutputSection::getSectionName() {
180+
std::string OutputSection::getSectionName() const {
181181
return sectionTypeToString(Type);
182182
}
183183

184-
std::string SubSection::getSectionName() {
184+
std::string SubSection::getSectionName() const {
185185
return std::string("subsection <type=") + std::to_string(Type) + ">";
186186
}
187187

@@ -191,7 +191,7 @@ void OutputSection::createHeader(size_t BodySize) {
191191
writeUleb128(OS, Type, nullptr);
192192
writeUleb128(OS, BodySize, "section size");
193193
OS.flush();
194-
log("createHeader: " + toString(this) + " body=" + Twine(BodySize) +
194+
log("createHeader: " + toString(*this) + " body=" + Twine(BodySize) +
195195
" total=" + Twine(getSize()));
196196
}
197197

@@ -222,7 +222,7 @@ CodeSection::CodeSection(uint32_t NumFunctions, ArrayRef<ObjFile *> Objs)
222222
}
223223

224224
void CodeSection::writeTo(uint8_t *Buf) {
225-
log("writing " + toString(this));
225+
log("writing " + toString(*this));
226226
log(" size=" + Twine(getSize()));
227227
Buf += Offset;
228228

@@ -303,7 +303,7 @@ DataSection::DataSection(ArrayRef<OutputSegment *> Segments)
303303
}
304304

305305
void DataSection::writeTo(uint8_t *Buf) {
306-
log("writing " + toString(this) + " size=" + Twine(getSize()) +
306+
log("writing " + toString(*this) + " size=" + Twine(getSize()) +
307307
" body=" + Twine(BodySize));
308308
Buf += Offset;
309309

lld/wasm/OutputSections.h

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace lld {
2323
namespace wasm {
2424
class OutputSection;
2525
}
26-
std::string toString(wasm::OutputSection *Section);
26+
std::string toString(const wasm::OutputSection &Section);
2727

2828
namespace wasm {
2929

@@ -34,28 +34,24 @@ class OutputSection {
3434
public:
3535
OutputSection(uint32_t Type, std::string Name = "")
3636
: Type(Type), Name(Name) {}
37-
3837
virtual ~OutputSection() = default;
3938

40-
std::string getSectionName();
41-
39+
std::string getSectionName() const;
4240
void setOffset(size_t NewOffset) {
43-
log("setOffset: " + toString(this) + " -> " + Twine(NewOffset));
41+
log("setOffset: " + toString(*this) + ": " + Twine(NewOffset));
4442
Offset = NewOffset;
4543
}
46-
4744
void createHeader(size_t BodySize);
4845
virtual size_t getSize() const = 0;
4946
virtual void writeTo(uint8_t *Buf) = 0;
5047
virtual void finalizeContents() {}
48+
virtual uint32_t numRelocations() const { return 0; }
49+
virtual void writeRelocations(raw_ostream &OS) const {}
5150

5251
std::string Header;
5352
uint32_t Type;
5453
std::string Name;
5554

56-
virtual uint32_t numRelocations() const { return 0; }
57-
virtual void writeRelocations(raw_ostream &OS) const {}
58-
5955
protected:
6056
size_t Offset = 0;
6157
};
@@ -70,7 +66,7 @@ class SyntheticSection : public OutputSection {
7066

7167
void writeTo(uint8_t *Buf) override {
7268
assert(Offset);
73-
log("writing " + toString(this));
69+
log("writing " + toString(*this));
7470
memcpy(Buf + Offset, Header.data(), Header.size());
7571
memcpy(Buf + Offset + Header.size(), Body.data(), Body.size());
7672
}
@@ -99,8 +95,7 @@ class SubSection : public SyntheticSection {
9995
public:
10096
explicit SubSection(uint32_t Type) : SyntheticSection(Type) {}
10197

102-
std::string getSectionName();
103-
98+
std::string getSectionName() const;
10499
void writeToStream(raw_ostream &OS) {
105100
writeBytes(OS, Header.data(), Header.size());
106101
writeBytes(OS, Body.data(), Body.size());

lld/wasm/Writer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ void Writer::layoutMemory() {
522522
SyntheticSection *Writer::createSyntheticSection(uint32_t Type,
523523
std::string Name) {
524524
auto Sec = make<SyntheticSection>(Type, Name);
525-
log("createSection: " + toString(Sec));
525+
log("createSection: " + toString(*Sec));
526526
OutputSections.push_back(Sec);
527527
return Sec;
528528
}

0 commit comments

Comments
 (0)