29 : Obj(Obj), ErrHandler(EH) {}
65 bool HasError =
false;
70 class SubSectionWriter {
72 std::string OutString;
76 SubSectionWriter(
raw_ostream &OS) : OS(OS), StringStream(OutString) {}
133 switch (InitExpr.
Opcode) {
156 void WasmWriter::writeSectionContent(
raw_ostream &OS,
168 void WasmWriter::writeSectionContent(
raw_ostream &OS,
173 SubSectionWriter SubSection(OS);
242 for (
const auto &
C : Section.
Comdats) {
255 void WasmWriter::writeSectionContent(
raw_ostream &OS,
261 SubSectionWriter SubSection(OS);
273 void WasmWriter::writeSectionContent(
raw_ostream &OS,
276 int Fields = int(!Section.
Languages.empty()) +
int(!Section.
Tools.empty()) +
277 int(!Section.
SDKs.empty());
284 if (
Field.second->empty())
295 void WasmWriter::writeSectionContent(
raw_ostream &OS,
305 void WasmWriter::writeSectionContent(
raw_ostream &OS,
307 if (
auto S = dyn_cast<WasmYAML::DylinkSection>(&Section)) {
308 writeSectionContent(OS, *S);
309 }
else if (
auto S = dyn_cast<WasmYAML::NameSection>(&Section)) {
310 writeSectionContent(OS, *S);
311 }
else if (
auto S = dyn_cast<WasmYAML::LinkingSection>(&Section)) {
312 writeSectionContent(OS, *S);
313 }
else if (
auto S = dyn_cast<WasmYAML::ProducersSection>(&Section)) {
314 writeSectionContent(OS, *S);
315 }
else if (
auto S = dyn_cast<WasmYAML::TargetFeaturesSection>(&Section)) {
316 writeSectionContent(OS, *S);
323 void WasmWriter::writeSectionContent(
raw_ostream &OS,
328 if (Sig.
Index != ExpectedIndex) {
343 void WasmWriter::writeSectionContent(
raw_ostream &OS,
350 switch (Import.
Kind) {
353 NumImportedFunctions++;
358 NumImportedGlobals++;
363 NumImportedGlobals++;
379 void WasmWriter::writeSectionContent(
raw_ostream &OS,
386 void WasmWriter::writeSectionContent(
raw_ostream &OS,
396 void WasmWriter::writeSectionContent(
raw_ostream &OS,
401 void WasmWriter::writeSectionContent(
raw_ostream &OS,
404 for (
auto &Table : Section.
Tables) {
410 void WasmWriter::writeSectionContent(
raw_ostream &OS,
417 void WasmWriter::writeSectionContent(
raw_ostream &OS,
420 uint32_t ExpectedIndex = NumImportedGlobals;
421 for (
auto &Global : Section.
Globals) {
422 if (Global.Index != ExpectedIndex) {
429 writeInitExpr(OS, Global.InitExpr);
433 void WasmWriter::writeSectionContent(
raw_ostream &OS,
436 uint32_t ExpectedIndex = NumImportedEvents;
437 for (
auto &Event : Section.
Events) {
438 if (Event.Index != ExpectedIndex) {
448 void WasmWriter::writeSectionContent(
raw_ostream &OS,
451 for (
auto &Segment : Section.
Segments) {
453 writeInitExpr(OS, Segment.Offset);
456 for (
auto &
Function : Segment.Functions)
461 void WasmWriter::writeSectionContent(
raw_ostream &OS,
464 uint32_t ExpectedIndex = NumImportedFunctions;
466 std::string OutString;
468 if (Func.Index != ExpectedIndex) {
475 for (
auto &LocalDecl : Func.Locals) {
480 Func.Body.writeAsBinary(StringStream);
483 StringStream.
flush();
489 void WasmWriter::writeSectionContent(
raw_ostream &OS,
492 for (
auto &Segment : Section.
Segments) {
497 writeInitExpr(OS, Segment.Offset);
499 Segment.Content.writeAsBinary(OS);
503 void WasmWriter::writeSectionContent(
raw_ostream &OS,
518 auto *CustomSection = cast<WasmYAML::CustomSection>(&Sec);
533 switch (Reloc.Type) {
534 case wasm::R_WASM_MEMORY_ADDR_LEB:
535 case wasm::R_WASM_MEMORY_ADDR_SLEB:
536 case wasm::R_WASM_MEMORY_ADDR_I32:
537 case wasm::R_WASM_FUNCTION_OFFSET_I32:
538 case wasm::R_WASM_SECTION_OFFSET_I32:
551 for (
const std::unique_ptr<WasmYAML::Section> &Sec : Obj.Sections) {
553 if (
auto S = dyn_cast<WasmYAML::CustomSection>(Sec.get()))
560 std::string OutString;
562 if (
auto S = dyn_cast<WasmYAML::CustomSection>(Sec.get()))
563 writeSectionContent(StringStream, *S);
564 else if (
auto S = dyn_cast<WasmYAML::TypeSection>(Sec.get()))
565 writeSectionContent(StringStream, *S);
566 else if (
auto S = dyn_cast<WasmYAML::ImportSection>(Sec.get()))
567 writeSectionContent(StringStream, *S);
568 else if (
auto S = dyn_cast<WasmYAML::FunctionSection>(Sec.get()))
569 writeSectionContent(StringStream, *S);
570 else if (
auto S = dyn_cast<WasmYAML::TableSection>(Sec.get()))
571 writeSectionContent(StringStream, *S);
572 else if (
auto S = dyn_cast<WasmYAML::MemorySection>(Sec.get()))
573 writeSectionContent(StringStream, *S);
574 else if (
auto S = dyn_cast<WasmYAML::GlobalSection>(Sec.get()))
575 writeSectionContent(StringStream, *S);
576 else if (
auto S = dyn_cast<WasmYAML::EventSection>(Sec.get()))
577 writeSectionContent(StringStream, *S);
578 else if (
auto S = dyn_cast<WasmYAML::ExportSection>(Sec.get()))
579 writeSectionContent(StringStream, *S);
580 else if (
auto S = dyn_cast<WasmYAML::StartSection>(Sec.get()))
581 writeSectionContent(StringStream, *S);
582 else if (
auto S = dyn_cast<WasmYAML::ElemSection>(Sec.get()))
583 writeSectionContent(StringStream, *S);
584 else if (
auto S = dyn_cast<WasmYAML::CodeSection>(Sec.get()))
585 writeSectionContent(StringStream, *S);
586 else if (
auto S = dyn_cast<WasmYAML::DataSection>(Sec.get()))
587 writeSectionContent(StringStream, *S);
588 else if (
auto S = dyn_cast<WasmYAML::DataCountSection>(Sec.get()))
589 writeSectionContent(StringStream, *S);
596 StringStream.
flush();
605 for (
const std::unique_ptr<WasmYAML::Section> &Sec : Obj.Sections) {
606 if (Sec->Relocations.empty()) {
612 std::string OutString;
614 writeRelocSection(StringStream, *Sec, SectionIndex++);
615 StringStream.
flush();
628 WasmWriter Writer(Doc, EH);
629 return Writer.writeWasm(Out);
static int writeLimits(const WasmYAML::Limits &Lim, raw_ostream &OS)
std::vector< InitFunction > InitFunctions
std::vector< Comdat > Comdats
std::vector< Relocation > Relocations
std::vector< Limits > Memories
std::vector< Signature > Signatures
This class represents lattice values for constants.
An efficient, type-erasing, non-owning reference to a callable.
void write32le(void *P, uint32_t V)
std::vector< Import > Imports
Export information to summary.
const unsigned WASM_SYMBOL_UNDEFINED
std::vector< ValueType > ReturnTypes
std::vector< SegmentInfo > SegmentInfos
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
std::vector< SymbolInfo > SymbolTable
static int writeUint32(raw_ostream &OS, uint32_t Value)
bool isValidSectionOrder(unsigned ID, StringRef CustomSectionName="")
std::vector< Function > Functions
static int writeUint8(raw_ostream &OS, uint8_t Value)
union llvm::wasm::WasmInitExpr::@151 Value
LLVM_NODISCARD size_t size() const
size - Get the string size.
Analysis containing CSE Info
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...
Import information from summary.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
std::vector< Export > Exports
std::vector< uint32_t > FunctionTypes
static int writeStringRef(const StringRef &Str, raw_ostream &OS)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
raw_ostream & write(unsigned char C)
static Error reportError(StringRef Message)
const unsigned WASM_SYMBOL_EXPLICIT_NAME
unsigned encodeULEB128(uint64_t Value, raw_ostream &OS, unsigned PadTo=0)
Utility function to encode a ULEB128 value to an output stream.
unsigned encodeSLEB128(int64_t Value, raw_ostream &OS, unsigned PadTo=0)
Utility function to encode a SLEB128 value to an output stream.
Common declarations for yaml2obj.
std::vector< Table > Tables
std::vector< ElemSegment > Segments
std::vector< FeatureEntry > Features
static int writeUint64(raw_ostream &OS, uint64_t Value)
std::vector< Event > Events
std::vector< StringRef > Needed
void write64le(void *P, uint64_t V)
std::vector< DataSegment > Segments
wasm::WasmDataReference DataRef
std::vector< ValueType > ParamTypes
std::vector< NameEntry > FunctionNames
std::vector< Global > Globals
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
A raw_ostream that writes to an std::string.
LLVM Value Representation.
This class implements an extremely fast bulk output stream that can only output to a stream...
StringRef - Represent a constant reference to a string, i.e.
bool yaml2wasm(WasmYAML::Object &Doc, raw_ostream &Out, ErrorHandler EH)