OLD | NEW |
---|---|
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #ifndef RUNTIME_VM_KERNEL_TO_IL_H_ | 5 #ifndef RUNTIME_VM_KERNEL_TO_IL_H_ |
6 #define RUNTIME_VM_KERNEL_TO_IL_H_ | 6 #define RUNTIME_VM_KERNEL_TO_IL_H_ |
7 | 7 |
8 #if !defined(DART_PRECOMPILED_RUNTIME) | 8 #if !defined(DART_PRECOMPILED_RUNTIME) |
9 | 9 |
10 #include "vm/growable_array.h" | 10 #include "vm/growable_array.h" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
74 } else { | 74 } else { |
75 return pair->value; | 75 return pair->value; |
76 } | 76 } |
77 } | 77 } |
78 | 78 |
79 inline Pair* LookupPair(const Key& key) { | 79 inline Pair* LookupPair(const Key& key) { |
80 return DirectChainedHashMap<RawPointerKeyValueTrait<K, V> >::Lookup(key); | 80 return DirectChainedHashMap<RawPointerKeyValueTrait<K, V> >::Lookup(key); |
81 } | 81 } |
82 }; | 82 }; |
83 | 83 |
84 | |
85 template <typename V> | |
86 class IntKeyRawPointerValueTrait { | |
87 public: | |
88 typedef int64_t Key; | |
89 typedef V Value; | |
90 | |
91 struct Pair { | |
92 Key key; | |
93 Value value; | |
94 Pair() : key(NULL), value() {} | |
95 Pair(const Key key, const Value& value) : key(key), value(value) {} | |
96 Pair(const Pair& other) : key(other.key), value(other.value) {} | |
97 }; | |
98 | |
99 static Key KeyOf(Pair kv) { return kv.key; } | |
100 static Value ValueOf(Pair kv) { return kv.value; } | |
101 static intptr_t Hashcode(Key key) { return reinterpret_cast<intptr_t>(key); } | |
102 static bool IsKeyEqual(Pair kv, Key key) { return kv.key == key; } | |
103 }; | |
104 | |
105 template <typename V> | |
106 class IntMap : public DirectChainedHashMap<IntKeyRawPointerValueTrait<V> > { | |
107 public: | |
108 typedef typename IntKeyRawPointerValueTrait<V>::Key Key; | |
109 typedef typename IntKeyRawPointerValueTrait<V>::Value Value; | |
110 typedef typename IntKeyRawPointerValueTrait<V>::Pair Pair; | |
111 | |
112 inline void Insert(const Key& key, const Value& value) { | |
113 Pair pair(key, value); | |
114 DirectChainedHashMap<IntKeyRawPointerValueTrait<V> >::Insert(pair); | |
115 } | |
116 | |
117 inline V Lookup(const Key& key) { | |
118 Pair* pair = | |
119 DirectChainedHashMap<IntKeyRawPointerValueTrait<V> >::Lookup(key); | |
120 if (pair == NULL) { | |
121 return V(); | |
122 } else { | |
123 return pair->value; | |
124 } | |
125 } | |
126 | |
127 inline Pair* LookupPair(const Key& key) { | |
128 return DirectChainedHashMap<IntKeyRawPointerValueTrait<V> >::Lookup(key); | |
129 } | |
130 }; | |
131 | |
84 template <typename K, typename V> | 132 template <typename K, typename V> |
85 class MallocMap | 133 class MallocMap |
86 : public MallocDirectChainedHashMap<RawPointerKeyValueTrait<K, V> > { | 134 : public MallocDirectChainedHashMap<RawPointerKeyValueTrait<K, V> > { |
87 public: | 135 public: |
88 typedef typename RawPointerKeyValueTrait<K, V>::Key Key; | 136 typedef typename RawPointerKeyValueTrait<K, V>::Key Key; |
89 typedef typename RawPointerKeyValueTrait<K, V>::Value Value; | 137 typedef typename RawPointerKeyValueTrait<K, V>::Value Value; |
90 typedef typename RawPointerKeyValueTrait<K, V>::Pair Pair; | 138 typedef typename RawPointerKeyValueTrait<K, V>::Pair Pair; |
91 | 139 |
92 inline void Insert(const Key& key, const Value& value) { | 140 inline void Insert(const Key& key, const Value& value) { |
93 Pair pair(key, value); | 141 Pair pair(key, value); |
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
495 Zone* zone_; | 543 Zone* zone_; |
496 TranslationHelper& translation_helper_; | 544 TranslationHelper& translation_helper_; |
497 DartTypeTranslator& type_translator_; | 545 DartTypeTranslator& type_translator_; |
498 | 546 |
499 Script& script_; | 547 Script& script_; |
500 Instance& result_; | 548 Instance& result_; |
501 }; | 549 }; |
502 | 550 |
503 | 551 |
504 struct FunctionScope { | 552 struct FunctionScope { |
505 FunctionNode* function; | 553 int64_t kernelFileOffset; |
Kevin Millikin (Google)
2017/03/28 06:42:23
This should be named kernel_file_offset to fit the
jensj
2017/03/28 08:56:28
Done.
| |
506 LocalScope* scope; | 554 LocalScope* scope; |
507 }; | 555 }; |
508 | 556 |
509 | 557 |
510 class ScopeBuildingResult : public ZoneAllocated { | 558 class ScopeBuildingResult : public ZoneAllocated { |
511 public: | 559 public: |
512 ScopeBuildingResult() | 560 ScopeBuildingResult() |
513 : this_variable(NULL), | 561 : this_variable(NULL), |
514 type_arguments_variable(NULL), | 562 type_arguments_variable(NULL), |
515 switch_variable(NULL), | 563 switch_variable(NULL), |
516 finally_return_variable(NULL), | 564 finally_return_variable(NULL), |
517 setter_value(NULL), | 565 setter_value(NULL), |
518 yield_jump_variable(NULL), | 566 yield_jump_variable(NULL), |
519 yield_context_variable(NULL) {} | 567 yield_context_variable(NULL) {} |
520 | 568 |
521 Map<VariableDeclaration, LocalVariable*> locals; | 569 IntMap<LocalVariable*> locals; |
522 Map<TreeNode, LocalScope*> scopes; | 570 IntMap<LocalScope*> scopes; |
523 GrowableArray<FunctionScope> function_scopes; | 571 GrowableArray<FunctionScope> function_scopes; |
524 | 572 |
525 // Only non-NULL for instance functions. | 573 // Only non-NULL for instance functions. |
526 LocalVariable* this_variable; | 574 LocalVariable* this_variable; |
527 | 575 |
528 // Only non-NULL for factory constructor functions. | 576 // Only non-NULL for factory constructor functions. |
529 LocalVariable* type_arguments_variable; | 577 LocalVariable* type_arguments_variable; |
530 | 578 |
531 // Non-NULL when the function contains a switch statement. | 579 // Non-NULL when the function contains a switch statement. |
532 LocalVariable* switch_variable; | 580 LocalVariable* switch_variable; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
599 virtual void VisitTryCatch(TryCatch* node); | 647 virtual void VisitTryCatch(TryCatch* node); |
600 virtual void VisitTryFinally(TryFinally* node); | 648 virtual void VisitTryFinally(TryFinally* node); |
601 virtual void VisitYieldStatement(YieldStatement* node); | 649 virtual void VisitYieldStatement(YieldStatement* node); |
602 virtual void VisitAssertStatement(AssertStatement* node); | 650 virtual void VisitAssertStatement(AssertStatement* node); |
603 | 651 |
604 virtual void VisitFunctionNode(FunctionNode* node); | 652 virtual void VisitFunctionNode(FunctionNode* node); |
605 | 653 |
606 virtual void VisitConstructor(Constructor* node); | 654 virtual void VisitConstructor(Constructor* node); |
607 | 655 |
608 private: | 656 private: |
609 void EnterScope(TreeNode* node, TokenPosition start_position); | 657 template <typename NewScopeType> |
658 void EnterScope(NewScopeType* node, TokenPosition start_position); | |
610 void ExitScope(TokenPosition end_position); | 659 void ExitScope(TokenPosition end_position); |
611 | 660 |
612 const Type& TranslateVariableType(VariableDeclaration* variable); | 661 const Type& TranslateVariableType(VariableDeclaration* variable); |
613 LocalVariable* MakeVariable(TokenPosition declaration_pos, | 662 LocalVariable* MakeVariable(TokenPosition declaration_pos, |
614 TokenPosition token_pos, | 663 TokenPosition token_pos, |
615 const dart::String& name, | 664 const dart::String& name, |
616 const AbstractType& type); | 665 const AbstractType& type); |
617 | 666 |
618 void AddParameters(FunctionNode* function, intptr_t pos = 0); | 667 void AddParameters(FunctionNode* function, intptr_t pos = 0); |
619 void AddParameter(VariableDeclaration* declaration, intptr_t pos); | 668 void AddParameter(VariableDeclaration* declaration, intptr_t pos); |
620 void AddVariable(VariableDeclaration* declaration); | 669 void AddVariable(VariableDeclaration* declaration); |
621 void AddExceptionVariable(GrowableArray<LocalVariable*>* variables, | 670 void AddExceptionVariable(GrowableArray<LocalVariable*>* variables, |
622 const char* prefix, | 671 const char* prefix, |
623 intptr_t nesting_depth); | 672 intptr_t nesting_depth); |
624 void AddTryVariables(); | 673 void AddTryVariables(); |
625 void AddCatchVariables(); | 674 void AddCatchVariables(); |
626 void AddIteratorVariable(); | 675 void AddIteratorVariable(); |
627 void AddSwitchVariable(); | 676 void AddSwitchVariable(); |
628 | 677 |
629 // Record an assignment or reference to a variable. If the occurrence is | 678 // Record an assignment or reference to a variable. If the occurrence is |
630 // in a nested function, ensure that the variable is handled properly as a | 679 // in a nested function, ensure that the variable is handled properly as a |
631 // captured variable. | 680 // captured variable. |
632 void LookupVariable(VariableDeclaration* declaration); | 681 void LookupVariable(VariableDeclaration* declaration); |
633 | 682 |
634 const dart::String& GenerateName(const char* prefix, intptr_t suffix); | 683 const dart::String& GenerateName(const char* prefix, intptr_t suffix); |
635 | 684 |
636 void HandleLocalFunction(TreeNode* parent, FunctionNode* function); | 685 template <typename FunctionType> |
686 void HandleLocalFunction(FunctionType* parent, FunctionNode* function); | |
637 void HandleSpecialLoad(LocalVariable** variable, const dart::String& symbol); | 687 void HandleSpecialLoad(LocalVariable** variable, const dart::String& symbol); |
638 void LookupCapturedVariableByName(LocalVariable** variable, | 688 void LookupCapturedVariableByName(LocalVariable** variable, |
639 const dart::String& name); | 689 const dart::String& name); |
640 | 690 |
641 struct DepthState { | 691 struct DepthState { |
642 explicit DepthState(intptr_t function) | 692 explicit DepthState(intptr_t function) |
643 : loop_(0), | 693 : loop_(0), |
644 function_(function), | 694 function_(function), |
645 try_(0), | 695 try_(0), |
646 catch_(0), | 696 catch_(0), |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
774 | 824 |
775 Fragment TranslateStatement(Statement* statement); | 825 Fragment TranslateStatement(Statement* statement); |
776 Fragment TranslateCondition(Expression* expression, bool* negate); | 826 Fragment TranslateCondition(Expression* expression, bool* negate); |
777 Fragment TranslateExpression(Expression* expression); | 827 Fragment TranslateExpression(Expression* expression); |
778 | 828 |
779 Fragment TranslateFinallyFinalizers(TryFinallyBlock* outer_finally, | 829 Fragment TranslateFinallyFinalizers(TryFinallyBlock* outer_finally, |
780 intptr_t target_context_depth); | 830 intptr_t target_context_depth); |
781 | 831 |
782 Fragment TranslateFunctionNode(FunctionNode* node, TreeNode* parent); | 832 Fragment TranslateFunctionNode(FunctionNode* node, TreeNode* parent); |
783 | 833 |
784 Fragment EnterScope(TreeNode* node, bool* new_context = NULL); | 834 Fragment EnterScope(int64_t kernel_offset, bool* new_context = NULL); |
785 Fragment ExitScope(TreeNode* node); | 835 Fragment ExitScope(int64_t kernel_offset); |
786 | 836 |
787 Fragment LoadContextAt(int depth); | 837 Fragment LoadContextAt(int depth); |
788 Fragment AdjustContextTo(int depth); | 838 Fragment AdjustContextTo(int depth); |
789 | 839 |
790 Fragment PushContext(int size); | 840 Fragment PushContext(int size); |
791 Fragment PopContext(); | 841 Fragment PopContext(); |
792 | 842 |
793 Fragment LoadInstantiatorTypeArguments(); | 843 Fragment LoadInstantiatorTypeArguments(); |
794 Fragment InstantiateType(const AbstractType& type); | 844 Fragment InstantiateType(const AbstractType& type); |
795 Fragment InstantiateTypeArguments(const TypeArguments& type_arguments); | 845 Fragment InstantiateTypeArguments(const TypeArguments& type_arguments); |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1029 namespace kernel { | 1079 namespace kernel { |
1030 | 1080 |
1031 RawObject* EvaluateMetadata(TreeNode* const kernel_node); | 1081 RawObject* EvaluateMetadata(TreeNode* const kernel_node); |
1032 RawObject* BuildParameterDescriptor(TreeNode* const kernel_node); | 1082 RawObject* BuildParameterDescriptor(TreeNode* const kernel_node); |
1033 | 1083 |
1034 } // namespace kernel | 1084 } // namespace kernel |
1035 } // namespace dart | 1085 } // namespace dart |
1036 | 1086 |
1037 #endif // !defined(DART_PRECOMPILED_RUNTIME) | 1087 #endif // !defined(DART_PRECOMPILED_RUNTIME) |
1038 #endif // RUNTIME_VM_KERNEL_TO_IL_H_ | 1088 #endif // RUNTIME_VM_KERNEL_TO_IL_H_ |
OLD | NEW |