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

Method ParseScriptModule

src/wast-parser.cc:3956–4014  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3954}
3955
3956Result WastParser::ParseScriptModule(
3957 std::unique_ptr<ScriptModule>* out_module) {
3958 WABT_TRACE(ParseScriptModule);
3959 EXPECT(Lpar);
3960 Location loc = GetLocation();
3961 EXPECT(Module);
3962 std::string name;
3963 CHECK_RESULT(ParseBindVarOpt(&name));
3964
3965 switch (Peek()) {
3966 case TokenType::Bin: {
3967 DropToken();
3968 std::vector<uint8_t> data;
3969 // TODO(binji): The spec allows this to be empty, switch to
3970 // ParseTextListOpt.
3971 CHECK_RESULT(ParseTextList(&data));
3972
3973 auto bsm = std::make_unique<BinaryScriptModule>();
3974 bsm->name = name;
3975 bsm->loc = loc;
3976 bsm->data = std::move(data);
3977 *out_module = std::move(bsm);
3978 break;
3979 }
3980
3981 case TokenType::Quote: {
3982 DropToken();
3983 std::vector<uint8_t> data;
3984 // TODO(binji): The spec allows this to be empty, switch to
3985 // ParseTextListOpt.
3986 CHECK_RESULT(ParseTextList(&data));
3987
3988 auto qsm = std::make_unique<QuotedScriptModule>();
3989 qsm->name = name;
3990 qsm->loc = loc;
3991 qsm->data = std::move(data);
3992 *out_module = std::move(qsm);
3993 break;
3994 }
3995
3996 default: {
3997 auto tsm = std::make_unique<TextScriptModule>();
3998 tsm->module.name = name;
3999 tsm->module.loc = loc;
4000 tsm->module.filename = lexer_->Filename();
4001 if (IsModuleField(PeekPair()) || PeekIsCustom()) {
4002 CHECK_RESULT(ParseModuleFieldList(&tsm->module));
4003 } else if (!PeekMatch(TokenType::Rpar)) {
4004 ConsumeIfLpar();
4005 return ErrorExpected({"a module field"});
4006 }
4007 *out_module = std::move(tsm);
4008 break;
4009 }
4010 }
4011
4012 EXPECT(Rpar);
4013 return Result::Ok;

Callers

nothing calls this directly

Calls 2

IsModuleFieldFunction · 0.85
FilenameMethod · 0.80

Tested by

no test coverage detected