Procházet zdrojové kódy

Move ReferenceTypes to WasmParseTree.h and rename to GlobalReferenceTypes

Michael Ferris před 9 roky
rodič
revize
1fe1f79f71

+ 5 - 5
lib/Runtime/Library/WebAssemblyInstance.cpp

@@ -379,7 +379,7 @@ void WebAssemblyInstance::LoadImports(
                 JavascriptError::ThrowTypeError(ctx, WASMERR_InvalidImport);
             }
 
-            Assert(global->GetReferenceType() == Wasm::ReferenceTypes::ImportedReference);
+            Assert(global->GetReferenceType() == Wasm::GlobalReferenceTypes::ImportedReference);
             Wasm::WasmConstLitNode cnst = {0};
             switch (global->GetType())
             {
@@ -410,17 +410,17 @@ void WebAssemblyInstance::LoadGlobals(WebAssemblyModule * wasmModule, ScriptCont
         Wasm::WasmGlobal* global = wasmModule->GetGlobal(i);
         Wasm::WasmConstLitNode cnst = {};
 
-        if (global->GetReferenceType() == Wasm::ReferenceTypes::ImportedReference)
+        if (global->GetReferenceType() == Wasm::GlobalReferenceTypes::ImportedReference)
         {
             // the value should already be resolved
             continue;
         }
 
-        if (global->GetReferenceType() == Wasm::ReferenceTypes::LocalReference)
+        if (global->GetReferenceType() == Wasm::GlobalReferenceTypes::LocalReference)
         {
             Wasm::WasmGlobal* sourceGlobal = wasmModule->GetGlobal(global->GetGlobalIndexInit());
-            if (sourceGlobal->GetReferenceType() != Wasm::ReferenceTypes::Const &&
-                sourceGlobal->GetReferenceType() != Wasm::ReferenceTypes::ImportedReference)
+            if (sourceGlobal->GetReferenceType() != Wasm::GlobalReferenceTypes::Const &&
+                sourceGlobal->GetReferenceType() != Wasm::GlobalReferenceTypes::ImportedReference)
             {
                 JavascriptError::ThrowTypeError(ctx, WASMERR_InvalidGlobalRef);
             }

+ 1 - 1
lib/Runtime/Library/WebAssemblyModule.cpp

@@ -599,7 +599,7 @@ WebAssemblyModule::GetOffsetFromInit(const Wasm::WasmNode& initExpr, const WebAs
 }
 
 void
-WebAssemblyModule::AddGlobal(Wasm::ReferenceTypes::Type refType, Wasm::WasmTypes::WasmType type, bool isMutable, Wasm::WasmNode init)
+WebAssemblyModule::AddGlobal(Wasm::GlobalReferenceTypes::Type refType, Wasm::WasmTypes::WasmType type, bool isMutable, Wasm::WasmNode init)
 {
     Wasm::WasmGlobal* global = Anew(&m_alloc, Wasm::WasmGlobal, refType, m_globalCounts[type]++, type, isMutable, init);
     m_globals->Add(global);

+ 1 - 17
lib/Runtime/Library/WebAssemblyModule.h

@@ -17,22 +17,6 @@ namespace Wasm
     class WasmGlobal;
     struct WasmImport;
     struct WasmExport;
-    namespace ReferenceTypes
-    {
-        enum Type;
-    }
-    namespace WasmTypes
-    {
-        enum WasmType;
-    }
-    namespace FunctionIndexTypes
-    {
-        enum Type;
-    }
-    namespace ExternalKinds
-    {
-        enum ExternalKind;
-    }
 }
 
 namespace Js
@@ -114,7 +98,7 @@ public:
 
     uint GetOffsetFromInit(const Wasm::WasmNode& initexpr, const class WebAssemblyEnvironment* env) const;
 
-    void AddGlobal(Wasm::ReferenceTypes::Type refType, Wasm::WasmTypes::WasmType type, bool isMutable, Wasm::WasmNode init);
+    void AddGlobal(Wasm::GlobalReferenceTypes::Type refType, Wasm::WasmTypes::WasmType type, bool isMutable, Wasm::WasmNode init);
     uint32 GetGlobalCount() const;
     Wasm::WasmGlobal* GetGlobal(uint32 index) const;
 

+ 4 - 4
lib/WasmReader/WasmBinaryReader.cpp

@@ -897,14 +897,14 @@ WasmBinaryReader::ReadGlobalsSection()
         case  wbF32Const:
         case  wbF64Const:
         case  wbI64Const:
-            m_module->AddGlobal(ReferenceTypes::Const, type, isMutable, globalNode);
+            m_module->AddGlobal(GlobalReferenceTypes::Const, type, isMutable, globalNode);
             break;
         case  wbGetGlobal:
-            if (m_module->GetGlobal(globalNode.var.num)->GetReferenceType() != ReferenceTypes::ImportedReference)
+            if (m_module->GetGlobal(globalNode.var.num)->GetReferenceType() != GlobalReferenceTypes::ImportedReference)
             {
                 ThrowDecodingError(_u("Global can only be initialized with a const or an imported global"));
             }
-            m_module->AddGlobal(ReferenceTypes::LocalReference, type, isMutable, globalNode);
+            m_module->AddGlobal(GlobalReferenceTypes::LocalReference, type, isMutable, globalNode);
             break;
         default:
             Assert(UNREACHED);
@@ -963,7 +963,7 @@ WasmBinaryReader::ReadImportEntries()
         {
             WasmTypes::WasmType type = ReadWasmType(len);
             bool isMutable = ReadConst<UINT8>() == 1;
-            m_module->AddGlobal(ReferenceTypes::ImportedReference, type, isMutable, {});
+            m_module->AddGlobal(GlobalReferenceTypes::ImportedReference, type, isMutable, {});
             m_module->AddGlobalImport(modName, modNameLen, fnName, fnNameLen);
             break;
         }

+ 2 - 2
lib/WasmReader/WasmGlobal.cpp

@@ -12,7 +12,7 @@ namespace Wasm
 
     Wasm::WasmConstLitNode WasmGlobal::GetConstInit() const
     {
-        if (GetReferenceType() != ReferenceTypes::Const)
+        if (GetReferenceType() != GlobalReferenceTypes::Const)
         {
             throw WasmCompilationException(_u("Global must be initialized from a const to retrieve the const value"));
         }
@@ -21,7 +21,7 @@ namespace Wasm
 
     uint32 WasmGlobal::GetGlobalIndexInit() const
     {
-        if (GetReferenceType() != ReferenceTypes::LocalReference)
+        if (GetReferenceType() != GlobalReferenceTypes::LocalReference)
         {
             throw WasmCompilationException(_u("Global must be initialized from another global to retrieve its index"));
         }

+ 3 - 11
lib/WasmReader/WasmGlobal.h

@@ -7,18 +7,10 @@
 
 namespace Wasm
 {
-    namespace ReferenceTypes
-    {
-        enum Type
-        {
-            Invalid, Const, LocalReference, ImportedReference
-        };
-    }
-
     class WasmGlobal
     {
     public:
-        WasmGlobal(ReferenceTypes::Type refType, uint offset, WasmTypes::WasmType type, bool isMutable, WasmNode init) :
+        WasmGlobal(GlobalReferenceTypes::Type refType, uint offset, WasmTypes::WasmType type, bool isMutable, WasmNode init) :
             m_rType(refType),
             m_offset(offset),
             m_type(type),
@@ -28,12 +20,12 @@ namespace Wasm
         WasmTypes::WasmType GetType() const { return m_type; }
         bool IsMutable() const { return m_isMutable; }
         uint GetOffset() const { return m_offset; }
-        ReferenceTypes::Type GetReferenceType() const { return m_rType; }
+        GlobalReferenceTypes::Type GetReferenceType() const { return m_rType; }
 
         WasmConstLitNode GetConstInit() const;
         uint32 GetGlobalIndexInit() const;
     private:
-        ReferenceTypes::Type m_rType;
+        GlobalReferenceTypes::Type m_rType;
         WasmTypes::WasmType m_type;
         bool m_isMutable;
         uint m_offset;

+ 8 - 0
lib/WasmReader/WasmParseTree.h

@@ -47,6 +47,14 @@ namespace Wasm
         bool CanBeExported(Type funcType);
     }
 
+    namespace GlobalReferenceTypes
+    {
+        enum Type
+        {
+            Invalid, Const, LocalReference, ImportedReference
+        };
+    }
+
     struct WasmOpCodeSignatures
     {
 #define WASM_SIGNATURE(id, nTypes, ...) static const WasmTypes::WasmType id[nTypes]; DebugOnly(static const int n##id = nTypes;)