OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/wasm/asm-wasm-builder.h" | 7 #include "src/wasm/asm-wasm-builder.h" |
8 #include "src/wasm/wasm-macro-gen.h" | 8 #include "src/wasm/wasm-macro-gen.h" |
9 #include "src/wasm/wasm-opcodes.h" | 9 #include "src/wasm/wasm-opcodes.h" |
10 | 10 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 | 70 |
71 void Compile() { | 71 void Compile() { |
72 InitializeInitFunction(); | 72 InitializeInitFunction(); |
73 RECURSE(VisitFunctionLiteral(literal_)); | 73 RECURSE(VisitFunctionLiteral(literal_)); |
74 } | 74 } |
75 | 75 |
76 void VisitVariableDeclaration(VariableDeclaration* decl) {} | 76 void VisitVariableDeclaration(VariableDeclaration* decl) {} |
77 | 77 |
78 void VisitFunctionDeclaration(FunctionDeclaration* decl) { | 78 void VisitFunctionDeclaration(FunctionDeclaration* decl) { |
79 DCHECK(!in_function_); | 79 DCHECK(!in_function_); |
80 DCHECK(current_function_builder_ == nullptr); | 80 DCHECK_NULL(current_function_builder_); |
81 uint16_t index = LookupOrInsertFunction(decl->proxy()->var()); | 81 uint16_t index = LookupOrInsertFunction(decl->proxy()->var()); |
82 current_function_builder_ = builder_->FunctionAt(index); | 82 current_function_builder_ = builder_->FunctionAt(index); |
83 in_function_ = true; | 83 in_function_ = true; |
84 RECURSE(Visit(decl->fun())); | 84 RECURSE(Visit(decl->fun())); |
85 in_function_ = false; | 85 in_function_ = false; |
86 current_function_builder_ = nullptr; | 86 current_function_builder_ = nullptr; |
87 local_variables_.Clear(); | 87 local_variables_.Clear(); |
88 } | 88 } |
89 | 89 |
90 void VisitImportDeclaration(ImportDeclaration* decl) {} | 90 void VisitImportDeclaration(ImportDeclaration* decl) {} |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 } else { | 162 } else { |
163 current_function_builder_->Emit(kExprNop); | 163 current_function_builder_->Emit(kExprNop); |
164 } | 164 } |
165 if (stmt->HasElseStatement()) { | 165 if (stmt->HasElseStatement()) { |
166 RECURSE(Visit(stmt->else_statement())); | 166 RECURSE(Visit(stmt->else_statement())); |
167 } | 167 } |
168 } | 168 } |
169 | 169 |
170 void VisitContinueStatement(ContinueStatement* stmt) { | 170 void VisitContinueStatement(ContinueStatement* stmt) { |
171 DCHECK(in_function_); | 171 DCHECK(in_function_); |
172 DCHECK(stmt->target() != NULL); | 172 DCHECK_NOT_NULL(stmt->target()); |
173 int i = static_cast<int>(breakable_blocks_.size()) - 1; | 173 int i = static_cast<int>(breakable_blocks_.size()) - 1; |
174 int block_distance = 0; | 174 int block_distance = 0; |
175 for (; i >= 0; i--) { | 175 for (; i >= 0; i--) { |
176 auto elem = breakable_blocks_.at(i); | 176 auto elem = breakable_blocks_.at(i); |
177 if (elem.first == stmt->target()) { | 177 if (elem.first == stmt->target()) { |
178 DCHECK(elem.second); | 178 DCHECK(elem.second); |
179 break; | 179 break; |
180 } else if (elem.second) { | 180 } else if (elem.second) { |
181 block_distance += 2; | 181 block_distance += 2; |
182 } else { | 182 } else { |
183 block_distance += 1; | 183 block_distance += 1; |
184 } | 184 } |
185 } | 185 } |
186 DCHECK(i >= 0); | 186 DCHECK(i >= 0); |
187 current_function_builder_->EmitWithU8(kExprBr, block_distance); | 187 current_function_builder_->EmitWithU8(kExprBr, block_distance); |
188 current_function_builder_->Emit(kExprNop); | 188 current_function_builder_->Emit(kExprNop); |
189 } | 189 } |
190 | 190 |
191 void VisitBreakStatement(BreakStatement* stmt) { | 191 void VisitBreakStatement(BreakStatement* stmt) { |
192 DCHECK(in_function_); | 192 DCHECK(in_function_); |
193 DCHECK(stmt->target() != NULL); | 193 DCHECK_NOT_NULL(stmt->target()); |
194 int i = static_cast<int>(breakable_blocks_.size()) - 1; | 194 int i = static_cast<int>(breakable_blocks_.size()) - 1; |
195 int block_distance = 0; | 195 int block_distance = 0; |
196 for (; i >= 0; i--) { | 196 for (; i >= 0; i--) { |
197 auto elem = breakable_blocks_.at(i); | 197 auto elem = breakable_blocks_.at(i); |
198 if (elem.first == stmt->target()) { | 198 if (elem.first == stmt->target()) { |
199 if (elem.second) { | 199 if (elem.second) { |
200 block_distance++; | 200 block_distance++; |
201 } | 201 } |
202 break; | 202 break; |
203 } else if (elem.second) { | 203 } else if (elem.second) { |
(...skipping 25 matching lines...) Expand all Loading... |
229 current_function_builder_->Emit(kExprSetLocal); | 229 current_function_builder_->Emit(kExprSetLocal); |
230 AddLeb128(index, true); | 230 AddLeb128(index, true); |
231 byte code[] = {WASM_I32(value)}; | 231 byte code[] = {WASM_I32(value)}; |
232 current_function_builder_->EmitCode(code, sizeof(code)); | 232 current_function_builder_->EmitCode(code, sizeof(code)); |
233 block_size_++; | 233 block_size_++; |
234 } | 234 } |
235 | 235 |
236 void CompileCase(CaseClause* clause, uint16_t fall_through, | 236 void CompileCase(CaseClause* clause, uint16_t fall_through, |
237 VariableProxy* tag) { | 237 VariableProxy* tag) { |
238 Literal* label = clause->label()->AsLiteral(); | 238 Literal* label = clause->label()->AsLiteral(); |
239 DCHECK(label != nullptr); | 239 DCHECK_NOT_NULL(label); |
240 block_size_++; | 240 block_size_++; |
241 current_function_builder_->Emit(kExprIf); | 241 current_function_builder_->Emit(kExprIf); |
242 current_function_builder_->Emit(kExprI32Ior); | 242 current_function_builder_->Emit(kExprI32Ior); |
243 current_function_builder_->Emit(kExprI32Eq); | 243 current_function_builder_->Emit(kExprI32Eq); |
244 VisitVariableProxy(tag); | 244 VisitVariableProxy(tag); |
245 VisitLiteral(label); | 245 VisitLiteral(label); |
246 current_function_builder_->Emit(kExprGetLocal); | 246 current_function_builder_->Emit(kExprGetLocal); |
247 AddLeb128(fall_through, true); | 247 AddLeb128(fall_through, true); |
248 BlockVisitor visitor(this, nullptr, kExprBlock, false, 0); | 248 BlockVisitor visitor(this, nullptr, kExprBlock, false, 0); |
249 SetLocalTo(fall_through, 1); | 249 SetLocalTo(fall_through, 1); |
250 ZoneList<Statement*>* stmts = clause->statements(); | 250 ZoneList<Statement*>* stmts = clause->statements(); |
251 block_size_ += stmts->length(); | 251 block_size_ += stmts->length(); |
252 RECURSE(VisitStatements(stmts)); | 252 RECURSE(VisitStatements(stmts)); |
253 } | 253 } |
254 | 254 |
255 void VisitSwitchStatement(SwitchStatement* stmt) { | 255 void VisitSwitchStatement(SwitchStatement* stmt) { |
256 VariableProxy* tag = stmt->tag()->AsVariableProxy(); | 256 VariableProxy* tag = stmt->tag()->AsVariableProxy(); |
257 DCHECK(tag != NULL); | 257 DCHECK_NOT_NULL(tag); |
258 BlockVisitor visitor(this, stmt->AsBreakableStatement(), kExprBlock, false, | 258 BlockVisitor visitor(this, stmt->AsBreakableStatement(), kExprBlock, false, |
259 0); | 259 0); |
260 uint16_t fall_through = current_function_builder_->AddLocal(kAstI32); | 260 uint16_t fall_through = current_function_builder_->AddLocal(kAstI32); |
261 SetLocalTo(fall_through, 0); | 261 SetLocalTo(fall_through, 0); |
262 | 262 |
263 ZoneList<CaseClause*>* clauses = stmt->cases(); | 263 ZoneList<CaseClause*>* clauses = stmt->cases(); |
264 for (int i = 0; i < clauses->length(); ++i) { | 264 for (int i = 0; i < clauses->length(); ++i) { |
265 CaseClause* clause = clauses->at(i); | 265 CaseClause* clause = clauses->at(i); |
266 if (!clause->is_default()) { | 266 if (!clause->is_default()) { |
267 CompileCase(clause, fall_through, tag); | 267 CompileCase(clause, fall_through, tag); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 | 337 |
338 void VisitFunctionLiteral(FunctionLiteral* expr) { | 338 void VisitFunctionLiteral(FunctionLiteral* expr) { |
339 Scope* scope = expr->scope(); | 339 Scope* scope = expr->scope(); |
340 if (in_function_) { | 340 if (in_function_) { |
341 if (expr->bounds().lower->IsFunction()) { | 341 if (expr->bounds().lower->IsFunction()) { |
342 FunctionType* func_type = expr->bounds().lower->AsFunction(); | 342 FunctionType* func_type = expr->bounds().lower->AsFunction(); |
343 LocalType return_type = TypeFrom(func_type->Result()); | 343 LocalType return_type = TypeFrom(func_type->Result()); |
344 current_function_builder_->ReturnType(return_type); | 344 current_function_builder_->ReturnType(return_type); |
345 for (int i = 0; i < expr->parameter_count(); i++) { | 345 for (int i = 0; i < expr->parameter_count(); i++) { |
346 LocalType type = TypeFrom(func_type->Parameter(i)); | 346 LocalType type = TypeFrom(func_type->Parameter(i)); |
347 DCHECK(type != kAstStmt); | 347 DCHECK_NE(kAstStmt, type); |
348 LookupOrInsertLocal(scope->parameter(i), type); | 348 LookupOrInsertLocal(scope->parameter(i), type); |
349 } | 349 } |
350 } else { | 350 } else { |
351 UNREACHABLE(); | 351 UNREACHABLE(); |
352 } | 352 } |
353 } | 353 } |
354 RECURSE(VisitStatements(expr->body())); | 354 RECURSE(VisitStatements(expr->body())); |
355 RECURSE(VisitDeclarations(scope->declarations())); | 355 RECURSE(VisitDeclarations(scope->declarations())); |
356 } | 356 } |
357 | 357 |
(...skipping 20 matching lines...) Expand all Loading... |
378 } | 378 } |
379 is_set_op_ = false; | 379 is_set_op_ = false; |
380 } else { | 380 } else { |
381 if (var->IsContextSlot()) { | 381 if (var->IsContextSlot()) { |
382 current_function_builder_->Emit(kExprLoadGlobal); | 382 current_function_builder_->Emit(kExprLoadGlobal); |
383 } else { | 383 } else { |
384 current_function_builder_->Emit(kExprGetLocal); | 384 current_function_builder_->Emit(kExprGetLocal); |
385 } | 385 } |
386 } | 386 } |
387 LocalType var_type = TypeOf(expr); | 387 LocalType var_type = TypeOf(expr); |
388 DCHECK(var_type != kAstStmt); | 388 DCHECK_NE(kAstStmt, var_type); |
389 if (var->IsContextSlot()) { | 389 if (var->IsContextSlot()) { |
390 AddLeb128(LookupOrInsertGlobal(var, var_type), false); | 390 AddLeb128(LookupOrInsertGlobal(var, var_type), false); |
391 } else { | 391 } else { |
392 AddLeb128(LookupOrInsertLocal(var, var_type), true); | 392 AddLeb128(LookupOrInsertLocal(var, var_type), true); |
393 } | 393 } |
394 } | 394 } |
395 } | 395 } |
396 | 396 |
397 void VisitLiteral(Literal* expr) { | 397 void VisitLiteral(Literal* expr) { |
398 if (in_function_) { | 398 if (in_function_) { |
(...skipping 26 matching lines...) Expand all Loading... |
425 } | 425 } |
426 | 426 |
427 void VisitRegExpLiteral(RegExpLiteral* expr) { UNREACHABLE(); } | 427 void VisitRegExpLiteral(RegExpLiteral* expr) { UNREACHABLE(); } |
428 | 428 |
429 void VisitObjectLiteral(ObjectLiteral* expr) { | 429 void VisitObjectLiteral(ObjectLiteral* expr) { |
430 ZoneList<ObjectLiteralProperty*>* props = expr->properties(); | 430 ZoneList<ObjectLiteralProperty*>* props = expr->properties(); |
431 for (int i = 0; i < props->length(); ++i) { | 431 for (int i = 0; i < props->length(); ++i) { |
432 ObjectLiteralProperty* prop = props->at(i); | 432 ObjectLiteralProperty* prop = props->at(i); |
433 DCHECK(marking_exported); | 433 DCHECK(marking_exported); |
434 VariableProxy* expr = prop->value()->AsVariableProxy(); | 434 VariableProxy* expr = prop->value()->AsVariableProxy(); |
435 DCHECK(expr != nullptr); | 435 DCHECK_NOT_NULL(expr); |
436 Variable* var = expr->var(); | 436 Variable* var = expr->var(); |
437 Literal* name = prop->key()->AsLiteral(); | 437 Literal* name = prop->key()->AsLiteral(); |
438 DCHECK(name != nullptr); | 438 DCHECK_NOT_NULL(name); |
439 DCHECK(name->IsPropertyName()); | 439 DCHECK(name->IsPropertyName()); |
440 const AstRawString* raw_name = name->AsRawPropertyName(); | 440 const AstRawString* raw_name = name->AsRawPropertyName(); |
441 if (var->is_function()) { | 441 if (var->is_function()) { |
442 uint16_t index = LookupOrInsertFunction(var); | 442 uint16_t index = LookupOrInsertFunction(var); |
443 builder_->FunctionAt(index)->Exported(1); | 443 builder_->FunctionAt(index)->Exported(1); |
444 builder_->FunctionAt(index) | 444 builder_->FunctionAt(index) |
445 ->SetName(raw_name->raw_data(), raw_name->length()); | 445 ->SetName(raw_name->raw_data(), raw_name->length()); |
446 } | 446 } |
447 } | 447 } |
448 } | 448 } |
(...skipping 20 matching lines...) Expand all Loading... |
469 sig.AddReturn(static_cast<LocalType>(return_type)); | 469 sig.AddReturn(static_cast<LocalType>(return_type)); |
470 } | 470 } |
471 for (int i = 0; i < func_type->Arity(); i++) { | 471 for (int i = 0; i < func_type->Arity(); i++) { |
472 sig.AddParam(TypeFrom(func_type->Parameter(i))); | 472 sig.AddParam(TypeFrom(func_type->Parameter(i))); |
473 } | 473 } |
474 uint16_t signature_index = builder_->AddSignature(sig.Build()); | 474 uint16_t signature_index = builder_->AddSignature(sig.Build()); |
475 InsertFunctionTable(table->var(), next_table_index_, signature_index); | 475 InsertFunctionTable(table->var(), next_table_index_, signature_index); |
476 next_table_index_ += funcs->values()->length(); | 476 next_table_index_ += funcs->values()->length(); |
477 for (int i = 0; i < funcs->values()->length(); i++) { | 477 for (int i = 0; i < funcs->values()->length(); i++) { |
478 VariableProxy* func = funcs->values()->at(i)->AsVariableProxy(); | 478 VariableProxy* func = funcs->values()->at(i)->AsVariableProxy(); |
479 DCHECK(func != nullptr); | 479 DCHECK_NOT_NULL(func); |
480 builder_->AddIndirectFunction(LookupOrInsertFunction(func->var())); | 480 builder_->AddIndirectFunction(LookupOrInsertFunction(func->var())); |
481 } | 481 } |
482 } | 482 } |
483 | 483 |
484 struct FunctionTableIndices : public ZoneObject { | 484 struct FunctionTableIndices : public ZoneObject { |
485 uint32_t start_index; | 485 uint32_t start_index; |
486 uint16_t signature_index; | 486 uint16_t signature_index; |
487 }; | 487 }; |
488 | 488 |
489 void InsertFunctionTable(Variable* v, uint32_t start_index, | 489 void InsertFunctionTable(Variable* v, uint32_t start_index, |
490 uint16_t signature_index) { | 490 uint16_t signature_index) { |
491 FunctionTableIndices* container = new (zone()) FunctionTableIndices(); | 491 FunctionTableIndices* container = new (zone()) FunctionTableIndices(); |
492 container->start_index = start_index; | 492 container->start_index = start_index; |
493 container->signature_index = signature_index; | 493 container->signature_index = signature_index; |
494 ZoneHashMap::Entry* entry = function_tables_.LookupOrInsert( | 494 ZoneHashMap::Entry* entry = function_tables_.LookupOrInsert( |
495 v, ComputePointerHash(v), ZoneAllocationPolicy(zone())); | 495 v, ComputePointerHash(v), ZoneAllocationPolicy(zone())); |
496 entry->value = container; | 496 entry->value = container; |
497 } | 497 } |
498 | 498 |
499 FunctionTableIndices* LookupFunctionTable(Variable* v) { | 499 FunctionTableIndices* LookupFunctionTable(Variable* v) { |
500 ZoneHashMap::Entry* entry = | 500 ZoneHashMap::Entry* entry = |
501 function_tables_.Lookup(v, ComputePointerHash(v)); | 501 function_tables_.Lookup(v, ComputePointerHash(v)); |
502 DCHECK(entry != nullptr); | 502 DCHECK_NOT_NULL(entry); |
503 return reinterpret_cast<FunctionTableIndices*>(entry->value); | 503 return reinterpret_cast<FunctionTableIndices*>(entry->value); |
504 } | 504 } |
505 | 505 |
506 class ImportedFunctionTable { | 506 class ImportedFunctionTable { |
507 private: | 507 private: |
508 class ImportedFunctionIndices : public ZoneObject { | 508 class ImportedFunctionIndices : public ZoneObject { |
509 public: | 509 public: |
510 const unsigned char* name_; | 510 const unsigned char* name_; |
511 int name_length_; | 511 int name_length_; |
512 WasmModuleBuilder::SignatureMap signature_to_index_; | 512 WasmModuleBuilder::SignatureMap signature_to_index_; |
(...skipping 14 matching lines...) Expand all Loading... |
527 void AddImport(Variable* v, const unsigned char* name, int name_length) { | 527 void AddImport(Variable* v, const unsigned char* name, int name_length) { |
528 ImportedFunctionIndices* indices = new (builder_->zone()) | 528 ImportedFunctionIndices* indices = new (builder_->zone()) |
529 ImportedFunctionIndices(name, name_length, builder_->zone()); | 529 ImportedFunctionIndices(name, name_length, builder_->zone()); |
530 ZoneHashMap::Entry* entry = table_.LookupOrInsert( | 530 ZoneHashMap::Entry* entry = table_.LookupOrInsert( |
531 v, ComputePointerHash(v), ZoneAllocationPolicy(builder_->zone())); | 531 v, ComputePointerHash(v), ZoneAllocationPolicy(builder_->zone())); |
532 entry->value = indices; | 532 entry->value = indices; |
533 } | 533 } |
534 | 534 |
535 uint16_t GetFunctionIndex(Variable* v, FunctionSig* sig) { | 535 uint16_t GetFunctionIndex(Variable* v, FunctionSig* sig) { |
536 ZoneHashMap::Entry* entry = table_.Lookup(v, ComputePointerHash(v)); | 536 ZoneHashMap::Entry* entry = table_.Lookup(v, ComputePointerHash(v)); |
537 DCHECK(entry != nullptr); | 537 DCHECK_NOT_NULL(entry); |
538 ImportedFunctionIndices* indices = | 538 ImportedFunctionIndices* indices = |
539 reinterpret_cast<ImportedFunctionIndices*>(entry->value); | 539 reinterpret_cast<ImportedFunctionIndices*>(entry->value); |
540 WasmModuleBuilder::SignatureMap::iterator pos = | 540 WasmModuleBuilder::SignatureMap::iterator pos = |
541 indices->signature_to_index_.find(sig); | 541 indices->signature_to_index_.find(sig); |
542 if (pos != indices->signature_to_index_.end()) { | 542 if (pos != indices->signature_to_index_.end()) { |
543 return pos->second; | 543 return pos->second; |
544 } else { | 544 } else { |
545 uint16_t index = builder_->builder_->AddFunction(); | 545 uint16_t index = builder_->builder_->AddFunction(); |
546 indices->signature_to_index_[sig] = index; | 546 indices->signature_to_index_[sig] = index; |
547 WasmFunctionBuilder* function = builder_->builder_->FunctionAt(index); | 547 WasmFunctionBuilder* function = builder_->builder_->FunctionAt(index); |
548 function->External(1); | 548 function->External(1); |
549 function->SetName(indices->name_, indices->name_length_); | 549 function->SetName(indices->name_, indices->name_length_); |
550 if (sig->return_count() > 0) { | 550 if (sig->return_count() > 0) { |
551 function->ReturnType(sig->GetReturn()); | 551 function->ReturnType(sig->GetReturn()); |
552 } | 552 } |
553 for (size_t i = 0; i < sig->parameter_count(); i++) { | 553 for (size_t i = 0; i < sig->parameter_count(); i++) { |
554 function->AddParam(sig->GetParam(i)); | 554 function->AddParam(sig->GetParam(i)); |
555 } | 555 } |
556 return index; | 556 return index; |
557 } | 557 } |
558 } | 558 } |
559 }; | 559 }; |
560 | 560 |
561 void VisitAssignment(Assignment* expr) { | 561 void VisitAssignment(Assignment* expr) { |
562 bool in_init = false; | 562 bool in_init = false; |
563 if (!in_function_) { | 563 if (!in_function_) { |
564 BinaryOperation* binop = expr->value()->AsBinaryOperation(); | 564 BinaryOperation* binop = expr->value()->AsBinaryOperation(); |
565 if (binop != nullptr) { | 565 if (binop != nullptr) { |
566 Property* prop = binop->left()->AsProperty(); | 566 Property* prop = binop->left()->AsProperty(); |
567 DCHECK(prop != nullptr); | 567 DCHECK_NOT_NULL(prop); |
568 LoadInitFunction(); | 568 LoadInitFunction(); |
569 is_set_op_ = true; | 569 is_set_op_ = true; |
570 RECURSE(Visit(expr->target())); | 570 RECURSE(Visit(expr->target())); |
571 DCHECK(!is_set_op_); | 571 DCHECK(!is_set_op_); |
572 if (binop->op() == Token::MUL) { | 572 if (binop->op() == Token::MUL) { |
573 DCHECK(binop->right()->IsLiteral()); | 573 DCHECK(binop->right()->IsLiteral()); |
574 DCHECK(binop->right()->AsLiteral()->raw_value()->AsNumber() == 1.0); | 574 DCHECK_EQ(1.0, binop->right()->AsLiteral()->raw_value()->AsNumber()); |
575 DCHECK(binop->right()->AsLiteral()->raw_value()->ContainsDot()); | 575 DCHECK(binop->right()->AsLiteral()->raw_value()->ContainsDot()); |
576 VisitForeignVariable(true, prop); | 576 VisitForeignVariable(true, prop); |
577 } else if (binop->op() == Token::BIT_OR) { | 577 } else if (binop->op() == Token::BIT_OR) { |
578 DCHECK(binop->right()->IsLiteral()); | 578 DCHECK(binop->right()->IsLiteral()); |
579 DCHECK(binop->right()->AsLiteral()->raw_value()->AsNumber() == 0.0); | 579 DCHECK_EQ(0.0, binop->right()->AsLiteral()->raw_value()->AsNumber()); |
580 DCHECK(!binop->right()->AsLiteral()->raw_value()->ContainsDot()); | 580 DCHECK(!binop->right()->AsLiteral()->raw_value()->ContainsDot()); |
581 VisitForeignVariable(false, prop); | 581 VisitForeignVariable(false, prop); |
582 } else { | 582 } else { |
583 UNREACHABLE(); | 583 UNREACHABLE(); |
584 } | 584 } |
585 UnLoadInitFunction(); | 585 UnLoadInitFunction(); |
586 return; | 586 return; |
587 } | 587 } |
588 // TODO(bradnelson): Get rid of this. | 588 // TODO(bradnelson): Get rid of this. |
589 if (TypeOf(expr->value()) == kAstStmt) { | 589 if (TypeOf(expr->value()) == kAstStmt) { |
590 Property* prop = expr->value()->AsProperty(); | 590 Property* prop = expr->value()->AsProperty(); |
591 if (prop != nullptr) { | 591 if (prop != nullptr) { |
592 VariableProxy* vp = prop->obj()->AsVariableProxy(); | 592 VariableProxy* vp = prop->obj()->AsVariableProxy(); |
593 if (vp != nullptr && vp->var()->IsParameter() && | 593 if (vp != nullptr && vp->var()->IsParameter() && |
594 vp->var()->index() == 1) { | 594 vp->var()->index() == 1) { |
595 VariableProxy* target = expr->target()->AsVariableProxy(); | 595 VariableProxy* target = expr->target()->AsVariableProxy(); |
596 if (target->bounds().lower->Is(Type::Function())) { | 596 if (target->bounds().lower->Is(Type::Function())) { |
597 const AstRawString* name = | 597 const AstRawString* name = |
598 prop->key()->AsLiteral()->AsRawPropertyName(); | 598 prop->key()->AsLiteral()->AsRawPropertyName(); |
599 imported_function_table_.AddImport( | 599 imported_function_table_.AddImport( |
600 target->var(), name->raw_data(), name->length()); | 600 target->var(), name->raw_data(), name->length()); |
601 } | 601 } |
602 } | 602 } |
603 } | 603 } |
604 ArrayLiteral* funcs = expr->value()->AsArrayLiteral(); | 604 ArrayLiteral* funcs = expr->value()->AsArrayLiteral(); |
605 if (funcs != nullptr && | 605 if (funcs != nullptr && |
606 funcs->bounds().lower->AsArray()->Element()->IsFunction()) { | 606 funcs->bounds().lower->AsArray()->Element()->IsFunction()) { |
607 VariableProxy* target = expr->target()->AsVariableProxy(); | 607 VariableProxy* target = expr->target()->AsVariableProxy(); |
608 DCHECK(target != nullptr); | 608 DCHECK_NOT_NULL(target); |
609 AddFunctionTable(target, funcs); | 609 AddFunctionTable(target, funcs); |
610 } | 610 } |
611 return; | 611 return; |
612 } | 612 } |
613 in_init = true; | 613 in_init = true; |
614 LoadInitFunction(); | 614 LoadInitFunction(); |
615 } | 615 } |
616 BinaryOperation* value_op = expr->value()->AsBinaryOperation(); | 616 BinaryOperation* value_op = expr->value()->AsBinaryOperation(); |
617 if (value_op != nullptr && MatchBinaryOperation(value_op) == kAsIs) { | 617 if (value_op != nullptr && MatchBinaryOperation(value_op) == kAsIs) { |
618 VariableProxy* target_var = expr->target()->AsVariableProxy(); | 618 VariableProxy* target_var = expr->target()->AsVariableProxy(); |
(...skipping 12 matching lines...) Expand all Loading... |
631 UnLoadInitFunction(); | 631 UnLoadInitFunction(); |
632 } | 632 } |
633 } | 633 } |
634 | 634 |
635 void VisitYield(Yield* expr) { UNREACHABLE(); } | 635 void VisitYield(Yield* expr) { UNREACHABLE(); } |
636 | 636 |
637 void VisitThrow(Throw* expr) { UNREACHABLE(); } | 637 void VisitThrow(Throw* expr) { UNREACHABLE(); } |
638 | 638 |
639 void VisitForeignVariable(bool is_float, Property* expr) { | 639 void VisitForeignVariable(bool is_float, Property* expr) { |
640 DCHECK(expr->obj()->AsVariableProxy()); | 640 DCHECK(expr->obj()->AsVariableProxy()); |
641 DCHECK(expr->obj()->AsVariableProxy()->var()->location() == | 641 DCHECK(VariableLocation::PARAMETER == |
642 VariableLocation::PARAMETER); | 642 expr->obj()->AsVariableProxy()->var()->location()); |
643 DCHECK(expr->obj()->AsVariableProxy()->var()->index() == 1); | 643 DCHECK_EQ(1, expr->obj()->AsVariableProxy()->var()->index()); |
644 Literal* key_literal = expr->key()->AsLiteral(); | 644 Literal* key_literal = expr->key()->AsLiteral(); |
645 DCHECK(key_literal != nullptr); | 645 DCHECK_NOT_NULL(key_literal); |
646 if (!key_literal->value().is_null() && !foreign_.is_null() && | 646 if (!key_literal->value().is_null() && !foreign_.is_null() && |
647 foreign_->IsObject()) { | 647 foreign_->IsObject()) { |
648 Handle<Name> name = | 648 Handle<Name> name = |
649 i::Object::ToName(isolate_, key_literal->value()).ToHandleChecked(); | 649 i::Object::ToName(isolate_, key_literal->value()).ToHandleChecked(); |
650 MaybeHandle<Object> maybe_value = i::Object::GetProperty(foreign_, name); | 650 MaybeHandle<Object> maybe_value = i::Object::GetProperty(foreign_, name); |
651 if (!maybe_value.is_null()) { | 651 if (!maybe_value.is_null()) { |
652 Handle<Object> value = maybe_value.ToHandleChecked(); | 652 Handle<Object> value = maybe_value.ToHandleChecked(); |
653 if (is_float) { | 653 if (is_float) { |
654 MaybeHandle<Object> maybe_nvalue = i::Object::ToNumber(value); | 654 MaybeHandle<Object> maybe_nvalue = i::Object::ToNumber(value); |
655 if (!maybe_nvalue.is_null()) { | 655 if (!maybe_nvalue.is_null()) { |
(...skipping 24 matching lines...) Expand all Loading... |
680 byte code[] = {WASM_F64(std::numeric_limits<double>::quiet_NaN())}; | 680 byte code[] = {WASM_F64(std::numeric_limits<double>::quiet_NaN())}; |
681 current_function_builder_->EmitCode(code, sizeof(code)); | 681 current_function_builder_->EmitCode(code, sizeof(code)); |
682 } else { | 682 } else { |
683 byte code[] = {WASM_I32(0)}; | 683 byte code[] = {WASM_I32(0)}; |
684 current_function_builder_->EmitCode(code, sizeof(code)); | 684 current_function_builder_->EmitCode(code, sizeof(code)); |
685 } | 685 } |
686 } | 686 } |
687 | 687 |
688 void VisitProperty(Property* expr) { | 688 void VisitProperty(Property* expr) { |
689 Expression* obj = expr->obj(); | 689 Expression* obj = expr->obj(); |
690 DCHECK(obj->bounds().lower == obj->bounds().upper); | 690 DCHECK_EQ(obj->bounds().lower, obj->bounds().upper); |
691 Type* type = obj->bounds().lower; | 691 Type* type = obj->bounds().lower; |
692 MachineType mtype; | 692 MachineType mtype; |
693 int size; | 693 int size; |
694 if (type->Is(cache_.kUint8Array)) { | 694 if (type->Is(cache_.kUint8Array)) { |
695 mtype = MachineType::Uint8(); | 695 mtype = MachineType::Uint8(); |
696 size = 1; | 696 size = 1; |
697 } else if (type->Is(cache_.kInt8Array)) { | 697 } else if (type->Is(cache_.kInt8Array)) { |
698 mtype = MachineType::Int8(); | 698 mtype = MachineType::Int8(); |
699 size = 1; | 699 size = 1; |
700 } else if (type->Is(cache_.kUint16Array)) { | 700 } else if (type->Is(cache_.kUint16Array)) { |
(...skipping 28 matching lines...) Expand all Loading... |
729 // Allow more general expression in byte arrays than the spec | 729 // Allow more general expression in byte arrays than the spec |
730 // strictly permits. | 730 // strictly permits. |
731 // Early versions of Emscripten emit HEAP8[HEAP32[..]|0] in | 731 // Early versions of Emscripten emit HEAP8[HEAP32[..]|0] in |
732 // places that strictly should be HEAP8[HEAP32[..]>>0]. | 732 // places that strictly should be HEAP8[HEAP32[..]>>0]. |
733 RECURSE(Visit(expr->key())); | 733 RECURSE(Visit(expr->key())); |
734 return; | 734 return; |
735 } else { | 735 } else { |
736 Literal* value = expr->key()->AsLiteral(); | 736 Literal* value = expr->key()->AsLiteral(); |
737 if (value) { | 737 if (value) { |
738 DCHECK(value->raw_value()->IsNumber()); | 738 DCHECK(value->raw_value()->IsNumber()); |
739 DCHECK(kAstI32 == TypeOf(value)); | 739 DCHECK_EQ(kAstI32, TypeOf(value)); |
740 int val = static_cast<int>(value->raw_value()->AsNumber()); | 740 int val = static_cast<int>(value->raw_value()->AsNumber()); |
741 byte code[] = {WASM_I32(val * size)}; | 741 byte code[] = {WASM_I32(val * size)}; |
742 current_function_builder_->EmitCode(code, sizeof(code)); | 742 current_function_builder_->EmitCode(code, sizeof(code)); |
743 return; | 743 return; |
744 } | 744 } |
745 BinaryOperation* binop = expr->key()->AsBinaryOperation(); | 745 BinaryOperation* binop = expr->key()->AsBinaryOperation(); |
746 if (binop) { | 746 if (binop) { |
747 DCHECK(Token::SAR == binop->op()); | 747 DCHECK_EQ(Token::SAR, binop->op()); |
748 DCHECK(binop->right()->AsLiteral()->raw_value()->IsNumber()); | 748 DCHECK(binop->right()->AsLiteral()->raw_value()->IsNumber()); |
749 DCHECK(kAstI32 == TypeOf(binop->right()->AsLiteral())); | 749 DCHECK(kAstI32 == TypeOf(binop->right()->AsLiteral())); |
750 DCHECK(size == | 750 DCHECK_EQ(size, |
751 1 << static_cast<int>( | 751 1 << static_cast<int>( |
752 binop->right()->AsLiteral()->raw_value()->AsNumber())); | 752 binop->right()->AsLiteral()->raw_value()->AsNumber())); |
753 // Mask bottom bits to match asm.js behavior. | 753 // Mask bottom bits to match asm.js behavior. |
754 current_function_builder_->Emit(kExprI32And); | 754 current_function_builder_->Emit(kExprI32And); |
755 byte code[] = {WASM_I8(~(size - 1))}; | 755 byte code[] = {WASM_I8(~(size - 1))}; |
756 current_function_builder_->EmitCode(code, sizeof(code)); | 756 current_function_builder_->EmitCode(code, sizeof(code)); |
757 RECURSE(Visit(binop->left())); | 757 RECURSE(Visit(binop->left())); |
758 return; | 758 return; |
759 } | 759 } |
760 } | 760 } |
761 UNREACHABLE(); | 761 UNREACHABLE(); |
762 } | 762 } |
(...skipping 24 matching lines...) Expand all Loading... |
787 } | 787 } |
788 current_function_builder_->Emit(kExprCallFunction); | 788 current_function_builder_->Emit(kExprCallFunction); |
789 std::vector<uint8_t> index_arr = UnsignedLEB128From(index); | 789 std::vector<uint8_t> index_arr = UnsignedLEB128From(index); |
790 current_function_builder_->EmitCode( | 790 current_function_builder_->EmitCode( |
791 &index_arr[0], static_cast<uint32_t>(index_arr.size())); | 791 &index_arr[0], static_cast<uint32_t>(index_arr.size())); |
792 break; | 792 break; |
793 } | 793 } |
794 case Call::KEYED_PROPERTY_CALL: { | 794 case Call::KEYED_PROPERTY_CALL: { |
795 DCHECK(in_function_); | 795 DCHECK(in_function_); |
796 Property* p = expr->expression()->AsProperty(); | 796 Property* p = expr->expression()->AsProperty(); |
797 DCHECK(p != nullptr); | 797 DCHECK_NOT_NULL(p); |
798 VariableProxy* var = p->obj()->AsVariableProxy(); | 798 VariableProxy* var = p->obj()->AsVariableProxy(); |
799 DCHECK(var != nullptr); | 799 DCHECK_NOT_NULL(var); |
800 FunctionTableIndices* indices = LookupFunctionTable(var->var()); | 800 FunctionTableIndices* indices = LookupFunctionTable(var->var()); |
801 current_function_builder_->EmitWithU8(kExprCallIndirect, | 801 current_function_builder_->EmitWithU8(kExprCallIndirect, |
802 indices->signature_index); | 802 indices->signature_index); |
803 current_function_builder_->Emit(kExprI32Add); | 803 current_function_builder_->Emit(kExprI32Add); |
804 byte code[] = {WASM_I32(indices->start_index)}; | 804 byte code[] = {WASM_I32(indices->start_index)}; |
805 current_function_builder_->EmitCode(code, sizeof(code)); | 805 current_function_builder_->EmitCode(code, sizeof(code)); |
806 RECURSE(Visit(p->key())); | 806 RECURSE(Visit(p->key())); |
807 break; | 807 break; |
808 } | 808 } |
809 default: | 809 default: |
810 UNREACHABLE(); | 810 UNREACHABLE(); |
811 } | 811 } |
812 ZoneList<Expression*>* args = expr->arguments(); | 812 ZoneList<Expression*>* args = expr->arguments(); |
813 for (int i = 0; i < args->length(); ++i) { | 813 for (int i = 0; i < args->length(); ++i) { |
814 Expression* arg = args->at(i); | 814 Expression* arg = args->at(i); |
815 RECURSE(Visit(arg)); | 815 RECURSE(Visit(arg)); |
816 } | 816 } |
817 } | 817 } |
818 | 818 |
819 void VisitCallNew(CallNew* expr) { UNREACHABLE(); } | 819 void VisitCallNew(CallNew* expr) { UNREACHABLE(); } |
820 | 820 |
821 void VisitCallRuntime(CallRuntime* expr) { UNREACHABLE(); } | 821 void VisitCallRuntime(CallRuntime* expr) { UNREACHABLE(); } |
822 | 822 |
823 void VisitUnaryOperation(UnaryOperation* expr) { | 823 void VisitUnaryOperation(UnaryOperation* expr) { |
824 switch (expr->op()) { | 824 switch (expr->op()) { |
825 case Token::NOT: { | 825 case Token::NOT: { |
826 DCHECK(TypeOf(expr->expression()) == kAstI32); | 826 DCHECK_EQ(kAstI32, TypeOf(expr->expression())); |
827 current_function_builder_->Emit(kExprBoolNot); | 827 current_function_builder_->Emit(kExprBoolNot); |
828 break; | 828 break; |
829 } | 829 } |
830 default: | 830 default: |
831 UNREACHABLE(); | 831 UNREACHABLE(); |
832 } | 832 } |
833 RECURSE(Visit(expr->expression())); | 833 RECURSE(Visit(expr->expression())); |
834 } | 834 } |
835 | 835 |
836 void VisitCountOperation(CountOperation* expr) { UNREACHABLE(); } | 836 void VisitCountOperation(CountOperation* expr) { UNREACHABLE(); } |
837 | 837 |
838 bool MatchIntBinaryOperation(BinaryOperation* expr, Token::Value op, | 838 bool MatchIntBinaryOperation(BinaryOperation* expr, Token::Value op, |
839 int32_t val) { | 839 int32_t val) { |
840 DCHECK(expr->right() != nullptr); | 840 DCHECK_NOT_NULL(expr->right()); |
841 if (expr->op() == op && expr->right()->IsLiteral() && | 841 if (expr->op() == op && expr->right()->IsLiteral() && |
842 TypeOf(expr) == kAstI32) { | 842 TypeOf(expr) == kAstI32) { |
843 Literal* right = expr->right()->AsLiteral(); | 843 Literal* right = expr->right()->AsLiteral(); |
844 DCHECK(right->raw_value()->IsNumber()); | 844 DCHECK(right->raw_value()->IsNumber()); |
845 if (static_cast<int32_t>(right->raw_value()->AsNumber()) == val) { | 845 if (static_cast<int32_t>(right->raw_value()->AsNumber()) == val) { |
846 return true; | 846 return true; |
847 } | 847 } |
848 } | 848 } |
849 return false; | 849 return false; |
850 } | 850 } |
851 | 851 |
852 bool MatchDoubleBinaryOperation(BinaryOperation* expr, Token::Value op, | 852 bool MatchDoubleBinaryOperation(BinaryOperation* expr, Token::Value op, |
853 double val) { | 853 double val) { |
854 DCHECK(expr->right() != nullptr); | 854 DCHECK_NOT_NULL(expr->right()); |
855 if (expr->op() == op && expr->right()->IsLiteral() && | 855 if (expr->op() == op && expr->right()->IsLiteral() && |
856 TypeOf(expr) == kAstF64) { | 856 TypeOf(expr) == kAstF64) { |
857 Literal* right = expr->right()->AsLiteral(); | 857 Literal* right = expr->right()->AsLiteral(); |
858 DCHECK(right->raw_value()->IsNumber()); | 858 DCHECK(right->raw_value()->IsNumber()); |
859 if (right->raw_value()->AsNumber() == val) { | 859 if (right->raw_value()->AsNumber() == val) { |
860 return true; | 860 return true; |
861 } | 861 } |
862 } | 862 } |
863 return false; | 863 return false; |
864 } | 864 } |
(...skipping 14 matching lines...) Expand all Loading... |
879 if (MatchIntBinaryOperation(expr, Token::SHR, 0)) { | 879 if (MatchIntBinaryOperation(expr, Token::SHR, 0)) { |
880 // TODO(titzer): this probably needs to be kToUint | 880 // TODO(titzer): this probably needs to be kToUint |
881 return (TypeOf(expr->left()) == kAstI32) ? kAsIs : kToInt; | 881 return (TypeOf(expr->left()) == kAstI32) ? kAsIs : kToInt; |
882 } else { | 882 } else { |
883 return kNone; | 883 return kNone; |
884 } | 884 } |
885 } | 885 } |
886 | 886 |
887 ConvertOperation MatchXor(BinaryOperation* expr) { | 887 ConvertOperation MatchXor(BinaryOperation* expr) { |
888 if (MatchIntBinaryOperation(expr, Token::BIT_XOR, 0xffffffff)) { | 888 if (MatchIntBinaryOperation(expr, Token::BIT_XOR, 0xffffffff)) { |
889 DCHECK(TypeOf(expr->left()) == kAstI32); | 889 DCHECK_EQ(kAstI32, TypeOf(expr->left())); |
890 DCHECK(TypeOf(expr->right()) == kAstI32); | 890 DCHECK_EQ(kAstI32, TypeOf(expr->right())); |
891 BinaryOperation* op = expr->left()->AsBinaryOperation(); | 891 BinaryOperation* op = expr->left()->AsBinaryOperation(); |
892 if (op != nullptr) { | 892 if (op != nullptr) { |
893 if (MatchIntBinaryOperation(op, Token::BIT_XOR, 0xffffffff)) { | 893 if (MatchIntBinaryOperation(op, Token::BIT_XOR, 0xffffffff)) { |
894 DCHECK(TypeOf(op->right()) == kAstI32); | 894 DCHECK_EQ(kAstI32, TypeOf(op->right())); |
895 if (TypeOf(op->left()) != kAstI32) { | 895 if (TypeOf(op->left()) != kAstI32) { |
896 return kToInt; | 896 return kToInt; |
897 } else { | 897 } else { |
898 return kAsIs; | 898 return kAsIs; |
899 } | 899 } |
900 } | 900 } |
901 } | 901 } |
902 } | 902 } |
903 return kNone; | 903 return kNone; |
904 } | 904 } |
905 | 905 |
906 ConvertOperation MatchMul(BinaryOperation* expr) { | 906 ConvertOperation MatchMul(BinaryOperation* expr) { |
907 if (MatchDoubleBinaryOperation(expr, Token::MUL, 1.0)) { | 907 if (MatchDoubleBinaryOperation(expr, Token::MUL, 1.0)) { |
908 DCHECK(TypeOf(expr->right()) == kAstF64); | 908 DCHECK_EQ(kAstF64, TypeOf(expr->right())); |
909 if (TypeOf(expr->left()) != kAstF64) { | 909 if (TypeOf(expr->left()) != kAstF64) { |
910 return kToDouble; | 910 return kToDouble; |
911 } else { | 911 } else { |
912 return kAsIs; | 912 return kAsIs; |
913 } | 913 } |
914 } else { | 914 } else { |
915 return kNone; | 915 return kNone; |
916 } | 916 } |
917 } | 917 } |
918 | 918 |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1112 if (left_index == kFixnum && right_index == kFixnum) { | 1112 if (left_index == kFixnum && right_index == kFixnum) { |
1113 left_index = kInt32; | 1113 left_index = kInt32; |
1114 right_index = kInt32; | 1114 right_index = kInt32; |
1115 } | 1115 } |
1116 DCHECK((left_index == right_index) || | 1116 DCHECK((left_index == right_index) || |
1117 (ignore_sign && (left_index <= 1) && (right_index <= 1))); | 1117 (ignore_sign && (left_index <= 1) && (right_index <= 1))); |
1118 return left_index; | 1118 return left_index; |
1119 } | 1119 } |
1120 | 1120 |
1121 TypeIndex TypeIndexOf(Expression* expr) { | 1121 TypeIndex TypeIndexOf(Expression* expr) { |
1122 DCHECK(expr->bounds().lower == expr->bounds().upper); | 1122 DCHECK_EQ(expr->bounds().lower, expr->bounds().upper); |
1123 Type* type = expr->bounds().lower; | 1123 Type* type = expr->bounds().lower; |
1124 if (type->Is(cache_.kAsmFixnum)) { | 1124 if (type->Is(cache_.kAsmFixnum)) { |
1125 return kFixnum; | 1125 return kFixnum; |
1126 } else if (type->Is(cache_.kAsmSigned)) { | 1126 } else if (type->Is(cache_.kAsmSigned)) { |
1127 return kInt32; | 1127 return kInt32; |
1128 } else if (type->Is(cache_.kAsmUnsigned)) { | 1128 } else if (type->Is(cache_.kAsmUnsigned)) { |
1129 return kUint32; | 1129 return kUint32; |
1130 } else if (type->Is(cache_.kAsmInt)) { | 1130 } else if (type->Is(cache_.kAsmInt)) { |
1131 return kInt32; | 1131 return kInt32; |
1132 } else if (type->Is(cache_.kAsmFloat)) { | 1132 } else if (type->Is(cache_.kAsmFloat)) { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1172 void VisitRewritableAssignmentExpression( | 1172 void VisitRewritableAssignmentExpression( |
1173 RewritableAssignmentExpression* expr) { | 1173 RewritableAssignmentExpression* expr) { |
1174 UNREACHABLE(); | 1174 UNREACHABLE(); |
1175 } | 1175 } |
1176 | 1176 |
1177 struct IndexContainer : public ZoneObject { | 1177 struct IndexContainer : public ZoneObject { |
1178 uint16_t index; | 1178 uint16_t index; |
1179 }; | 1179 }; |
1180 | 1180 |
1181 uint16_t LookupOrInsertLocal(Variable* v, LocalType type) { | 1181 uint16_t LookupOrInsertLocal(Variable* v, LocalType type) { |
1182 DCHECK(current_function_builder_ != nullptr); | 1182 DCHECK_NOT_NULL(current_function_builder_); |
1183 ZoneHashMap::Entry* entry = | 1183 ZoneHashMap::Entry* entry = |
1184 local_variables_.Lookup(v, ComputePointerHash(v)); | 1184 local_variables_.Lookup(v, ComputePointerHash(v)); |
1185 if (entry == nullptr) { | 1185 if (entry == nullptr) { |
1186 uint16_t index; | 1186 uint16_t index; |
1187 if (v->IsParameter()) { | 1187 if (v->IsParameter()) { |
1188 index = current_function_builder_->AddParam(type); | 1188 index = current_function_builder_->AddParam(type); |
1189 } else { | 1189 } else { |
1190 index = current_function_builder_->AddLocal(type); | 1190 index = current_function_builder_->AddLocal(type); |
1191 } | 1191 } |
1192 IndexContainer* container = new (zone()) IndexContainer(); | 1192 IndexContainer* container = new (zone()) IndexContainer(); |
(...skipping 14 matching lines...) Expand all Loading... |
1207 IndexContainer* container = new (zone()) IndexContainer(); | 1207 IndexContainer* container = new (zone()) IndexContainer(); |
1208 container->index = index; | 1208 container->index = index; |
1209 entry = global_variables_.LookupOrInsert(v, ComputePointerHash(v), | 1209 entry = global_variables_.LookupOrInsert(v, ComputePointerHash(v), |
1210 ZoneAllocationPolicy(zone())); | 1210 ZoneAllocationPolicy(zone())); |
1211 entry->value = container; | 1211 entry->value = container; |
1212 } | 1212 } |
1213 return (reinterpret_cast<IndexContainer*>(entry->value))->index; | 1213 return (reinterpret_cast<IndexContainer*>(entry->value))->index; |
1214 } | 1214 } |
1215 | 1215 |
1216 uint16_t LookupOrInsertFunction(Variable* v) { | 1216 uint16_t LookupOrInsertFunction(Variable* v) { |
1217 DCHECK(builder_ != nullptr); | 1217 DCHECK_NOT_NULL(builder_); |
1218 ZoneHashMap::Entry* entry = functions_.Lookup(v, ComputePointerHash(v)); | 1218 ZoneHashMap::Entry* entry = functions_.Lookup(v, ComputePointerHash(v)); |
1219 if (entry == nullptr) { | 1219 if (entry == nullptr) { |
1220 uint16_t index = builder_->AddFunction(); | 1220 uint16_t index = builder_->AddFunction(); |
1221 IndexContainer* container = new (zone()) IndexContainer(); | 1221 IndexContainer* container = new (zone()) IndexContainer(); |
1222 container->index = index; | 1222 container->index = index; |
1223 entry = functions_.LookupOrInsert(v, ComputePointerHash(v), | 1223 entry = functions_.LookupOrInsert(v, ComputePointerHash(v), |
1224 ZoneAllocationPolicy(zone())); | 1224 ZoneAllocationPolicy(zone())); |
1225 entry->value = container; | 1225 entry->value = container; |
1226 } | 1226 } |
1227 return (reinterpret_cast<IndexContainer*>(entry->value))->index; | 1227 return (reinterpret_cast<IndexContainer*>(entry->value))->index; |
1228 } | 1228 } |
1229 | 1229 |
1230 LocalType TypeOf(Expression* expr) { | 1230 LocalType TypeOf(Expression* expr) { |
1231 DCHECK(expr->bounds().lower == expr->bounds().upper); | 1231 DCHECK_EQ(expr->bounds().lower, expr->bounds().upper); |
1232 return TypeFrom(expr->bounds().lower); | 1232 return TypeFrom(expr->bounds().lower); |
1233 } | 1233 } |
1234 | 1234 |
1235 LocalType TypeFrom(Type* type) { | 1235 LocalType TypeFrom(Type* type) { |
1236 if (type->Is(cache_.kAsmInt)) { | 1236 if (type->Is(cache_.kAsmInt)) { |
1237 return kAstI32; | 1237 return kAstI32; |
1238 } else if (type->Is(cache_.kAsmFloat)) { | 1238 } else if (type->Is(cache_.kAsmFloat)) { |
1239 return kAstF32; | 1239 return kAstF32; |
1240 } else if (type->Is(cache_.kAsmDouble)) { | 1240 } else if (type->Is(cache_.kAsmDouble)) { |
1241 return kAstF64; | 1241 return kAstF64; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1280 // that zone in constructor may be thrown away once wasm module is written. | 1280 // that zone in constructor may be thrown away once wasm module is written. |
1281 WasmModuleIndex* AsmWasmBuilder::Run() { | 1281 WasmModuleIndex* AsmWasmBuilder::Run() { |
1282 AsmWasmBuilderImpl impl(isolate_, zone_, literal_, foreign_); | 1282 AsmWasmBuilderImpl impl(isolate_, zone_, literal_, foreign_); |
1283 impl.Compile(); | 1283 impl.Compile(); |
1284 WasmModuleWriter* writer = impl.builder_->Build(zone_); | 1284 WasmModuleWriter* writer = impl.builder_->Build(zone_); |
1285 return writer->WriteTo(zone_); | 1285 return writer->WriteTo(zone_); |
1286 } | 1286 } |
1287 } // namespace wasm | 1287 } // namespace wasm |
1288 } // namespace internal | 1288 } // namespace internal |
1289 } // namespace v8 | 1289 } // namespace v8 |
OLD | NEW |