| 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> |
| 6 #include <set> | 6 #include <set> |
| 7 #include <string> | 7 #include <string> |
| 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/longjump.h" | 15 #include "vm/longjump.h" |
| 15 #include "vm/method_recognizer.h" | 16 #include "vm/method_recognizer.h" |
| 16 #include "vm/object_store.h" | 17 #include "vm/object_store.h" |
| 17 #include "vm/report.h" | 18 #include "vm/report.h" |
| 18 #include "vm/resolver.h" | 19 #include "vm/resolver.h" |
| 19 #include "vm/stack_frame.h" | 20 #include "vm/stack_frame.h" |
| 20 | 21 |
| 21 #if !defined(DART_PRECOMPILED_RUNTIME) | 22 #if !defined(DART_PRECOMPILED_RUNTIME) |
| 22 namespace dart { | 23 namespace dart { |
| 23 | 24 |
| (...skipping 931 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 955 intptr_t try_index() { return try_index_; } | 956 intptr_t try_index() { return try_index_; } |
| 956 TryCatchBlock* outer() const { return outer_; } | 957 TryCatchBlock* outer() const { return outer_; } |
| 957 | 958 |
| 958 private: | 959 private: |
| 959 FlowGraphBuilder* builder_; | 960 FlowGraphBuilder* builder_; |
| 960 TryCatchBlock* outer_; | 961 TryCatchBlock* outer_; |
| 961 intptr_t try_index_; | 962 intptr_t try_index_; |
| 962 }; | 963 }; |
| 963 | 964 |
| 964 | 965 |
| 965 class CatchBlock { | |
| 966 public: | |
| 967 CatchBlock(FlowGraphBuilder* builder, | |
| 968 LocalVariable* exception_var, | |
| 969 LocalVariable* stack_trace_var, | |
| 970 intptr_t catch_try_index) | |
| 971 : builder_(builder), | |
| 972 outer_(builder->catch_block_), | |
| 973 exception_var_(exception_var), | |
| 974 stack_trace_var_(stack_trace_var), | |
| 975 catch_try_index_(catch_try_index) { | |
| 976 builder_->catch_block_ = this; | |
| 977 } | |
| 978 ~CatchBlock() { builder_->catch_block_ = outer_; } | |
| 979 | |
| 980 LocalVariable* exception_var() { return exception_var_; } | |
| 981 LocalVariable* stack_trace_var() { return stack_trace_var_; } | |
| 982 intptr_t catch_try_index() { return catch_try_index_; } | |
| 983 | |
| 984 private: | |
| 985 FlowGraphBuilder* builder_; | |
| 986 CatchBlock* outer_; | |
| 987 LocalVariable* exception_var_; | |
| 988 LocalVariable* stack_trace_var_; | |
| 989 intptr_t catch_try_index_; | |
| 990 }; | |
| 991 | |
| 992 | |
| 993 Fragment& Fragment::operator+=(const Fragment& other) { | 966 Fragment& Fragment::operator+=(const Fragment& other) { |
| 994 if (entry == NULL) { | 967 if (entry == NULL) { |
| 995 entry = other.entry; | 968 entry = other.entry; |
| 996 current = other.current; | 969 current = other.current; |
| 997 } else if (current != NULL && other.entry != NULL) { | 970 } else if (current != NULL && other.entry != NULL) { |
| 998 current->LinkTo(other.entry); | 971 current->LinkTo(other.entry); |
| 999 current = other.current; | 972 current = other.current; |
| 1000 } | 973 } |
| 1001 return *this; | 974 return *this; |
| 1002 } | 975 } |
| (...skipping 968 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1971 scopes_(NULL), | 1944 scopes_(NULL), |
| 1972 breakable_block_(NULL), | 1945 breakable_block_(NULL), |
| 1973 switch_block_(NULL), | 1946 switch_block_(NULL), |
| 1974 try_finally_block_(NULL), | 1947 try_finally_block_(NULL), |
| 1975 try_catch_block_(NULL), | 1948 try_catch_block_(NULL), |
| 1976 next_used_try_index_(0), | 1949 next_used_try_index_(0), |
| 1977 catch_block_(NULL), | 1950 catch_block_(NULL), |
| 1978 type_translator_(&translation_helper_, | 1951 type_translator_(&translation_helper_, |
| 1979 &active_class_, | 1952 &active_class_, |
| 1980 /* finalize= */ true), | 1953 /* finalize= */ true), |
| 1981 constant_evaluator_(this, | 1954 constant_evaluator_(this, zone_, &translation_helper_, &type_translator_), |
| 1982 zone_, | 1955 streaming_flow_graph_builder_(NULL) {} |
| 1983 &translation_helper_, | |
| 1984 &type_translator_) {} | |
| 1985 | 1956 |
| 1986 | 1957 |
| 1987 FlowGraphBuilder::~FlowGraphBuilder() {} | 1958 FlowGraphBuilder::~FlowGraphBuilder() { |
| 1959 if (streaming_flow_graph_builder_ != NULL) { |
| 1960 delete streaming_flow_graph_builder_; |
| 1961 } |
| 1962 } |
| 1988 | 1963 |
| 1989 | 1964 |
| 1990 Fragment FlowGraphBuilder::TranslateFinallyFinalizers( | 1965 Fragment FlowGraphBuilder::TranslateFinallyFinalizers( |
| 1991 TryFinallyBlock* outer_finally, | 1966 TryFinallyBlock* outer_finally, |
| 1992 intptr_t target_context_depth) { | 1967 intptr_t target_context_depth) { |
| 1993 TryFinallyBlock* const saved_block = try_finally_block_; | 1968 TryFinallyBlock* const saved_block = try_finally_block_; |
| 1994 TryCatchBlock* const saved_try_catch_block = try_catch_block_; | 1969 TryCatchBlock* const saved_try_catch_block = try_catch_block_; |
| 1995 const intptr_t saved_depth = context_depth_; | 1970 const intptr_t saved_depth = context_depth_; |
| 1996 const intptr_t saved_try_depth = try_depth_; | 1971 const intptr_t saved_try_depth = try_depth_; |
| 1997 | 1972 |
| (...skipping 1028 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3026 parsed_function_->Bailout("kernel::FlowGraphBuilder", reason); | 3001 parsed_function_->Bailout("kernel::FlowGraphBuilder", reason); |
| 3027 } | 3002 } |
| 3028 } | 3003 } |
| 3029 | 3004 |
| 3030 | 3005 |
| 3031 FlowGraph* FlowGraphBuilder::BuildGraph() { | 3006 FlowGraph* FlowGraphBuilder::BuildGraph() { |
| 3032 const dart::Function& function = parsed_function_->function(); | 3007 const dart::Function& function = parsed_function_->function(); |
| 3033 | 3008 |
| 3034 if (function.IsConstructorClosureFunction()) return NULL; | 3009 if (function.IsConstructorClosureFunction()) return NULL; |
| 3035 | 3010 |
| 3011 TreeNode* library_node = node_; |
| 3012 if (node_ != NULL) { |
| 3013 const dart::Function* parent = &function; |
| 3014 while (true) { |
| 3015 library_node = static_cast<kernel::TreeNode*>(parent->kernel_function()); |
| 3016 while (library_node != NULL && !library_node->IsLibrary()) { |
| 3017 if (library_node->IsMember()) { |
| 3018 library_node = Member::Cast(library_node)->parent(); |
| 3019 } else if (library_node->IsClass()) { |
| 3020 library_node = Class::Cast(library_node)->parent(); |
| 3021 break; |
| 3022 } else { |
| 3023 library_node = NULL; |
| 3024 break; |
| 3025 } |
| 3026 } |
| 3027 if (library_node != NULL) break; |
| 3028 parent = &dart::Function::Handle(parent->parent_function()); |
| 3029 } |
| 3030 } |
| 3031 if (streaming_flow_graph_builder_ != NULL) { |
| 3032 delete streaming_flow_graph_builder_; |
| 3033 streaming_flow_graph_builder_ = NULL; |
| 3034 } |
| 3035 if (library_node != NULL && library_node->IsLibrary()) { |
| 3036 Library* library = Library::Cast(library_node); |
| 3037 streaming_flow_graph_builder_ = new StreamingFlowGraphBuilder( |
| 3038 this, library->kernel_data(), library->kernel_data_size()); |
| 3039 } |
| 3040 |
| 3036 dart::Class& klass = | 3041 dart::Class& klass = |
| 3037 dart::Class::Handle(zone_, parsed_function_->function().Owner()); | 3042 dart::Class::Handle(zone_, parsed_function_->function().Owner()); |
| 3038 | 3043 |
| 3039 Function& outermost_function = Function::Handle(Z); | 3044 Function& outermost_function = Function::Handle(Z); |
| 3040 TreeNode* outermost_node = NULL; | 3045 TreeNode* outermost_node = NULL; |
| 3041 Class* kernel_class = NULL; | 3046 Class* kernel_class = NULL; |
| 3042 DiscoverEnclosingElements(Z, function, &outermost_function, &outermost_node, | 3047 DiscoverEnclosingElements(Z, function, &outermost_function, &outermost_node, |
| 3043 &kernel_class); | 3048 &kernel_class); |
| 3044 | 3049 |
| 3045 // Mark that we are using [klass]/[kernell_klass] as active class. Resolving | 3050 // Mark that we are using [klass]/[kernell_klass] as active class. Resolving |
| (...skipping 2301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5347 } | 5352 } |
| 5348 instructions += PushArgument(); | 5353 instructions += PushArgument(); |
| 5349 instructions += ThrowException(node->position()); | 5354 instructions += ThrowException(node->position()); |
| 5350 ASSERT(instructions.is_closed()); | 5355 ASSERT(instructions.is_closed()); |
| 5351 | 5356 |
| 5352 fragment_ = instructions; | 5357 fragment_ = instructions; |
| 5353 } | 5358 } |
| 5354 | 5359 |
| 5355 | 5360 |
| 5356 void FlowGraphBuilder::VisitRethrow(Rethrow* node) { | 5361 void FlowGraphBuilder::VisitRethrow(Rethrow* node) { |
| 5357 Fragment instructions; | 5362 fragment_ = streaming_flow_graph_builder_->BuildAt(node->kernel_offset()); |
| 5358 | |
| 5359 instructions = DebugStepCheck(node->position()) + instructions; | |
| 5360 instructions += LoadLocal(catch_block_->exception_var()); | |
| 5361 instructions += PushArgument(); | |
| 5362 instructions += LoadLocal(catch_block_->stack_trace_var()); | |
| 5363 instructions += PushArgument(); | |
| 5364 instructions += | |
| 5365 RethrowException(node->position(), catch_block_->catch_try_index()); | |
| 5366 | |
| 5367 fragment_ = instructions; | |
| 5368 } | 5363 } |
| 5369 | 5364 |
| 5370 | 5365 |
| 5371 Fragment FlowGraphBuilder::TranslateArguments(Arguments* node, | 5366 Fragment FlowGraphBuilder::TranslateArguments(Arguments* node, |
| 5372 Array* argument_names) { | 5367 Array* argument_names) { |
| 5373 Fragment instructions; | 5368 Fragment instructions; |
| 5374 | 5369 |
| 5375 List<Expression>& positional = node->positional(); | 5370 List<Expression>& positional = node->positional(); |
| 5376 for (intptr_t i = 0; i < positional.length(); ++i) { | 5371 for (intptr_t i = 0; i < positional.length(); ++i) { |
| 5377 instructions += TranslateExpression(positional[i]); | 5372 instructions += TranslateExpression(positional[i]); |
| (...skipping 1111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6489 thread->clear_sticky_error(); | 6484 thread->clear_sticky_error(); |
| 6490 return error.raw(); | 6485 return error.raw(); |
| 6491 } | 6486 } |
| 6492 } | 6487 } |
| 6493 | 6488 |
| 6494 | 6489 |
| 6495 } // namespace kernel | 6490 } // namespace kernel |
| 6496 } // namespace dart | 6491 } // namespace dart |
| 6497 | 6492 |
| 6498 #endif // !defined(DART_PRECOMPILED_RUNTIME) | 6493 #endif // !defined(DART_PRECOMPILED_RUNTIME) |
| OLD | NEW |