summaryrefslogtreecommitdiff
path: root/src/wast-parser.cc
diff options
context:
space:
mode:
authorBen Smith <binjimin@gmail.com>2018-12-04 12:19:55 -0800
committerGitHub <noreply@github.com>2018-12-04 12:19:55 -0800
commitb94c2056529885af1ac056ceec07735bb45b9e80 (patch)
tree020e9b2e61931ccc2cff69797578380f69d84527 /src/wast-parser.cc
parent96e12c00b3bec700f851e94b63708ead1d7f84ad (diff)
downloadwabt-b94c2056529885af1ac056ceec07735bb45b9e80.tar.gz
wabt-b94c2056529885af1ac056ceec07735bb45b9e80.tar.bz2
wabt-b94c2056529885af1ac056ceec07735bb45b9e80.zip
Combine param_binding and local_binding in IR (#969)
The `BindingHash` object is used to map from a name to an Index, and to detect multiply-defined names. Since the locals and params use the same Index space and namespace, they should always have been using the same `BindingHash`.
Diffstat (limited to 'src/wast-parser.cc')
-rw-r--r--src/wast-parser.cc16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/wast-parser.cc b/src/wast-parser.cc
index 7b3b6e48..f9e89151 100644
--- a/src/wast-parser.cc
+++ b/src/wast-parser.cc
@@ -887,7 +887,7 @@ Result WastParser::ParseFuncModuleField(Module* module) {
Func& func = import->func;
CHECK_RESULT(ParseInlineImport(import.get()));
CHECK_RESULT(ParseTypeUseOpt(&func.decl));
- CHECK_RESULT(ParseFuncSignature(&func.decl.sig, &func.param_bindings));
+ CHECK_RESULT(ParseFuncSignature(&func.decl.sig, &func.bindings));
CHECK_RESULT(ErrorIfLpar({"type", "param", "result"}));
auto field =
MakeUnique<ImportModuleField>(std::move(import), GetLocation());
@@ -896,10 +896,10 @@ Result WastParser::ParseFuncModuleField(Module* module) {
auto field = MakeUnique<FuncModuleField>(loc, name);
Func& func = field->func;
CHECK_RESULT(ParseTypeUseOpt(&func.decl));
- CHECK_RESULT(ParseFuncSignature(&func.decl.sig, &func.param_bindings));
+ CHECK_RESULT(ParseFuncSignature(&func.decl.sig, &func.bindings));
TypeVector local_types;
CHECK_RESULT(ParseBoundValueTypeList(TokenType::Local, &local_types,
- &func.local_bindings));
+ &func.bindings, func.GetNumParams()));
func.local_types.Set(local_types);
CHECK_RESULT(ParseTerminatingInstrList(&func.exprs));
module->AppendField(std::move(field));
@@ -985,8 +985,8 @@ Result WastParser::ParseImportModuleField(Module* module) {
CHECK_RESULT(ParseTypeUseOpt(&import->func.decl));
EXPECT(Rpar);
} else {
- CHECK_RESULT(ParseFuncSignature(&import->func.decl.sig,
- &import->func.param_bindings));
+ CHECK_RESULT(
+ ParseFuncSignature(&import->func.decl.sig, &import->func.bindings));
CHECK_RESULT(ErrorIfLpar({"param", "result"}));
EXPECT(Rpar);
}
@@ -1232,7 +1232,8 @@ Result WastParser::ParseUnboundFuncSignature(FuncSignature* sig) {
Result WastParser::ParseBoundValueTypeList(TokenType token,
TypeVector* types,
- BindingHash* bindings) {
+ BindingHash* bindings,
+ Index binding_index_offset) {
WABT_TRACE(ParseBoundValueTypeList);
while (MatchLpar(token)) {
if (PeekMatch(TokenType::Var)) {
@@ -1241,7 +1242,8 @@ Result WastParser::ParseBoundValueTypeList(TokenType token,
Location loc = GetLocation();
ParseBindVarOpt(&name);
CHECK_RESULT(ParseValueType(&type));
- bindings->emplace(name, Binding(loc, types->size()));
+ bindings->emplace(name,
+ Binding(loc, binding_index_offset + types->size()));
types->push_back(type);
} else {
CHECK_RESULT(ParseValueTypeList(types));