5 #ifndef V8_ASMJS_ASM_PARSER_H_ 6 #define V8_ASMJS_ASM_PARSER_H_ 11 #include "src/asmjs/asm-scanner.h" 12 #include "src/asmjs/asm-types.h" 13 #include "src/wasm/wasm-module-builder.h" 14 #include "src/zone/zone-containers.h" 19 class Utf16CharacterStream;
38 #define V(_unused1, name, _unused2, _unused3) kMath##name, 39 STDLIB_MATH_FUNCTION_LIST(
V)
41 #define V(name, _unused1) kMath##name, 42 STDLIB_MATH_VALUE_LIST(
V)
44 #define V(name, _unused1, _unused2, _unused3) k##name, 45 STDLIB_ARRAY_TYPE_LIST(
V)
55 const char* failure_message()
const {
return failure_message_; }
56 int failure_location()
const {
return failure_location_; }
58 const StdlibSet* stdlib_uses()
const {
return &stdlib_uses_; }
70 #define V(_unused0, Name, _unused1, _unused2) kMath##Name, 71 STDLIB_MATH_FUNCTION_LIST(
V)
73 #define V(Name, _unused1) kMath##Name, 74 STDLIB_MATH_VALUE_LIST(
V)
82 struct FunctionImportInfo {
88 : function_name(name), cache(zone) {}
94 FunctionImportInfo*
import =
nullptr;
97 VarKind kind = VarKind::kUnused;
98 bool mutable_variable =
true;
99 bool function_defined =
false;
102 struct GlobalImport {
104 ValueType value_type;
108 enum class BlockKind { kRegular, kLoop, kOther };
112 AsmJsScanner::token_t label;
118 template <
typename T>
119 class CachedVectors {
121 explicit CachedVectors(
Zone* zone) : reusable_vectors_(zone) {}
123 Zone* zone()
const {
return reusable_vectors_.get_allocator().zone(); }
126 if (reusable_vectors_.empty())
return;
127 reusable_vectors_.back().swap(*vec);
128 reusable_vectors_.pop_back();
133 reusable_vectors_.emplace_back(std::move(*vec));
140 template <
typename T>
141 class CachedVector final :
public ZoneVector<T> {
143 explicit CachedVector(CachedVectors<T>& cache)
147 ~CachedVector() { cache_->reuse(
this); }
150 CachedVectors<T>* cache_;
163 CachedVectors<ValueType> cached_valuetype_vectors_{zone_};
164 CachedVectors<AsmType*> cached_asm_type_p_vectors_{zone_};
165 CachedVectors<AsmJsScanner::token_t> cached_token_t_vectors_{zone_};
166 CachedVectors<int32_t> cached_int_vectors_{zone_};
168 int function_temp_locals_offset_;
169 int function_temp_locals_used_;
170 int function_temp_locals_depth_;
174 const char* failure_message_;
175 int failure_location_;
178 AsmJsScanner::token_t stdlib_name_;
179 AsmJsScanner::token_t foreign_name_;
180 AsmJsScanner::token_t heap_name_;
182 static const AsmJsScanner::token_t kTokenNone = 0;
185 bool inside_heap_assignment_;
206 size_t call_coercion_position_;
211 AsmType* call_coercion_deferred_;
215 size_t call_coercion_deferred_position_;
221 size_t heap_access_shift_position_;
223 static const size_t kNoHeapAccessShift = -1;
227 AsmJsScanner::token_t pending_label_;
233 Zone* zone() {
return zone_; }
235 inline bool Peek(AsmJsScanner::token_t token) {
236 return scanner_.Token() == token;
239 inline bool Check(AsmJsScanner::token_t token) {
240 if (scanner_.Token() == token) {
248 inline bool CheckForZero() {
249 if (scanner_.IsUnsigned() && scanner_.AsUnsigned() == 0) {
257 inline bool CheckForDouble(
double* value) {
258 if (scanner_.IsDouble()) {
259 *value = scanner_.AsDouble();
267 inline bool CheckForUnsigned(
uint32_t* value) {
268 if (scanner_.IsUnsigned()) {
269 *value = scanner_.AsUnsigned();
278 if (scanner_.IsUnsigned() && scanner_.AsUnsigned() < limit) {
279 *value = scanner_.AsUnsigned();
287 inline AsmJsScanner::token_t Consume() {
288 AsmJsScanner::token_t ret = scanner_.Token();
293 void SkipSemicolon();
295 VarInfo* GetVarInfo(AsmJsScanner::token_t token);
297 void DeclareGlobal(VarInfo* info,
bool mutable_variable,
AsmType*
type,
300 void DeclareStdlibFunc(VarInfo* info, VarKind kind,
AsmType*
type);
302 bool mutable_variable, VarInfo* info);
313 void BareBegin(BlockKind kind = BlockKind::kOther,
314 AsmJsScanner::token_t label = 0);
316 int FindContinueLabelDepth(AsmJsScanner::token_t label);
317 int FindBreakLabelDepth(AsmJsScanner::token_t label);
320 void Begin(AsmJsScanner::token_t label = 0);
321 void Loop(AsmJsScanner::token_t label = 0);
324 void InitializeStdlibTypes();
329 void ValidateModule();
330 void ValidateModuleParameters();
331 void ValidateModuleVars();
332 void ValidateModuleVar(
bool mutable_variable);
333 void ValidateModuleVarImport(VarInfo* info,
bool mutable_variable);
334 void ValidateModuleVarStdlib(VarInfo* info);
335 void ValidateModuleVarNewStdlib(VarInfo* info);
336 void ValidateModuleVarFromGlobal(VarInfo* info,
bool mutable_variable);
338 void ValidateExport();
339 void ValidateFunctionTable();
340 void ValidateFunction();
342 void ValidateFunctionLocals(
size_t param_count,
344 void ValidateStatement();
356 void LabelledStatement();
359 void ValidateDefault();
366 AsmType* AssignmentExpression();
368 AsmType* MultiplicativeExpression();
371 AsmType* RelationalExpression();
373 AsmType* BitwiseANDExpression();
374 AsmType* BitwiseXORExpression();
375 AsmType* BitwiseORExpression();
376 AsmType* ConditionalExpression();
377 AsmType* ParenthesizedExpression();
380 void ValidateHeapAccess();
381 void ValidateFloatCoercion();
386 void ScanToClosingParenthesis();
398 #endif // V8_ASMJS_ASM_PARSER_H_