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 #include <map> | 5 #include <map> |
zra
2017/04/07 17:36:31
It looks like this is not used.
regis
2017/04/11 04:23:08
Removed
| |
6 #include <set> | 6 #include <set> |
7 #include <string> | 7 #include <string> |
zra
2017/04/07 17:36:31
ditto
regis
2017/04/11 04:23:08
I can compile with <string> removed, but git cl up
| |
8 | 8 |
9 #include "vm/kernel_to_il.h" | 9 #include "vm/kernel_to_il.h" |
10 | 10 |
11 #include "vm/compiler.h" | 11 #include "vm/compiler.h" |
12 #include "vm/intermediate_language.h" | 12 #include "vm/intermediate_language.h" |
13 #include "vm/kernel_reader.h" | 13 #include "vm/kernel_reader.h" |
14 #include "vm/kernel_binary_flowgraph.h" | 14 #include "vm/kernel_binary_flowgraph.h" |
15 #include "vm/longjump.h" | 15 #include "vm/longjump.h" |
16 #include "vm/method_recognizer.h" | 16 #include "vm/method_recognizer.h" |
17 #include "vm/object_store.h" | 17 #include "vm/object_store.h" |
(...skipping 2129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2147 | 2147 |
2148 instructions += LoadLocal(scopes_->this_variable); | 2148 instructions += LoadLocal(scopes_->this_variable); |
2149 instructions += LoadField(type_arguments_field_offset); | 2149 instructions += LoadField(type_arguments_field_offset); |
2150 } else { | 2150 } else { |
2151 instructions += NullConstant(); | 2151 instructions += NullConstant(); |
2152 } | 2152 } |
2153 return instructions; | 2153 return instructions; |
2154 } | 2154 } |
2155 | 2155 |
2156 | 2156 |
2157 Fragment FlowGraphBuilder::LoadFunctionTypeArguments() { | |
2158 UNIMPLEMENTED(); // TODO(regis) | |
2159 return Fragment(NULL); | |
2160 } | |
2161 | |
2162 | |
2157 Fragment FlowGraphBuilder::InstantiateType(const AbstractType& type) { | 2163 Fragment FlowGraphBuilder::InstantiateType(const AbstractType& type) { |
2158 InstantiateTypeInstr* instr = new (Z) | 2164 Value* function_type_args = Pop(); |
2159 InstantiateTypeInstr(TokenPosition::kNoSource, type, Pop(), | 2165 Value* instantiator_type_args = Pop(); |
2160 NULL); // TODO(regis): Pop function type arguments. | 2166 InstantiateTypeInstr* instr = |
2167 new (Z) InstantiateTypeInstr(TokenPosition::kNoSource, type, | |
2168 instantiator_type_args, function_type_args); | |
2161 Push(instr); | 2169 Push(instr); |
2162 return Fragment(instr); | 2170 return Fragment(instr); |
2163 } | 2171 } |
2164 | 2172 |
2165 | 2173 |
2166 Fragment FlowGraphBuilder::InstantiateTypeArguments( | 2174 Fragment FlowGraphBuilder::InstantiateTypeArguments( |
2167 const TypeArguments& type_arguments) { | 2175 const TypeArguments& type_arguments) { |
2176 Value* function_type_args = Pop(); | |
2177 Value* instantiator_type_args = Pop(); | |
2168 InstantiateTypeArgumentsInstr* instr = new (Z) InstantiateTypeArgumentsInstr( | 2178 InstantiateTypeArgumentsInstr* instr = new (Z) InstantiateTypeArgumentsInstr( |
2169 TokenPosition::kNoSource, type_arguments, *active_class_.klass, Pop(), | 2179 TokenPosition::kNoSource, type_arguments, *active_class_.klass, |
2170 NULL); // TODO(regis): Pop function type arguments. | 2180 instantiator_type_args, function_type_args); |
2171 Push(instr); | 2181 Push(instr); |
2172 return Fragment(instr); | 2182 return Fragment(instr); |
2173 } | 2183 } |
2174 | 2184 |
2175 | 2185 |
2176 Fragment FlowGraphBuilder::TranslateInstantiatedTypeArguments( | 2186 Fragment FlowGraphBuilder::TranslateInstantiatedTypeArguments( |
2177 const TypeArguments& type_arguments) { | 2187 const TypeArguments& type_arguments) { |
2178 Fragment instructions; | 2188 Fragment instructions; |
2179 | 2189 |
2180 if (type_arguments.IsNull() || type_arguments.IsInstantiated()) { | 2190 if (type_arguments.IsNull() || type_arguments.IsInstantiated()) { |
(...skipping 12 matching lines...) Expand all Loading... | |
2193 // This is for example the case here: | 2203 // This is for example the case here: |
2194 // class Foo<T> { | 2204 // class Foo<T> { |
2195 // newList() => new List<T>(); | 2205 // newList() => new List<T>(); |
2196 // } | 2206 // } |
2197 // We just use the type argument vector from the [Foo] object and pass it | 2207 // We just use the type argument vector from the [Foo] object and pass it |
2198 // directly to the `new List<T>()` factory constructor. | 2208 // directly to the `new List<T>()` factory constructor. |
2199 instructions += LoadInstantiatorTypeArguments(); | 2209 instructions += LoadInstantiatorTypeArguments(); |
2200 } else { | 2210 } else { |
2201 // Otherwise we need to resolve [TypeParameterType]s in the type | 2211 // Otherwise we need to resolve [TypeParameterType]s in the type |
2202 // expression based on the current instantiator type argument vector. | 2212 // expression based on the current instantiator type argument vector. |
2203 instructions += LoadInstantiatorTypeArguments(); | 2213 if (!type_arguments.IsInstantiated(kCurrentClass)) { |
2214 instructions += LoadInstantiatorTypeArguments(); | |
2215 } else { | |
2216 instructions += NullConstant(); | |
2217 } | |
2218 if (!type_arguments.IsInstantiated(kCurrentFunction)) { | |
2219 instructions += LoadFunctionTypeArguments(); | |
2220 } else { | |
2221 instructions += NullConstant(); | |
2222 } | |
2204 instructions += InstantiateTypeArguments(type_arguments); | 2223 instructions += InstantiateTypeArguments(type_arguments); |
2205 } | 2224 } |
2206 } | 2225 } |
2207 return instructions; | 2226 return instructions; |
2208 } | 2227 } |
2209 | 2228 |
2210 | 2229 |
2211 Fragment FlowGraphBuilder::AllocateContext(int size) { | 2230 Fragment FlowGraphBuilder::AllocateContext(int size) { |
2212 AllocateContextInstr* allocate = | 2231 AllocateContextInstr* allocate = |
2213 new (Z) AllocateContextInstr(TokenPosition::kNoSource, size); | 2232 new (Z) AllocateContextInstr(TokenPosition::kNoSource, size); |
(...skipping 1593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3807 Push(instr); | 3826 Push(instr); |
3808 return Fragment(instr); | 3827 return Fragment(instr); |
3809 } | 3828 } |
3810 | 3829 |
3811 | 3830 |
3812 Fragment FlowGraphBuilder::AssertAssignable(const dart::AbstractType& dst_type, | 3831 Fragment FlowGraphBuilder::AssertAssignable(const dart::AbstractType& dst_type, |
3813 const dart::String& dst_name) { | 3832 const dart::String& dst_name) { |
3814 Fragment instructions; | 3833 Fragment instructions; |
3815 Value* value = Pop(); | 3834 Value* value = Pop(); |
3816 | 3835 |
3817 instructions += LoadInstantiatorTypeArguments(); | 3836 if (!dst_type.IsInstantiated(kCurrentClass)) { |
3818 Value* type_args = Pop(); | 3837 instructions += LoadInstantiatorTypeArguments(); |
3838 } else { | |
3839 instructions += NullConstant(); | |
3840 } | |
3841 Value* instantiator_type_args = Pop(); | |
3819 | 3842 |
3820 AssertAssignableInstr* instr = new (Z) | 3843 if (!dst_type.IsInstantiated(kCurrentFunction)) { |
3821 AssertAssignableInstr(TokenPosition::kNoSource, value, type_args, | 3844 instructions += LoadFunctionTypeArguments(); |
3822 NULL, // TODO(regis): Pop function type arguments. | 3845 } else { |
3823 dst_type, dst_name, H.thread()->GetNextDeoptId()); | 3846 instructions += NullConstant(); |
3847 } | |
3848 Value* function_type_args = Pop(); | |
3849 | |
3850 AssertAssignableInstr* instr = new (Z) AssertAssignableInstr( | |
3851 TokenPosition::kNoSource, value, instantiator_type_args, | |
3852 function_type_args, dst_type, dst_name, H.thread()->GetNextDeoptId()); | |
3824 Push(instr); | 3853 Push(instr); |
3825 | 3854 |
3826 instructions += Fragment(instr); | 3855 instructions += Fragment(instr); |
3827 | 3856 |
3828 return instructions; | 3857 return instructions; |
3829 } | 3858 } |
3830 | 3859 |
3831 | 3860 |
3832 FlowGraph* FlowGraphBuilder::BuildGraphOfMethodExtractor( | 3861 FlowGraph* FlowGraphBuilder::BuildGraphOfMethodExtractor( |
3833 const Function& method) { | 3862 const Function& method) { |
(...skipping 814 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4648 | 4677 |
4649 | 4678 |
4650 void FlowGraphBuilder::VisitTypeLiteral(TypeLiteral* node) { | 4679 void FlowGraphBuilder::VisitTypeLiteral(TypeLiteral* node) { |
4651 const AbstractType& type = T.TranslateType(node->type()); | 4680 const AbstractType& type = T.TranslateType(node->type()); |
4652 if (type.IsMalformed()) H.ReportError("Malformed type literal"); | 4681 if (type.IsMalformed()) H.ReportError("Malformed type literal"); |
4653 | 4682 |
4654 Fragment instructions; | 4683 Fragment instructions; |
4655 if (type.IsInstantiated()) { | 4684 if (type.IsInstantiated()) { |
4656 instructions += Constant(type); | 4685 instructions += Constant(type); |
4657 } else { | 4686 } else { |
4658 instructions += LoadInstantiatorTypeArguments(); | 4687 if (!type.IsInstantiated(kCurrentClass)) { |
4688 instructions += LoadInstantiatorTypeArguments(); | |
4689 } else { | |
4690 instructions += NullConstant(); | |
4691 } | |
4692 if (!type.IsInstantiated(kCurrentFunction)) { | |
4693 instructions += LoadFunctionTypeArguments(); | |
4694 } else { | |
4695 instructions += NullConstant(); | |
4696 } | |
4659 instructions += InstantiateType(type); | 4697 instructions += InstantiateType(type); |
4660 } | 4698 } |
4661 fragment_ = instructions; | 4699 fragment_ = instructions; |
4662 } | 4700 } |
4663 | 4701 |
4664 | 4702 |
4665 void FlowGraphBuilder::VisitVariableGet(VariableGet* node) { | 4703 void FlowGraphBuilder::VisitVariableGet(VariableGet* node) { |
4666 fragment_ = LoadLocal(LookupVariable(node->variable())); | 4704 fragment_ = LoadLocal(LookupVariable(node->variable())); |
4667 } | 4705 } |
4668 | 4706 |
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5074 instructions += Constant(type); | 5112 instructions += Constant(type); |
5075 instructions += PushArgument(); // Type. | 5113 instructions += PushArgument(); // Type. |
5076 instructions += InstanceCall( | 5114 instructions += InstanceCall( |
5077 node->position(), | 5115 node->position(), |
5078 dart::Library::PrivateCoreLibName(Symbols::_simpleInstanceOf()), | 5116 dart::Library::PrivateCoreLibName(Symbols::_simpleInstanceOf()), |
5079 Token::kIS, 2, 2); // 2 checked arguments. | 5117 Token::kIS, 2, 2); // 2 checked arguments. |
5080 fragment_ = instructions; | 5118 fragment_ = instructions; |
5081 return; | 5119 return; |
5082 } | 5120 } |
5083 | 5121 |
5084 if (!type.IsInstantiated()) { | 5122 if (!type.IsInstantiated(kCurrentClass)) { |
5085 instructions += LoadInstantiatorTypeArguments(); | 5123 instructions += LoadInstantiatorTypeArguments(); |
5086 } else { | 5124 } else { |
5087 instructions += NullConstant(); | 5125 instructions += NullConstant(); |
5088 } | 5126 } |
5089 instructions += PushArgument(); // Type arguments. | 5127 instructions += PushArgument(); // Instantiator type arguments. |
5128 | |
5129 if (!type.IsInstantiated(kCurrentFunction)) { | |
5130 instructions += LoadFunctionTypeArguments(); | |
5131 } else { | |
5132 instructions += NullConstant(); | |
5133 } | |
5134 instructions += PushArgument(); // Function type arguments. | |
5090 | 5135 |
5091 instructions += Constant(type); | 5136 instructions += Constant(type); |
5092 instructions += PushArgument(); // Type. | 5137 instructions += PushArgument(); // Type. |
5093 | 5138 |
5094 instructions += | 5139 instructions += |
5095 InstanceCall(node->position(), | 5140 InstanceCall(node->position(), |
5096 dart::Library::PrivateCoreLibName(Symbols::_instanceOf()), | 5141 dart::Library::PrivateCoreLibName(Symbols::_instanceOf()), |
5097 Token::kIS, 3); | 5142 Token::kIS, 4); |
5098 } | 5143 } |
5099 | 5144 |
5100 fragment_ = instructions; | 5145 fragment_ = instructions; |
5101 } | 5146 } |
5102 | 5147 |
5103 | 5148 |
5104 void FlowGraphBuilder::VisitAsExpression(AsExpression* node) { | 5149 void FlowGraphBuilder::VisitAsExpression(AsExpression* node) { |
5105 Fragment instructions = TranslateExpression(node->operand()); | 5150 Fragment instructions = TranslateExpression(node->operand()); |
5106 | 5151 |
5107 // The VM does not like an Object_as call with a dynamic type. We need to | 5152 // The VM does not like an Object_as call with a dynamic type. We need to |
5108 // special case this situation. | 5153 // special case this situation. |
5109 const Type& object_type = Type::Handle(Z, Type::ObjectType()); | 5154 const Type& object_type = Type::Handle(Z, Type::ObjectType()); |
5110 const AbstractType& type = T.TranslateType(node->type()); | 5155 const AbstractType& type = T.TranslateType(node->type()); |
5111 if (type.IsMalformed()) { | 5156 if (type.IsMalformed()) { |
5112 instructions += Drop(); | 5157 instructions += Drop(); |
5113 instructions += ThrowTypeError(); | 5158 instructions += ThrowTypeError(); |
5114 fragment_ = instructions; | 5159 fragment_ = instructions; |
5115 return; | 5160 return; |
5116 } | 5161 } |
5117 | 5162 |
5118 if (type.IsInstantiated() && | 5163 if (type.IsInstantiated() && |
5119 object_type.IsSubtypeOf(type, NULL, NULL, Heap::kOld)) { | 5164 object_type.IsSubtypeOf(type, NULL, NULL, Heap::kOld)) { |
5120 // We already evaluated the operand on the left and just leave it there as | 5165 // We already evaluated the operand on the left and just leave it there as |
5121 // the result of the `obj as dynamic` expression. | 5166 // the result of the `obj as dynamic` expression. |
5122 } else { | 5167 } else { |
5123 instructions += PushArgument(); | 5168 instructions += PushArgument(); |
5124 | 5169 |
5125 if (!type.IsInstantiated()) { | 5170 if (!type.IsInstantiated(kCurrentClass)) { |
5126 instructions += LoadInstantiatorTypeArguments(); | 5171 instructions += LoadInstantiatorTypeArguments(); |
5127 } else { | 5172 } else { |
5128 instructions += NullConstant(); | 5173 instructions += NullConstant(); |
5129 } | 5174 } |
5130 instructions += PushArgument(); // Type arguments. | 5175 instructions += PushArgument(); // Instantiator type arguments. |
5176 | |
5177 if (!type.IsInstantiated(kCurrentFunction)) { | |
5178 instructions += LoadFunctionTypeArguments(); | |
5179 } else { | |
5180 instructions += NullConstant(); | |
5181 } | |
5182 instructions += PushArgument(); // Function type arguments. | |
5131 | 5183 |
5132 instructions += Constant(type); | 5184 instructions += Constant(type); |
5133 instructions += PushArgument(); // Type. | 5185 instructions += PushArgument(); // Type. |
5134 | 5186 |
5135 instructions += InstanceCall( | 5187 instructions += InstanceCall( |
5136 node->position(), dart::Library::PrivateCoreLibName(Symbols::_as()), | 5188 node->position(), dart::Library::PrivateCoreLibName(Symbols::_as()), |
5137 Token::kAS, 3); | 5189 Token::kAS, 4); |
5138 } | 5190 } |
5139 | 5191 |
5140 fragment_ = instructions; | 5192 fragment_ = instructions; |
5141 } | 5193 } |
5142 | 5194 |
5143 | 5195 |
5144 void FlowGraphBuilder::VisitConditionalExpression(ConditionalExpression* node) { | 5196 void FlowGraphBuilder::VisitConditionalExpression(ConditionalExpression* node) { |
5145 bool negate; | 5197 bool negate; |
5146 Fragment instructions = TranslateCondition(node->condition(), &negate); | 5198 Fragment instructions = TranslateCondition(node->condition(), &negate); |
5147 | 5199 |
(...skipping 1020 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6168 } | 6220 } |
6169 | 6221 |
6170 if (type_guard != NULL) { | 6222 if (type_guard != NULL) { |
6171 if (type_guard->IsMalformed()) { | 6223 if (type_guard->IsMalformed()) { |
6172 catch_body += ThrowTypeError(); | 6224 catch_body += ThrowTypeError(); |
6173 catch_body += Drop(); | 6225 catch_body += Drop(); |
6174 } else { | 6226 } else { |
6175 catch_body += LoadLocal(CurrentException()); | 6227 catch_body += LoadLocal(CurrentException()); |
6176 catch_body += PushArgument(); // exception | 6228 catch_body += PushArgument(); // exception |
6177 catch_body += NullConstant(); | 6229 catch_body += NullConstant(); |
6178 catch_body += PushArgument(); // type arguments | 6230 catch_body += PushArgument(); // instantiator type arguments |
6231 catch_body += NullConstant(); | |
6232 catch_body += PushArgument(); // function type arguments | |
6179 catch_body += Constant(*type_guard); | 6233 catch_body += Constant(*type_guard); |
6180 catch_body += PushArgument(); // guard type | 6234 catch_body += PushArgument(); // guard type |
6181 catch_body += InstanceCall( | 6235 catch_body += InstanceCall( |
6182 TokenPosition::kNoSource, | 6236 TokenPosition::kNoSource, |
6183 dart::Library::PrivateCoreLibName(Symbols::_instanceOf()), | 6237 dart::Library::PrivateCoreLibName(Symbols::_instanceOf()), |
6184 Token::kIS, 3); | 6238 Token::kIS, 4); |
6185 | 6239 |
6186 TargetEntryInstr* catch_entry; | 6240 TargetEntryInstr* catch_entry; |
6187 TargetEntryInstr* next_catch_entry; | 6241 TargetEntryInstr* next_catch_entry; |
6188 catch_body += BranchIfTrue(&catch_entry, &next_catch_entry); | 6242 catch_body += BranchIfTrue(&catch_entry, &next_catch_entry); |
6189 | 6243 |
6190 Fragment(catch_entry) + catch_handler_body; | 6244 Fragment(catch_entry) + catch_handler_body; |
6191 catch_body = Fragment(next_catch_entry); | 6245 catch_body = Fragment(next_catch_entry); |
6192 } | 6246 } |
6193 } else { | 6247 } else { |
6194 catch_body += catch_handler_body; | 6248 catch_body += catch_handler_body; |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6503 thread->clear_sticky_error(); | 6557 thread->clear_sticky_error(); |
6504 return error.raw(); | 6558 return error.raw(); |
6505 } | 6559 } |
6506 } | 6560 } |
6507 | 6561 |
6508 | 6562 |
6509 } // namespace kernel | 6563 } // namespace kernel |
6510 } // namespace dart | 6564 } // namespace dart |
6511 | 6565 |
6512 #endif // !defined(DART_PRECOMPILED_RUNTIME) | 6566 #endif // !defined(DART_PRECOMPILED_RUNTIME) |
OLD | NEW |