[PATCH] D45794: [WebAssembly] MC: Refactor section creation code
Phabricator via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 23 12:19:44 PDT 2018
This revision was not accepted when it landed; it landed in state "Needs Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rL330632: [WebAssembly] MC: Refactor section creation code (authored by sbc, committed by ).
Repository:
rL LLVM
https://reviews.llvm.org/D45794
Files:
llvm/trunk/lib/MC/WasmObjectWriter.cpp
Index: llvm/trunk/lib/MC/WasmObjectWriter.cpp
===================================================================
--- llvm/trunk/lib/MC/WasmObjectWriter.cpp
+++ llvm/trunk/lib/MC/WasmObjectWriter.cpp
@@ -220,8 +220,8 @@
return TargetObjectWriter->getRelocType(Target, Fixup);
}
- void startSection(SectionBookkeeping &Section, unsigned SectionId,
- const char *Name = nullptr);
+ void startSection(SectionBookkeeping &Section, unsigned SectionId);
+ void startCustomSection(SectionBookkeeping &Section, StringRef Name);
void endSection(SectionBookkeeping &Section);
public:
@@ -304,12 +304,8 @@
// Write out a section header and a patchable section size field.
void WasmObjectWriter::startSection(SectionBookkeeping &Section,
- unsigned SectionId,
- const char *Name) {
- assert((Name != nullptr) == (SectionId == wasm::WASM_SEC_CUSTOM) &&
- "Only custom sections can have names");
-
- DEBUG(dbgs() << "startSection " << SectionId << ": " << Name << "\n");
+ unsigned SectionId) {
+ DEBUG(dbgs() << "startSection " << SectionId << "\n");
write8(SectionId);
Section.SizeOffset = getStream().tell();
@@ -320,12 +316,14 @@
// The position where the section starts, for measuring its size.
Section.ContentsOffset = getStream().tell();
+}
+void WasmObjectWriter::startCustomSection(SectionBookkeeping &Section,
+ StringRef Name) {
+ DEBUG(dbgs() << "startCustomSection " << Name << "\n");
+ startSection(Section, wasm::WASM_SEC_CUSTOM);
// Custom sections in wasm also have a string identifier.
- if (SectionId == wasm::WASM_SEC_CUSTOM) {
- assert(Name);
- writeString(Name);
- }
+ writeString(Name);
}
// Now that the section is complete and we know how big it is, patch up the
@@ -843,7 +841,7 @@
return;
SectionBookkeeping Section;
- startSection(Section, wasm::WASM_SEC_CUSTOM, "reloc.CODE");
+ startCustomSection(Section, "reloc.CODE");
encodeULEB128(wasm::WASM_SEC_CODE, getStream());
encodeULEB128(CodeRelocations.size(), getStream());
@@ -861,7 +859,7 @@
return;
SectionBookkeeping Section;
- startSection(Section, wasm::WASM_SEC_CUSTOM, "reloc.DATA");
+ startCustomSection(Section, "reloc.DATA");
encodeULEB128(wasm::WASM_SEC_DATA, getStream());
encodeULEB128(DataRelocations.size(), getStream());
@@ -876,7 +874,7 @@
ArrayRef<std::pair<uint16_t, uint32_t>> InitFuncs,
const std::map<StringRef, std::vector<WasmComdatEntry>> &Comdats) {
SectionBookkeeping Section;
- startSection(Section, wasm::WASM_SEC_CUSTOM, "linking");
+ startCustomSection(Section, "linking");
SectionBookkeeping SubSection;
if (SymbolInfos.size() != 0) {
@@ -950,8 +948,7 @@
ArrayRef<WasmCustomSection> CustomSections) {
for (const auto &CustomSection : CustomSections) {
SectionBookkeeping Section;
- startSection(Section, wasm::WASM_SEC_CUSTOM,
- CustomSection.Name.str().c_str());
+ startCustomSection(Section, CustomSection.Name);
writeBytes(CustomSection.Contents);
endSection(Section);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45794.143618.patch
Type: text/x-patch
Size: 3217 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180423/35241687/attachment.bin>
More information about the llvm-commits
mailing list