MCPcopy Create free account
hub / github.com/WasmVM/WasmVM / parse_globalsection

Method parse_globalsection

src/lib/parse/ParseContext.cpp:830–864  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

828}
829
830void ParseContext::parse_globalsection() {
831 tok_.expect(TokenType::LParen);
832 tok_.expect_keyword("global");
833 index_t global_idx = global_map_.records.size();
834 // optional Id
835 if (tok_.peek().type == TokenType::Id) {
836 std::string id = tok_.consume().text;
837 if (global_map_.id_map.contains(id))
838 throw Exception::Parse("duplicated global id '" + id + "'", tok_.location());
839 global_map_.id_map[id] = global_idx;
840 }
841 // exportabbr*
842 while (tok_.peek().type == TokenType::LParen &&
843 tok_.peek2().type == TokenType::Keyword && tok_.peek2().text == "export") {
844 WasmExport& exp = module_.exports.emplace_back();
845 exp.name = parse_exportabbr();
846 exp.index = global_idx;
847 exp.desc = WasmExport::DescType::global;
848 }
849 // import or normal
850 if (tok_.peek().type == TokenType::LParen &&
851 tok_.peek2().type == TokenType::Keyword && tok_.peek2().text == "import") {
852 global_map_.records.emplace_back(IndexSpace::Type::Import);
853 auto [imod, iname] = parse_importabbr();
854 WasmImport& imp = module_.imports.emplace_back();
855 imp.desc = parse_globaltype();
856 imp.module = imod; imp.name = iname;
857 } else {
858 global_map_.records.emplace_back(IndexSpace::Type::Normal);
859 WasmGlobal& global = module_.globals.emplace_back();
860 global.type = parse_globaltype();
861 global.init = parse_constexpr();
862 }
863 tok_.expect(TokenType::RParen);
864}
865
866void ParseContext::parse_exportsection() {
867 tok_.expect(TokenType::LParen);

Callers

nothing calls this directly

Calls 6

ParseClass · 0.85
expectMethod · 0.80
expect_keywordMethod · 0.80
peekMethod · 0.80
consumeMethod · 0.45
locationMethod · 0.45

Tested by

no test coverage detected