summaryrefslogtreecommitdiff
path: root/src/parser
diff options
context:
space:
mode:
Diffstat (limited to 'src/parser')
-rw-r--r--src/parser/context-decls.cpp13
-rw-r--r--src/parser/contexts.h29
-rw-r--r--src/parser/parsers.h43
3 files changed, 58 insertions, 27 deletions
diff --git a/src/parser/context-decls.cpp b/src/parser/context-decls.cpp
index c78c47d60..c5b212038 100644
--- a/src/parser/context-decls.cpp
+++ b/src/parser/context-decls.cpp
@@ -82,10 +82,11 @@ Result<> ParseDeclsCtx::addFunc(Name name,
Result<Table*> ParseDeclsCtx::addTableDecl(Index pos,
Name name,
ImportNames* importNames,
- Limits limits) {
+ TableType type) {
auto t = std::make_unique<Table>();
- t->initial = limits.initial;
- t->max = limits.max ? *limits.max : Table::kUnlimitedSize;
+ t->indexType = type.indexType;
+ t->initial = type.limits.initial;
+ t->max = type.limits.max ? *type.limits.max : Table::kUnlimitedSize;
if (name.is()) {
if (wasm.getTableOrNull(name)) {
// TODO: if the existing table is not explicitly named, fix its name and
@@ -105,10 +106,10 @@ Result<Table*> ParseDeclsCtx::addTableDecl(Index pos,
Result<> ParseDeclsCtx::addTable(Name name,
const std::vector<Name>& exports,
ImportNames* import,
- Limits limits,
+ TableType type,
Index pos) {
CHECK_ERR(checkImport(pos, import));
- auto t = addTableDecl(pos, name, import, limits);
+ auto t = addTableDecl(pos, name, import, type);
CHECK_ERR(t);
CHECK_ERR(addExports(in, wasm, *t, exports, ExternalKind::Table));
// TODO: table annotations
@@ -138,7 +139,7 @@ Result<Memory*> ParseDeclsCtx::addMemoryDecl(Index pos,
ImportNames* importNames,
MemType type) {
auto m = std::make_unique<Memory>();
- m->indexType = type.type;
+ m->indexType = type.indexType;
m->initial = type.limits.initial;
m->max = type.limits.max ? *type.limits.max : Memory::kUnlimitedSize;
m->shared = type.shared;
diff --git a/src/parser/contexts.h b/src/parser/contexts.h
index cead35f60..8f0c6cdff 100644
--- a/src/parser/contexts.h
+++ b/src/parser/contexts.h
@@ -46,7 +46,7 @@ struct Limits {
};
struct MemType {
- Type type;
+ Type indexType;
Limits limits;
bool shared;
};
@@ -56,6 +56,11 @@ struct Memarg {
uint32_t align;
};
+struct TableType {
+ Type indexType;
+ Limits limits;
+};
+
// The location, possible name, and index in the respective module index space
// of a module-level definition in the input.
struct DefPos {
@@ -853,7 +858,7 @@ struct ParseDeclsCtx : NullTypeParserCtx, NullInstrParserCtx {
using LimitsT = Limits;
using ElemListT = Index;
using DataStringT = std::vector<char>;
- using TableTypeT = Limits;
+ using TableTypeT = TableType;
using MemTypeT = MemType;
Lexer in;
@@ -942,7 +947,9 @@ struct ParseDeclsCtx : NullTypeParserCtx, NullInstrParserCtx {
Limits getLimitsFromElems(Index elems) { return {elems, elems}; }
- Limits makeTableType(Limits limits, TypeT) { return limits; }
+ TableType makeTableType(Type indexType, Limits limits, TypeT) {
+ return {indexType, limits};
+ }
std::vector<char> makeDataString() { return {}; }
void appendDataString(std::vector<char>& data, std::string_view str) {
@@ -954,8 +961,8 @@ struct ParseDeclsCtx : NullTypeParserCtx, NullInstrParserCtx {
return {size, size};
}
- MemType makeMemType(Type type, Limits limits, bool shared) {
- return {type, limits, shared};
+ MemType makeMemType(Type indexType, Limits limits, bool shared) {
+ return {indexType, limits, shared};
}
Result<TypeUseT>
@@ -975,10 +982,12 @@ struct ParseDeclsCtx : NullTypeParserCtx, NullInstrParserCtx {
std::vector<Annotation>&&,
Index pos);
- Result<Table*>
- addTableDecl(Index pos, Name name, ImportNames* importNames, Limits limits);
+ Result<Table*> addTableDecl(Index pos,
+ Name name,
+ ImportNames* importNames,
+ TableType limits);
Result<>
- addTable(Name, const std::vector<Name>&, ImportNames*, Limits, Index);
+ addTable(Name, const std::vector<Name>&, ImportNames*, TableType, Index);
// TODO: Record index of implicit elem for use when parsing types and instrs.
Result<> addImplicitElems(TypeT, ElemListT&& elems);
@@ -1252,7 +1261,7 @@ struct ParseModuleTypesCtx : TypeParserCtx<ParseModuleTypesCtx>,
LimitsT getLimitsFromElems(ElemListT) { return Ok{}; }
- Type makeTableType(LimitsT, Type type) { return type; }
+ Type makeTableType(Type indexType, LimitsT, Type type) { return type; }
LimitsT getLimitsFromData(DataStringT) { return Ok{}; }
MemTypeT makeMemType(Type, LimitsT, bool) { return Ok{}; }
@@ -1441,7 +1450,7 @@ struct ParseDefsCtx : TypeParserCtx<ParseDefsCtx> {
LimitsT getLimitsFromElems(std::vector<Expression*>& elems) { return Ok{}; }
- TableTypeT makeTableType(LimitsT, Type) { return Ok{}; }
+ TableTypeT makeTableType(Type, LimitsT, Type) { return Ok{}; }
struct CatchInfo {
Name tag;
diff --git a/src/parser/parsers.h b/src/parser/parsers.h
index 4d54b3655..30a828822 100644
--- a/src/parser/parsers.h
+++ b/src/parser/parsers.h
@@ -44,6 +44,8 @@ template<typename Ctx> Result<typename Ctx::MemTypeT> memtype(Ctx&);
template<typename Ctx>
Result<typename Ctx::MemTypeT> memtypeContinued(Ctx&, Type indexType);
template<typename Ctx> Result<typename Ctx::TableTypeT> tabletype(Ctx&);
+template<typename Ctx>
+Result<typename Ctx::TableTypeT> tabletypeContinued(Ctx&, Type indexType);
template<typename Ctx> Result<typename Ctx::GlobalTypeT> globaltype(Ctx&);
template<typename Ctx> Result<uint32_t> tupleArity(Ctx&);
@@ -815,16 +817,28 @@ Result<typename Ctx::MemTypeT> memtypeContinued(Ctx& ctx, Type indexType) {
return ctx.makeMemType(indexType, *limits, shared);
}
-// tabletype ::= limits32 reftype
+// tabletype ::= (limits32 | 'i32' limits32 | 'i64' limit64) reftype
template<typename Ctx> Result<typename Ctx::TableTypeT> tabletype(Ctx& ctx) {
- auto limits = limits32(ctx);
+ Type indexType = Type::i32;
+ if (ctx.in.takeKeyword("i64"sv)) {
+ indexType = Type::i64;
+ } else {
+ ctx.in.takeKeyword("i32"sv);
+ }
+ return tabletypeContinued(ctx, indexType);
+}
+
+template<typename Ctx>
+Result<typename Ctx::TableTypeT> tabletypeContinued(Ctx& ctx, Type indexType) {
+ auto limits = indexType == Type::i32 ? limits32(ctx) : limits64(ctx);
CHECK_ERR(limits);
auto type = reftype(ctx);
CHECK_ERR(type);
+
if (!type) {
return ctx.in.err("expected reftype");
}
- return ctx.makeTableType(*limits, *type);
+ return ctx.makeTableType(indexType, *limits, *type);
}
// globaltype ::= t:valtype => const t
@@ -3049,8 +3063,8 @@ template<typename Ctx> MaybeResult<> func(Ctx& ctx) {
}
// table ::= '(' 'table' id? ('(' 'export' name ')')*
-// '(' 'import' mod:name nm:name ')'? tabletype ')'
-// | '(' 'table' id? ('(' 'export' name ')')*
+// '(' 'import' mod:name nm:name ')'? index_type? tabletype ')'
+// | '(' 'table' id? ('(' 'export' name ')')* index_type?
// reftype '(' 'elem' (elemexpr* | funcidx*) ')' ')'
template<typename Ctx> MaybeResult<> table(Ctx& ctx) {
auto pos = ctx.in.getPos();
@@ -3069,6 +3083,13 @@ template<typename Ctx> MaybeResult<> table(Ctx& ctx) {
auto import = inlineImport(ctx.in);
CHECK_ERR(import);
+ auto indexType = Type::i32;
+ if (ctx.in.takeKeyword("i64"sv)) {
+ indexType = Type::i64;
+ } else {
+ ctx.in.takeKeyword("i32"sv);
+ }
+
// Reftype if we have inline elements.
auto type = reftype(ctx);
CHECK_ERR(type);
@@ -3103,10 +3124,10 @@ template<typename Ctx> MaybeResult<> table(Ctx& ctx) {
if (!ctx.in.takeRParen()) {
return ctx.in.err("expected end of inline elems");
}
- ttype = ctx.makeTableType(ctx.getLimitsFromElems(list), *type);
+ ttype = ctx.makeTableType(indexType, ctx.getLimitsFromElems(list), *type);
elems = std::move(list);
} else {
- auto tabtype = tabletype(ctx);
+ auto tabtype = tabletypeContinued(ctx, indexType);
CHECK_ERR(tabtype);
ttype = *tabtype;
}
@@ -3124,10 +3145,10 @@ template<typename Ctx> MaybeResult<> table(Ctx& ctx) {
return Ok{};
}
-// mem ::= '(' 'memory' id? ('(' 'export' name ')')* index_type?
-// ('(' 'data' b:datastring ')' | memtype) ')'
-// | '(' 'memory' id? ('(' 'export' name ')')*
-// '(' 'import' mod:name nm:name ')' memtype ')'
+// memory ::= '(' 'memory' id? ('(' 'export' name ')')* index_type?
+// ('(' 'data' b:datastring ')' | memtype) ')'
+// | '(' 'memory' id? ('(' 'export' name ')')*
+// '(' 'import' mod:name nm:name ')' index_type? memtype ')'
template<typename Ctx> MaybeResult<> memory(Ctx& ctx) {
auto pos = ctx.in.getPos();
if (!ctx.in.takeSExprStart("memory"sv)) {