29 : Obj(Obj), ErrHandler(EH) {}
66 bool HasError =
false;
71class SubSectionWriter {
73 std::string OutString;
92 char Data[
sizeof(
Value)];
99 char Data[
sizeof(
Value)];
106 char Data[
sizeof(
Value)];
107 memcpy(Data, &
Value,
sizeof(Data));
126void WasmWriter::reportError(
const Twine &Msg) {
167 SubSectionWriter SubSection(
OS);
183 if (
Section.RuntimePath.size()) {
198 SubSectionWriter SubSection(
OS);
201 if (
Section.SymbolTable.size()) {
239 if (
Section.SegmentInfos.size()) {
251 if (
Section.InitFunctions.size()) {
265 for (
const auto &
C :
Section.Comdats) {
281 if (
Section.FunctionNames.size()) {
284 SubSectionWriter SubSection(
OS);
294 if (
Section.GlobalNames.size()) {
297 SubSectionWriter SubSection(
OS);
307 if (
Section.DataSegmentNames.size()) {
310 SubSectionWriter SubSection(
OS);
325 int Fields = int(!
Section.Languages.empty()) + int(!
Section.Tools.empty()) +
333 if (
Field.second->empty())
337 for (
auto &Entry : *
Field.second) {
348 for (
auto &E :
Section.Features) {
356 if (
auto S = dyn_cast<WasmYAML::DylinkSection>(&Section)) {
357 writeSectionContent(
OS, *S);
358 }
else if (
auto S = dyn_cast<WasmYAML::NameSection>(&Section)) {
359 writeSectionContent(
OS, *S);
360 }
else if (
auto S = dyn_cast<WasmYAML::LinkingSection>(&Section)) {
361 writeSectionContent(
OS, *S);
362 }
else if (
auto S = dyn_cast<WasmYAML::ProducersSection>(&Section)) {
363 writeSectionContent(
OS, *S);
364 }
else if (
auto S = dyn_cast<WasmYAML::TargetFeaturesSection>(&Section)) {
365 writeSectionContent(
OS, *S);
377 if (Sig.
Index != ExpectedIndex) {
402 NumImportedFunctions++;
407 NumImportedGlobals++;
454 uint32_t ExpectedIndex = NumImportedTables;
455 for (
auto &Table :
Section.Tables) {
456 if (Table.Index != ExpectedIndex) {
485 uint32_t ExpectedIndex = NumImportedGlobals;
487 if (
Global.Index != ExpectedIndex) {
501 for (
auto &Segment :
Section.Segments) {
506 writeInitExpr(
OS, Segment.Offset);
512 if (Segment.ElemKind !=
uint32_t(wasm::ValType::FUNCREF)) {
521 for (
auto &
Function : Segment.Functions)
529 uint32_t ExpectedIndex = NumImportedFunctions;
530 for (
auto &Func :
Section.Functions) {
531 std::string OutString;
533 if (
Func.Index != ExpectedIndex) {
540 for (
auto &LocalDecl :
Func.Locals) {
545 Func.Body.writeAsBinary(StringStream);
548 StringStream.
flush();
557 for (
auto &Segment :
Section.Segments) {
562 writeInitExpr(
OS, Segment.Offset);
564 Segment.Content.writeAsBinary(
OS);
583 auto *CustomSection = cast<WasmYAML::CustomSection>(&Sec);
610 for (
const std::unique_ptr<WasmYAML::Section> &Sec : Obj.Sections) {
612 if (
auto S = dyn_cast<WasmYAML::CustomSection>(Sec.get()))
614 if (!Checker.isValidSectionOrder(Sec->Type, SecName)) {
620 std::string OutString;
622 if (
auto S = dyn_cast<WasmYAML::CustomSection>(Sec.get()))
623 writeSectionContent(StringStream, *S);
624 else if (
auto S = dyn_cast<WasmYAML::TypeSection>(Sec.get()))
625 writeSectionContent(StringStream, *S);
626 else if (
auto S = dyn_cast<WasmYAML::ImportSection>(Sec.get()))
627 writeSectionContent(StringStream, *S);
628 else if (
auto S = dyn_cast<WasmYAML::FunctionSection>(Sec.get()))
629 writeSectionContent(StringStream, *S);
630 else if (
auto S = dyn_cast<WasmYAML::TableSection>(Sec.get()))
631 writeSectionContent(StringStream, *S);
632 else if (
auto S = dyn_cast<WasmYAML::MemorySection>(Sec.get()))
633 writeSectionContent(StringStream, *S);
634 else if (
auto S = dyn_cast<WasmYAML::TagSection>(Sec.get()))
635 writeSectionContent(StringStream, *S);
636 else if (
auto S = dyn_cast<WasmYAML::GlobalSection>(Sec.get()))
637 writeSectionContent(StringStream, *S);
638 else if (
auto S = dyn_cast<WasmYAML::ExportSection>(Sec.get()))
639 writeSectionContent(StringStream, *S);
640 else if (
auto S = dyn_cast<WasmYAML::StartSection>(Sec.get()))
641 writeSectionContent(StringStream, *S);
642 else if (
auto S = dyn_cast<WasmYAML::ElemSection>(Sec.get()))
643 writeSectionContent(StringStream, *S);
644 else if (
auto S = dyn_cast<WasmYAML::CodeSection>(Sec.get()))
645 writeSectionContent(StringStream, *S);
646 else if (
auto S = dyn_cast<WasmYAML::DataSection>(Sec.get()))
647 writeSectionContent(StringStream, *S);
648 else if (
auto S = dyn_cast<WasmYAML::DataCountSection>(Sec.get()))
649 writeSectionContent(StringStream, *S);
656 StringStream.
flush();
658 unsigned HeaderSecSizeEncodingLen =
659 Sec->HeaderSecSizeEncodingLen.value_or(5);
663 if (HeaderSecSizeEncodingLen < RequiredLen) {
664 reportError(
"section header length can't be encoded in a LEB of size " +
665 Twine(HeaderSecSizeEncodingLen));
675 for (
const std::unique_ptr<WasmYAML::Section> &Sec : Obj.Sections) {
676 if (Sec->Relocations.empty()) {
682 std::string OutString;
684 writeRelocSection(StringStream, *Sec, SectionIndex++);
685 StringStream.
flush();
698 WasmWriter Writer(Doc, EH);
699 return Writer.writeWasm(Out);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static Error reportError(StringRef Message)
Analysis containing CSE Info
static int writeUint32(raw_ostream &OS, uint32_t Value)
static int writeLimits(const WasmYAML::Limits &Lim, raw_ostream &OS)
static int writeStringRef(const StringRef &Str, raw_ostream &OS)
static int writeUint8(raw_ostream &OS, uint8_t Value)
static int writeUint64(raw_ostream &OS, uint64_t Value)
StringRef - Represent a constant reference to a string, i.e.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
LLVM Value Representation.
An efficient, type-erasing, non-owning reference to a callable.
This class implements an extremely fast bulk output stream that can only output to a stream.
raw_ostream & write(unsigned char C)
A raw_ostream that writes to an std::string.
LLVM_ABI void writeAsBinary(raw_ostream &OS, uint64_t N=UINT64_MAX) const
Write the contents (regardless of whether it is binary or a hex string) as binary to the given raw_os...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
NodeAddr< FuncNode * > Func
void write64le(void *P, uint64_t V)
void write32le(void *P, uint32_t V)
const unsigned WASM_SYMBOL_UNDEFINED
@ WASM_DATA_SEGMENT_IS_PASSIVE
@ WASM_DATA_SEGMENT_HAS_MEMINDEX
@ WASM_LIMITS_FLAG_HAS_MAX
@ WASM_DYLINK_RUNTIME_PATH
@ WASM_ELEM_SEGMENT_HAS_TABLE_NUMBER
@ WASM_SYMBOL_TYPE_GLOBAL
@ WASM_SYMBOL_TYPE_SECTION
@ WASM_SYMBOL_TYPE_FUNCTION
LLVM_ABI bool relocTypeHasAddend(uint32_t type)
LLVM_ABI llvm::StringRef sectionTypeToString(uint32_t type)
const unsigned WASM_SYMBOL_EXPLICIT_NAME
@ WASM_NAMES_DATA_SEGMENT
const unsigned WASM_ELEM_SEGMENT_MASK_HAS_ELEM_DESC
LLVM_ABI bool yaml2wasm(WasmYAML::Object &Doc, raw_ostream &Out, ErrorHandler EH)
This is an optimization pass for GlobalISel generic memory operations.
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are tuples (A, B,...
@ Export
Export information to summary.
@ Import
Import information from summary.
@ Global
Append to llvm.global_dtors.
LLVM_ABI unsigned getULEB128Size(uint64_t Value)
Utility function to get the size of the ULEB128-encoded value.
unsigned encodeSLEB128(int64_t Value, raw_ostream &OS, unsigned PadTo=0)
Utility function to encode a SLEB128 value to an output stream.
unsigned encodeULEB128(uint64_t Value, raw_ostream &OS, unsigned PadTo=0)
Utility function to encode a ULEB128 value to an output stream.
wasm::WasmInitExprMVP Inst
std::vector< Relocation > Relocations
std::vector< ValueType > ReturnTypes
std::vector< ValueType > ParamTypes
union llvm::wasm::WasmInitExprMVP::@188 Value
Common declarations for yaml2obj.