Derek Schuff | 349a48f | 2017-03-30 19:44:09 +0000 | [diff] [blame] | 1 | //===- yaml2wasm - Convert YAML to a Wasm object file --------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | /// |
| 10 | /// \file |
Adrian Prantl | 26b584c | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 11 | /// The Wasm component of yaml2obj. |
Derek Schuff | 349a48f | 2017-03-30 19:44:09 +0000 | [diff] [blame] | 12 | /// |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | // |
Sam Clegg | d578479 | 2018-02-23 05:08:34 +0000 | [diff] [blame] | 15 | |
Heejin Ahn | e2f3e50 | 2018-12-15 00:58:12 +0000 | [diff] [blame] | 16 | #include "llvm/Object/Wasm.h" |
Derek Schuff | 349a48f | 2017-03-30 19:44:09 +0000 | [diff] [blame] | 17 | #include "llvm/ObjectYAML/ObjectYAML.h" |
| 18 | #include "llvm/Support/Endian.h" |
| 19 | #include "llvm/Support/LEB128.h" |
| 20 | |
| 21 | using namespace llvm; |
| 22 | |
| 23 | /// This parses a yaml stream that represents a Wasm object file. |
| 24 | /// See docs/yaml2obj for the yaml scheema. |
| 25 | class WasmWriter { |
| 26 | public: |
| 27 | WasmWriter(WasmYAML::Object &Obj) : Obj(Obj) {} |
| 28 | int writeWasm(raw_ostream &OS); |
Sam Clegg | 1e975c1 | 2017-06-20 04:04:59 +0000 | [diff] [blame] | 29 | |
| 30 | private: |
Sam Clegg | 194a4e0 | 2018-04-24 18:11:36 +0000 | [diff] [blame] | 31 | int writeRelocSection(raw_ostream &OS, WasmYAML::Section &Sec, |
| 32 | uint32_t SectionIndex); |
Sam Clegg | afe8111 | 2017-05-05 18:12:34 +0000 | [diff] [blame] | 33 | |
Derek Schuff | 349a48f | 2017-03-30 19:44:09 +0000 | [diff] [blame] | 34 | int writeSectionContent(raw_ostream &OS, WasmYAML::CustomSection &Section); |
| 35 | int writeSectionContent(raw_ostream &OS, WasmYAML::TypeSection &Section); |
| 36 | int writeSectionContent(raw_ostream &OS, WasmYAML::ImportSection &Section); |
| 37 | int writeSectionContent(raw_ostream &OS, WasmYAML::FunctionSection &Section); |
| 38 | int writeSectionContent(raw_ostream &OS, WasmYAML::TableSection &Section); |
| 39 | int writeSectionContent(raw_ostream &OS, WasmYAML::MemorySection &Section); |
| 40 | int writeSectionContent(raw_ostream &OS, WasmYAML::GlobalSection &Section); |
Heejin Ahn | 8bcdd04 | 2018-11-14 02:46:21 +0000 | [diff] [blame] | 41 | int writeSectionContent(raw_ostream &OS, WasmYAML::EventSection &Section); |
Derek Schuff | 349a48f | 2017-03-30 19:44:09 +0000 | [diff] [blame] | 42 | int writeSectionContent(raw_ostream &OS, WasmYAML::ExportSection &Section); |
| 43 | int writeSectionContent(raw_ostream &OS, WasmYAML::StartSection &Section); |
| 44 | int writeSectionContent(raw_ostream &OS, WasmYAML::ElemSection &Section); |
| 45 | int writeSectionContent(raw_ostream &OS, WasmYAML::CodeSection &Section); |
| 46 | int writeSectionContent(raw_ostream &OS, WasmYAML::DataSection &Section); |
| 47 | |
Sam Clegg | 1e975c1 | 2017-06-20 04:04:59 +0000 | [diff] [blame] | 48 | // Custom section types |
Sam Clegg | 45c215a | 2018-11-14 18:36:24 +0000 | [diff] [blame] | 49 | int writeSectionContent(raw_ostream &OS, WasmYAML::DylinkSection &Section); |
Sam Clegg | 1e975c1 | 2017-06-20 04:04:59 +0000 | [diff] [blame] | 50 | int writeSectionContent(raw_ostream &OS, WasmYAML::NameSection &Section); |
| 51 | int writeSectionContent(raw_ostream &OS, WasmYAML::LinkingSection &Section); |
Derek Schuff | 349a48f | 2017-03-30 19:44:09 +0000 | [diff] [blame] | 52 | WasmYAML::Object &Obj; |
Sam Clegg | 6b54fc3 | 2018-01-09 21:38:53 +0000 | [diff] [blame] | 53 | uint32_t NumImportedFunctions = 0; |
| 54 | uint32_t NumImportedGlobals = 0; |
Heejin Ahn | 8bcdd04 | 2018-11-14 02:46:21 +0000 | [diff] [blame] | 55 | uint32_t NumImportedEvents = 0; |
Derek Schuff | 349a48f | 2017-03-30 19:44:09 +0000 | [diff] [blame] | 56 | }; |
| 57 | |
| 58 | static int writeUint64(raw_ostream &OS, uint64_t Value) { |
| 59 | char Data[sizeof(Value)]; |
| 60 | support::endian::write64le(Data, Value); |
| 61 | OS.write(Data, sizeof(Data)); |
| 62 | return 0; |
| 63 | } |
| 64 | |
| 65 | static int writeUint32(raw_ostream &OS, uint32_t Value) { |
| 66 | char Data[sizeof(Value)]; |
| 67 | support::endian::write32le(Data, Value); |
| 68 | OS.write(Data, sizeof(Data)); |
| 69 | return 0; |
| 70 | } |
| 71 | |
| 72 | static int writeUint8(raw_ostream &OS, uint8_t Value) { |
| 73 | char Data[sizeof(Value)]; |
| 74 | memcpy(Data, &Value, sizeof(Data)); |
| 75 | OS.write(Data, sizeof(Data)); |
| 76 | return 0; |
| 77 | } |
| 78 | |
Sam Clegg | afe8111 | 2017-05-05 18:12:34 +0000 | [diff] [blame] | 79 | static int writeStringRef(const StringRef &Str, raw_ostream &OS) { |
Derek Schuff | 349a48f | 2017-03-30 19:44:09 +0000 | [diff] [blame] | 80 | encodeULEB128(Str.size(), OS); |
| 81 | OS << Str; |
| 82 | return 0; |
| 83 | } |
| 84 | |
Sam Clegg | afe8111 | 2017-05-05 18:12:34 +0000 | [diff] [blame] | 85 | static int writeLimits(const WasmYAML::Limits &Lim, raw_ostream &OS) { |
Sam Clegg | 9f474de | 2018-03-01 18:06:21 +0000 | [diff] [blame] | 86 | writeUint8(OS, Lim.Flags); |
Derek Schuff | 349a48f | 2017-03-30 19:44:09 +0000 | [diff] [blame] | 87 | encodeULEB128(Lim.Initial, OS); |
| 88 | if (Lim.Flags & wasm::WASM_LIMITS_FLAG_HAS_MAX) |
| 89 | encodeULEB128(Lim.Maximum, OS); |
| 90 | return 0; |
| 91 | } |
| 92 | |
Sam Clegg | afe8111 | 2017-05-05 18:12:34 +0000 | [diff] [blame] | 93 | static int writeInitExpr(const wasm::WasmInitExpr &InitExpr, raw_ostream &OS) { |
Derek Schuff | 349a48f | 2017-03-30 19:44:09 +0000 | [diff] [blame] | 94 | writeUint8(OS, InitExpr.Opcode); |
| 95 | switch (InitExpr.Opcode) { |
| 96 | case wasm::WASM_OPCODE_I32_CONST: |
| 97 | encodeSLEB128(InitExpr.Value.Int32, OS); |
| 98 | break; |
| 99 | case wasm::WASM_OPCODE_I64_CONST: |
| 100 | encodeSLEB128(InitExpr.Value.Int64, OS); |
| 101 | break; |
| 102 | case wasm::WASM_OPCODE_F32_CONST: |
| 103 | writeUint32(OS, InitExpr.Value.Float32); |
| 104 | break; |
| 105 | case wasm::WASM_OPCODE_F64_CONST: |
| 106 | writeUint64(OS, InitExpr.Value.Float64); |
| 107 | break; |
Thomas Lively | 37a984b | 2019-01-08 06:25:55 +0000 | [diff] [blame] | 108 | case wasm::WASM_OPCODE_GLOBAL_GET: |
Derek Schuff | 349a48f | 2017-03-30 19:44:09 +0000 | [diff] [blame] | 109 | encodeULEB128(InitExpr.Value.Global, OS); |
| 110 | break; |
| 111 | default: |
Sam Clegg | 6b54fc3 | 2018-01-09 21:38:53 +0000 | [diff] [blame] | 112 | errs() << "Unknown opcode in init_expr: " << InitExpr.Opcode << "\n"; |
Derek Schuff | 349a48f | 2017-03-30 19:44:09 +0000 | [diff] [blame] | 113 | return 1; |
| 114 | } |
| 115 | writeUint8(OS, wasm::WASM_OPCODE_END); |
| 116 | return 0; |
| 117 | } |
| 118 | |
Sam Clegg | 49ab5d5 | 2017-06-27 20:27:59 +0000 | [diff] [blame] | 119 | class SubSectionWriter { |
| 120 | raw_ostream &OS; |
| 121 | std::string OutString; |
| 122 | raw_string_ostream StringStream; |
Sam Clegg | 1e975c1 | 2017-06-20 04:04:59 +0000 | [diff] [blame] | 123 | |
Sam Clegg | 49ab5d5 | 2017-06-27 20:27:59 +0000 | [diff] [blame] | 124 | public: |
| 125 | SubSectionWriter(raw_ostream &OS) : OS(OS), StringStream(OutString) {} |
Sam Clegg | 1e975c1 | 2017-06-20 04:04:59 +0000 | [diff] [blame] | 126 | |
Sam Clegg | 49ab5d5 | 2017-06-27 20:27:59 +0000 | [diff] [blame] | 127 | void Done() { |
Sam Clegg | 1e975c1 | 2017-06-20 04:04:59 +0000 | [diff] [blame] | 128 | StringStream.flush(); |
| 129 | encodeULEB128(OutString.size(), OS); |
| 130 | OS << OutString; |
Sam Clegg | 49ab5d5 | 2017-06-27 20:27:59 +0000 | [diff] [blame] | 131 | OutString.clear(); |
| 132 | } |
| 133 | |
Heejin Ahn | 581d231 | 2018-09-05 01:27:38 +0000 | [diff] [blame] | 134 | raw_ostream &GetStream() { return StringStream; } |
Sam Clegg | 49ab5d5 | 2017-06-27 20:27:59 +0000 | [diff] [blame] | 135 | }; |
| 136 | |
Heejin Ahn | 581d231 | 2018-09-05 01:27:38 +0000 | [diff] [blame] | 137 | int WasmWriter::writeSectionContent(raw_ostream &OS, |
Sam Clegg | 45c215a | 2018-11-14 18:36:24 +0000 | [diff] [blame] | 138 | WasmYAML::DylinkSection &Section) { |
| 139 | writeStringRef(Section.Name, OS); |
| 140 | encodeULEB128(Section.MemorySize, OS); |
| 141 | encodeULEB128(Section.MemoryAlignment, OS); |
| 142 | encodeULEB128(Section.TableSize, OS); |
| 143 | encodeULEB128(Section.TableAlignment, OS); |
Sam Clegg | 559201d | 2018-12-12 23:40:58 +0000 | [diff] [blame] | 144 | encodeULEB128(Section.Needed.size(), OS); |
| 145 | for (StringRef Needed : Section.Needed) { |
| 146 | writeStringRef(Needed, OS); |
| 147 | } |
Sam Clegg | 45c215a | 2018-11-14 18:36:24 +0000 | [diff] [blame] | 148 | return 0; |
| 149 | } |
| 150 | |
| 151 | int WasmWriter::writeSectionContent(raw_ostream &OS, |
Heejin Ahn | 581d231 | 2018-09-05 01:27:38 +0000 | [diff] [blame] | 152 | WasmYAML::LinkingSection &Section) { |
Sam Clegg | 49ab5d5 | 2017-06-27 20:27:59 +0000 | [diff] [blame] | 153 | writeStringRef(Section.Name, OS); |
Sam Clegg | 14598cb | 2018-04-26 18:15:32 +0000 | [diff] [blame] | 154 | encodeULEB128(Section.Version, OS); |
Sam Clegg | 49ab5d5 | 2017-06-27 20:27:59 +0000 | [diff] [blame] | 155 | |
| 156 | SubSectionWriter SubSection(OS); |
| 157 | |
Sam Clegg | d578479 | 2018-02-23 05:08:34 +0000 | [diff] [blame] | 158 | // SYMBOL_TABLE subsection |
| 159 | if (Section.SymbolTable.size()) { |
Sam Clegg | 9f474de | 2018-03-01 18:06:21 +0000 | [diff] [blame] | 160 | writeUint8(OS, wasm::WASM_SYMBOL_TABLE); |
Sam Clegg | 49ab5d5 | 2017-06-27 20:27:59 +0000 | [diff] [blame] | 161 | |
Sam Clegg | d578479 | 2018-02-23 05:08:34 +0000 | [diff] [blame] | 162 | encodeULEB128(Section.SymbolTable.size(), SubSection.GetStream()); |
Benjamin Kramer | f998d9c | 2018-02-23 12:20:18 +0000 | [diff] [blame] | 163 | #ifndef NDEBUG |
Sam Clegg | d578479 | 2018-02-23 05:08:34 +0000 | [diff] [blame] | 164 | uint32_t SymbolIndex = 0; |
| 165 | #endif |
| 166 | for (const WasmYAML::SymbolInfo &Info : Section.SymbolTable) { |
| 167 | assert(Info.Index == SymbolIndex++); |
Sam Clegg | 9f474de | 2018-03-01 18:06:21 +0000 | [diff] [blame] | 168 | writeUint8(SubSection.GetStream(), Info.Kind); |
Sam Clegg | 49ab5d5 | 2017-06-27 20:27:59 +0000 | [diff] [blame] | 169 | encodeULEB128(Info.Flags, SubSection.GetStream()); |
Sam Clegg | d578479 | 2018-02-23 05:08:34 +0000 | [diff] [blame] | 170 | switch (Info.Kind) { |
| 171 | case wasm::WASM_SYMBOL_TYPE_FUNCTION: |
| 172 | case wasm::WASM_SYMBOL_TYPE_GLOBAL: |
Heejin Ahn | 8bcdd04 | 2018-11-14 02:46:21 +0000 | [diff] [blame] | 173 | case wasm::WASM_SYMBOL_TYPE_EVENT: |
Sam Clegg | d578479 | 2018-02-23 05:08:34 +0000 | [diff] [blame] | 174 | encodeULEB128(Info.ElementIndex, SubSection.GetStream()); |
Hans Wennborg | 831b204 | 2019-02-12 12:27:08 +0000 | [diff] [blame] | 175 | if ((Info.Flags & wasm::WASM_SYMBOL_UNDEFINED) == 0 || |
| 176 | (Info.Flags & wasm::WASM_SYMBOL_EXPLICIT_NAME) != 0) |
Sam Clegg | d578479 | 2018-02-23 05:08:34 +0000 | [diff] [blame] | 177 | writeStringRef(Info.Name, SubSection.GetStream()); |
| 178 | break; |
| 179 | case wasm::WASM_SYMBOL_TYPE_DATA: |
| 180 | writeStringRef(Info.Name, SubSection.GetStream()); |
| 181 | if ((Info.Flags & wasm::WASM_SYMBOL_UNDEFINED) == 0) { |
| 182 | encodeULEB128(Info.DataRef.Segment, SubSection.GetStream()); |
| 183 | encodeULEB128(Info.DataRef.Offset, SubSection.GetStream()); |
| 184 | encodeULEB128(Info.DataRef.Size, SubSection.GetStream()); |
| 185 | } |
| 186 | break; |
Sam Clegg | db15975 | 2018-04-26 19:27:28 +0000 | [diff] [blame] | 187 | case wasm::WASM_SYMBOL_TYPE_SECTION: |
| 188 | encodeULEB128(Info.ElementIndex, SubSection.GetStream()); |
| 189 | break; |
Sam Clegg | d578479 | 2018-02-23 05:08:34 +0000 | [diff] [blame] | 190 | default: |
| 191 | llvm_unreachable("unexpected kind"); |
| 192 | } |
Sam Clegg | 49ab5d5 | 2017-06-27 20:27:59 +0000 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | SubSection.Done(); |
Sam Clegg | 1e975c1 | 2017-06-20 04:04:59 +0000 | [diff] [blame] | 196 | } |
Sam Clegg | 81e3824 | 2017-09-20 19:03:35 +0000 | [diff] [blame] | 197 | |
| 198 | // SEGMENT_NAMES subsection |
Sam Clegg | e286417 | 2017-09-29 16:50:08 +0000 | [diff] [blame] | 199 | if (Section.SegmentInfos.size()) { |
Sam Clegg | 9f474de | 2018-03-01 18:06:21 +0000 | [diff] [blame] | 200 | writeUint8(OS, wasm::WASM_SEGMENT_INFO); |
Sam Clegg | e286417 | 2017-09-29 16:50:08 +0000 | [diff] [blame] | 201 | encodeULEB128(Section.SegmentInfos.size(), SubSection.GetStream()); |
| 202 | for (const WasmYAML::SegmentInfo &SegmentInfo : Section.SegmentInfos) { |
Sam Clegg | e286417 | 2017-09-29 16:50:08 +0000 | [diff] [blame] | 203 | writeStringRef(SegmentInfo.Name, SubSection.GetStream()); |
| 204 | encodeULEB128(SegmentInfo.Alignment, SubSection.GetStream()); |
| 205 | encodeULEB128(SegmentInfo.Flags, SubSection.GetStream()); |
Sam Clegg | 81e3824 | 2017-09-20 19:03:35 +0000 | [diff] [blame] | 206 | } |
| 207 | SubSection.Done(); |
| 208 | } |
Sam Clegg | e1acb56 | 2017-12-14 21:10:03 +0000 | [diff] [blame] | 209 | |
| 210 | // INIT_FUNCS subsection |
| 211 | if (Section.InitFunctions.size()) { |
Sam Clegg | 9f474de | 2018-03-01 18:06:21 +0000 | [diff] [blame] | 212 | writeUint8(OS, wasm::WASM_INIT_FUNCS); |
Sam Clegg | e1acb56 | 2017-12-14 21:10:03 +0000 | [diff] [blame] | 213 | encodeULEB128(Section.InitFunctions.size(), SubSection.GetStream()); |
| 214 | for (const WasmYAML::InitFunction &Func : Section.InitFunctions) { |
| 215 | encodeULEB128(Func.Priority, SubSection.GetStream()); |
Sam Clegg | d578479 | 2018-02-23 05:08:34 +0000 | [diff] [blame] | 216 | encodeULEB128(Func.Symbol, SubSection.GetStream()); |
Sam Clegg | e1acb56 | 2017-12-14 21:10:03 +0000 | [diff] [blame] | 217 | } |
| 218 | SubSection.Done(); |
| 219 | } |
Sam Clegg | e92250a | 2018-01-09 23:43:14 +0000 | [diff] [blame] | 220 | |
| 221 | // COMDAT_INFO subsection |
| 222 | if (Section.Comdats.size()) { |
Sam Clegg | 9f474de | 2018-03-01 18:06:21 +0000 | [diff] [blame] | 223 | writeUint8(OS, wasm::WASM_COMDAT_INFO); |
Sam Clegg | e92250a | 2018-01-09 23:43:14 +0000 | [diff] [blame] | 224 | encodeULEB128(Section.Comdats.size(), SubSection.GetStream()); |
| 225 | for (const auto &C : Section.Comdats) { |
| 226 | writeStringRef(C.Name, SubSection.GetStream()); |
| 227 | encodeULEB128(0, SubSection.GetStream()); // flags for future use |
| 228 | encodeULEB128(C.Entries.size(), SubSection.GetStream()); |
| 229 | for (const WasmYAML::ComdatEntry &Entry : C.Entries) { |
Sam Clegg | 9f474de | 2018-03-01 18:06:21 +0000 | [diff] [blame] | 230 | writeUint8(SubSection.GetStream(), Entry.Kind); |
Sam Clegg | e92250a | 2018-01-09 23:43:14 +0000 | [diff] [blame] | 231 | encodeULEB128(Entry.Index, SubSection.GetStream()); |
| 232 | } |
| 233 | } |
| 234 | SubSection.Done(); |
| 235 | } |
| 236 | |
Sam Clegg | 1e975c1 | 2017-06-20 04:04:59 +0000 | [diff] [blame] | 237 | return 0; |
| 238 | } |
| 239 | |
Heejin Ahn | 581d231 | 2018-09-05 01:27:38 +0000 | [diff] [blame] | 240 | int WasmWriter::writeSectionContent(raw_ostream &OS, |
| 241 | WasmYAML::NameSection &Section) { |
Sam Clegg | afe8111 | 2017-05-05 18:12:34 +0000 | [diff] [blame] | 242 | writeStringRef(Section.Name, OS); |
| 243 | if (Section.FunctionNames.size()) { |
Sam Clegg | 9f474de | 2018-03-01 18:06:21 +0000 | [diff] [blame] | 244 | writeUint8(OS, wasm::WASM_NAMES_FUNCTION); |
Sam Clegg | afe8111 | 2017-05-05 18:12:34 +0000 | [diff] [blame] | 245 | |
Sam Clegg | 49ab5d5 | 2017-06-27 20:27:59 +0000 | [diff] [blame] | 246 | SubSectionWriter SubSection(OS); |
| 247 | |
| 248 | encodeULEB128(Section.FunctionNames.size(), SubSection.GetStream()); |
Sam Clegg | afe8111 | 2017-05-05 18:12:34 +0000 | [diff] [blame] | 249 | for (const WasmYAML::NameEntry &NameEntry : Section.FunctionNames) { |
Sam Clegg | 49ab5d5 | 2017-06-27 20:27:59 +0000 | [diff] [blame] | 250 | encodeULEB128(NameEntry.Index, SubSection.GetStream()); |
| 251 | writeStringRef(NameEntry.Name, SubSection.GetStream()); |
Sam Clegg | afe8111 | 2017-05-05 18:12:34 +0000 | [diff] [blame] | 252 | } |
| 253 | |
Sam Clegg | 49ab5d5 | 2017-06-27 20:27:59 +0000 | [diff] [blame] | 254 | SubSection.Done(); |
Sam Clegg | afe8111 | 2017-05-05 18:12:34 +0000 | [diff] [blame] | 255 | } |
| 256 | return 0; |
| 257 | } |
| 258 | |
Derek Schuff | 349a48f | 2017-03-30 19:44:09 +0000 | [diff] [blame] | 259 | int WasmWriter::writeSectionContent(raw_ostream &OS, |
| 260 | WasmYAML::CustomSection &Section) { |
Sam Clegg | 45c215a | 2018-11-14 18:36:24 +0000 | [diff] [blame] | 261 | if (auto S = dyn_cast<WasmYAML::DylinkSection>(&Section)) { |
| 262 | if (auto Err = writeSectionContent(OS, *S)) |
| 263 | return Err; |
| 264 | } else if (auto S = dyn_cast<WasmYAML::NameSection>(&Section)) { |
Sam Clegg | 1e975c1 | 2017-06-20 04:04:59 +0000 | [diff] [blame] | 265 | if (auto Err = writeSectionContent(OS, *S)) |
| 266 | return Err; |
| 267 | } else if (auto S = dyn_cast<WasmYAML::LinkingSection>(&Section)) { |
| 268 | if (auto Err = writeSectionContent(OS, *S)) |
| 269 | return Err; |
Sam Clegg | afe8111 | 2017-05-05 18:12:34 +0000 | [diff] [blame] | 270 | } else { |
Sam Clegg | b068ce9 | 2018-04-12 20:31:12 +0000 | [diff] [blame] | 271 | writeStringRef(Section.Name, OS); |
Sam Clegg | afe8111 | 2017-05-05 18:12:34 +0000 | [diff] [blame] | 272 | Section.Payload.writeAsBinary(OS); |
| 273 | } |
Derek Schuff | 349a48f | 2017-03-30 19:44:09 +0000 | [diff] [blame] | 274 | return 0; |
| 275 | } |
| 276 | |
| 277 | int WasmWriter::writeSectionContent(raw_ostream &OS, |
| 278 | WasmYAML::TypeSection &Section) { |
| 279 | encodeULEB128(Section.Signatures.size(), OS); |
Sam Clegg | 6b54fc3 | 2018-01-09 21:38:53 +0000 | [diff] [blame] | 280 | uint32_t ExpectedIndex = 0; |
Sam Clegg | afe8111 | 2017-05-05 18:12:34 +0000 | [diff] [blame] | 281 | for (const WasmYAML::Signature &Sig : Section.Signatures) { |
Sam Clegg | 6b54fc3 | 2018-01-09 21:38:53 +0000 | [diff] [blame] | 282 | if (Sig.Index != ExpectedIndex) { |
| 283 | errs() << "Unexpected type index: " << Sig.Index << "\n"; |
| 284 | return 1; |
| 285 | } |
| 286 | ++ExpectedIndex; |
Sam Clegg | 9f474de | 2018-03-01 18:06:21 +0000 | [diff] [blame] | 287 | writeUint8(OS, Sig.Form); |
Derek Schuff | 349a48f | 2017-03-30 19:44:09 +0000 | [diff] [blame] | 288 | encodeULEB128(Sig.ParamTypes.size(), OS); |
| 289 | for (auto ParamType : Sig.ParamTypes) |
Sam Clegg | 9f474de | 2018-03-01 18:06:21 +0000 | [diff] [blame] | 290 | writeUint8(OS, ParamType); |
Derek Schuff | 349a48f | 2017-03-30 19:44:09 +0000 | [diff] [blame] | 291 | if (Sig.ReturnType == wasm::WASM_TYPE_NORESULT) { |
Sam Clegg | 9f474de | 2018-03-01 18:06:21 +0000 | [diff] [blame] | 292 | encodeULEB128(0, OS); |
Derek Schuff | 349a48f | 2017-03-30 19:44:09 +0000 | [diff] [blame] | 293 | } else { |
| 294 | encodeULEB128(1, OS); |
Sam Clegg | 9f474de | 2018-03-01 18:06:21 +0000 | [diff] [blame] | 295 | writeUint8(OS, Sig.ReturnType); |
Derek Schuff | 349a48f | 2017-03-30 19:44:09 +0000 | [diff] [blame] | 296 | } |
| 297 | } |
| 298 | return 0; |
| 299 | } |
| 300 | |
| 301 | int WasmWriter::writeSectionContent(raw_ostream &OS, |
| 302 | WasmYAML::ImportSection &Section) { |
| 303 | encodeULEB128(Section.Imports.size(), OS); |
Sam Clegg | afe8111 | 2017-05-05 18:12:34 +0000 | [diff] [blame] | 304 | for (const WasmYAML::Import &Import : Section.Imports) { |
Derek Schuff | 349a48f | 2017-03-30 19:44:09 +0000 | [diff] [blame] | 305 | writeStringRef(Import.Module, OS); |
| 306 | writeStringRef(Import.Field, OS); |
Sam Clegg | 9f474de | 2018-03-01 18:06:21 +0000 | [diff] [blame] | 307 | writeUint8(OS, Import.Kind); |
Derek Schuff | 349a48f | 2017-03-30 19:44:09 +0000 | [diff] [blame] | 308 | switch (Import.Kind) { |
| 309 | case wasm::WASM_EXTERNAL_FUNCTION: |
| 310 | encodeULEB128(Import.SigIndex, OS); |
Sam Clegg | 6b54fc3 | 2018-01-09 21:38:53 +0000 | [diff] [blame] | 311 | NumImportedFunctions++; |
Derek Schuff | 349a48f | 2017-03-30 19:44:09 +0000 | [diff] [blame] | 312 | break; |
| 313 | case wasm::WASM_EXTERNAL_GLOBAL: |
Sam Clegg | 9f474de | 2018-03-01 18:06:21 +0000 | [diff] [blame] | 314 | writeUint8(OS, Import.GlobalImport.Type); |
Sam Clegg | bde17ff | 2017-05-10 00:14:04 +0000 | [diff] [blame] | 315 | writeUint8(OS, Import.GlobalImport.Mutable); |
Sam Clegg | 6b54fc3 | 2018-01-09 21:38:53 +0000 | [diff] [blame] | 316 | NumImportedGlobals++; |
Sam Clegg | 65e284e | 2017-05-09 23:48:41 +0000 | [diff] [blame] | 317 | break; |
Heejin Ahn | 8bcdd04 | 2018-11-14 02:46:21 +0000 | [diff] [blame] | 318 | case wasm::WASM_EXTERNAL_EVENT: |
| 319 | writeUint32(OS, Import.EventImport.Attribute); |
| 320 | writeUint32(OS, Import.EventImport.SigIndex); |
| 321 | NumImportedGlobals++; |
| 322 | break; |
Sam Clegg | 65e284e | 2017-05-09 23:48:41 +0000 | [diff] [blame] | 323 | case wasm::WASM_EXTERNAL_MEMORY: |
| 324 | writeLimits(Import.Memory, OS); |
| 325 | break; |
| 326 | case wasm::WASM_EXTERNAL_TABLE: |
Heejin Ahn | 581d231 | 2018-09-05 01:27:38 +0000 | [diff] [blame] | 327 | writeUint8(OS, Import.TableImport.ElemType); |
Sam Clegg | bde17ff | 2017-05-10 00:14:04 +0000 | [diff] [blame] | 328 | writeLimits(Import.TableImport.TableLimits, OS); |
Derek Schuff | 349a48f | 2017-03-30 19:44:09 +0000 | [diff] [blame] | 329 | break; |
| 330 | default: |
Sam Clegg | 6b54fc3 | 2018-01-09 21:38:53 +0000 | [diff] [blame] | 331 | errs() << "Unknown import type: " << Import.Kind << "\n"; |
Derek Schuff | 349a48f | 2017-03-30 19:44:09 +0000 | [diff] [blame] | 332 | return 1; |
| 333 | } |
| 334 | } |
| 335 | return 0; |
| 336 | } |
| 337 | |
| 338 | int WasmWriter::writeSectionContent(raw_ostream &OS, |
| 339 | WasmYAML::FunctionSection &Section) { |
| 340 | encodeULEB128(Section.FunctionTypes.size(), OS); |
| 341 | for (uint32_t FuncType : Section.FunctionTypes) { |
| 342 | encodeULEB128(FuncType, OS); |
| 343 | } |
| 344 | return 0; |
| 345 | } |
| 346 | |
| 347 | int WasmWriter::writeSectionContent(raw_ostream &OS, |
| 348 | WasmYAML::ExportSection &Section) { |
| 349 | encodeULEB128(Section.Exports.size(), OS); |
Sam Clegg | afe8111 | 2017-05-05 18:12:34 +0000 | [diff] [blame] | 350 | for (const WasmYAML::Export &Export : Section.Exports) { |
Derek Schuff | 349a48f | 2017-03-30 19:44:09 +0000 | [diff] [blame] | 351 | writeStringRef(Export.Name, OS); |
Sam Clegg | 9f474de | 2018-03-01 18:06:21 +0000 | [diff] [blame] | 352 | writeUint8(OS, Export.Kind); |
Derek Schuff | 349a48f | 2017-03-30 19:44:09 +0000 | [diff] [blame] | 353 | encodeULEB128(Export.Index, OS); |
| 354 | } |
| 355 | return 0; |
| 356 | } |
| 357 | |
| 358 | int WasmWriter::writeSectionContent(raw_ostream &OS, |
| 359 | WasmYAML::StartSection &Section) { |
| 360 | encodeULEB128(Section.StartFunction, OS); |
| 361 | return 0; |
| 362 | } |
| 363 | |
| 364 | int WasmWriter::writeSectionContent(raw_ostream &OS, |
| 365 | WasmYAML::TableSection &Section) { |
| 366 | encodeULEB128(Section.Tables.size(), OS); |
| 367 | for (auto &Table : Section.Tables) { |
Sam Clegg | 9f474de | 2018-03-01 18:06:21 +0000 | [diff] [blame] | 368 | writeUint8(OS, Table.ElemType); |
Derek Schuff | 349a48f | 2017-03-30 19:44:09 +0000 | [diff] [blame] | 369 | writeLimits(Table.TableLimits, OS); |
| 370 | } |
| 371 | return 0; |
| 372 | } |
| 373 | |
| 374 | int WasmWriter::writeSectionContent(raw_ostream &OS, |
| 375 | WasmYAML::MemorySection &Section) { |
| 376 | encodeULEB128(Section.Memories.size(), OS); |
Sam Clegg | afe8111 | 2017-05-05 18:12:34 +0000 | [diff] [blame] | 377 | for (const WasmYAML::Limits &Mem : Section.Memories) { |
Derek Schuff | 349a48f | 2017-03-30 19:44:09 +0000 | [diff] [blame] | 378 | writeLimits(Mem, OS); |
| 379 | } |
| 380 | return 0; |
| 381 | } |
| 382 | |
| 383 | int WasmWriter::writeSectionContent(raw_ostream &OS, |
| 384 | WasmYAML::GlobalSection &Section) { |
| 385 | encodeULEB128(Section.Globals.size(), OS); |
Sam Clegg | 6b54fc3 | 2018-01-09 21:38:53 +0000 | [diff] [blame] | 386 | uint32_t ExpectedIndex = NumImportedGlobals; |
Derek Schuff | 349a48f | 2017-03-30 19:44:09 +0000 | [diff] [blame] | 387 | for (auto &Global : Section.Globals) { |
Sam Clegg | 6b54fc3 | 2018-01-09 21:38:53 +0000 | [diff] [blame] | 388 | if (Global.Index != ExpectedIndex) { |
| 389 | errs() << "Unexpected global index: " << Global.Index << "\n"; |
| 390 | return 1; |
| 391 | } |
| 392 | ++ExpectedIndex; |
Sam Clegg | 9f474de | 2018-03-01 18:06:21 +0000 | [diff] [blame] | 393 | writeUint8(OS, Global.Type); |
Derek Schuff | 349a48f | 2017-03-30 19:44:09 +0000 | [diff] [blame] | 394 | writeUint8(OS, Global.Mutable); |
| 395 | writeInitExpr(Global.InitExpr, OS); |
| 396 | } |
| 397 | return 0; |
| 398 | } |
| 399 | |
| 400 | int WasmWriter::writeSectionContent(raw_ostream &OS, |
Heejin Ahn | 8bcdd04 | 2018-11-14 02:46:21 +0000 | [diff] [blame] | 401 | WasmYAML::EventSection &Section) { |
| 402 | encodeULEB128(Section.Events.size(), OS); |
| 403 | uint32_t ExpectedIndex = NumImportedEvents; |
| 404 | for (auto &Event : Section.Events) { |
| 405 | if (Event.Index != ExpectedIndex) { |
| 406 | errs() << "Unexpected event index: " << Event.Index << "\n"; |
| 407 | return 1; |
| 408 | } |
| 409 | ++ExpectedIndex; |
| 410 | encodeULEB128(Event.Attribute, OS); |
| 411 | encodeULEB128(Event.SigIndex, OS); |
| 412 | } |
| 413 | return 0; |
| 414 | } |
| 415 | |
| 416 | int WasmWriter::writeSectionContent(raw_ostream &OS, |
Derek Schuff | 349a48f | 2017-03-30 19:44:09 +0000 | [diff] [blame] | 417 | WasmYAML::ElemSection &Section) { |
| 418 | encodeULEB128(Section.Segments.size(), OS); |
| 419 | for (auto &Segment : Section.Segments) { |
| 420 | encodeULEB128(Segment.TableIndex, OS); |
| 421 | writeInitExpr(Segment.Offset, OS); |
| 422 | |
| 423 | encodeULEB128(Segment.Functions.size(), OS); |
| 424 | for (auto &Function : Segment.Functions) { |
| 425 | encodeULEB128(Function, OS); |
| 426 | } |
| 427 | } |
| 428 | return 0; |
| 429 | } |
| 430 | |
| 431 | int WasmWriter::writeSectionContent(raw_ostream &OS, |
| 432 | WasmYAML::CodeSection &Section) { |
| 433 | encodeULEB128(Section.Functions.size(), OS); |
Sam Clegg | 6b54fc3 | 2018-01-09 21:38:53 +0000 | [diff] [blame] | 434 | uint32_t ExpectedIndex = NumImportedFunctions; |
Derek Schuff | 349a48f | 2017-03-30 19:44:09 +0000 | [diff] [blame] | 435 | for (auto &Func : Section.Functions) { |
| 436 | std::string OutString; |
| 437 | raw_string_ostream StringStream(OutString); |
Sam Clegg | 6b54fc3 | 2018-01-09 21:38:53 +0000 | [diff] [blame] | 438 | if (Func.Index != ExpectedIndex) { |
| 439 | errs() << "Unexpected function index: " << Func.Index << "\n"; |
| 440 | return 1; |
| 441 | } |
| 442 | ++ExpectedIndex; |
Derek Schuff | 349a48f | 2017-03-30 19:44:09 +0000 | [diff] [blame] | 443 | |
| 444 | encodeULEB128(Func.Locals.size(), StringStream); |
| 445 | for (auto &LocalDecl : Func.Locals) { |
| 446 | encodeULEB128(LocalDecl.Count, StringStream); |
Sam Clegg | 9f474de | 2018-03-01 18:06:21 +0000 | [diff] [blame] | 447 | writeUint8(StringStream, LocalDecl.Type); |
Derek Schuff | 349a48f | 2017-03-30 19:44:09 +0000 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | Func.Body.writeAsBinary(StringStream); |
| 451 | |
| 452 | // Write the section size followed by the content |
| 453 | StringStream.flush(); |
| 454 | encodeULEB128(OutString.size(), OS); |
| 455 | OS << OutString; |
| 456 | } |
| 457 | return 0; |
| 458 | } |
| 459 | |
| 460 | int WasmWriter::writeSectionContent(raw_ostream &OS, |
| 461 | WasmYAML::DataSection &Section) { |
| 462 | encodeULEB128(Section.Segments.size(), OS); |
| 463 | for (auto &Segment : Section.Segments) { |
Sam Clegg | c9c28d9 | 2017-07-12 00:24:54 +0000 | [diff] [blame] | 464 | encodeULEB128(Segment.MemoryIndex, OS); |
Derek Schuff | 349a48f | 2017-03-30 19:44:09 +0000 | [diff] [blame] | 465 | writeInitExpr(Segment.Offset, OS); |
| 466 | encodeULEB128(Segment.Content.binary_size(), OS); |
| 467 | Segment.Content.writeAsBinary(OS); |
| 468 | } |
| 469 | return 0; |
| 470 | } |
| 471 | |
Sam Clegg | 194a4e0 | 2018-04-24 18:11:36 +0000 | [diff] [blame] | 472 | int WasmWriter::writeRelocSection(raw_ostream &OS, WasmYAML::Section &Sec, |
| 473 | uint32_t SectionIndex) { |
Derek Schuff | 349a48f | 2017-03-30 19:44:09 +0000 | [diff] [blame] | 474 | switch (Sec.Type) { |
Heejin Ahn | 581d231 | 2018-09-05 01:27:38 +0000 | [diff] [blame] | 475 | case wasm::WASM_SEC_CODE: |
| 476 | writeStringRef("reloc.CODE", OS); |
| 477 | break; |
| 478 | case wasm::WASM_SEC_DATA: |
| 479 | writeStringRef("reloc.DATA", OS); |
| 480 | break; |
| 481 | case wasm::WASM_SEC_CUSTOM: { |
| 482 | auto CustomSection = dyn_cast<WasmYAML::CustomSection>(&Sec); |
| 483 | if (!CustomSection->Name.startswith(".debug_")) { |
| 484 | llvm_unreachable("not yet implemented (only for debug sections)"); |
Derek Schuff | 349a48f | 2017-03-30 19:44:09 +0000 | [diff] [blame] | 485 | return 1; |
Heejin Ahn | 581d231 | 2018-09-05 01:27:38 +0000 | [diff] [blame] | 486 | } |
| 487 | |
| 488 | writeStringRef(("reloc." + CustomSection->Name).str(), OS); |
| 489 | break; |
| 490 | } |
| 491 | default: |
| 492 | llvm_unreachable("not yet implemented"); |
| 493 | return 1; |
Derek Schuff | 349a48f | 2017-03-30 19:44:09 +0000 | [diff] [blame] | 494 | } |
| 495 | |
Sam Clegg | 194a4e0 | 2018-04-24 18:11:36 +0000 | [diff] [blame] | 496 | encodeULEB128(SectionIndex, OS); |
Derek Schuff | 349a48f | 2017-03-30 19:44:09 +0000 | [diff] [blame] | 497 | encodeULEB128(Sec.Relocations.size(), OS); |
| 498 | |
Heejin Ahn | 581d231 | 2018-09-05 01:27:38 +0000 | [diff] [blame] | 499 | for (auto Reloc : Sec.Relocations) { |
Sam Clegg | 9f474de | 2018-03-01 18:06:21 +0000 | [diff] [blame] | 500 | writeUint8(OS, Reloc.Type); |
Derek Schuff | 349a48f | 2017-03-30 19:44:09 +0000 | [diff] [blame] | 501 | encodeULEB128(Reloc.Offset, OS); |
| 502 | encodeULEB128(Reloc.Index, OS); |
| 503 | switch (Reloc.Type) { |
Heejin Ahn | 581d231 | 2018-09-05 01:27:38 +0000 | [diff] [blame] | 504 | case wasm::R_WEBASSEMBLY_MEMORY_ADDR_LEB: |
| 505 | case wasm::R_WEBASSEMBLY_MEMORY_ADDR_SLEB: |
| 506 | case wasm::R_WEBASSEMBLY_MEMORY_ADDR_I32: |
| 507 | case wasm::R_WEBASSEMBLY_FUNCTION_OFFSET_I32: |
| 508 | case wasm::R_WEBASSEMBLY_SECTION_OFFSET_I32: |
| 509 | encodeULEB128(Reloc.Addend, OS); |
Derek Schuff | 349a48f | 2017-03-30 19:44:09 +0000 | [diff] [blame] | 510 | } |
| 511 | } |
| 512 | return 0; |
| 513 | } |
| 514 | |
Derek Schuff | 349a48f | 2017-03-30 19:44:09 +0000 | [diff] [blame] | 515 | int WasmWriter::writeWasm(raw_ostream &OS) { |
| 516 | // Write headers |
| 517 | OS.write(wasm::WasmMagic, sizeof(wasm::WasmMagic)); |
| 518 | writeUint32(OS, Obj.Header.Version); |
| 519 | |
| 520 | // Write each section |
Heejin Ahn | e2f3e50 | 2018-12-15 00:58:12 +0000 | [diff] [blame] | 521 | llvm::object::WasmSectionOrderChecker Checker; |
Derek Schuff | 349a48f | 2017-03-30 19:44:09 +0000 | [diff] [blame] | 522 | for (const std::unique_ptr<WasmYAML::Section> &Sec : Obj.Sections) { |
Heejin Ahn | e2f3e50 | 2018-12-15 00:58:12 +0000 | [diff] [blame] | 523 | StringRef SecName = ""; |
| 524 | if (auto S = dyn_cast<WasmYAML::CustomSection>(Sec.get())) |
| 525 | SecName = S->Name; |
| 526 | if (!Checker.isValidSectionOrder(Sec->Type, SecName)) { |
| 527 | errs() << "Out of order section type: " << Sec->Type << "\n"; |
| 528 | return 1; |
| 529 | } |
Sam Clegg | 6b54fc3 | 2018-01-09 21:38:53 +0000 | [diff] [blame] | 530 | encodeULEB128(Sec->Type, OS); |
Derek Schuff | 349a48f | 2017-03-30 19:44:09 +0000 | [diff] [blame] | 531 | std::string OutString; |
| 532 | raw_string_ostream StringStream(OutString); |
| 533 | if (auto S = dyn_cast<WasmYAML::CustomSection>(Sec.get())) { |
| 534 | if (auto Err = writeSectionContent(StringStream, *S)) |
| 535 | return Err; |
| 536 | } else if (auto S = dyn_cast<WasmYAML::TypeSection>(Sec.get())) { |
| 537 | if (auto Err = writeSectionContent(StringStream, *S)) |
| 538 | return Err; |
| 539 | } else if (auto S = dyn_cast<WasmYAML::ImportSection>(Sec.get())) { |
| 540 | if (auto Err = writeSectionContent(StringStream, *S)) |
| 541 | return Err; |
| 542 | } else if (auto S = dyn_cast<WasmYAML::FunctionSection>(Sec.get())) { |
| 543 | if (auto Err = writeSectionContent(StringStream, *S)) |
| 544 | return Err; |
| 545 | } else if (auto S = dyn_cast<WasmYAML::TableSection>(Sec.get())) { |
| 546 | if (auto Err = writeSectionContent(StringStream, *S)) |
| 547 | return Err; |
| 548 | } else if (auto S = dyn_cast<WasmYAML::MemorySection>(Sec.get())) { |
| 549 | if (auto Err = writeSectionContent(StringStream, *S)) |
| 550 | return Err; |
| 551 | } else if (auto S = dyn_cast<WasmYAML::GlobalSection>(Sec.get())) { |
| 552 | if (auto Err = writeSectionContent(StringStream, *S)) |
| 553 | return Err; |
Heejin Ahn | 8bcdd04 | 2018-11-14 02:46:21 +0000 | [diff] [blame] | 554 | } else if (auto S = dyn_cast<WasmYAML::EventSection>(Sec.get())) { |
| 555 | if (auto Err = writeSectionContent(StringStream, *S)) |
| 556 | return Err; |
Derek Schuff | 349a48f | 2017-03-30 19:44:09 +0000 | [diff] [blame] | 557 | } else if (auto S = dyn_cast<WasmYAML::ExportSection>(Sec.get())) { |
| 558 | if (auto Err = writeSectionContent(StringStream, *S)) |
| 559 | return Err; |
| 560 | } else if (auto S = dyn_cast<WasmYAML::StartSection>(Sec.get())) { |
| 561 | if (auto Err = writeSectionContent(StringStream, *S)) |
| 562 | return Err; |
| 563 | } else if (auto S = dyn_cast<WasmYAML::ElemSection>(Sec.get())) { |
| 564 | if (auto Err = writeSectionContent(StringStream, *S)) |
| 565 | return Err; |
| 566 | } else if (auto S = dyn_cast<WasmYAML::CodeSection>(Sec.get())) { |
| 567 | if (auto Err = writeSectionContent(StringStream, *S)) |
| 568 | return Err; |
| 569 | } else if (auto S = dyn_cast<WasmYAML::DataSection>(Sec.get())) { |
| 570 | if (auto Err = writeSectionContent(StringStream, *S)) |
| 571 | return Err; |
| 572 | } else { |
| 573 | errs() << "Unknown section type: " << Sec->Type << "\n"; |
| 574 | return 1; |
| 575 | } |
| 576 | StringStream.flush(); |
| 577 | |
| 578 | // Write the section size followed by the content |
| 579 | encodeULEB128(OutString.size(), OS); |
| 580 | OS << OutString; |
| 581 | } |
| 582 | |
| 583 | // write reloc sections for any section that have relocations |
Sam Clegg | 194a4e0 | 2018-04-24 18:11:36 +0000 | [diff] [blame] | 584 | uint32_t SectionIndex = 0; |
Derek Schuff | 349a48f | 2017-03-30 19:44:09 +0000 | [diff] [blame] | 585 | for (const std::unique_ptr<WasmYAML::Section> &Sec : Obj.Sections) { |
Sam Clegg | 194a4e0 | 2018-04-24 18:11:36 +0000 | [diff] [blame] | 586 | if (Sec->Relocations.empty()) { |
| 587 | SectionIndex++; |
Derek Schuff | 349a48f | 2017-03-30 19:44:09 +0000 | [diff] [blame] | 588 | continue; |
Sam Clegg | 194a4e0 | 2018-04-24 18:11:36 +0000 | [diff] [blame] | 589 | } |
Derek Schuff | 349a48f | 2017-03-30 19:44:09 +0000 | [diff] [blame] | 590 | |
Sam Clegg | 9f474de | 2018-03-01 18:06:21 +0000 | [diff] [blame] | 591 | writeUint8(OS, wasm::WASM_SEC_CUSTOM); |
Derek Schuff | 349a48f | 2017-03-30 19:44:09 +0000 | [diff] [blame] | 592 | std::string OutString; |
| 593 | raw_string_ostream StringStream(OutString); |
Sam Clegg | 194a4e0 | 2018-04-24 18:11:36 +0000 | [diff] [blame] | 594 | writeRelocSection(StringStream, *Sec, SectionIndex++); |
Derek Schuff | 349a48f | 2017-03-30 19:44:09 +0000 | [diff] [blame] | 595 | StringStream.flush(); |
| 596 | |
| 597 | encodeULEB128(OutString.size(), OS); |
| 598 | OS << OutString; |
| 599 | } |
| 600 | |
| 601 | return 0; |
| 602 | } |
| 603 | |
| 604 | int yaml2wasm(llvm::WasmYAML::Object &Doc, raw_ostream &Out) { |
| 605 | WasmWriter Writer(Doc); |
| 606 | |
| 607 | return Writer.writeWasm(Out); |
| 608 | } |