Bug 1316635: Remove AstDecode from AstDecodeGenerate{Ref,Name}; r?luke draft
authorBenjamin Bouvier <benj@benj.me>
Thu, 10 Nov 2016 18:34:52 +0100
changeset 437276 7035a732d4455d787e021328c2c4e11dade63cf5
parent 437275 f7c25889ba4dcfe14072aec87d26cf997ba87f87
child 437277 dac68d37b9c7f9a252bb6f02301988aeb7bf77ba
push id35371
push userbbouvier@mozilla.com
push dateThu, 10 Nov 2016 17:45:13 +0000
reviewersluke
bugs1316635
milestone52.0a1
Bug 1316635: Remove AstDecode from AstDecodeGenerate{Ref,Name}; r?luke MozReview-Commit-ID: FpmhtCQvUAj
js/src/wasm/WasmBinaryToAST.cpp
--- a/js/src/wasm/WasmBinaryToAST.cpp
+++ b/js/src/wasm/WasmBinaryToAST.cpp
@@ -205,17 +205,17 @@ class AstDecodeContext
     }
     uint32_t nextLabelIndex()
     {
         return currentLabelIndex_++;
     }
 };
 
 static bool
-AstDecodeGenerateName(AstDecodeContext& c, const AstName& prefix, uint32_t index, AstName* name)
+GenerateName(AstDecodeContext& c, const AstName& prefix, uint32_t index, AstName* name)
 {
     if (!c.generateNames) {
         *name = AstName();
         return true;
     }
 
     AstVector<char16_t> result(c.lifo);
     if (!result.append(u'$'))
@@ -241,27 +241,27 @@ AstDecodeGenerateName(AstDecodeContext& 
     if (!begin)
         return false;
 
     *name = AstName(begin, length);
     return true;
 }
 
 static bool
-AstDecodeGenerateRef(AstDecodeContext& c, const AstName& prefix, uint32_t index, AstRef* ref)
+GenerateRef(AstDecodeContext& c, const AstName& prefix, uint32_t index, AstRef* ref)
 {
     MOZ_ASSERT(index != AstNoIndex);
 
     if (!c.generateNames) {
         *ref = AstRef(index);
         return true;
     }
 
     AstName name;
-    if (!AstDecodeGenerateName(c, prefix, index, &name))
+    if (!GenerateName(c, prefix, index, &name))
         return false;
     MOZ_ASSERT(!name.empty());
 
     *ref = AstRef(name);
     ref->setIndex(index);
     return true;
 }
 
@@ -337,17 +337,17 @@ AstDecodeCall(AstDecodeContext& c)
         funcRef = AstRef(import->name());
     } else {
         uint32_t funcDefIndex = funcIndex - c.module().numFuncImports();
         if (funcDefIndex >= c.funcDefSigs().length())
             return c.iter().fail("callee index out of range");
 
         sigIndex = c.funcDefSigs()[funcDefIndex];
 
-        if (!AstDecodeGenerateRef(c, AstName(u"func"), funcIndex, &funcRef))
+        if (!GenerateRef(c, AstName(u"func"), funcIndex, &funcRef))
             return false;
     }
 
     const AstSig* sig = c.module().sigs()[sigIndex];
 
     AstExprVector args(c.lifo);
     if (!AstDecodeCallArgs(c, *sig, &args))
         return false;
