| 1320 | } |
| 1321 | |
| 1322 | void BinaryWriter::WriteLinkingSection() { |
| 1323 | BeginCustomSection(WABT_BINARY_SECTION_LINKING); |
| 1324 | WriteU32Leb128(stream_, 2, "metadata version"); |
| 1325 | const std::vector<Symbol>& symbols = symtab_.symbols(); |
| 1326 | if (symbols.size()) { |
| 1327 | stream_->WriteU8Enum(LinkingEntryType::SymbolTable, "symbol table"); |
| 1328 | BeginSubsection("symbol table"); |
| 1329 | WriteU32Leb128(stream_, symbols.size(), "num symbols"); |
| 1330 | |
| 1331 | for (const Symbol& sym : symbols) { |
| 1332 | stream_->WriteU8Enum(sym.type(), "symbol type"); |
| 1333 | WriteU32Leb128(stream_, sym.flags(), "symbol flags"); |
| 1334 | switch (sym.type()) { |
| 1335 | case SymbolType::Function: |
| 1336 | WriteU32Leb128(stream_, sym.AsFunction().index, "function index"); |
| 1337 | if (sym.defined() || sym.explicit_name()) { |
| 1338 | WriteStr(stream_, sym.name(), "function name", PrintChars::Yes); |
| 1339 | } |
| 1340 | break; |
| 1341 | case SymbolType::Data: |
| 1342 | WriteStr(stream_, sym.name(), "data name", PrintChars::Yes); |
| 1343 | if (sym.defined()) { |
| 1344 | WriteU32Leb128(stream_, sym.AsData().index, "data index"); |
| 1345 | WriteU32Leb128(stream_, sym.AsData().offset, "data offset"); |
| 1346 | WriteU32Leb128(stream_, sym.AsData().size, "data size"); |
| 1347 | } |
| 1348 | break; |
| 1349 | case SymbolType::Global: |
| 1350 | WriteU32Leb128(stream_, sym.AsGlobal().index, "global index"); |
| 1351 | if (sym.defined() || sym.explicit_name()) { |
| 1352 | WriteStr(stream_, sym.name(), "global name", PrintChars::Yes); |
| 1353 | } |
| 1354 | break; |
| 1355 | case SymbolType::Section: |
| 1356 | WriteU32Leb128(stream_, sym.AsSection().section, "section index"); |
| 1357 | break; |
| 1358 | case SymbolType::Tag: |
| 1359 | WriteU32Leb128(stream_, sym.AsTag().index, "tag index"); |
| 1360 | if (sym.defined() || sym.explicit_name()) { |
| 1361 | WriteStr(stream_, sym.name(), "tag name", PrintChars::Yes); |
| 1362 | } |
| 1363 | break; |
| 1364 | case SymbolType::Table: |
| 1365 | WriteU32Leb128(stream_, sym.AsTable().index, "table index"); |
| 1366 | if (sym.defined() || sym.explicit_name()) { |
| 1367 | WriteStr(stream_, sym.name(), "table name", PrintChars::Yes); |
| 1368 | } |
| 1369 | break; |
| 1370 | } |
| 1371 | } |
| 1372 | EndSubsection(); |
| 1373 | } |
| 1374 | EndSection(); |
| 1375 | } |
| 1376 | |
| 1377 | template <typename T> |
| 1378 | void BinaryWriter::WriteNames(const std::vector<T*>& elems, |
nothing calls this directly
no test coverage detected