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 // Required to get M_E etc. in MSVC. | |
8 #if defined(_WIN32) | |
9 #define _USE_MATH_DEFINES | |
10 #endif | |
11 #include <math.h> | |
12 | |
7 #include "src/wasm/asm-wasm-builder.h" | 13 #include "src/wasm/asm-wasm-builder.h" |
8 #include "src/wasm/wasm-macro-gen.h" | 14 #include "src/wasm/wasm-macro-gen.h" |
9 #include "src/wasm/wasm-opcodes.h" | 15 #include "src/wasm/wasm-opcodes.h" |
10 | 16 |
11 #include "src/ast/ast.h" | 17 #include "src/ast/ast.h" |
12 #include "src/ast/scopes.h" | 18 #include "src/ast/scopes.h" |
13 #include "src/codegen.h" | 19 #include "src/codegen.h" |
14 #include "src/type-cache.h" | 20 #include "src/type-cache.h" |
15 | 21 |
16 namespace v8 { | 22 namespace v8 { |
17 namespace internal { | 23 namespace internal { |
18 namespace wasm { | 24 namespace wasm { |
19 | 25 |
20 #define RECURSE(call) \ | 26 #define RECURSE(call) \ |
21 do { \ | 27 do { \ |
22 DCHECK(!HasStackOverflow()); \ | 28 DCHECK(!HasStackOverflow()); \ |
23 call; \ | 29 call; \ |
24 if (HasStackOverflow()) return; \ | 30 if (HasStackOverflow()) return; \ |
25 } while (false) | 31 } while (false) |
26 | 32 |
27 | 33 |
28 class AsmWasmBuilderImpl : public AstVisitor { | 34 class AsmWasmBuilderImpl : public AstVisitor { |
29 public: | 35 public: |
30 AsmWasmBuilderImpl(Isolate* isolate, Zone* zone, FunctionLiteral* literal, | 36 AsmWasmBuilderImpl(Isolate* isolate, Zone* zone, FunctionLiteral* literal, |
31 Handle<Object> foreign) | 37 Handle<Object> foreign, AsmTyper* typer) |
32 : local_variables_(HashMap::PointersMatch, | 38 : local_variables_(HashMap::PointersMatch, |
33 ZoneHashMap::kDefaultHashMapCapacity, | 39 ZoneHashMap::kDefaultHashMapCapacity, |
34 ZoneAllocationPolicy(zone)), | 40 ZoneAllocationPolicy(zone)), |
35 functions_(HashMap::PointersMatch, ZoneHashMap::kDefaultHashMapCapacity, | 41 functions_(HashMap::PointersMatch, ZoneHashMap::kDefaultHashMapCapacity, |
36 ZoneAllocationPolicy(zone)), | 42 ZoneAllocationPolicy(zone)), |
37 global_variables_(HashMap::PointersMatch, | 43 global_variables_(HashMap::PointersMatch, |
38 ZoneHashMap::kDefaultHashMapCapacity, | 44 ZoneHashMap::kDefaultHashMapCapacity, |
39 ZoneAllocationPolicy(zone)), | 45 ZoneAllocationPolicy(zone)), |
40 in_function_(false), | 46 in_function_(false), |
41 is_set_op_(false), | 47 is_set_op_(false), |
42 marking_exported(false), | 48 marking_exported(false), |
43 builder_(new (zone) WasmModuleBuilder(zone)), | 49 builder_(new (zone) WasmModuleBuilder(zone)), |
44 current_function_builder_(nullptr), | 50 current_function_builder_(nullptr), |
45 literal_(literal), | 51 literal_(literal), |
46 isolate_(isolate), | 52 isolate_(isolate), |
47 zone_(zone), | 53 zone_(zone), |
48 foreign_(foreign), | 54 foreign_(foreign), |
55 typer_(typer), | |
49 cache_(TypeCache::Get()), | 56 cache_(TypeCache::Get()), |
50 breakable_blocks_(zone), | 57 breakable_blocks_(zone), |
51 block_size_(0), | 58 block_size_(0), |
52 init_function_index_(0), | 59 init_function_index_(0), |
53 next_table_index_(0), | 60 next_table_index_(0), |
54 function_tables_(HashMap::PointersMatch, | 61 function_tables_(HashMap::PointersMatch, |
55 ZoneHashMap::kDefaultHashMapCapacity, | 62 ZoneHashMap::kDefaultHashMapCapacity, |
56 ZoneAllocationPolicy(zone)), | 63 ZoneAllocationPolicy(zone)), |
57 imported_function_table_(this) { | 64 imported_function_table_(this) { |
58 InitializeAstVisitor(isolate); | 65 InitializeAstVisitor(isolate); |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
364 } | 371 } |
365 | 372 |
366 void VisitConditional(Conditional* expr) { | 373 void VisitConditional(Conditional* expr) { |
367 DCHECK(in_function_); | 374 DCHECK(in_function_); |
368 current_function_builder_->Emit(kExprIfElse); | 375 current_function_builder_->Emit(kExprIfElse); |
369 RECURSE(Visit(expr->condition())); | 376 RECURSE(Visit(expr->condition())); |
370 RECURSE(Visit(expr->then_expression())); | 377 RECURSE(Visit(expr->then_expression())); |
371 RECURSE(Visit(expr->else_expression())); | 378 RECURSE(Visit(expr->else_expression())); |
372 } | 379 } |
373 | 380 |
381 bool VisitStdlibConstant(Variable* var) { | |
382 AsmTyper::StandardMember standard_object = | |
383 typer_->VariableAsStandardMember(var); | |
384 double value; | |
385 switch (standard_object) { | |
386 case AsmTyper::kInfinity: { | |
387 value = std::numeric_limits<double>::infinity(); | |
388 break; | |
389 } | |
390 case AsmTyper::kNaN: { | |
391 value = std::numeric_limits<double>::quiet_NaN(); | |
392 break; | |
393 } | |
394 case AsmTyper::kMathE: { | |
395 value = M_E; | |
396 break; | |
397 } | |
398 case AsmTyper::kMathLN10: { | |
399 value = M_LN10; | |
400 break; | |
401 } | |
402 case AsmTyper::kMathLN2: { | |
403 value = M_LN2; | |
404 break; | |
405 } | |
406 case AsmTyper::kMathLOG10E: { | |
407 value = M_LOG10E; | |
408 break; | |
409 } | |
410 case AsmTyper::kMathLOG2E: { | |
411 value = M_LOG2E; | |
412 break; | |
413 } | |
414 case AsmTyper::kMathPI: { | |
415 value = M_PI; | |
416 break; | |
417 } | |
418 case AsmTyper::kMathSQRT1_2: { | |
419 value = M_SQRT1_2; | |
420 break; | |
421 } | |
422 case AsmTyper::kMathSQRT2: { | |
423 value = M_SQRT2; | |
424 break; | |
425 } | |
426 default: { return false; } | |
427 } | |
428 byte code[] = {WASM_F64(value)}; | |
429 current_function_builder_->EmitCode(code, sizeof(code)); | |
430 return true; | |
431 } | |
432 | |
374 void VisitVariableProxy(VariableProxy* expr) { | 433 void VisitVariableProxy(VariableProxy* expr) { |
375 if (in_function_) { | 434 if (in_function_) { |
376 Variable* var = expr->var(); | 435 Variable* var = expr->var(); |
377 if (is_set_op_) { | 436 if (is_set_op_) { |
378 if (var->IsContextSlot()) { | 437 if (var->IsContextSlot()) { |
379 current_function_builder_->Emit(kExprStoreGlobal); | 438 current_function_builder_->Emit(kExprStoreGlobal); |
380 } else { | 439 } else { |
381 current_function_builder_->Emit(kExprSetLocal); | 440 current_function_builder_->Emit(kExprSetLocal); |
382 } | 441 } |
383 is_set_op_ = false; | 442 is_set_op_ = false; |
384 } else { | 443 } else { |
444 if (VisitStdlibConstant(var)) { | |
445 return; | |
446 } | |
385 if (var->IsContextSlot()) { | 447 if (var->IsContextSlot()) { |
386 current_function_builder_->Emit(kExprLoadGlobal); | 448 current_function_builder_->Emit(kExprLoadGlobal); |
387 } else { | 449 } else { |
388 current_function_builder_->Emit(kExprGetLocal); | 450 current_function_builder_->Emit(kExprGetLocal); |
389 } | 451 } |
390 } | 452 } |
391 LocalType var_type = TypeOf(expr); | 453 LocalType var_type = TypeOf(expr); |
392 DCHECK_NE(kAstStmt, var_type); | 454 DCHECK_NE(kAstStmt, var_type); |
393 if (var->IsContextSlot()) { | 455 if (var->IsContextSlot()) { |
394 AddLeb128(LookupOrInsertGlobal(var, var_type), false); | 456 AddLeb128(LookupOrInsertGlobal(var, var_type), false); |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
582 DCHECK(binop->right()->IsLiteral()); | 644 DCHECK(binop->right()->IsLiteral()); |
583 DCHECK_EQ(0.0, binop->right()->AsLiteral()->raw_value()->AsNumber()); | 645 DCHECK_EQ(0.0, binop->right()->AsLiteral()->raw_value()->AsNumber()); |
584 DCHECK(!binop->right()->AsLiteral()->raw_value()->ContainsDot()); | 646 DCHECK(!binop->right()->AsLiteral()->raw_value()->ContainsDot()); |
585 VisitForeignVariable(false, prop); | 647 VisitForeignVariable(false, prop); |
586 } else { | 648 } else { |
587 UNREACHABLE(); | 649 UNREACHABLE(); |
588 } | 650 } |
589 UnLoadInitFunction(); | 651 UnLoadInitFunction(); |
590 return; | 652 return; |
591 } | 653 } |
592 // TODO(bradnelson): Get rid of this. | 654 Property* prop = expr->value()->AsProperty(); |
593 if (TypeOf(expr->value()) == kAstStmt) { | 655 if (prop != nullptr) { |
594 Property* prop = expr->value()->AsProperty(); | 656 VariableProxy* vp = prop->obj()->AsVariableProxy(); |
595 if (prop != nullptr) { | 657 if (vp != nullptr && vp->var()->IsParameter() && |
596 VariableProxy* vp = prop->obj()->AsVariableProxy(); | 658 vp->var()->index() == 1) { |
597 if (vp != nullptr && vp->var()->IsParameter() && | 659 VariableProxy* target = expr->target()->AsVariableProxy(); |
598 vp->var()->index() == 1) { | 660 if (target->bounds().lower->Is(Type::Function())) { |
599 VariableProxy* target = expr->target()->AsVariableProxy(); | 661 const AstRawString* name = |
600 if (target->bounds().lower->Is(Type::Function())) { | 662 prop->key()->AsLiteral()->AsRawPropertyName(); |
601 const AstRawString* name = | 663 imported_function_table_.AddImport(target->var(), name->raw_data(), |
602 prop->key()->AsLiteral()->AsRawPropertyName(); | 664 name->length()); |
603 imported_function_table_.AddImport( | |
604 target->var(), name->raw_data(), name->length()); | |
605 } | |
606 } | 665 } |
607 } | 666 } |
608 ArrayLiteral* funcs = expr->value()->AsArrayLiteral(); | 667 // Property values in module scope don't emit code, so return. |
609 if (funcs != nullptr && | 668 return; |
610 funcs->bounds().lower->AsArray()->Element()->IsFunction()) { | 669 } |
611 VariableProxy* target = expr->target()->AsVariableProxy(); | 670 ArrayLiteral* funcs = expr->value()->AsArrayLiteral(); |
612 DCHECK_NOT_NULL(target); | 671 if (funcs != nullptr && |
613 AddFunctionTable(target, funcs); | 672 funcs->bounds().lower->AsArray()->Element()->IsFunction()) { |
614 } | 673 VariableProxy* target = expr->target()->AsVariableProxy(); |
674 DCHECK_NOT_NULL(target); | |
675 AddFunctionTable(target, funcs); | |
676 // Only add to the function table. No init needed. | |
677 return; | |
678 } | |
679 if (expr->value()->IsCallNew()) { | |
680 // No init code to emit for CallNew nodes. | |
615 return; | 681 return; |
616 } | 682 } |
617 in_init = true; | 683 in_init = true; |
618 LoadInitFunction(); | 684 LoadInitFunction(); |
619 } | 685 } |
620 BinaryOperation* value_op = expr->value()->AsBinaryOperation(); | 686 BinaryOperation* value_op = expr->value()->AsBinaryOperation(); |
621 if (value_op != nullptr && MatchBinaryOperation(value_op) == kAsIs) { | 687 if (value_op != nullptr && MatchBinaryOperation(value_op) == kAsIs) { |
622 VariableProxy* target_var = expr->target()->AsVariableProxy(); | 688 VariableProxy* target_var = expr->target()->AsVariableProxy(); |
623 VariableProxy* effective_value_var = GetLeft(value_op)->AsVariableProxy(); | 689 VariableProxy* effective_value_var = GetLeft(value_op)->AsVariableProxy(); |
624 if (target_var != nullptr && effective_value_var != nullptr && | 690 if (target_var != nullptr && effective_value_var != nullptr && |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
758 current_function_builder_->Emit(kExprI32And); | 824 current_function_builder_->Emit(kExprI32And); |
759 byte code[] = {WASM_I8(~(size - 1))}; | 825 byte code[] = {WASM_I8(~(size - 1))}; |
760 current_function_builder_->EmitCode(code, sizeof(code)); | 826 current_function_builder_->EmitCode(code, sizeof(code)); |
761 RECURSE(Visit(binop->left())); | 827 RECURSE(Visit(binop->left())); |
762 return; | 828 return; |
763 } | 829 } |
764 } | 830 } |
765 UNREACHABLE(); | 831 UNREACHABLE(); |
766 } | 832 } |
767 | 833 |
834 bool VisitStdlibFunction(Call* call, VariableProxy* expr) { | |
835 Variable* var = expr->var(); | |
836 AsmTyper::StandardMember standard_object = | |
837 typer_->VariableAsStandardMember(var); | |
838 ZoneList<Expression*>* args = call->arguments(); | |
839 LocalType call_type = TypeOf(call); | |
840 switch (standard_object) { | |
841 case AsmTyper::kNone: { | |
842 return false; | |
843 } | |
844 case AsmTyper::kMathAcos: { | |
845 UNREACHABLE(); | |
846 break; // TODO(bradnelson): Implement as external. | |
847 } | |
848 case AsmTyper::kMathAsin: { | |
849 UNREACHABLE(); | |
850 break; // TODO(bradnelson): Implement as external. | |
851 } | |
852 case AsmTyper::kMathAtan: { | |
853 UNREACHABLE(); | |
854 break; // TODO(bradnelson): Implement as external. | |
855 } | |
856 case AsmTyper::kMathCos: { | |
857 UNREACHABLE(); | |
858 break; // TODO(bradnelson): Implement as external. | |
859 } | |
860 case AsmTyper::kMathSin: { | |
861 UNREACHABLE(); | |
862 break; // TODO(bradnelson): Implement as external. | |
863 } | |
864 case AsmTyper::kMathTan: { | |
865 UNREACHABLE(); | |
866 break; // TODO(bradnelson): Implement as external. | |
867 } | |
868 case AsmTyper::kMathExp: { | |
869 UNREACHABLE(); | |
870 break; // TODO(bradnelson): Implement as external. | |
871 } | |
872 case AsmTyper::kMathLog: { | |
873 UNREACHABLE(); | |
874 break; // TODO(bradnelson): Implement as external. | |
875 } | |
876 case AsmTyper::kMathCeil: { | |
877 if (call_type == kAstF32) { | |
878 current_function_builder_->Emit(kExprF32Ceil); | |
879 } else if (call_type == kAstF64) { | |
880 current_function_builder_->Emit(kExprF64Ceil); | |
881 } else { | |
882 UNREACHABLE(); | |
883 } | |
884 break; | |
885 } | |
886 case AsmTyper::kMathFloor: { | |
887 if (call_type == kAstF32) { | |
888 current_function_builder_->Emit(kExprF32Floor); | |
889 } else if (call_type == kAstF64) { | |
890 current_function_builder_->Emit(kExprF64Floor); | |
891 } else { | |
892 UNREACHABLE(); | |
893 } | |
894 break; | |
895 } | |
896 case AsmTyper::kMathSqrt: { | |
897 if (call_type == kAstF32) { | |
898 current_function_builder_->Emit(kExprF32Sqrt); | |
899 } else if (call_type == kAstF64) { | |
900 current_function_builder_->Emit(kExprF64Sqrt); | |
901 } else { | |
902 UNREACHABLE(); | |
903 } | |
904 break; | |
905 } | |
906 case AsmTyper::kMathAbs: { | |
907 // TODO(bradnelson): Handle signed. | |
908 if (call_type == kAstF32) { | |
909 current_function_builder_->Emit(kExprF32Abs); | |
910 } else if (call_type == kAstF64) { | |
911 current_function_builder_->Emit(kExprF64Abs); | |
912 } else { | |
913 UNREACHABLE(); | |
914 } | |
915 break; | |
916 } | |
917 case AsmTyper::kMathMin: { | |
918 // TODO(bradnelson): Handle signed. | |
919 // TODO(bradnelson): Change wasm to match Math.min in asm.js mode. | |
titzer
2016/02/23 15:57:58
Are we collecting tests for these somewhere?
bradn
2016/02/23 16:17:09
Will do.
| |
920 if (call_type == kAstF32) { | |
921 current_function_builder_->Emit(kExprF32Min); | |
922 } else if (call_type == kAstF64) { | |
923 current_function_builder_->Emit(kExprF64Min); | |
924 } else { | |
925 UNREACHABLE(); | |
926 } | |
927 break; | |
928 } | |
929 case AsmTyper::kMathMax: { | |
930 // TODO(bradnelson): Handle signed. | |
931 // TODO(bradnelson): Change wasm to match Math.max in asm.js mode. | |
932 if (call_type == kAstF32) { | |
933 current_function_builder_->Emit(kExprF32Max); | |
934 } else if (call_type == kAstF64) { | |
935 current_function_builder_->Emit(kExprF64Max); | |
936 } else { | |
937 UNREACHABLE(); | |
938 } | |
939 break; | |
940 } | |
941 case AsmTyper::kMathAtan2: { | |
942 UNREACHABLE(); | |
943 break; // TODO(bradnelson): Implement as external. | |
944 } | |
945 case AsmTyper::kMathPow: { | |
946 UNREACHABLE(); | |
947 break; // TODO(bradnelson): Implement as external. | |
948 } | |
949 case AsmTyper::kMathImul: { | |
950 current_function_builder_->Emit(kExprI32Mul); | |
951 break; | |
952 } | |
953 case AsmTyper::kMathFround: { | |
954 DCHECK(args->length() == 1); | |
955 Literal* literal = args->at(0)->AsLiteral(); | |
956 if (literal != nullptr) { | |
957 if (literal->raw_value()->IsNumber()) { | |
958 float val = static_cast<float>(literal->raw_value()->AsNumber()); | |
959 byte code[] = {WASM_F32(val)}; | |
960 current_function_builder_->EmitCode(code, sizeof(code)); | |
961 return true; | |
962 } | |
963 } | |
964 break; | |
965 } | |
966 default: { | |
967 UNREACHABLE(); | |
968 break; | |
969 } | |
970 } | |
971 VisitCallArgs(call); | |
972 return true; | |
973 } | |
974 | |
975 void VisitCallArgs(Call* expr) { | |
976 ZoneList<Expression*>* args = expr->arguments(); | |
977 for (int i = 0; i < args->length(); ++i) { | |
978 Expression* arg = args->at(i); | |
979 RECURSE(Visit(arg)); | |
980 } | |
981 } | |
982 | |
768 void VisitCall(Call* expr) { | 983 void VisitCall(Call* expr) { |
769 Call::CallType call_type = expr->GetCallType(isolate_); | 984 Call::CallType call_type = expr->GetCallType(isolate_); |
770 switch (call_type) { | 985 switch (call_type) { |
771 case Call::OTHER_CALL: { | 986 case Call::OTHER_CALL: { |
772 DCHECK(in_function_); | 987 DCHECK(in_function_); |
988 VariableProxy* proxy = expr->expression()->AsVariableProxy(); | |
989 if (proxy != nullptr) { | |
990 if (VisitStdlibFunction(expr, proxy)) { | |
991 return; | |
992 } | |
993 } | |
773 uint16_t index; | 994 uint16_t index; |
774 VariableProxy* vp = expr->expression()->AsVariableProxy(); | 995 VariableProxy* vp = expr->expression()->AsVariableProxy(); |
775 if (vp != nullptr && | 996 if (vp != nullptr && |
776 Type::Any()->Is(vp->bounds().lower->AsFunction()->Result())) { | 997 Type::Any()->Is(vp->bounds().lower->AsFunction()->Result())) { |
777 LocalType return_type = TypeOf(expr); | 998 LocalType return_type = TypeOf(expr); |
778 ZoneList<Expression*>* args = expr->arguments(); | 999 ZoneList<Expression*>* args = expr->arguments(); |
779 FunctionSig::Builder sig(zone(), return_type == kAstStmt ? 0 : 1, | 1000 FunctionSig::Builder sig(zone(), return_type == kAstStmt ? 0 : 1, |
780 args->length()); | 1001 args->length()); |
781 if (return_type != kAstStmt) { | 1002 if (return_type != kAstStmt) { |
782 sig.AddReturn(return_type); | 1003 sig.AddReturn(return_type); |
(...skipping 23 matching lines...) Expand all Loading... | |
806 indices->signature_index); | 1027 indices->signature_index); |
807 current_function_builder_->Emit(kExprI32Add); | 1028 current_function_builder_->Emit(kExprI32Add); |
808 byte code[] = {WASM_I32(indices->start_index)}; | 1029 byte code[] = {WASM_I32(indices->start_index)}; |
809 current_function_builder_->EmitCode(code, sizeof(code)); | 1030 current_function_builder_->EmitCode(code, sizeof(code)); |
810 RECURSE(Visit(p->key())); | 1031 RECURSE(Visit(p->key())); |
811 break; | 1032 break; |
812 } | 1033 } |
813 default: | 1034 default: |
814 UNREACHABLE(); | 1035 UNREACHABLE(); |
815 } | 1036 } |
816 ZoneList<Expression*>* args = expr->arguments(); | 1037 VisitCallArgs(expr); |
817 for (int i = 0; i < args->length(); ++i) { | |
818 Expression* arg = args->at(i); | |
819 RECURSE(Visit(arg)); | |
820 } | |
821 } | 1038 } |
822 | 1039 |
823 void VisitCallNew(CallNew* expr) { UNREACHABLE(); } | 1040 void VisitCallNew(CallNew* expr) { UNREACHABLE(); } |
824 | 1041 |
825 void VisitCallRuntime(CallRuntime* expr) { UNREACHABLE(); } | 1042 void VisitCallRuntime(CallRuntime* expr) { UNREACHABLE(); } |
826 | 1043 |
827 void VisitUnaryOperation(UnaryOperation* expr) { | 1044 void VisitUnaryOperation(UnaryOperation* expr) { |
828 switch (expr->op()) { | 1045 switch (expr->op()) { |
829 case Token::NOT: { | 1046 case Token::NOT: { |
830 DCHECK_EQ(kAstI32, TypeOf(expr->expression())); | 1047 DCHECK_EQ(kAstI32, TypeOf(expr->expression())); |
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1255 ZoneHashMap global_variables_; | 1472 ZoneHashMap global_variables_; |
1256 bool in_function_; | 1473 bool in_function_; |
1257 bool is_set_op_; | 1474 bool is_set_op_; |
1258 bool marking_exported; | 1475 bool marking_exported; |
1259 WasmModuleBuilder* builder_; | 1476 WasmModuleBuilder* builder_; |
1260 WasmFunctionBuilder* current_function_builder_; | 1477 WasmFunctionBuilder* current_function_builder_; |
1261 FunctionLiteral* literal_; | 1478 FunctionLiteral* literal_; |
1262 Isolate* isolate_; | 1479 Isolate* isolate_; |
1263 Zone* zone_; | 1480 Zone* zone_; |
1264 Handle<Object> foreign_; | 1481 Handle<Object> foreign_; |
1482 AsmTyper* typer_; | |
1265 TypeCache const& cache_; | 1483 TypeCache const& cache_; |
1266 ZoneVector<std::pair<BreakableStatement*, bool>> breakable_blocks_; | 1484 ZoneVector<std::pair<BreakableStatement*, bool>> breakable_blocks_; |
1267 int block_size_; | 1485 int block_size_; |
1268 uint16_t init_function_index_; | 1486 uint16_t init_function_index_; |
1269 uint32_t next_table_index_; | 1487 uint32_t next_table_index_; |
1270 ZoneHashMap function_tables_; | 1488 ZoneHashMap function_tables_; |
1271 ImportedFunctionTable imported_function_table_; | 1489 ImportedFunctionTable imported_function_table_; |
1272 | 1490 |
1273 DEFINE_AST_VISITOR_SUBCLASS_MEMBERS(); | 1491 DEFINE_AST_VISITOR_SUBCLASS_MEMBERS(); |
1274 | 1492 |
1275 private: | 1493 private: |
1276 DISALLOW_COPY_AND_ASSIGN(AsmWasmBuilderImpl); | 1494 DISALLOW_COPY_AND_ASSIGN(AsmWasmBuilderImpl); |
1277 }; | 1495 }; |
1278 | 1496 |
1279 AsmWasmBuilder::AsmWasmBuilder(Isolate* isolate, Zone* zone, | 1497 AsmWasmBuilder::AsmWasmBuilder(Isolate* isolate, Zone* zone, |
1280 FunctionLiteral* literal, Handle<Object> foreign) | 1498 FunctionLiteral* literal, Handle<Object> foreign, |
1281 : isolate_(isolate), zone_(zone), literal_(literal), foreign_(foreign) {} | 1499 AsmTyper* typer) |
1500 : isolate_(isolate), | |
1501 zone_(zone), | |
1502 literal_(literal), | |
1503 foreign_(foreign), | |
1504 typer_(typer) {} | |
1282 | 1505 |
1283 // TODO(aseemgarg): probably should take zone (to write wasm to) as input so | 1506 // TODO(aseemgarg): probably should take zone (to write wasm to) as input so |
1284 // that zone in constructor may be thrown away once wasm module is written. | 1507 // that zone in constructor may be thrown away once wasm module is written. |
1285 WasmModuleIndex* AsmWasmBuilder::Run() { | 1508 WasmModuleIndex* AsmWasmBuilder::Run() { |
1286 AsmWasmBuilderImpl impl(isolate_, zone_, literal_, foreign_); | 1509 AsmWasmBuilderImpl impl(isolate_, zone_, literal_, foreign_, typer_); |
1287 impl.Compile(); | 1510 impl.Compile(); |
1288 WasmModuleWriter* writer = impl.builder_->Build(zone_); | 1511 WasmModuleWriter* writer = impl.builder_->Build(zone_); |
1289 return writer->WriteTo(zone_); | 1512 return writer->WriteTo(zone_); |
1290 } | 1513 } |
1291 } // namespace wasm | 1514 } // namespace wasm |
1292 } // namespace internal | 1515 } // namespace internal |
1293 } // namespace v8 | 1516 } // namespace v8 |
OLD | NEW |