MCPcopy Create free account
hub / github.com/WebAssembly/wabt / WriteCodeMetadataSections

Method WriteCodeMetadataSections

src/binary-writer.cc:1894–1939  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1892}
1893
1894void BinaryWriter::WriteCodeMetadataSections() {
1895 if (code_metadata_sections_.empty())
1896 return;
1897
1898 section_count_ -= 1;
1899 // We have to increment the code section's index; adjust anything
1900 // that might have captured it.
1901 for (RelocSection& section : reloc_sections_) {
1902 if (section.section_index == section_count_) {
1903 assert(last_section_type_ == BinarySection::Code);
1904 section.section_index += code_metadata_sections_.size();
1905 }
1906 }
1907
1908 MemoryStream tmp_stream;
1909 Stream* main_stream = stream_;
1910 stream_ = &tmp_stream;
1911 for (auto& s : code_metadata_sections_) {
1912 std::string name = "metadata.code.";
1913 name.append(s.first);
1914 auto& section = s.second;
1915 BeginCustomSection(name.c_str());
1916 WriteU32Leb128(stream_, section.entries.size(), "function count");
1917 for (auto& f : section.entries) {
1918 WriteU32Leb128WithReloc(f.func_idx, "function index",
1919 RelocType::FuncIndexLEB);
1920 WriteU32Leb128(stream_, f.entries.size(), "instances count");
1921 for (auto& a : f.entries) {
1922 WriteU32Leb128(stream_, a.offset, "code offset");
1923 WriteU32Leb128(stream_, a.data.size(), "data length");
1924 stream_->WriteData(a.data.data(), a.data.size(), "data",
1925 PrintChars::Yes);
1926 }
1927 }
1928 EndSection();
1929 }
1930 stream_ = main_stream;
1931 auto buf = tmp_stream.ReleaseOutputBuffer();
1932 stream_->MoveData(code_start_ + buf->data.size(), code_start_,
1933 stream_->offset() - code_start_);
1934 stream_->WriteDataAt(code_start_, buf->data.data(), buf->data.size());
1935 stream_->AddOffset(buf->data.size());
1936 code_start_ += buf->data.size();
1937 section_count_ += 1;
1938 last_section_type_ = BinarySection::Code;
1939}
1940
1941} // end anonymous namespace
1942

Callers

nothing calls this directly

Calls 11

dataMethod · 0.80
ReleaseOutputBufferMethod · 0.80
MoveDataMethod · 0.80
WriteDataAtMethod · 0.80
AddOffsetMethod · 0.80
WriteU32Leb128Function · 0.70
emptyMethod · 0.45
sizeMethod · 0.45
appendMethod · 0.45
WriteDataMethod · 0.45
offsetMethod · 0.45

Tested by

no test coverage detected