diff options
Diffstat (limited to 'llvm/tools')
-rw-r--r-- | llvm/tools/obj2yaml/wasm2yaml.cpp | 23 | ||||
-rw-r--r-- | llvm/tools/yaml2obj/yaml2wasm.cpp | 27 |
2 files changed, 50 insertions, 0 deletions
diff --git a/llvm/tools/obj2yaml/wasm2yaml.cpp b/llvm/tools/obj2yaml/wasm2yaml.cpp index 7581bbef50a..0bd5642b760 100644 --- a/llvm/tools/obj2yaml/wasm2yaml.cpp +++ b/llvm/tools/obj2yaml/wasm2yaml.cpp @@ -133,6 +133,29 @@ WasmDumper::dumpCustomSection(const WasmSection &WasmSec) { } CustomSec = std::move(LinkingSec); + } else if (WasmSec.Name == "producers") { + std::unique_ptr<WasmYAML::ProducersSection> ProducersSec = + make_unique<WasmYAML::ProducersSection>(); + const llvm::wasm::WasmProducerInfo &Info = Obj.getProducerInfo(); + for (auto &E : Info.Languages) { + WasmYAML::ProducerEntry Producer; + Producer.Name = E.first; + Producer.Version = E.second; + ProducersSec->Languages.push_back(Producer); + } + for (auto &E : Info.Tools) { + WasmYAML::ProducerEntry Producer; + Producer.Name = E.first; + Producer.Version = E.second; + ProducersSec->Tools.push_back(Producer); + } + for (auto &E : Info.SDKs) { + WasmYAML::ProducerEntry Producer; + Producer.Name = E.first; + Producer.Version = E.second; + ProducersSec->SDKs.push_back(Producer); + } + CustomSec = std::move(ProducersSec); } else { CustomSec = make_unique<WasmYAML::CustomSection>(WasmSec.Name); } diff --git a/llvm/tools/yaml2obj/yaml2wasm.cpp b/llvm/tools/yaml2obj/yaml2wasm.cpp index 2d3e3b71f08..242bc6b6442 100644 --- a/llvm/tools/yaml2obj/yaml2wasm.cpp +++ b/llvm/tools/yaml2obj/yaml2wasm.cpp @@ -49,6 +49,7 @@ private: int writeSectionContent(raw_ostream &OS, WasmYAML::DylinkSection &Section); int writeSectionContent(raw_ostream &OS, WasmYAML::NameSection &Section); int writeSectionContent(raw_ostream &OS, WasmYAML::LinkingSection &Section); + int writeSectionContent(raw_ostream &OS, WasmYAML::ProducersSection &Section); WasmYAML::Object &Obj; uint32_t NumImportedFunctions = 0; uint32_t NumImportedGlobals = 0; @@ -256,6 +257,29 @@ int WasmWriter::writeSectionContent(raw_ostream &OS, } int WasmWriter::writeSectionContent(raw_ostream &OS, + WasmYAML::ProducersSection &Section) { + writeStringRef(Section.Name, OS); + int Fields = int(!Section.Languages.empty()) + int(!Section.Tools.empty()) + + int(!Section.SDKs.empty()); + if (Fields == 0) + return 0; + encodeULEB128(Fields, OS); + for (auto &Field : {std::make_pair(StringRef("language"), &Section.Languages), + std::make_pair(StringRef("processed-by"), &Section.Tools), + std::make_pair(StringRef("sdk"), &Section.SDKs)}) { + if (Field.second->empty()) + continue; + writeStringRef(Field.first, OS); + encodeULEB128(Field.second->size(), OS); + for (auto &Entry : *Field.second) { + writeStringRef(Entry.Name, OS); + writeStringRef(Entry.Version, OS); + } + } + return 0; +} + +int WasmWriter::writeSectionContent(raw_ostream &OS, WasmYAML::CustomSection &Section) { if (auto S = dyn_cast<WasmYAML::DylinkSection>(&Section)) { if (auto Err = writeSectionContent(OS, *S)) @@ -266,6 +290,9 @@ int WasmWriter::writeSectionContent(raw_ostream &OS, } else if (auto S = dyn_cast<WasmYAML::LinkingSection>(&Section)) { if (auto Err = writeSectionContent(OS, *S)) return Err; + } else if (auto S = dyn_cast<WasmYAML::ProducersSection>(&Section)) { + if (auto Err = writeSectionContent(OS, *S)) + return Err; } else { writeStringRef(Section.Name, OS); Section.Payload.writeAsBinary(OS); |