Skip to content

Commit 1fe1f79

Browse files
committed
Move ReferenceTypes to WasmParseTree.h and rename to GlobalReferenceTypes
1 parent 2319406 commit 1fe1f79

7 files changed

Lines changed: 24 additions & 40 deletions

File tree

lib/Runtime/Library/WebAssemblyInstance.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ void WebAssemblyInstance::LoadImports(
379379
JavascriptError::ThrowTypeError(ctx, WASMERR_InvalidImport);
380380
}
381381

382-
Assert(global->GetReferenceType() == Wasm::ReferenceTypes::ImportedReference);
382+
Assert(global->GetReferenceType() == Wasm::GlobalReferenceTypes::ImportedReference);
383383
Wasm::WasmConstLitNode cnst = {0};
384384
switch (global->GetType())
385385
{
@@ -410,17 +410,17 @@ void WebAssemblyInstance::LoadGlobals(WebAssemblyModule * wasmModule, ScriptCont
410410
Wasm::WasmGlobal* global = wasmModule->GetGlobal(i);
411411
Wasm::WasmConstLitNode cnst = {};
412412

413-
if (global->GetReferenceType() == Wasm::ReferenceTypes::ImportedReference)
413+
if (global->GetReferenceType() == Wasm::GlobalReferenceTypes::ImportedReference)
414414
{
415415
// the value should already be resolved
416416
continue;
417417
}
418418

419-
if (global->GetReferenceType() == Wasm::ReferenceTypes::LocalReference)
419+
if (global->GetReferenceType() == Wasm::GlobalReferenceTypes::LocalReference)
420420
{
421421
Wasm::WasmGlobal* sourceGlobal = wasmModule->GetGlobal(global->GetGlobalIndexInit());
422-
if (sourceGlobal->GetReferenceType() != Wasm::ReferenceTypes::Const &&
423-
sourceGlobal->GetReferenceType() != Wasm::ReferenceTypes::ImportedReference)
422+
if (sourceGlobal->GetReferenceType() != Wasm::GlobalReferenceTypes::Const &&
423+
sourceGlobal->GetReferenceType() != Wasm::GlobalReferenceTypes::ImportedReference)
424424
{
425425
JavascriptError::ThrowTypeError(ctx, WASMERR_InvalidGlobalRef);
426426
}

lib/Runtime/Library/WebAssemblyModule.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ WebAssemblyModule::GetOffsetFromInit(const Wasm::WasmNode& initExpr, const WebAs
599599
}
600600

601601
void
602-
WebAssemblyModule::AddGlobal(Wasm::ReferenceTypes::Type refType, Wasm::WasmTypes::WasmType type, bool isMutable, Wasm::WasmNode init)
602+
WebAssemblyModule::AddGlobal(Wasm::GlobalReferenceTypes::Type refType, Wasm::WasmTypes::WasmType type, bool isMutable, Wasm::WasmNode init)
603603
{
604604
Wasm::WasmGlobal* global = Anew(&m_alloc, Wasm::WasmGlobal, refType, m_globalCounts[type]++, type, isMutable, init);
605605
m_globals->Add(global);

lib/Runtime/Library/WebAssemblyModule.h

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,6 @@ namespace Wasm
1717
class WasmGlobal;
1818
struct WasmImport;
1919
struct WasmExport;
20-
namespace ReferenceTypes
21-
{
22-
enum Type;
23-
}
24-
namespace WasmTypes
25-
{
26-
enum WasmType;
27-
}
28-
namespace FunctionIndexTypes
29-
{
30-
enum Type;
31-
}
32-
namespace ExternalKinds
33-
{
34-
enum ExternalKind;
35-
}
3620
}
3721

3822
namespace Js
@@ -114,7 +98,7 @@ class WebAssemblyModule : public DynamicObject
11498

11599
uint GetOffsetFromInit(const Wasm::WasmNode& initexpr, const class WebAssemblyEnvironment* env) const;
116100

117-
void AddGlobal(Wasm::ReferenceTypes::Type refType, Wasm::WasmTypes::WasmType type, bool isMutable, Wasm::WasmNode init);
101+
void AddGlobal(Wasm::GlobalReferenceTypes::Type refType, Wasm::WasmTypes::WasmType type, bool isMutable, Wasm::WasmNode init);
118102
uint32 GetGlobalCount() const;
119103
Wasm::WasmGlobal* GetGlobal(uint32 index) const;
120104

lib/WasmReader/WasmBinaryReader.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -897,14 +897,14 @@ WasmBinaryReader::ReadGlobalsSection()
897897
case wbF32Const:
898898
case wbF64Const:
899899
case wbI64Const:
900-
m_module->AddGlobal(ReferenceTypes::Const, type, isMutable, globalNode);
900+
m_module->AddGlobal(GlobalReferenceTypes::Const, type, isMutable, globalNode);
901901
break;
902902
case wbGetGlobal:
903-
if (m_module->GetGlobal(globalNode.var.num)->GetReferenceType() != ReferenceTypes::ImportedReference)
903+
if (m_module->GetGlobal(globalNode.var.num)->GetReferenceType() != GlobalReferenceTypes::ImportedReference)
904904
{
905905
ThrowDecodingError(_u("Global can only be initialized with a const or an imported global"));
906906
}
907-
m_module->AddGlobal(ReferenceTypes::LocalReference, type, isMutable, globalNode);
907+
m_module->AddGlobal(GlobalReferenceTypes::LocalReference, type, isMutable, globalNode);
908908
break;
909909
default:
910910
Assert(UNREACHED);
@@ -963,7 +963,7 @@ WasmBinaryReader::ReadImportEntries()
963963
{
964964
WasmTypes::WasmType type = ReadWasmType(len);
965965
bool isMutable = ReadConst<UINT8>() == 1;
966-
m_module->AddGlobal(ReferenceTypes::ImportedReference, type, isMutable, {});
966+
m_module->AddGlobal(GlobalReferenceTypes::ImportedReference, type, isMutable, {});
967967
m_module->AddGlobalImport(modName, modNameLen, fnName, fnNameLen);
968968
break;
969969
}

lib/WasmReader/WasmGlobal.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace Wasm
1212

1313
Wasm::WasmConstLitNode WasmGlobal::GetConstInit() const
1414
{
15-
if (GetReferenceType() != ReferenceTypes::Const)
15+
if (GetReferenceType() != GlobalReferenceTypes::Const)
1616
{
1717
throw WasmCompilationException(_u("Global must be initialized from a const to retrieve the const value"));
1818
}
@@ -21,7 +21,7 @@ namespace Wasm
2121

2222
uint32 WasmGlobal::GetGlobalIndexInit() const
2323
{
24-
if (GetReferenceType() != ReferenceTypes::LocalReference)
24+
if (GetReferenceType() != GlobalReferenceTypes::LocalReference)
2525
{
2626
throw WasmCompilationException(_u("Global must be initialized from another global to retrieve its index"));
2727
}

lib/WasmReader/WasmGlobal.h

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,10 @@
77

88
namespace Wasm
99
{
10-
namespace ReferenceTypes
11-
{
12-
enum Type
13-
{
14-
Invalid, Const, LocalReference, ImportedReference
15-
};
16-
}
17-
1810
class WasmGlobal
1911
{
2012
public:
21-
WasmGlobal(ReferenceTypes::Type refType, uint offset, WasmTypes::WasmType type, bool isMutable, WasmNode init) :
13+
WasmGlobal(GlobalReferenceTypes::Type refType, uint offset, WasmTypes::WasmType type, bool isMutable, WasmNode init) :
2214
m_rType(refType),
2315
m_offset(offset),
2416
m_type(type),
@@ -28,12 +20,12 @@ namespace Wasm
2820
WasmTypes::WasmType GetType() const { return m_type; }
2921
bool IsMutable() const { return m_isMutable; }
3022
uint GetOffset() const { return m_offset; }
31-
ReferenceTypes::Type GetReferenceType() const { return m_rType; }
23+
GlobalReferenceTypes::Type GetReferenceType() const { return m_rType; }
3224

3325
WasmConstLitNode GetConstInit() const;
3426
uint32 GetGlobalIndexInit() const;
3527
private:
36-
ReferenceTypes::Type m_rType;
28+
GlobalReferenceTypes::Type m_rType;
3729
WasmTypes::WasmType m_type;
3830
bool m_isMutable;
3931
uint m_offset;

lib/WasmReader/WasmParseTree.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ namespace Wasm
4747
bool CanBeExported(Type funcType);
4848
}
4949

50+
namespace GlobalReferenceTypes
51+
{
52+
enum Type
53+
{
54+
Invalid, Const, LocalReference, ImportedReference
55+
};
56+
}
57+
5058
struct WasmOpCodeSignatures
5159
{
5260
#define WASM_SIGNATURE(id, nTypes, ...) static const WasmTypes::WasmType id[nTypes]; DebugOnly(static const int n##id = nTypes;)

0 commit comments

Comments
 (0)