diff options
Diffstat (limited to 'llvm/lib/ObjectYAML/WasmEmitter.cpp')
| -rw-r--r-- | llvm/lib/ObjectYAML/WasmEmitter.cpp | 43 |
1 files changed, 24 insertions, 19 deletions
diff --git a/llvm/lib/ObjectYAML/WasmEmitter.cpp b/llvm/lib/ObjectYAML/WasmEmitter.cpp index 888ba115e2d9..80a8c56f6912 100644 --- a/llvm/lib/ObjectYAML/WasmEmitter.cpp +++ b/llvm/lib/ObjectYAML/WasmEmitter.cpp @@ -157,13 +157,24 @@ void WasmWriter::writeInitExpr(raw_ostream &OS, void WasmWriter::writeSectionContent(raw_ostream &OS, WasmYAML::DylinkSection &Section) { writeStringRef(Section.Name, OS); - encodeULEB128(Section.MemorySize, OS); - encodeULEB128(Section.MemoryAlignment, OS); - encodeULEB128(Section.TableSize, OS); - encodeULEB128(Section.TableAlignment, OS); - encodeULEB128(Section.Needed.size(), OS); - for (StringRef Needed : Section.Needed) - writeStringRef(Needed, OS); + + writeUint8(OS, wasm::WASM_DYLINK_MEM_INFO); + SubSectionWriter SubSection(OS); + raw_ostream &SubOS = SubSection.getStream(); + encodeULEB128(Section.MemorySize, SubOS); + encodeULEB128(Section.MemoryAlignment, SubOS); + encodeULEB128(Section.TableSize, SubOS); + encodeULEB128(Section.TableAlignment, SubOS); + SubSection.done(); + + if (Section.Needed.size()) { + writeUint8(OS, wasm::WASM_DYLINK_NEEDED); + raw_ostream &SubOS = SubSection.getStream(); + encodeULEB128(Section.Needed.size(), SubOS); + for (StringRef Needed : Section.Needed) + writeStringRef(Needed, SubOS); + SubSection.done(); + } } void WasmWriter::writeSectionContent(raw_ostream &OS, @@ -386,8 +397,8 @@ void WasmWriter::writeSectionContent(raw_ostream &OS, NumImportedGlobals++; break; case wasm::WASM_EXTERNAL_TAG: - writeUint32(OS, Import.TagImport.Attribute); - writeUint32(OS, Import.TagImport.SigIndex); + writeUint8(OS, 0); // Reserved 'attribute' field + encodeULEB128(Import.SigIndex, OS); NumImportedTags++; break; case wasm::WASM_EXTERNAL_MEMORY: @@ -451,16 +462,10 @@ void WasmWriter::writeSectionContent(raw_ostream &OS, void WasmWriter::writeSectionContent(raw_ostream &OS, WasmYAML::TagSection &Section) { - encodeULEB128(Section.Tags.size(), OS); - uint32_t ExpectedIndex = NumImportedTags; - for (auto &Tag : Section.Tags) { - if (Tag.Index != ExpectedIndex) { - reportError("unexpected tag index: " + Twine(Tag.Index)); - return; - } - ++ExpectedIndex; - encodeULEB128(Tag.Attribute, OS); - encodeULEB128(Tag.SigIndex, OS); + encodeULEB128(Section.TagTypes.size(), OS); + for (uint32_t TagType : Section.TagTypes) { + writeUint8(OS, 0); // Reserved 'attribute' field + encodeULEB128(TagType, OS); } } |
