29 : Obj(Obj), ErrHandler(EH) {}
66 bool HasError =
false;
71class SubSectionWriter {
73 std::string OutString;
77 SubSectionWriter(
raw_ostream &OS) : OS(OS), StringStream(OutString) {}
126void WasmWriter::reportError(
const Twine &Msg) {
162void WasmWriter::writeSectionContent(
raw_ostream &OS,
167 SubSectionWriter SubSection(OS);
185void WasmWriter::writeSectionContent(
raw_ostream &OS,
190 SubSectionWriter SubSection(OS);
193 if (
Section.SymbolTable.size()) {
231 if (
Section.SegmentInfos.size()) {
243 if (
Section.InitFunctions.size()) {
257 for (
const auto &
C :
Section.Comdats) {
262 writeUint8(SubSection.getStream(), Entry.Kind);
270void WasmWriter::writeSectionContent(
raw_ostream &OS,
273 if (
Section.FunctionNames.size()) {
276 SubSectionWriter SubSection(OS);
286 if (
Section.GlobalNames.size()) {
289 SubSectionWriter SubSection(OS);
299 if (
Section.DataSegmentNames.size()) {
302 SubSectionWriter SubSection(OS);
314void WasmWriter::writeSectionContent(
raw_ostream &OS,
317 int Fields = int(!
Section.Languages.empty()) + int(!
Section.Tools.empty()) +
325 if (
Field.second->empty())
329 for (
auto &Entry : *
Field.second) {
336void WasmWriter::writeSectionContent(
raw_ostream &OS,
346void WasmWriter::writeSectionContent(
raw_ostream &OS,
348 if (
auto S = dyn_cast<WasmYAML::DylinkSection>(&Section)) {
349 writeSectionContent(OS, *S);
350 }
else if (
auto S = dyn_cast<WasmYAML::NameSection>(&Section)) {
351 writeSectionContent(OS, *S);
352 }
else if (
auto S = dyn_cast<WasmYAML::LinkingSection>(&Section)) {
353 writeSectionContent(OS, *S);
354 }
else if (
auto S = dyn_cast<WasmYAML::ProducersSection>(&Section)) {
355 writeSectionContent(OS, *S);
356 }
else if (
auto S = dyn_cast<WasmYAML::TargetFeaturesSection>(&Section)) {
357 writeSectionContent(OS, *S);
360 Section.Payload.writeAsBinary(OS);
364void WasmWriter::writeSectionContent(
raw_ostream &OS,
369 if (Sig.
Index != ExpectedIndex) {
384void WasmWriter::writeSectionContent(
raw_ostream &OS,
394 NumImportedFunctions++;
399 NumImportedGlobals++;
421void WasmWriter::writeSectionContent(
raw_ostream &OS,
428void WasmWriter::writeSectionContent(
raw_ostream &OS,
438void WasmWriter::writeSectionContent(
raw_ostream &OS,
443void WasmWriter::writeSectionContent(
raw_ostream &OS,
446 uint32_t ExpectedIndex = NumImportedTables;
447 for (
auto &Table :
Section.Tables) {
448 if (Table.Index != ExpectedIndex) {
458void WasmWriter::writeSectionContent(
raw_ostream &OS,
465void WasmWriter::writeSectionContent(
raw_ostream &OS,
474void WasmWriter::writeSectionContent(
raw_ostream &OS,
477 uint32_t ExpectedIndex = NumImportedGlobals;
479 if (
Global.Index != ExpectedIndex) {
486 writeInitExpr(OS,
Global.Init);
490void WasmWriter::writeSectionContent(
raw_ostream &OS,
493 for (
auto &Segment :
Section.Segments) {
498 writeInitExpr(OS, Segment.Offset);
504 if (Segment.ElemKind !=
uint32_t(wasm::ValType::FUNCREF)) {
508 const uint8_t ElemKind = 0;
513 for (
auto &
Function : Segment.Functions)
518void WasmWriter::writeSectionContent(
raw_ostream &OS,
521 uint32_t ExpectedIndex = NumImportedFunctions;
522 for (
auto &Func :
Section.Functions) {
523 std::string OutString;
525 if (
Func.Index != ExpectedIndex) {
532 for (
auto &LocalDecl :
Func.Locals) {
537 Func.Body.writeAsBinary(StringStream);
540 StringStream.
flush();
546void WasmWriter::writeSectionContent(
raw_ostream &OS,
549 for (
auto &Segment :
Section.Segments) {
554 writeInitExpr(OS, Segment.Offset);
556 Segment.Content.writeAsBinary(OS);
560void WasmWriter::writeSectionContent(
raw_ostream &OS,
575 auto *CustomSection = cast<WasmYAML::CustomSection>(&Sec);
602 for (
const std::unique_ptr<WasmYAML::Section> &Sec : Obj.Sections) {
604 if (
auto S = dyn_cast<WasmYAML::CustomSection>(Sec.get()))
611 std::string OutString;
613 if (
auto S = dyn_cast<WasmYAML::CustomSection>(Sec.get()))
614 writeSectionContent(StringStream, *S);
615 else if (
auto S = dyn_cast<WasmYAML::TypeSection>(Sec.get()))
616 writeSectionContent(StringStream, *S);
617 else if (
auto S = dyn_cast<WasmYAML::ImportSection>(Sec.get()))
618 writeSectionContent(StringStream, *S);
619 else if (
auto S = dyn_cast<WasmYAML::FunctionSection>(Sec.get()))
620 writeSectionContent(StringStream, *S);
621 else if (
auto S = dyn_cast<WasmYAML::TableSection>(Sec.get()))
622 writeSectionContent(StringStream, *S);
623 else if (
auto S = dyn_cast<WasmYAML::MemorySection>(Sec.get()))
624 writeSectionContent(StringStream, *S);
625 else if (
auto S = dyn_cast<WasmYAML::TagSection>(Sec.get()))
626 writeSectionContent(StringStream, *S);
627 else if (
auto S = dyn_cast<WasmYAML::GlobalSection>(Sec.get()))
628 writeSectionContent(StringStream, *S);
629 else if (
auto S = dyn_cast<WasmYAML::ExportSection>(Sec.get()))
630 writeSectionContent(StringStream, *S);
631 else if (
auto S = dyn_cast<WasmYAML::StartSection>(Sec.get()))
632 writeSectionContent(StringStream, *S);
633 else if (
auto S = dyn_cast<WasmYAML::ElemSection>(Sec.get()))
634 writeSectionContent(StringStream, *S);
635 else if (
auto S = dyn_cast<WasmYAML::CodeSection>(Sec.get()))
636 writeSectionContent(StringStream, *S);
637 else if (
auto S = dyn_cast<WasmYAML::DataSection>(Sec.get()))
638 writeSectionContent(StringStream, *S);
639 else if (
auto S = dyn_cast<WasmYAML::DataCountSection>(Sec.get()))
640 writeSectionContent(StringStream, *S);
647 StringStream.
flush();
656 for (
const std::unique_ptr<WasmYAML::Section> &Sec : Obj.Sections) {
657 if (Sec->Relocations.empty()) {
663 std::string OutString;
665 writeRelocSection(StringStream, *Sec, SectionIndex++);
666 StringStream.
flush();
679 WasmWriter Writer(Doc, EH);
680 return Writer.writeWasm(Out);
static Error reportError(StringRef Message)
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Analysis containing CSE Info
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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.
bool isValidSectionOrder(unsigned ID, StringRef CustomSectionName="")
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.
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.
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
const unsigned WASM_ELEM_SEGMENT_MASK_HAS_ELEM_KIND
@ WASM_ELEM_SEGMENT_HAS_TABLE_NUMBER
@ WASM_SYMBOL_TYPE_GLOBAL
@ WASM_SYMBOL_TYPE_SECTION
@ WASM_SYMBOL_TYPE_FUNCTION
@ WASM_NAMES_DATA_SEGMENT
bool relocTypeHasAddend(uint32_t type)
const unsigned WASM_SYMBOL_EXPLICIT_NAME
bool yaml2wasm(WasmYAML::Object &Doc, raw_ostream &Out, ErrorHandler EH)
This is an optimization pass for GlobalISel generic memory operations.
@ Export
Export information to summary.
@ Import
Import information from summary.
@ Global
Append to llvm.global_dtors.
detail::enumerator< R > enumerate(R &&TheRange)
Given an input range, returns a new range whose values are are pair (A,B) such that A is the 0-based ...
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::@176 Value
Common declarations for yaml2obj.