diff options
Diffstat (limited to 'llvm/tools')
| -rw-r--r-- | llvm/tools/llvm-readobj/WasmDumper.cpp | 15 | ||||
| -rw-r--r-- | llvm/tools/obj2yaml/wasm2yaml.cpp | 17 | ||||
| -rw-r--r-- | llvm/tools/yaml2obj/yaml2wasm.cpp | 37 |
3 files changed, 51 insertions, 18 deletions
diff --git a/llvm/tools/llvm-readobj/WasmDumper.cpp b/llvm/tools/llvm-readobj/WasmDumper.cpp index 2d979958983..79d3db4e2d2 100644 --- a/llvm/tools/llvm-readobj/WasmDumper.cpp +++ b/llvm/tools/llvm-readobj/WasmDumper.cpp @@ -25,20 +25,19 @@ namespace { static const EnumEntry<unsigned> WasmSymbolTypes[] = { #define ENUM_ENTRY(X) \ { #X, wasm::WASM_SYMBOL_TYPE_##X } - ENUM_ENTRY(FUNCTION), - ENUM_ENTRY(DATA), - ENUM_ENTRY(GLOBAL), - ENUM_ENTRY(SECTION), + ENUM_ENTRY(FUNCTION), ENUM_ENTRY(DATA), ENUM_ENTRY(GLOBAL), + ENUM_ENTRY(SECTION), ENUM_ENTRY(EVENT), #undef ENUM_ENTRY }; static const EnumEntry<uint32_t> WasmSectionTypes[] = { #define ENUM_ENTRY(X) \ { #X, wasm::WASM_SEC_##X } - ENUM_ENTRY(CUSTOM), ENUM_ENTRY(TYPE), ENUM_ENTRY(IMPORT), - ENUM_ENTRY(FUNCTION), ENUM_ENTRY(TABLE), ENUM_ENTRY(MEMORY), - ENUM_ENTRY(GLOBAL), ENUM_ENTRY(EXPORT), ENUM_ENTRY(START), - ENUM_ENTRY(ELEM), ENUM_ENTRY(CODE), ENUM_ENTRY(DATA), + ENUM_ENTRY(CUSTOM), ENUM_ENTRY(TYPE), ENUM_ENTRY(IMPORT), + ENUM_ENTRY(FUNCTION), ENUM_ENTRY(TABLE), ENUM_ENTRY(MEMORY), + ENUM_ENTRY(GLOBAL), ENUM_ENTRY(EVENT), ENUM_ENTRY(EXPORT), + ENUM_ENTRY(START), ENUM_ENTRY(ELEM), ENUM_ENTRY(CODE), + ENUM_ENTRY(DATA), #undef ENUM_ENTRY }; diff --git a/llvm/tools/obj2yaml/wasm2yaml.cpp b/llvm/tools/obj2yaml/wasm2yaml.cpp index a1120a96571..8bbc9fb468c 100644 --- a/llvm/tools/obj2yaml/wasm2yaml.cpp +++ b/llvm/tools/obj2yaml/wasm2yaml.cpp @@ -107,6 +107,7 @@ WasmDumper::dumpCustomSection(const WasmSection &WasmSec) { break; case wasm::WASM_SYMBOL_TYPE_FUNCTION: case wasm::WASM_SYMBOL_TYPE_GLOBAL: + case wasm::WASM_SYMBOL_TYPE_EVENT: Info.ElementIndex = Symbol.ElementIndex; break; case wasm::WASM_SYMBOL_TYPE_SECTION: @@ -182,6 +183,10 @@ ErrorOr<WasmYAML::Object *> WasmDumper::dump() { Im.GlobalImport.Type = Import.Global.Type; Im.GlobalImport.Mutable = Import.Global.Mutable; break; + case wasm::WASM_EXTERNAL_EVENT: + Im.EventImport.Attribute = Import.Event.Attribute; + Im.EventImport.SigIndex = Import.Event.SigIndex; + break; case wasm::WASM_EXTERNAL_TABLE: Im.TableImport = make_table(Import.Table); break; @@ -231,6 +236,18 @@ ErrorOr<WasmYAML::Object *> WasmDumper::dump() { S = std::move(GlobalSec); break; } + case wasm::WASM_SEC_EVENT: { + auto EventSec = make_unique<WasmYAML::EventSection>(); + for (auto &Event : Obj.events()) { + WasmYAML::Event E; + E.Index = Event.Index; + E.Attribute = Event.Type.Attribute; + E.SigIndex = Event.Type.SigIndex; + EventSec->Events.push_back(E); + } + S = std::move(EventSec); + break; + } case wasm::WASM_SEC_START: { auto StartSec = make_unique<WasmYAML::StartSection>(); StartSec->StartFunction = Obj.startFunction(); diff --git a/llvm/tools/yaml2obj/yaml2wasm.cpp b/llvm/tools/yaml2obj/yaml2wasm.cpp index 2b1e256f8f6..4a9269d96a1 100644 --- a/llvm/tools/yaml2obj/yaml2wasm.cpp +++ b/llvm/tools/yaml2obj/yaml2wasm.cpp @@ -37,6 +37,7 @@ private: int writeSectionContent(raw_ostream &OS, WasmYAML::TableSection &Section); int writeSectionContent(raw_ostream &OS, WasmYAML::MemorySection &Section); int writeSectionContent(raw_ostream &OS, WasmYAML::GlobalSection &Section); + int writeSectionContent(raw_ostream &OS, WasmYAML::EventSection &Section); int writeSectionContent(raw_ostream &OS, WasmYAML::ExportSection &Section); int writeSectionContent(raw_ostream &OS, WasmYAML::StartSection &Section); int writeSectionContent(raw_ostream &OS, WasmYAML::ElemSection &Section); @@ -49,6 +50,7 @@ private: WasmYAML::Object &Obj; uint32_t NumImportedFunctions = 0; uint32_t NumImportedGlobals = 0; + uint32_t NumImportedEvents = 0; }; static int writeUint64(raw_ostream &OS, uint64_t Value) { @@ -152,6 +154,7 @@ int WasmWriter::writeSectionContent(raw_ostream &OS, switch (Info.Kind) { case wasm::WASM_SYMBOL_TYPE_FUNCTION: case wasm::WASM_SYMBOL_TYPE_GLOBAL: + case wasm::WASM_SYMBOL_TYPE_EVENT: encodeULEB128(Info.ElementIndex, SubSection.GetStream()); if ((Info.Flags & wasm::WASM_SYMBOL_UNDEFINED) == 0) writeStringRef(Info.Name, SubSection.GetStream()); @@ -292,6 +295,11 @@ int WasmWriter::writeSectionContent(raw_ostream &OS, writeUint8(OS, Import.GlobalImport.Mutable); NumImportedGlobals++; break; + case wasm::WASM_EXTERNAL_EVENT: + writeUint32(OS, Import.EventImport.Attribute); + writeUint32(OS, Import.EventImport.SigIndex); + NumImportedGlobals++; + break; case wasm::WASM_EXTERNAL_MEMORY: writeLimits(Import.Memory, OS); break; @@ -370,6 +378,22 @@ int WasmWriter::writeSectionContent(raw_ostream &OS, } int WasmWriter::writeSectionContent(raw_ostream &OS, + WasmYAML::EventSection &Section) { + encodeULEB128(Section.Events.size(), OS); + uint32_t ExpectedIndex = NumImportedEvents; + for (auto &Event : Section.Events) { + if (Event.Index != ExpectedIndex) { + errs() << "Unexpected event index: " << Event.Index << "\n"; + return 1; + } + ++ExpectedIndex; + encodeULEB128(Event.Attribute, OS); + encodeULEB128(Event.SigIndex, OS); + } + return 0; +} + +int WasmWriter::writeSectionContent(raw_ostream &OS, WasmYAML::ElemSection &Section) { encodeULEB128(Section.Segments.size(), OS); for (auto &Segment : Section.Segments) { @@ -474,17 +498,7 @@ int WasmWriter::writeWasm(raw_ostream &OS) { writeUint32(OS, Obj.Header.Version); // Write each section - uint32_t LastType = 0; for (const std::unique_ptr<WasmYAML::Section> &Sec : Obj.Sections) { - uint32_t Type = Sec->Type; - if (Type != wasm::WASM_SEC_CUSTOM) { - if (Type < LastType) { - errs() << "Out of order section type: " << Type << "\n"; - return 1; - } - LastType = Type; - } - encodeULEB128(Sec->Type, OS); std::string OutString; raw_string_ostream StringStream(OutString); @@ -509,6 +523,9 @@ int WasmWriter::writeWasm(raw_ostream &OS) { } else if (auto S = dyn_cast<WasmYAML::GlobalSection>(Sec.get())) { if (auto Err = writeSectionContent(StringStream, *S)) return Err; + } else if (auto S = dyn_cast<WasmYAML::EventSection>(Sec.get())) { + if (auto Err = writeSectionContent(StringStream, *S)) + return Err; } else if (auto S = dyn_cast<WasmYAML::ExportSection>(Sec.get())) { if (auto Err = writeSectionContent(StringStream, *S)) return Err; |

