| 448 | // Global section |
| 449 | |
| 450 | auto globals( |
| 451 | const vec<byte_t>& binary, const ownvec<ImportType>& imports |
| 452 | ) -> ownvec<GlobalType> { |
| 453 | auto pos = bin::section(binary, SEC_GLOBAL); |
| 454 | size_t size = pos != nullptr ? bin::u32(pos) : 0; |
| 455 | auto v = ownvec<GlobalType>::make_uninitialized( |
| 456 | size + count(imports, ExternKind::GLOBAL)); |
| 457 | size_t j = 0; |
| 458 | for (uint32_t i = 0; i < imports.size(); ++i) { |
| 459 | auto et = imports[i]->type(); |
| 460 | if (et->kind() == ExternKind::GLOBAL) { |
| 461 | v[j++] = et->global()->copy(); |
| 462 | } |
| 463 | } |
| 464 | if (pos != nullptr) { |
| 465 | for (; j < v.size(); ++j) { |
| 466 | v[j] = bin::globaltype(pos); |
| 467 | expr_skip(pos); |
| 468 | } |
| 469 | assert(pos = bin::section_end(binary, SEC_GLOBAL)); |
| 470 | } |
| 471 | return v; |
| 472 | } |
| 473 | |
| 474 | |
| 475 | // Table section |