forked from chakra-core/ChakraCore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWasmParseTree.cpp
More file actions
158 lines (140 loc) · 3.37 KB
/
WasmParseTree.cpp
File metadata and controls
158 lines (140 loc) · 3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft Corporation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
#include "WasmReaderPch.h"
namespace Wasm
{
namespace Simd
{
bool IsEnabled()
{
#ifdef ENABLE_WASM_SIMD
return CONFIG_FLAG_RELEASE(WasmSimd);
#else
return false;
#endif
}
}
namespace Threads
{
bool IsEnabled()
{
#ifdef ENABLE_WASM
return CONFIG_FLAG(WasmThreads) && CONFIG_FLAG(ESSharedArrayBuffer);
#else
return false;
#endif
}
}
namespace WasmNontrapping
{
bool IsEnabled()
{
#ifdef ENABLE_WASM
return CONFIG_FLAG(WasmNontrapping);
#else
return false;
#endif
}
}
namespace SignExtends
{
bool IsEnabled()
{
#ifdef ENABLE_WASM
return CONFIG_FLAG(WasmSignExtends);
#else
return false;
#endif
}
}
}
#ifdef ENABLE_WASM
namespace Wasm
{
namespace Simd
{
void EnsureSimdIsEnabled()
{
if (!Wasm::Simd::IsEnabled())
{
throw WasmCompilationException(_u("Wasm.Simd support is not enabled"));
}
}
}
namespace WasmTypes
{
bool IsLocalType(WasmTypes::WasmType type)
{
// Check if type in range ]Void,Limit[
#ifdef ENABLE_WASM_SIMD
if (type == WasmTypes::V128 && !Simd::IsEnabled())
{
return false;
}
#endif
return type >= WasmTypes::FirstLocalType && type < WasmTypes::Limit;
}
uint32 GetTypeByteSize(WasmType type)
{
switch (type)
{
case Void: return sizeof(Js::Var);
case I32: return sizeof(int32);
case I64: return sizeof(int64);
case F32: return sizeof(float);
case F64: return sizeof(double);
#ifdef ENABLE_WASM_SIMD
case V128:
Simd::EnsureSimdIsEnabled();
CompileAssert(sizeof(Simd::simdvec) == 16);
return sizeof(Simd::simdvec);
#endif
case Ptr: return sizeof(void*);
default:
Js::Throw::InternalError();
}
}
const char16 * GetTypeName(WasmType type)
{
switch (type) {
case WasmTypes::WasmType::Void: return _u("void");
case WasmTypes::WasmType::I32: return _u("i32");
case WasmTypes::WasmType::I64: return _u("i64");
case WasmTypes::WasmType::F32: return _u("f32");
case WasmTypes::WasmType::F64: return _u("f64");
#ifdef ENABLE_WASM_SIMD
case WasmTypes::WasmType::V128:
Simd::EnsureSimdIsEnabled();
return _u("m128");
#endif
case WasmTypes::WasmType::Any: return _u("any");
default: Assert(UNREACHED); break;
}
return _u("unknown");
}
} // namespace WasmTypes
WasmTypes::WasmType LanguageTypes::ToWasmType(int8 binType)
{
switch (binType)
{
case LanguageTypes::i32: return WasmTypes::I32;
case LanguageTypes::i64: return WasmTypes::I64;
case LanguageTypes::f32: return WasmTypes::F32;
case LanguageTypes::f64: return WasmTypes::F64;
#ifdef ENABLE_WASM_SIMD
case LanguageTypes::v128:
Simd::EnsureSimdIsEnabled();
return WasmTypes::V128;
#endif
default:
throw WasmCompilationException(_u("Invalid binary type %d"), binType);
}
}
bool FunctionIndexTypes::CanBeExported(FunctionIndexTypes::Type funcType)
{
return funcType == FunctionIndexTypes::Function || funcType == FunctionIndexTypes::ImportThunk;
}
} // namespace Wasm
#endif // ENABLE_WASM