@@ -380,17 +380,17 @@ AstDecodeCallIndirect(AstDecodeContext& 
         return true;
 
     if (sigIndex >= c.module().sigs().length())
         return c.iter().fail("signature index out of range");
 
     AstDecodeStackItem index = c.popCopy();
 
     AstRef sigRef;
-    if (!AstDecodeGenerateRef(c, AstName(u"type"), sigIndex, &sigRef))
+    if (!GenerateRef(c, AstName(u"type"), sigIndex, &sigRef))
         return false;
 
     const AstSig* sig = c.module().sigs()[sigIndex];
     AstExprVector args(c.lifo);
     if (!AstDecodeCallArgs(c, *sig, &args))
         return false;
 
     if (!AstDecodeCallReturn(c, *sig))
@@ -417,17 +417,17 @@ AstDecodeGetBlockRef(AstDecodeContext& c
     if (!c.generateNames || depth >= c.blockLabels().length()) {
         // Also ignoring if it's a function body label.
         *ref = AstRef(depth);
         return true;
     }
 
     uint32_t index = c.blockLabels().length() - depth - 1;
     if (c.blockLabels()[index].empty()) {
-        if (!AstDecodeGenerateName(c, AstName(u"label"), c.nextLabelIndex(), &c.blockLabels()[index]))
+        if (!GenerateName(c, AstName(u"label"), c.nextLabelIndex(), &c.blockLabels()[index]))
             return false;
     }
     *ref = AstRef(c.blockLabels()[index]);
     ref->setIndex(depth);
     return true;
 }
 
 static bool
@@ -874,17 +874,17 @@ AstDecodeBranch(AstDecodeContext& c, Exp
 static bool
 AstDecodeGetLocal(AstDecodeContext& c)
 {
     uint32_t getLocalId;
     if (!c.iter().readGetLocal(c.locals(), &getLocalId))
         return false;
 
     AstRef localRef;
-    if (!AstDecodeGenerateRef(c, AstName(u"var"), getLocalId, &localRef))
+    if (!GenerateRef(c, AstName(u"var"), getLocalId, &localRef))
         return false;
 
     AstGetLocal* getLocal = new(c.lifo) AstGetLocal(localRef);
     if (!getLocal)
         return false;
 
     if (!c.push(AstDecodeStackItem(getLocal)))
         return false;
@@ -897,17 +897,17 @@ AstDecodeSetLocal(AstDecodeContext& c)
 {
     uint32_t setLocalId;
     if (!c.iter().readSetLocal(c.locals(), &setLocalId, nullptr))
         return false;
 
     AstDecodeStackItem setLocalValue = c.popCopy();
 
     AstRef localRef;
-    if (!AstDecodeGenerateRef(c, AstName(u"var"), setLocalId, &localRef))
+    if (!GenerateRef(c, AstName(u"var"), setLocalId, &localRef))
         return false;
 
     AstSetLocal* setLocal = new(c.lifo) AstSetLocal(localRef, *setLocalValue.expr);
     if (!setLocal)
         return false;
 
     AstExpr* expr = c.handleVoidExpr(setLocal);
     if (!expr)
@@ -924,17 +924,17 @@ AstDecodeTeeLocal(AstDecodeContext& c)
 {
     uint32_t teeLocalId;
     if (!c.iter().readTeeLocal(c.locals(), &teeLocalId, nullptr))
         return false;
 
     AstDecodeStackItem teeLocalValue = c.popCopy();
 
     AstRef localRef;
-    if (!AstDecodeGenerateRef(c, AstName(u"var"), teeLocalId, &localRef))
+    if (!GenerateRef(c, AstName(u"var"), teeLocalId, &localRef))
         return false;
 
     AstTeeLocal* teeLocal = new(c.lifo) AstTeeLocal(localRef, *teeLocalValue.expr);
     if (!teeLocal)
         return false;
 
     if (!c.push(AstDecodeStackItem(teeLocal)))
         return false;
@@ -945,17 +945,17 @@ AstDecodeTeeLocal(AstDecodeContext& c)
 static bool
 AstDecodeGetGlobal(AstDecodeContext& c)
 {
     uint32_t globalId;
     if (!c.iter().readGetGlobal(c.globalDescs(), &globalId))
         return false;
 
     AstRef globalRef;
-    if (!AstDecodeGenerateRef(c, AstName(u"global"), globalId, &globalRef))
+    if (!GenerateRef(c, AstName(u"global"), globalId, &globalRef))
         return false;
 
     auto* getGlobal = new(c.lifo) AstGetGlobal(globalRef);
     if (!getGlobal)
         return false;
 
     if (!c.push(AstDecodeStackItem(getGlobal)))
         return false;
@@ -968,17 +968,17 @@ AstDecodeSetGlobal(AstDecodeContext& c)
 {
     uint32_t globalId;
     if (!c.iter().readSetGlobal(c.globalDescs(), &globalId, nullptr))
         return false;
 
     AstDecodeStackItem value = c.popCopy();
 
     AstRef globalRef;
-    if (!AstDecodeGenerateRef(c, AstName(u"global"), globalId, &globalRef))
+    if (!GenerateRef(c, AstName(u"global"), globalId, &globalRef))
         return false;
 
     auto* setGlobal = new(c.lifo) AstSetGlobal(globalRef, *value.expr);
     if (!setGlobal)
         return false;
 
     AstExpr* expr = c.handleVoidExpr(setGlobal);
     if (!expr)
@@ -1441,17 +1441,17 @@ AstDecodeTypeSection(AstDecodeContext& c
         const Sig& sig = (*sigs)[sigIndex];
 
         AstValTypeVector args(c.lifo);
         if (!args.appendAll(sig.args()))
             return false;
 
         AstSig sigNoName(Move(args), sig.ret());
         AstName sigName;
-        if (!AstDecodeGenerateName(c, AstName(u"type"), sigIndex, &sigName))
+        if (!GenerateName(c, AstName(u"type"), sigIndex, &sigName))
             return false;
 
         AstSig* astSig = new(c.lifo) AstSig(sigName, Move(sigNoName));
         if (!astSig || !c.module().append(astSig))
             return false;
     }
 
     return true;
@@ -1492,57 +1492,57 @@ AstDecodeImportSection(AstDecodeContext&
 
         AstName moduleName = ToAstName(c, import.module);
         AstName fieldName = ToAstName(c, import.field);
 
         AstImport* ast = nullptr;
         switch (import.kind) {
           case DefinitionKind::Function: {
             AstName importName;
-            if (!AstDecodeGenerateName(c, AstName(u"import"), lastFunc, &importName))
+            if (!GenerateName(c, AstName(u"import"), lastFunc, &importName))
                 return false;
 
             AstRef sigRef;
-            if (!AstDecodeGenerateRef(c, AstName(u"type"), funcSigIndices[lastFunc], &sigRef))
+            if (!GenerateRef(c, AstName(u"type"), funcSigIndices[lastFunc], &sigRef))
                 return false;
 
             ast = new(c.lifo) AstImport(importName, moduleName, fieldName, sigRef);
             lastFunc++;
             break;
           }
           case DefinitionKind::Global: {
             AstName importName;
-            if (!AstDecodeGenerateName(c, AstName(u"global"), lastGlobal, &importName))
+            if (!GenerateName(c, AstName(u"global"), lastGlobal, &importName))
                 return false;
 
             const GlobalDesc& global = globals[lastGlobal];
             ValType type = global.type();
             bool isMutable = global.isMutable();
 
             if (!c.addGlobalDesc(type, isMutable, /* import */ true))
                 return false;
 
             ast = new(c.lifo) AstImport(importName, moduleName, fieldName,
                                         AstGlobal(importName, type, isMutable));
             lastGlobal++;
             break;
           }
           case DefinitionKind::Table: {
             AstName importName;
-            if (!AstDecodeGenerateName(c, AstName(u"table"), lastTable, &importName))
+            if (!GenerateName(c, AstName(u"table"), lastTable, &importName))
                 return false;
 
             ast = new(c.lifo) AstImport(importName, moduleName, fieldName, DefinitionKind::Table,
                                         tables[lastTable].limits);
             lastTable++;
             break;
           }
           case DefinitionKind::Memory: {
             AstName importName;
-            if (!AstDecodeGenerateName(c, AstName(u"memory"), lastMemory, &importName))
+            if (!GenerateName(c, AstName(u"memory"), lastMemory, &importName))
                 return false;
 
             ast = new(c.lifo) AstImport(importName, moduleName, fieldName, DefinitionKind::Memory,
                                         *memory);
             lastMemory++;
             break;
           }
         }
@@ -1593,17 +1593,17 @@ AstDecodeTableSection(AstDecodeContext& 
 
     if (table.initial > MaxTableElems)
         return c.d.fail("too many table elements");
 
     if (c.module().hasTable())
         return c.d.fail("already have a table");
 
     AstName name;
-    if (!AstDecodeGenerateName(c, AstName(u"table"), c.module().tables().length(), &name))
+    if (!GenerateName(c, AstName(u"table"), c.module().tables().length(), &name))
         return false;
 
     if (!c.module().addTable(name, table))
         return false;
 
     if (!c.d.finishSection(sectionStart, sectionSize, "table"))
         return false;
 
@@ -1634,17 +1634,17 @@ AstDecodeMemorySection(AstDecodeContext&
 {
     bool present;
     Limits memory;
     if (!DecodeMemorySection(c.d, c.module().hasMemory(), &memory, &present))
         return false;
 
     if (present) {
         AstName name;
-        if (!AstDecodeGenerateName(c, AstName(u"memory"), c.module().memories().length(), &name))
+        if (!GenerateName(c, AstName(u"memory"), c.module().memories().length(), &name))
             return false;
         if (!c.module().addMemory(name, memory))
             return false;
     }
 
     return true;
 }
 
@@ -1652,17 +1652,17 @@ static AstExpr*
 ToAstExpr(AstDecodeContext& c, const InitExpr& initExpr)
 {
     switch (initExpr.kind()) {
       case InitExpr::Kind::Constant: {
         return new(c.lifo) AstConst(Val(initExpr.val()));
       }
       case InitExpr::Kind::GetGlobal: {
         AstRef globalRef;
-        if (!AstDecodeGenerateRef(c, AstName(u"global"), initExpr.globalIndex(), &globalRef))
+        if (!GenerateRef(c, AstName(u"global"), initExpr.globalIndex(), &globalRef))
             return nullptr;
         return new(c.lifo) AstGetGlobal(globalRef);
       }
     }
     return nullptr;
 }
 
 static bool
@@ -1675,17 +1675,17 @@ AstDecodeInitializerExpression(AstDecode
     *init = ToAstExpr(c, initExpr);
     return !!*init;
 }
 
 static bool
 AstDecodeGlobal(AstDecodeContext& c, uint32_t i, AstGlobal* global)
 {
     AstName name;
-    if (!AstDecodeGenerateName(c, AstName(u"global"), i, &name))
+    if (!GenerateName(c, AstName(u"global"), i, &name))
         return false;
 
     ValType type;
     bool isMutable;
     if (!DecodeGlobalType(c.d, &type, &isMutable))
         return false;
 
     AstExpr* init;
@@ -1808,30 +1808,28 @@ AstDecodeFunctionBody(AstDecodeContext &
         return false;
 
     if (!DecodeLocalEntries(c.d, &locals))
         return c.d.fail("failed decoding local entries");
 
     c.startFunction(&iter, &locals, sig->ret());
 
     AstName funcName;
-    if (!AstDecodeGenerateName(c, AstName(u"func"),
-                               c.module().numFuncImports() + funcDefIndex,
-                               &funcName))
+    if (!GenerateName(c, AstName(u"func"), c.module().numFuncImports() + funcDefIndex, &funcName))
         return false;
 
     uint32_t numParams = sig->args().length();
     uint32_t numLocals = locals.length();
     for (uint32_t i = numParams; i < numLocals; i++) {
         if (!vars.append(locals[i]))
             return false;
     }
     for (uint32_t i = 0; i < numLocals; i++) {
         AstName varName;
-        if (!AstDecodeGenerateName(c, AstName(u"var"), i, &varName))
+        if (!GenerateName(c, AstName(u"var"), i, &varName))
             return false;
         if (!localsNames.append(varName))
             return false;
     }
 
     if (!c.iter().readFunctionStart(sig->ret()))
         return false;
 
@@ -1860,17 +1858,17 @@ AstDecodeFunctionBody(AstDecodeContext &
         return false;
 
     c.endFunction();
 
     if (c.d.currentPosition() != bodyEnd)
         return c.d.fail("function body length mismatch");
 
     AstRef sigRef;
-    if (!AstDecodeGenerateRef(c, AstName(u"type"), sigIndex, &sigRef))
+    if (!GenerateRef(c, AstName(u"type"), sigIndex, &sigRef))
         return false;
 
     *func = new(c.lifo) AstFunc(funcName, sigRef, Move(vars), Move(localsNames), Move(body));
     if (!*func)
         return false;
     (*func)->setOffset(offset);
 
     return true;
@@ -2012,17 +2010,17 @@ AstDecodeStartSection(AstDecodeContext &
     if (sectionStart == Decoder::NotStarted)
         return true;
 
     uint32_t funcIndex;
     if (!c.d.readVarU32(&funcIndex))
         return c.d.fail("failed to read start func index");
 
     AstRef funcRef;
-    if (!AstDecodeGenerateRef(c, AstName(u"func"), funcIndex, &funcRef))
+    if (!GenerateRef(c, AstName(u"func"), funcIndex, &funcRef))
         return false;
 
     c.module().setStartFunc(AstStartFunc(funcRef));
 
     if (!c.d.finishSection(sectionStart, sectionSize, "start"))
         return false;
 
     return true;