2017-03-31 03:44:09 +08:00
|
|
|
//===------ utils/wasm2yaml.cpp - obj2yaml conversion tool ------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2017-03-31 03:44:09 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "obj2yaml.h"
|
|
|
|
#include "llvm/Object/COFF.h"
|
|
|
|
#include "llvm/ObjectYAML/WasmYAML.h"
|
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
|
|
|
#include "llvm/Support/YAMLTraits.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
2017-06-20 12:04:59 +08:00
|
|
|
using object::WasmSection;
|
2017-03-31 03:44:09 +08:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class WasmDumper {
|
|
|
|
const object::WasmObjectFile &Obj;
|
|
|
|
|
|
|
|
public:
|
|
|
|
WasmDumper(const object::WasmObjectFile &O) : Obj(O) {}
|
2017-06-20 12:04:59 +08:00
|
|
|
|
2017-03-31 03:44:09 +08:00
|
|
|
ErrorOr<WasmYAML::Object *> dump();
|
2017-06-20 12:04:59 +08:00
|
|
|
|
|
|
|
std::unique_ptr<WasmYAML::CustomSection>
|
|
|
|
dumpCustomSection(const WasmSection &WasmSec);
|
2017-03-31 03:44:09 +08:00
|
|
|
};
|
|
|
|
|
2017-06-20 12:04:59 +08:00
|
|
|
} // namespace
|
|
|
|
|
[WebAssembly] clang-tidy (NFC)
Summary:
This patch fixes clang-tidy warnings on wasm-only files.
The list of checks used is:
`-*,clang-diagnostic-*,llvm-*,misc-*,-misc-unused-parameters,readability-identifier-naming,modernize-*`
(LLVM's default .clang-tidy list is the same except it does not have
`modernize-*`. But I've seen in multiple CLs in LLVM the modernize style
was recommended and code was fixed based on the style, so I added it as
well.)
The common fixes are:
- Variable names start with an uppercase letter
- Function names start with a lowercase letter
- Use `auto` when you use casts so the type is evident
- Use inline initialization for class member variables
- Use `= default` for empty constructors / destructors
- Use `using` in place of `typedef`
Reviewers: sbc100, tlively, aardappel
Subscribers: dschuff, sunfish, jgravelle-google, yurydelendik, kripken, MatzeB, mgorny, rupprecht, llvm-commits
Differential Revision: https://reviews.llvm.org/D57500
llvm-svn: 353075
2019-02-05 03:13:39 +08:00
|
|
|
static WasmYAML::Table makeTable(const wasm::WasmTable &Table) {
|
2017-05-10 07:48:41 +08:00
|
|
|
WasmYAML::Table T;
|
|
|
|
T.ElemType = Table.ElemType;
|
|
|
|
T.TableLimits.Flags = Table.Limits.Flags;
|
|
|
|
T.TableLimits.Initial = Table.Limits.Initial;
|
|
|
|
T.TableLimits.Maximum = Table.Limits.Maximum;
|
|
|
|
return T;
|
|
|
|
}
|
|
|
|
|
[WebAssembly] clang-tidy (NFC)
Summary:
This patch fixes clang-tidy warnings on wasm-only files.
The list of checks used is:
`-*,clang-diagnostic-*,llvm-*,misc-*,-misc-unused-parameters,readability-identifier-naming,modernize-*`
(LLVM's default .clang-tidy list is the same except it does not have
`modernize-*`. But I've seen in multiple CLs in LLVM the modernize style
was recommended and code was fixed based on the style, so I added it as
well.)
The common fixes are:
- Variable names start with an uppercase letter
- Function names start with a lowercase letter
- Use `auto` when you use casts so the type is evident
- Use inline initialization for class member variables
- Use `= default` for empty constructors / destructors
- Use `using` in place of `typedef`
Reviewers: sbc100, tlively, aardappel
Subscribers: dschuff, sunfish, jgravelle-google, yurydelendik, kripken, MatzeB, mgorny, rupprecht, llvm-commits
Differential Revision: https://reviews.llvm.org/D57500
llvm-svn: 353075
2019-02-05 03:13:39 +08:00
|
|
|
static WasmYAML::Limits makeLimits(const wasm::WasmLimits &Limits) {
|
2017-05-10 07:48:41 +08:00
|
|
|
WasmYAML::Limits L;
|
|
|
|
L.Flags = Limits.Flags;
|
|
|
|
L.Initial = Limits.Initial;
|
|
|
|
L.Maximum = Limits.Maximum;
|
|
|
|
return L;
|
|
|
|
}
|
|
|
|
|
2018-09-05 09:27:38 +08:00
|
|
|
std::unique_ptr<WasmYAML::CustomSection>
|
|
|
|
WasmDumper::dumpCustomSection(const WasmSection &WasmSec) {
|
2017-06-20 12:04:59 +08:00
|
|
|
std::unique_ptr<WasmYAML::CustomSection> CustomSec;
|
2018-11-15 02:36:24 +08:00
|
|
|
if (WasmSec.Name == "dylink") {
|
|
|
|
std::unique_ptr<WasmYAML::DylinkSection> DylinkSec =
|
2019-08-15 23:54:37 +08:00
|
|
|
std::make_unique<WasmYAML::DylinkSection>();
|
2018-11-15 02:36:24 +08:00
|
|
|
const wasm::WasmDylinkInfo& Info = Obj.dylinkInfo();
|
|
|
|
DylinkSec->MemorySize = Info.MemorySize;
|
|
|
|
DylinkSec->MemoryAlignment = Info.MemoryAlignment;
|
|
|
|
DylinkSec->TableSize = Info.TableSize;
|
|
|
|
DylinkSec->TableAlignment = Info.TableAlignment;
|
2018-12-13 07:40:58 +08:00
|
|
|
DylinkSec->Needed = Info.Needed;
|
2018-11-15 02:36:24 +08:00
|
|
|
CustomSec = std::move(DylinkSec);
|
|
|
|
} else if (WasmSec.Name == "name") {
|
2018-09-05 09:27:38 +08:00
|
|
|
std::unique_ptr<WasmYAML::NameSection> NameSec =
|
2019-08-15 23:54:37 +08:00
|
|
|
std::make_unique<WasmYAML::NameSection>();
|
2018-09-05 09:27:38 +08:00
|
|
|
for (const llvm::wasm::WasmFunctionName &Func : Obj.debugNames()) {
|
2017-06-20 12:04:59 +08:00
|
|
|
WasmYAML::NameEntry NameEntry;
|
2018-01-18 03:28:43 +08:00
|
|
|
NameEntry.Name = Func.Name;
|
|
|
|
NameEntry.Index = Func.Index;
|
2017-06-20 12:04:59 +08:00
|
|
|
NameSec->FunctionNames.push_back(NameEntry);
|
|
|
|
}
|
|
|
|
CustomSec = std::move(NameSec);
|
|
|
|
} else if (WasmSec.Name == "linking") {
|
2018-09-05 09:27:38 +08:00
|
|
|
std::unique_ptr<WasmYAML::LinkingSection> LinkingSec =
|
2019-08-15 23:54:37 +08:00
|
|
|
std::make_unique<WasmYAML::LinkingSection>();
|
2018-04-27 02:15:32 +08:00
|
|
|
LinkingSec->Version = Obj.linkingData().Version;
|
|
|
|
|
2018-03-14 23:44:45 +08:00
|
|
|
ArrayRef<StringRef> Comdats = Obj.linkingData().Comdats;
|
|
|
|
for (StringRef ComdatName : Comdats)
|
2018-01-10 07:43:14 +08:00
|
|
|
LinkingSec->Comdats.emplace_back(WasmYAML::Comdat{ComdatName, {}});
|
|
|
|
for (auto &Func : Obj.functions()) {
|
2018-03-14 23:44:45 +08:00
|
|
|
if (Func.Comdat != UINT32_MAX) {
|
|
|
|
LinkingSec->Comdats[Func.Comdat].Entries.emplace_back(
|
2018-09-05 09:27:38 +08:00
|
|
|
WasmYAML::ComdatEntry{wasm::WASM_COMDAT_FUNCTION, Func.Index});
|
2018-01-10 07:43:14 +08:00
|
|
|
}
|
|
|
|
}
|
2018-04-27 02:15:32 +08:00
|
|
|
|
2018-01-10 07:43:14 +08:00
|
|
|
uint32_t SegmentIndex = 0;
|
2017-09-21 03:03:35 +08:00
|
|
|
for (const object::WasmSegment &Segment : Obj.dataSegments()) {
|
|
|
|
if (!Segment.Data.Name.empty()) {
|
2017-09-30 00:50:08 +08:00
|
|
|
WasmYAML::SegmentInfo SegmentInfo;
|
|
|
|
SegmentInfo.Name = Segment.Data.Name;
|
2018-01-10 07:43:14 +08:00
|
|
|
SegmentInfo.Index = SegmentIndex;
|
2017-09-30 00:50:08 +08:00
|
|
|
SegmentInfo.Alignment = Segment.Data.Alignment;
|
2019-02-20 06:56:19 +08:00
|
|
|
SegmentInfo.Flags = Segment.Data.LinkerFlags;
|
2017-09-30 00:50:08 +08:00
|
|
|
LinkingSec->SegmentInfos.push_back(SegmentInfo);
|
2017-09-21 03:03:35 +08:00
|
|
|
}
|
2018-03-14 23:44:45 +08:00
|
|
|
if (Segment.Data.Comdat != UINT32_MAX) {
|
|
|
|
LinkingSec->Comdats[Segment.Data.Comdat].Entries.emplace_back(
|
2018-01-10 07:43:14 +08:00
|
|
|
WasmYAML::ComdatEntry{wasm::WASM_COMDAT_DATA, SegmentIndex});
|
|
|
|
}
|
|
|
|
SegmentIndex++;
|
2017-09-21 03:03:35 +08:00
|
|
|
}
|
2018-04-27 02:15:32 +08:00
|
|
|
|
2018-02-23 13:08:34 +08:00
|
|
|
uint32_t SymbolIndex = 0;
|
|
|
|
for (const wasm::WasmSymbolInfo &Symbol : Obj.linkingData().SymbolTable) {
|
|
|
|
WasmYAML::SymbolInfo Info;
|
|
|
|
Info.Index = SymbolIndex++;
|
|
|
|
Info.Kind = static_cast<uint32_t>(Symbol.Kind);
|
|
|
|
Info.Name = Symbol.Name;
|
|
|
|
Info.Flags = Symbol.Flags;
|
|
|
|
switch (Symbol.Kind) {
|
|
|
|
case wasm::WASM_SYMBOL_TYPE_DATA:
|
|
|
|
Info.DataRef = Symbol.DataRef;
|
|
|
|
break;
|
|
|
|
case wasm::WASM_SYMBOL_TYPE_FUNCTION:
|
|
|
|
case wasm::WASM_SYMBOL_TYPE_GLOBAL:
|
2018-11-14 10:46:21 +08:00
|
|
|
case wasm::WASM_SYMBOL_TYPE_EVENT:
|
2018-02-23 13:08:34 +08:00
|
|
|
Info.ElementIndex = Symbol.ElementIndex;
|
|
|
|
break;
|
2018-04-27 03:27:28 +08:00
|
|
|
case wasm::WASM_SYMBOL_TYPE_SECTION:
|
|
|
|
Info.ElementIndex = Symbol.ElementIndex;
|
|
|
|
break;
|
2017-06-20 12:04:59 +08:00
|
|
|
}
|
2018-02-23 13:08:34 +08:00
|
|
|
LinkingSec->SymbolTable.emplace_back(Info);
|
2017-06-20 12:04:59 +08:00
|
|
|
}
|
2018-04-27 02:15:32 +08:00
|
|
|
|
2017-12-15 05:10:03 +08:00
|
|
|
for (const wasm::WasmInitFunc &Func : Obj.linkingData().InitFunctions) {
|
2018-02-23 13:08:34 +08:00
|
|
|
WasmYAML::InitFunction F{Func.Priority, Func.Symbol};
|
2017-12-15 05:10:03 +08:00
|
|
|
LinkingSec->InitFunctions.emplace_back(F);
|
|
|
|
}
|
2018-04-27 02:15:32 +08:00
|
|
|
|
2017-06-20 12:04:59 +08:00
|
|
|
CustomSec = std::move(LinkingSec);
|
2019-01-17 10:29:55 +08:00
|
|
|
} else if (WasmSec.Name == "producers") {
|
|
|
|
std::unique_ptr<WasmYAML::ProducersSection> ProducersSec =
|
2019-08-15 23:54:37 +08:00
|
|
|
std::make_unique<WasmYAML::ProducersSection>();
|
2019-01-17 10:29:55 +08:00
|
|
|
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);
|
[WebAssembly] Target features section
Summary:
Implements a new target features section in assembly and object files
that records what features are used, required, and disallowed in
WebAssembly objects. The linker uses this information to ensure that
all objects participating in a link are feature-compatible and records
the set of used features in the output binary for use by optimizers
and other tools later in the toolchain.
The "atomics" feature is always required or disallowed to prevent
linking code with stripped atomics into multithreaded binaries. Other
features are marked used if they are enabled globally or on any
function in a module.
Future CLs will add linker flags for ignoring feature compatibility
checks and for specifying the set of allowed features, implement using
the presence of the "atomics" feature to control the type of memory
and segments in the linked binary, and add front-end flags for
relaxing the linkage policy for atomics.
Reviewers: aheejin, sbc100, dschuff
Subscribers: jgravelle-google, hiraditya, sunfish, mgrang, jfb, jdoerfert, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59173
llvm-svn: 356610
2019-03-21 04:26:45 +08:00
|
|
|
} else if (WasmSec.Name == "target_features") {
|
|
|
|
std::unique_ptr<WasmYAML::TargetFeaturesSection> TargetFeaturesSec =
|
2019-08-15 23:54:37 +08:00
|
|
|
std::make_unique<WasmYAML::TargetFeaturesSection>();
|
[WebAssembly] Target features section
Summary:
Implements a new target features section in assembly and object files
that records what features are used, required, and disallowed in
WebAssembly objects. The linker uses this information to ensure that
all objects participating in a link are feature-compatible and records
the set of used features in the output binary for use by optimizers
and other tools later in the toolchain.
The "atomics" feature is always required or disallowed to prevent
linking code with stripped atomics into multithreaded binaries. Other
features are marked used if they are enabled globally or on any
function in a module.
Future CLs will add linker flags for ignoring feature compatibility
checks and for specifying the set of allowed features, implement using
the presence of the "atomics" feature to control the type of memory
and segments in the linked binary, and add front-end flags for
relaxing the linkage policy for atomics.
Reviewers: aheejin, sbc100, dschuff
Subscribers: jgravelle-google, hiraditya, sunfish, mgrang, jfb, jdoerfert, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59173
llvm-svn: 356610
2019-03-21 04:26:45 +08:00
|
|
|
for (auto &E : Obj.getTargetFeatures()) {
|
|
|
|
WasmYAML::FeatureEntry Feature;
|
|
|
|
Feature.Prefix = E.Prefix;
|
|
|
|
Feature.Name = E.Name;
|
|
|
|
TargetFeaturesSec->Features.push_back(Feature);
|
|
|
|
}
|
|
|
|
CustomSec = std::move(TargetFeaturesSec);
|
2017-06-20 12:04:59 +08:00
|
|
|
} else {
|
2019-08-15 23:54:37 +08:00
|
|
|
CustomSec = std::make_unique<WasmYAML::CustomSection>(WasmSec.Name);
|
2017-06-20 12:04:59 +08:00
|
|
|
}
|
|
|
|
CustomSec->Payload = yaml::BinaryRef(WasmSec.Content);
|
|
|
|
return CustomSec;
|
|
|
|
}
|
|
|
|
|
2017-03-31 03:44:09 +08:00
|
|
|
ErrorOr<WasmYAML::Object *> WasmDumper::dump() {
|
2019-08-15 23:54:37 +08:00
|
|
|
auto Y = std::make_unique<WasmYAML::Object>();
|
2017-03-31 03:44:09 +08:00
|
|
|
|
|
|
|
// Dump header
|
|
|
|
Y->Header.Version = Obj.getHeader().Version;
|
|
|
|
|
|
|
|
// Dump sections
|
|
|
|
for (const auto &Sec : Obj.sections()) {
|
2017-06-20 12:04:59 +08:00
|
|
|
const WasmSection &WasmSec = Obj.getWasmSection(Sec);
|
2017-03-31 03:44:09 +08:00
|
|
|
std::unique_ptr<WasmYAML::Section> S;
|
|
|
|
switch (WasmSec.Type) {
|
|
|
|
case wasm::WASM_SEC_CUSTOM: {
|
|
|
|
if (WasmSec.Name.startswith("reloc.")) {
|
|
|
|
// Relocations are attached the sections they apply to rather than
|
|
|
|
// being represented as a custom section in the YAML output.
|
|
|
|
continue;
|
|
|
|
}
|
2017-06-20 12:04:59 +08:00
|
|
|
S = dumpCustomSection(WasmSec);
|
2017-03-31 03:44:09 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case wasm::WASM_SEC_TYPE: {
|
2019-08-15 23:54:37 +08:00
|
|
|
auto TypeSec = std::make_unique<WasmYAML::TypeSection>();
|
2017-03-31 03:44:09 +08:00
|
|
|
uint32_t Index = 0;
|
|
|
|
for (const auto &FunctionSig : Obj.types()) {
|
|
|
|
WasmYAML::Signature Sig;
|
|
|
|
Sig.Index = Index++;
|
2018-10-04 06:22:48 +08:00
|
|
|
for (const auto &ParamType : FunctionSig.Params)
|
[WebAssembly] clang-tidy (NFC)
Summary:
This patch fixes clang-tidy warnings on wasm-only files.
The list of checks used is:
`-*,clang-diagnostic-*,llvm-*,misc-*,-misc-unused-parameters,readability-identifier-naming,modernize-*`
(LLVM's default .clang-tidy list is the same except it does not have
`modernize-*`. But I've seen in multiple CLs in LLVM the modernize style
was recommended and code was fixed based on the style, so I added it as
well.)
The common fixes are:
- Variable names start with an uppercase letter
- Function names start with a lowercase letter
- Use `auto` when you use casts so the type is evident
- Use inline initialization for class member variables
- Use `= default` for empty constructors / destructors
- Use `using` in place of `typedef`
Reviewers: sbc100, tlively, aardappel
Subscribers: dschuff, sunfish, jgravelle-google, yurydelendik, kripken, MatzeB, mgorny, rupprecht, llvm-commits
Differential Revision: https://reviews.llvm.org/D57500
llvm-svn: 353075
2019-02-05 03:13:39 +08:00
|
|
|
Sig.ParamTypes.emplace_back(static_cast<uint32_t>(ParamType));
|
2019-10-19 04:27:30 +08:00
|
|
|
for (const auto &ReturnType : FunctionSig.Returns)
|
|
|
|
Sig.ReturnTypes.emplace_back(static_cast<uint32_t>(ReturnType));
|
2017-03-31 03:44:09 +08:00
|
|
|
TypeSec->Signatures.push_back(Sig);
|
|
|
|
}
|
|
|
|
S = std::move(TypeSec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case wasm::WASM_SEC_IMPORT: {
|
2019-08-15 23:54:37 +08:00
|
|
|
auto ImportSec = std::make_unique<WasmYAML::ImportSection>();
|
2017-03-31 03:44:09 +08:00
|
|
|
for (auto &Import : Obj.imports()) {
|
2017-05-10 07:48:41 +08:00
|
|
|
WasmYAML::Import Im;
|
|
|
|
Im.Module = Import.Module;
|
|
|
|
Im.Field = Import.Field;
|
|
|
|
Im.Kind = Import.Kind;
|
|
|
|
switch (Im.Kind) {
|
|
|
|
case wasm::WASM_EXTERNAL_FUNCTION:
|
|
|
|
Im.SigIndex = Import.SigIndex;
|
|
|
|
break;
|
|
|
|
case wasm::WASM_EXTERNAL_GLOBAL:
|
2017-05-10 08:14:04 +08:00
|
|
|
Im.GlobalImport.Type = Import.Global.Type;
|
|
|
|
Im.GlobalImport.Mutable = Import.Global.Mutable;
|
2017-05-10 07:48:41 +08:00
|
|
|
break;
|
2018-11-14 10:46:21 +08:00
|
|
|
case wasm::WASM_EXTERNAL_EVENT:
|
|
|
|
Im.EventImport.Attribute = Import.Event.Attribute;
|
|
|
|
Im.EventImport.SigIndex = Import.Event.SigIndex;
|
|
|
|
break;
|
2017-05-10 07:48:41 +08:00
|
|
|
case wasm::WASM_EXTERNAL_TABLE:
|
[WebAssembly] clang-tidy (NFC)
Summary:
This patch fixes clang-tidy warnings on wasm-only files.
The list of checks used is:
`-*,clang-diagnostic-*,llvm-*,misc-*,-misc-unused-parameters,readability-identifier-naming,modernize-*`
(LLVM's default .clang-tidy list is the same except it does not have
`modernize-*`. But I've seen in multiple CLs in LLVM the modernize style
was recommended and code was fixed based on the style, so I added it as
well.)
The common fixes are:
- Variable names start with an uppercase letter
- Function names start with a lowercase letter
- Use `auto` when you use casts so the type is evident
- Use inline initialization for class member variables
- Use `= default` for empty constructors / destructors
- Use `using` in place of `typedef`
Reviewers: sbc100, tlively, aardappel
Subscribers: dschuff, sunfish, jgravelle-google, yurydelendik, kripken, MatzeB, mgorny, rupprecht, llvm-commits
Differential Revision: https://reviews.llvm.org/D57500
llvm-svn: 353075
2019-02-05 03:13:39 +08:00
|
|
|
Im.TableImport = makeTable(Import.Table);
|
2017-05-10 07:48:41 +08:00
|
|
|
break;
|
|
|
|
case wasm::WASM_EXTERNAL_MEMORY:
|
[WebAssembly] clang-tidy (NFC)
Summary:
This patch fixes clang-tidy warnings on wasm-only files.
The list of checks used is:
`-*,clang-diagnostic-*,llvm-*,misc-*,-misc-unused-parameters,readability-identifier-naming,modernize-*`
(LLVM's default .clang-tidy list is the same except it does not have
`modernize-*`. But I've seen in multiple CLs in LLVM the modernize style
was recommended and code was fixed based on the style, so I added it as
well.)
The common fixes are:
- Variable names start with an uppercase letter
- Function names start with a lowercase letter
- Use `auto` when you use casts so the type is evident
- Use inline initialization for class member variables
- Use `= default` for empty constructors / destructors
- Use `using` in place of `typedef`
Reviewers: sbc100, tlively, aardappel
Subscribers: dschuff, sunfish, jgravelle-google, yurydelendik, kripken, MatzeB, mgorny, rupprecht, llvm-commits
Differential Revision: https://reviews.llvm.org/D57500
llvm-svn: 353075
2019-02-05 03:13:39 +08:00
|
|
|
Im.Memory = makeLimits(Import.Memory);
|
2017-05-10 07:48:41 +08:00
|
|
|
break;
|
2017-03-31 03:44:09 +08:00
|
|
|
}
|
2017-05-10 07:48:41 +08:00
|
|
|
ImportSec->Imports.push_back(Im);
|
2017-03-31 03:44:09 +08:00
|
|
|
}
|
|
|
|
S = std::move(ImportSec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case wasm::WASM_SEC_FUNCTION: {
|
2019-08-15 23:54:37 +08:00
|
|
|
auto FuncSec = std::make_unique<WasmYAML::FunctionSection>();
|
2017-03-31 03:44:09 +08:00
|
|
|
for (const auto &Func : Obj.functionTypes()) {
|
|
|
|
FuncSec->FunctionTypes.push_back(Func);
|
|
|
|
}
|
|
|
|
S = std::move(FuncSec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case wasm::WASM_SEC_TABLE: {
|
2019-08-15 23:54:37 +08:00
|
|
|
auto TableSec = std::make_unique<WasmYAML::TableSection>();
|
2017-05-10 07:48:41 +08:00
|
|
|
for (const wasm::WasmTable &Table : Obj.tables()) {
|
[WebAssembly] clang-tidy (NFC)
Summary:
This patch fixes clang-tidy warnings on wasm-only files.
The list of checks used is:
`-*,clang-diagnostic-*,llvm-*,misc-*,-misc-unused-parameters,readability-identifier-naming,modernize-*`
(LLVM's default .clang-tidy list is the same except it does not have
`modernize-*`. But I've seen in multiple CLs in LLVM the modernize style
was recommended and code was fixed based on the style, so I added it as
well.)
The common fixes are:
- Variable names start with an uppercase letter
- Function names start with a lowercase letter
- Use `auto` when you use casts so the type is evident
- Use inline initialization for class member variables
- Use `= default` for empty constructors / destructors
- Use `using` in place of `typedef`
Reviewers: sbc100, tlively, aardappel
Subscribers: dschuff, sunfish, jgravelle-google, yurydelendik, kripken, MatzeB, mgorny, rupprecht, llvm-commits
Differential Revision: https://reviews.llvm.org/D57500
llvm-svn: 353075
2019-02-05 03:13:39 +08:00
|
|
|
TableSec->Tables.push_back(makeTable(Table));
|
2017-03-31 03:44:09 +08:00
|
|
|
}
|
|
|
|
S = std::move(TableSec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case wasm::WASM_SEC_MEMORY: {
|
2019-08-15 23:54:37 +08:00
|
|
|
auto MemorySec = std::make_unique<WasmYAML::MemorySection>();
|
2017-05-10 07:48:41 +08:00
|
|
|
for (const wasm::WasmLimits &Memory : Obj.memories()) {
|
[WebAssembly] clang-tidy (NFC)
Summary:
This patch fixes clang-tidy warnings on wasm-only files.
The list of checks used is:
`-*,clang-diagnostic-*,llvm-*,misc-*,-misc-unused-parameters,readability-identifier-naming,modernize-*`
(LLVM's default .clang-tidy list is the same except it does not have
`modernize-*`. But I've seen in multiple CLs in LLVM the modernize style
was recommended and code was fixed based on the style, so I added it as
well.)
The common fixes are:
- Variable names start with an uppercase letter
- Function names start with a lowercase letter
- Use `auto` when you use casts so the type is evident
- Use inline initialization for class member variables
- Use `= default` for empty constructors / destructors
- Use `using` in place of `typedef`
Reviewers: sbc100, tlively, aardappel
Subscribers: dschuff, sunfish, jgravelle-google, yurydelendik, kripken, MatzeB, mgorny, rupprecht, llvm-commits
Differential Revision: https://reviews.llvm.org/D57500
llvm-svn: 353075
2019-02-05 03:13:39 +08:00
|
|
|
MemorySec->Memories.push_back(makeLimits(Memory));
|
2017-03-31 03:44:09 +08:00
|
|
|
}
|
|
|
|
S = std::move(MemorySec);
|
|
|
|
break;
|
|
|
|
}
|
2020-03-25 10:36:13 +08:00
|
|
|
case wasm::WASM_SEC_EVENT: {
|
|
|
|
auto EventSec = std::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;
|
|
|
|
}
|
2017-03-31 03:44:09 +08:00
|
|
|
case wasm::WASM_SEC_GLOBAL: {
|
2019-08-15 23:54:37 +08:00
|
|
|
auto GlobalSec = std::make_unique<WasmYAML::GlobalSection>();
|
2017-03-31 03:44:09 +08:00
|
|
|
for (auto &Global : Obj.globals()) {
|
|
|
|
WasmYAML::Global G;
|
2018-01-10 05:38:53 +08:00
|
|
|
G.Index = Global.Index;
|
2018-02-01 03:50:14 +08:00
|
|
|
G.Type = Global.Type.Type;
|
|
|
|
G.Mutable = Global.Type.Mutable;
|
2017-03-31 03:44:09 +08:00
|
|
|
G.InitExpr = Global.InitExpr;
|
|
|
|
GlobalSec->Globals.push_back(G);
|
|
|
|
}
|
|
|
|
S = std::move(GlobalSec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case wasm::WASM_SEC_START: {
|
2019-08-15 23:54:37 +08:00
|
|
|
auto StartSec = std::make_unique<WasmYAML::StartSection>();
|
2017-03-31 03:44:09 +08:00
|
|
|
StartSec->StartFunction = Obj.startFunction();
|
|
|
|
S = std::move(StartSec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case wasm::WASM_SEC_EXPORT: {
|
2019-08-15 23:54:37 +08:00
|
|
|
auto ExportSec = std::make_unique<WasmYAML::ExportSection>();
|
2017-03-31 03:44:09 +08:00
|
|
|
for (auto &Export : Obj.exports()) {
|
|
|
|
WasmYAML::Export Ex;
|
|
|
|
Ex.Name = Export.Name;
|
|
|
|
Ex.Kind = Export.Kind;
|
|
|
|
Ex.Index = Export.Index;
|
|
|
|
ExportSec->Exports.push_back(Ex);
|
|
|
|
}
|
|
|
|
S = std::move(ExportSec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case wasm::WASM_SEC_ELEM: {
|
2019-08-15 23:54:37 +08:00
|
|
|
auto ElemSec = std::make_unique<WasmYAML::ElemSection>();
|
2017-03-31 03:44:09 +08:00
|
|
|
for (auto &Segment : Obj.elements()) {
|
|
|
|
WasmYAML::ElemSegment Seg;
|
|
|
|
Seg.TableIndex = Segment.TableIndex;
|
|
|
|
Seg.Offset = Segment.Offset;
|
|
|
|
for (auto &Func : Segment.Functions) {
|
|
|
|
Seg.Functions.push_back(Func);
|
|
|
|
}
|
|
|
|
ElemSec->Segments.push_back(Seg);
|
|
|
|
}
|
|
|
|
S = std::move(ElemSec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case wasm::WASM_SEC_CODE: {
|
2019-08-15 23:54:37 +08:00
|
|
|
auto CodeSec = std::make_unique<WasmYAML::CodeSection>();
|
2017-03-31 03:44:09 +08:00
|
|
|
for (auto &Func : Obj.functions()) {
|
|
|
|
WasmYAML::Function Function;
|
2018-01-10 05:38:53 +08:00
|
|
|
Function.Index = Func.Index;
|
2017-03-31 03:44:09 +08:00
|
|
|
for (auto &Local : Func.Locals) {
|
|
|
|
WasmYAML::LocalDecl LocalDecl;
|
|
|
|
LocalDecl.Type = Local.Type;
|
|
|
|
LocalDecl.Count = Local.Count;
|
|
|
|
Function.Locals.push_back(LocalDecl);
|
|
|
|
}
|
|
|
|
Function.Body = yaml::BinaryRef(Func.Body);
|
|
|
|
CodeSec->Functions.push_back(Function);
|
|
|
|
}
|
|
|
|
S = std::move(CodeSec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case wasm::WASM_SEC_DATA: {
|
2019-08-15 23:54:37 +08:00
|
|
|
auto DataSec = std::make_unique<WasmYAML::DataSection>();
|
2017-09-21 03:03:35 +08:00
|
|
|
for (const object::WasmSegment &Segment : Obj.dataSegments()) {
|
2017-03-31 03:44:09 +08:00
|
|
|
WasmYAML::DataSegment Seg;
|
2017-07-12 08:24:54 +08:00
|
|
|
Seg.SectionOffset = Segment.SectionOffset;
|
2019-02-20 06:56:19 +08:00
|
|
|
Seg.InitFlags = Segment.Data.InitFlags;
|
2017-07-12 08:24:54 +08:00
|
|
|
Seg.MemoryIndex = Segment.Data.MemoryIndex;
|
|
|
|
Seg.Offset = Segment.Data.Offset;
|
|
|
|
Seg.Content = yaml::BinaryRef(Segment.Data.Content);
|
2017-03-31 03:44:09 +08:00
|
|
|
DataSec->Segments.push_back(Seg);
|
|
|
|
}
|
|
|
|
S = std::move(DataSec);
|
|
|
|
break;
|
|
|
|
}
|
2019-04-13 06:27:48 +08:00
|
|
|
case wasm::WASM_SEC_DATACOUNT: {
|
2019-08-15 23:54:37 +08:00
|
|
|
auto DataCountSec = std::make_unique<WasmYAML::DataCountSection>();
|
2019-04-13 06:27:48 +08:00
|
|
|
DataCountSec->Count = Obj.dataSegments().size();
|
|
|
|
S = std::move(DataCountSec);
|
|
|
|
break;
|
|
|
|
}
|
2017-03-31 03:44:09 +08:00
|
|
|
default:
|
|
|
|
llvm_unreachable("Unknown section type");
|
|
|
|
break;
|
|
|
|
}
|
2018-09-05 09:27:38 +08:00
|
|
|
for (const wasm::WasmRelocation &Reloc : WasmSec.Relocations) {
|
2017-03-31 03:44:09 +08:00
|
|
|
WasmYAML::Relocation R;
|
|
|
|
R.Type = Reloc.Type;
|
|
|
|
R.Index = Reloc.Index;
|
|
|
|
R.Offset = Reloc.Offset;
|
|
|
|
R.Addend = Reloc.Addend;
|
|
|
|
S->Relocations.push_back(R);
|
|
|
|
}
|
|
|
|
Y->Sections.push_back(std::move(S));
|
|
|
|
}
|
|
|
|
|
|
|
|
return Y.release();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::error_code wasm2yaml(raw_ostream &Out, const object::WasmObjectFile &Obj) {
|
|
|
|
WasmDumper Dumper(Obj);
|
|
|
|
ErrorOr<WasmYAML::Object *> YAMLOrErr = Dumper.dump();
|
|
|
|
if (std::error_code EC = YAMLOrErr.getError())
|
|
|
|
return EC;
|
|
|
|
|
|
|
|
std::unique_ptr<WasmYAML::Object> YAML(YAMLOrErr.get());
|
|
|
|
yaml::Output Yout(Out);
|
|
|
|
Yout << *YAML;
|
|
|
|
|
|
|
|
return std::error_code();
|
|
|
|
}
|