Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/parser/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ FILE(GLOB parser_HEADERS *.h)
set(parser_SOURCES
context-decls.cpp
context-defs.cpp
lexer.cpp
parse-1-decls.cpp
parse-2-typedefs.cpp
parse-3-implicit-types.cpp
Expand Down
33 changes: 33 additions & 0 deletions src/parser/context-decls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

#include "contexts.h"
#include "parsers.h"

namespace wasm::WATParser {

Expand Down Expand Up @@ -302,4 +303,36 @@ Result<> ParseDeclsCtx::addTag(Name name,
return Ok{};
}

bool ParseDeclsCtx::skipFunctionBody() {
using namespace std::string_view_literals;
size_t depth = 1;
while (depth > 0 && !in.empty()) {
if (in.takeLParen()) {
++depth;
continue;
}
if (in.takeRParen()) {
--depth;
continue;
}
if (auto kw = in.takeKeyword()) {
if (*kw == "block"sv || *kw == "loop"sv || *kw == "if"sv ||
*kw == "try"sv || *kw == "try_table"sv) {
in.takeID();
(void)typeuse(*this);
continue;
}
if (*kw == "call_indirect"sv || *kw == "return_call_indirect"sv) {
(void)maybeTableidx(*this);
(void)typeuse(*this, false);
continue;
}
continue;
}
in.take(1);
in.advance();
}
return true;
}

} // namespace wasm::WATParser
4 changes: 3 additions & 1 deletion src/parser/contexts.h
Original file line number Diff line number Diff line change
Expand Up @@ -1074,6 +1074,8 @@ struct ParseDeclsCtx : NullTypeParserCtx, NullInstrParserCtx {
recTypeDefs.push_back({{}, pos, Index(recTypeDefs.size()), {}});
}

bool skipFunctionBody();

Limits makeLimits(uint64_t n, std::optional<uint64_t> m) {
return Limits{n, m};
}
Expand Down Expand Up @@ -1985,7 +1987,7 @@ struct ParseDefsCtx : TypeParserCtx<ParseDefsCtx>, AnnotationParserCtx {
void setSrcLoc(const std::vector<Annotation>& annotations) {
const Annotation* annotation = nullptr;
for (auto& a : annotations) {
if (a.kind == srcAnnotationKind) {
if (a.kind.str == std::string_view("src")) {
annotation = &a;
}
}
Expand Down
Loading
Loading