Derek Schuff | d3d84fd | 2017-03-30 19:44:09 +0000 | [diff] [blame] | 1 | //===------ utils/wasm2yaml.cpp - obj2yaml conversion tool ------*- C++ -*-===// |
| 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 | #include "obj2yaml.h" |
| 11 | #include "llvm/Object/COFF.h" |
| 12 | #include "llvm/ObjectYAML/WasmYAML.h" |
| 13 | #include "llvm/Support/ErrorHandling.h" |
| 14 | #include "llvm/Support/YAMLTraits.h" |
| 15 | |
| 16 | using namespace llvm; |
Sam Clegg | b7787fd | 2017-06-20 04:04:59 +0000 | [diff] [blame] | 17 | using object::WasmSection; |
Derek Schuff | d3d84fd | 2017-03-30 19:44:09 +0000 | [diff] [blame] | 18 | |
| 19 | namespace { |
| 20 | |
| 21 | class WasmDumper { |
| 22 | const object::WasmObjectFile &Obj; |
| 23 | |
| 24 | public: |
| 25 | WasmDumper(const object::WasmObjectFile &O) : Obj(O) {} |
Sam Clegg | b7787fd | 2017-06-20 04:04:59 +0000 | [diff] [blame] | 26 | |
Derek Schuff | d3d84fd | 2017-03-30 19:44:09 +0000 | [diff] [blame] | 27 | ErrorOr<WasmYAML::Object *> dump(); |
Sam Clegg | b7787fd | 2017-06-20 04:04:59 +0000 | [diff] [blame] | 28 | |
| 29 | std::unique_ptr<WasmYAML::CustomSection> |
| 30 | dumpCustomSection(const WasmSection &WasmSec); |
Derek Schuff | d3d84fd | 2017-03-30 19:44:09 +0000 | [diff] [blame] | 31 | }; |
| 32 | |
Sam Clegg | b7787fd | 2017-06-20 04:04:59 +0000 | [diff] [blame] | 33 | } // namespace |
| 34 | |
| 35 | static WasmYAML::Table make_table(const wasm::WasmTable &Table) { |
Sam Clegg | 2ffff5a | 2017-05-09 23:48:41 +0000 | [diff] [blame] | 36 | WasmYAML::Table T; |
| 37 | T.ElemType = Table.ElemType; |
| 38 | T.TableLimits.Flags = Table.Limits.Flags; |
| 39 | T.TableLimits.Initial = Table.Limits.Initial; |
| 40 | T.TableLimits.Maximum = Table.Limits.Maximum; |
| 41 | return T; |
| 42 | } |
| 43 | |
Sam Clegg | b7787fd | 2017-06-20 04:04:59 +0000 | [diff] [blame] | 44 | static WasmYAML::Limits make_limits(const wasm::WasmLimits &Limits) { |
Sam Clegg | 2ffff5a | 2017-05-09 23:48:41 +0000 | [diff] [blame] | 45 | WasmYAML::Limits L; |
| 46 | L.Flags = Limits.Flags; |
| 47 | L.Initial = Limits.Initial; |
| 48 | L.Maximum = Limits.Maximum; |
| 49 | return L; |
| 50 | } |
| 51 | |
Heejin Ahn | f208f63 | 2018-09-05 01:27:38 +0000 | [diff] [blame] | 52 | std::unique_ptr<WasmYAML::CustomSection> |
| 53 | WasmDumper::dumpCustomSection(const WasmSection &WasmSec) { |
Sam Clegg | b7787fd | 2017-06-20 04:04:59 +0000 | [diff] [blame] | 54 | std::unique_ptr<WasmYAML::CustomSection> CustomSec; |
| 55 | if (WasmSec.Name == "name") { |
Heejin Ahn | f208f63 | 2018-09-05 01:27:38 +0000 | [diff] [blame] | 56 | std::unique_ptr<WasmYAML::NameSection> NameSec = |
| 57 | make_unique<WasmYAML::NameSection>(); |
| 58 | for (const llvm::wasm::WasmFunctionName &Func : Obj.debugNames()) { |
Sam Clegg | b7787fd | 2017-06-20 04:04:59 +0000 | [diff] [blame] | 59 | WasmYAML::NameEntry NameEntry; |
Sam Clegg | 9f3fe42 | 2018-01-17 19:28:43 +0000 | [diff] [blame] | 60 | NameEntry.Name = Func.Name; |
| 61 | NameEntry.Index = Func.Index; |
Sam Clegg | b7787fd | 2017-06-20 04:04:59 +0000 | [diff] [blame] | 62 | NameSec->FunctionNames.push_back(NameEntry); |
| 63 | } |
| 64 | CustomSec = std::move(NameSec); |
| 65 | } else if (WasmSec.Name == "linking") { |
Heejin Ahn | f208f63 | 2018-09-05 01:27:38 +0000 | [diff] [blame] | 66 | std::unique_ptr<WasmYAML::LinkingSection> LinkingSec = |
| 67 | make_unique<WasmYAML::LinkingSection>(); |
Sam Clegg | 6bb5a41 | 2018-04-26 18:15:32 +0000 | [diff] [blame] | 68 | LinkingSec->Version = Obj.linkingData().Version; |
| 69 | |
Nicholas Wilson | 027b935 | 2018-03-14 15:44:45 +0000 | [diff] [blame] | 70 | ArrayRef<StringRef> Comdats = Obj.linkingData().Comdats; |
| 71 | for (StringRef ComdatName : Comdats) |
Sam Clegg | ea7cace | 2018-01-09 23:43:14 +0000 | [diff] [blame] | 72 | LinkingSec->Comdats.emplace_back(WasmYAML::Comdat{ComdatName, {}}); |
Sam Clegg | ea7cace | 2018-01-09 23:43:14 +0000 | [diff] [blame] | 73 | for (auto &Func : Obj.functions()) { |
Nicholas Wilson | 027b935 | 2018-03-14 15:44:45 +0000 | [diff] [blame] | 74 | if (Func.Comdat != UINT32_MAX) { |
| 75 | LinkingSec->Comdats[Func.Comdat].Entries.emplace_back( |
Heejin Ahn | f208f63 | 2018-09-05 01:27:38 +0000 | [diff] [blame] | 76 | WasmYAML::ComdatEntry{wasm::WASM_COMDAT_FUNCTION, Func.Index}); |
Sam Clegg | ea7cace | 2018-01-09 23:43:14 +0000 | [diff] [blame] | 77 | } |
| 78 | } |
Sam Clegg | 6bb5a41 | 2018-04-26 18:15:32 +0000 | [diff] [blame] | 79 | |
Sam Clegg | ea7cace | 2018-01-09 23:43:14 +0000 | [diff] [blame] | 80 | uint32_t SegmentIndex = 0; |
Sam Clegg | d95ed95 | 2017-09-20 19:03:35 +0000 | [diff] [blame] | 81 | for (const object::WasmSegment &Segment : Obj.dataSegments()) { |
| 82 | if (!Segment.Data.Name.empty()) { |
Sam Clegg | 63ebb81 | 2017-09-29 16:50:08 +0000 | [diff] [blame] | 83 | WasmYAML::SegmentInfo SegmentInfo; |
| 84 | SegmentInfo.Name = Segment.Data.Name; |
Sam Clegg | ea7cace | 2018-01-09 23:43:14 +0000 | [diff] [blame] | 85 | SegmentInfo.Index = SegmentIndex; |
Sam Clegg | 63ebb81 | 2017-09-29 16:50:08 +0000 | [diff] [blame] | 86 | SegmentInfo.Alignment = Segment.Data.Alignment; |
| 87 | SegmentInfo.Flags = Segment.Data.Flags; |
| 88 | LinkingSec->SegmentInfos.push_back(SegmentInfo); |
Sam Clegg | d95ed95 | 2017-09-20 19:03:35 +0000 | [diff] [blame] | 89 | } |
Nicholas Wilson | 027b935 | 2018-03-14 15:44:45 +0000 | [diff] [blame] | 90 | if (Segment.Data.Comdat != UINT32_MAX) { |
| 91 | LinkingSec->Comdats[Segment.Data.Comdat].Entries.emplace_back( |
Sam Clegg | ea7cace | 2018-01-09 23:43:14 +0000 | [diff] [blame] | 92 | WasmYAML::ComdatEntry{wasm::WASM_COMDAT_DATA, SegmentIndex}); |
| 93 | } |
| 94 | SegmentIndex++; |
Sam Clegg | d95ed95 | 2017-09-20 19:03:35 +0000 | [diff] [blame] | 95 | } |
Sam Clegg | 6bb5a41 | 2018-04-26 18:15:32 +0000 | [diff] [blame] | 96 | |
Sam Clegg | 6c899ba | 2018-02-23 05:08:34 +0000 | [diff] [blame] | 97 | uint32_t SymbolIndex = 0; |
| 98 | for (const wasm::WasmSymbolInfo &Symbol : Obj.linkingData().SymbolTable) { |
| 99 | WasmYAML::SymbolInfo Info; |
| 100 | Info.Index = SymbolIndex++; |
| 101 | Info.Kind = static_cast<uint32_t>(Symbol.Kind); |
| 102 | Info.Name = Symbol.Name; |
| 103 | Info.Flags = Symbol.Flags; |
| 104 | switch (Symbol.Kind) { |
| 105 | case wasm::WASM_SYMBOL_TYPE_DATA: |
| 106 | Info.DataRef = Symbol.DataRef; |
| 107 | break; |
| 108 | case wasm::WASM_SYMBOL_TYPE_FUNCTION: |
| 109 | case wasm::WASM_SYMBOL_TYPE_GLOBAL: |
Heejin Ahn | da419bd | 2018-11-14 02:46:21 +0000 | [diff] [blame^] | 110 | case wasm::WASM_SYMBOL_TYPE_EVENT: |
Sam Clegg | 6c899ba | 2018-02-23 05:08:34 +0000 | [diff] [blame] | 111 | Info.ElementIndex = Symbol.ElementIndex; |
| 112 | break; |
Sam Clegg | 6a31a0d | 2018-04-26 19:27:28 +0000 | [diff] [blame] | 113 | case wasm::WASM_SYMBOL_TYPE_SECTION: |
| 114 | Info.ElementIndex = Symbol.ElementIndex; |
| 115 | break; |
Sam Clegg | b7787fd | 2017-06-20 04:04:59 +0000 | [diff] [blame] | 116 | } |
Sam Clegg | 6c899ba | 2018-02-23 05:08:34 +0000 | [diff] [blame] | 117 | LinkingSec->SymbolTable.emplace_back(Info); |
Sam Clegg | b7787fd | 2017-06-20 04:04:59 +0000 | [diff] [blame] | 118 | } |
Sam Clegg | 6bb5a41 | 2018-04-26 18:15:32 +0000 | [diff] [blame] | 119 | |
Sam Clegg | 4273998 | 2017-12-14 21:10:03 +0000 | [diff] [blame] | 120 | for (const wasm::WasmInitFunc &Func : Obj.linkingData().InitFunctions) { |
Sam Clegg | 6c899ba | 2018-02-23 05:08:34 +0000 | [diff] [blame] | 121 | WasmYAML::InitFunction F{Func.Priority, Func.Symbol}; |
Sam Clegg | 4273998 | 2017-12-14 21:10:03 +0000 | [diff] [blame] | 122 | LinkingSec->InitFunctions.emplace_back(F); |
| 123 | } |
Sam Clegg | 6bb5a41 | 2018-04-26 18:15:32 +0000 | [diff] [blame] | 124 | |
Sam Clegg | b7787fd | 2017-06-20 04:04:59 +0000 | [diff] [blame] | 125 | CustomSec = std::move(LinkingSec); |
| 126 | } else { |
| 127 | CustomSec = make_unique<WasmYAML::CustomSection>(WasmSec.Name); |
| 128 | } |
| 129 | CustomSec->Payload = yaml::BinaryRef(WasmSec.Content); |
| 130 | return CustomSec; |
| 131 | } |
| 132 | |
Derek Schuff | d3d84fd | 2017-03-30 19:44:09 +0000 | [diff] [blame] | 133 | ErrorOr<WasmYAML::Object *> WasmDumper::dump() { |
| 134 | auto Y = make_unique<WasmYAML::Object>(); |
| 135 | |
| 136 | // Dump header |
| 137 | Y->Header.Version = Obj.getHeader().Version; |
| 138 | |
| 139 | // Dump sections |
| 140 | for (const auto &Sec : Obj.sections()) { |
Sam Clegg | b7787fd | 2017-06-20 04:04:59 +0000 | [diff] [blame] | 141 | const WasmSection &WasmSec = Obj.getWasmSection(Sec); |
Derek Schuff | d3d84fd | 2017-03-30 19:44:09 +0000 | [diff] [blame] | 142 | std::unique_ptr<WasmYAML::Section> S; |
| 143 | switch (WasmSec.Type) { |
| 144 | case wasm::WASM_SEC_CUSTOM: { |
| 145 | if (WasmSec.Name.startswith("reloc.")) { |
| 146 | // Relocations are attached the sections they apply to rather than |
| 147 | // being represented as a custom section in the YAML output. |
| 148 | continue; |
| 149 | } |
Sam Clegg | b7787fd | 2017-06-20 04:04:59 +0000 | [diff] [blame] | 150 | S = dumpCustomSection(WasmSec); |
Derek Schuff | d3d84fd | 2017-03-30 19:44:09 +0000 | [diff] [blame] | 151 | break; |
| 152 | } |
| 153 | case wasm::WASM_SEC_TYPE: { |
| 154 | auto TypeSec = make_unique<WasmYAML::TypeSection>(); |
| 155 | uint32_t Index = 0; |
| 156 | for (const auto &FunctionSig : Obj.types()) { |
| 157 | WasmYAML::Signature Sig; |
| 158 | Sig.Index = Index++; |
Derek Schuff | 77a7a38 | 2018-10-03 22:22:48 +0000 | [diff] [blame] | 159 | Sig.ReturnType = wasm::WASM_TYPE_NORESULT; |
| 160 | assert(FunctionSig.Returns.size() <= 1 && |
| 161 | "Functions with multiple returns are not supported"); |
| 162 | if (FunctionSig.Returns.size()) |
| 163 | Sig.ReturnType = static_cast<uint32_t>(FunctionSig.Returns[0]); |
| 164 | for (const auto &ParamType : FunctionSig.Params) |
| 165 | Sig.ParamTypes.push_back(static_cast<uint32_t>(ParamType)); |
Derek Schuff | d3d84fd | 2017-03-30 19:44:09 +0000 | [diff] [blame] | 166 | TypeSec->Signatures.push_back(Sig); |
| 167 | } |
| 168 | S = std::move(TypeSec); |
| 169 | break; |
| 170 | } |
| 171 | case wasm::WASM_SEC_IMPORT: { |
| 172 | auto ImportSec = make_unique<WasmYAML::ImportSection>(); |
| 173 | for (auto &Import : Obj.imports()) { |
Sam Clegg | 2ffff5a | 2017-05-09 23:48:41 +0000 | [diff] [blame] | 174 | WasmYAML::Import Im; |
| 175 | Im.Module = Import.Module; |
| 176 | Im.Field = Import.Field; |
| 177 | Im.Kind = Import.Kind; |
| 178 | switch (Im.Kind) { |
| 179 | case wasm::WASM_EXTERNAL_FUNCTION: |
| 180 | Im.SigIndex = Import.SigIndex; |
| 181 | break; |
| 182 | case wasm::WASM_EXTERNAL_GLOBAL: |
Sam Clegg | 41db519 | 2017-05-10 00:14:04 +0000 | [diff] [blame] | 183 | Im.GlobalImport.Type = Import.Global.Type; |
| 184 | Im.GlobalImport.Mutable = Import.Global.Mutable; |
Sam Clegg | 2ffff5a | 2017-05-09 23:48:41 +0000 | [diff] [blame] | 185 | break; |
Heejin Ahn | da419bd | 2018-11-14 02:46:21 +0000 | [diff] [blame^] | 186 | case wasm::WASM_EXTERNAL_EVENT: |
| 187 | Im.EventImport.Attribute = Import.Event.Attribute; |
| 188 | Im.EventImport.SigIndex = Import.Event.SigIndex; |
| 189 | break; |
Sam Clegg | 2ffff5a | 2017-05-09 23:48:41 +0000 | [diff] [blame] | 190 | case wasm::WASM_EXTERNAL_TABLE: |
Sam Clegg | 41db519 | 2017-05-10 00:14:04 +0000 | [diff] [blame] | 191 | Im.TableImport = make_table(Import.Table); |
Sam Clegg | 2ffff5a | 2017-05-09 23:48:41 +0000 | [diff] [blame] | 192 | break; |
| 193 | case wasm::WASM_EXTERNAL_MEMORY: |
| 194 | Im.Memory = make_limits(Import.Memory); |
| 195 | break; |
Derek Schuff | d3d84fd | 2017-03-30 19:44:09 +0000 | [diff] [blame] | 196 | } |
Sam Clegg | 2ffff5a | 2017-05-09 23:48:41 +0000 | [diff] [blame] | 197 | ImportSec->Imports.push_back(Im); |
Derek Schuff | d3d84fd | 2017-03-30 19:44:09 +0000 | [diff] [blame] | 198 | } |
| 199 | S = std::move(ImportSec); |
| 200 | break; |
| 201 | } |
| 202 | case wasm::WASM_SEC_FUNCTION: { |
| 203 | auto FuncSec = make_unique<WasmYAML::FunctionSection>(); |
| 204 | for (const auto &Func : Obj.functionTypes()) { |
| 205 | FuncSec->FunctionTypes.push_back(Func); |
| 206 | } |
| 207 | S = std::move(FuncSec); |
| 208 | break; |
| 209 | } |
| 210 | case wasm::WASM_SEC_TABLE: { |
| 211 | auto TableSec = make_unique<WasmYAML::TableSection>(); |
Sam Clegg | 2ffff5a | 2017-05-09 23:48:41 +0000 | [diff] [blame] | 212 | for (const wasm::WasmTable &Table : Obj.tables()) { |
| 213 | TableSec->Tables.push_back(make_table(Table)); |
Derek Schuff | d3d84fd | 2017-03-30 19:44:09 +0000 | [diff] [blame] | 214 | } |
| 215 | S = std::move(TableSec); |
| 216 | break; |
| 217 | } |
| 218 | case wasm::WASM_SEC_MEMORY: { |
| 219 | auto MemorySec = make_unique<WasmYAML::MemorySection>(); |
Sam Clegg | 2ffff5a | 2017-05-09 23:48:41 +0000 | [diff] [blame] | 220 | for (const wasm::WasmLimits &Memory : Obj.memories()) { |
| 221 | MemorySec->Memories.push_back(make_limits(Memory)); |
Derek Schuff | d3d84fd | 2017-03-30 19:44:09 +0000 | [diff] [blame] | 222 | } |
| 223 | S = std::move(MemorySec); |
| 224 | break; |
| 225 | } |
| 226 | case wasm::WASM_SEC_GLOBAL: { |
| 227 | auto GlobalSec = make_unique<WasmYAML::GlobalSection>(); |
| 228 | for (auto &Global : Obj.globals()) { |
| 229 | WasmYAML::Global G; |
Sam Clegg | e53af7f | 2018-01-09 21:38:53 +0000 | [diff] [blame] | 230 | G.Index = Global.Index; |
Sam Clegg | 6e7f182 | 2018-01-31 19:50:14 +0000 | [diff] [blame] | 231 | G.Type = Global.Type.Type; |
| 232 | G.Mutable = Global.Type.Mutable; |
Derek Schuff | d3d84fd | 2017-03-30 19:44:09 +0000 | [diff] [blame] | 233 | G.InitExpr = Global.InitExpr; |
| 234 | GlobalSec->Globals.push_back(G); |
| 235 | } |
| 236 | S = std::move(GlobalSec); |
| 237 | break; |
| 238 | } |
Heejin Ahn | da419bd | 2018-11-14 02:46:21 +0000 | [diff] [blame^] | 239 | case wasm::WASM_SEC_EVENT: { |
| 240 | auto EventSec = make_unique<WasmYAML::EventSection>(); |
| 241 | for (auto &Event : Obj.events()) { |
| 242 | WasmYAML::Event E; |
| 243 | E.Index = Event.Index; |
| 244 | E.Attribute = Event.Type.Attribute; |
| 245 | E.SigIndex = Event.Type.SigIndex; |
| 246 | EventSec->Events.push_back(E); |
| 247 | } |
| 248 | S = std::move(EventSec); |
| 249 | break; |
| 250 | } |
Derek Schuff | d3d84fd | 2017-03-30 19:44:09 +0000 | [diff] [blame] | 251 | case wasm::WASM_SEC_START: { |
| 252 | auto StartSec = make_unique<WasmYAML::StartSection>(); |
| 253 | StartSec->StartFunction = Obj.startFunction(); |
| 254 | S = std::move(StartSec); |
| 255 | break; |
| 256 | } |
| 257 | case wasm::WASM_SEC_EXPORT: { |
| 258 | auto ExportSec = make_unique<WasmYAML::ExportSection>(); |
| 259 | for (auto &Export : Obj.exports()) { |
| 260 | WasmYAML::Export Ex; |
| 261 | Ex.Name = Export.Name; |
| 262 | Ex.Kind = Export.Kind; |
| 263 | Ex.Index = Export.Index; |
| 264 | ExportSec->Exports.push_back(Ex); |
| 265 | } |
| 266 | S = std::move(ExportSec); |
| 267 | break; |
| 268 | } |
| 269 | case wasm::WASM_SEC_ELEM: { |
| 270 | auto ElemSec = make_unique<WasmYAML::ElemSection>(); |
| 271 | for (auto &Segment : Obj.elements()) { |
| 272 | WasmYAML::ElemSegment Seg; |
| 273 | Seg.TableIndex = Segment.TableIndex; |
| 274 | Seg.Offset = Segment.Offset; |
| 275 | for (auto &Func : Segment.Functions) { |
| 276 | Seg.Functions.push_back(Func); |
| 277 | } |
| 278 | ElemSec->Segments.push_back(Seg); |
| 279 | } |
| 280 | S = std::move(ElemSec); |
| 281 | break; |
| 282 | } |
| 283 | case wasm::WASM_SEC_CODE: { |
| 284 | auto CodeSec = make_unique<WasmYAML::CodeSection>(); |
| 285 | for (auto &Func : Obj.functions()) { |
| 286 | WasmYAML::Function Function; |
Sam Clegg | e53af7f | 2018-01-09 21:38:53 +0000 | [diff] [blame] | 287 | Function.Index = Func.Index; |
Derek Schuff | d3d84fd | 2017-03-30 19:44:09 +0000 | [diff] [blame] | 288 | for (auto &Local : Func.Locals) { |
| 289 | WasmYAML::LocalDecl LocalDecl; |
| 290 | LocalDecl.Type = Local.Type; |
| 291 | LocalDecl.Count = Local.Count; |
| 292 | Function.Locals.push_back(LocalDecl); |
| 293 | } |
| 294 | Function.Body = yaml::BinaryRef(Func.Body); |
| 295 | CodeSec->Functions.push_back(Function); |
| 296 | } |
| 297 | S = std::move(CodeSec); |
| 298 | break; |
| 299 | } |
| 300 | case wasm::WASM_SEC_DATA: { |
| 301 | auto DataSec = make_unique<WasmYAML::DataSection>(); |
Sam Clegg | d95ed95 | 2017-09-20 19:03:35 +0000 | [diff] [blame] | 302 | for (const object::WasmSegment &Segment : Obj.dataSegments()) { |
Derek Schuff | d3d84fd | 2017-03-30 19:44:09 +0000 | [diff] [blame] | 303 | WasmYAML::DataSegment Seg; |
Sam Clegg | 9c07f94 | 2017-07-12 00:24:54 +0000 | [diff] [blame] | 304 | Seg.SectionOffset = Segment.SectionOffset; |
| 305 | Seg.MemoryIndex = Segment.Data.MemoryIndex; |
| 306 | Seg.Offset = Segment.Data.Offset; |
| 307 | Seg.Content = yaml::BinaryRef(Segment.Data.Content); |
Derek Schuff | d3d84fd | 2017-03-30 19:44:09 +0000 | [diff] [blame] | 308 | DataSec->Segments.push_back(Seg); |
| 309 | } |
| 310 | S = std::move(DataSec); |
| 311 | break; |
| 312 | } |
| 313 | default: |
| 314 | llvm_unreachable("Unknown section type"); |
| 315 | break; |
| 316 | } |
Heejin Ahn | f208f63 | 2018-09-05 01:27:38 +0000 | [diff] [blame] | 317 | for (const wasm::WasmRelocation &Reloc : WasmSec.Relocations) { |
Derek Schuff | d3d84fd | 2017-03-30 19:44:09 +0000 | [diff] [blame] | 318 | WasmYAML::Relocation R; |
| 319 | R.Type = Reloc.Type; |
| 320 | R.Index = Reloc.Index; |
| 321 | R.Offset = Reloc.Offset; |
| 322 | R.Addend = Reloc.Addend; |
| 323 | S->Relocations.push_back(R); |
| 324 | } |
| 325 | Y->Sections.push_back(std::move(S)); |
| 326 | } |
| 327 | |
| 328 | return Y.release(); |
| 329 | } |
| 330 | |
Derek Schuff | d3d84fd | 2017-03-30 19:44:09 +0000 | [diff] [blame] | 331 | std::error_code wasm2yaml(raw_ostream &Out, const object::WasmObjectFile &Obj) { |
| 332 | WasmDumper Dumper(Obj); |
| 333 | ErrorOr<WasmYAML::Object *> YAMLOrErr = Dumper.dump(); |
| 334 | if (std::error_code EC = YAMLOrErr.getError()) |
| 335 | return EC; |
| 336 | |
| 337 | std::unique_ptr<WasmYAML::Object> YAML(YAMLOrErr.get()); |
| 338 | yaml::Output Yout(Out); |
| 339 | Yout << *YAML; |
| 340 | |
| 341 | return std::error_code(); |
| 342 | } |