| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 "vm/flow_graph_builder.h" | 5 #include "vm/flow_graph_builder.h" |
| 6 | 6 |
| 7 #include "vm/ast_printer.h" | 7 #include "vm/ast_printer.h" |
| 8 #include "vm/bit_vector.h" | 8 #include "vm/bit_vector.h" |
| 9 #include "vm/code_descriptors.h" | 9 #include "vm/code_descriptors.h" |
| 10 #include "vm/dart_entry.h" | 10 #include "vm/dart_entry.h" |
| 11 #include "vm/flags.h" | 11 #include "vm/flags.h" |
| 12 #include "vm/il_printer.h" | 12 #include "vm/il_printer.h" |
| 13 #include "vm/intermediate_language.h" | 13 #include "vm/intermediate_language.h" |
| 14 #include "vm/longjump.h" | 14 #include "vm/longjump.h" |
| 15 #include "vm/object_store.h" | 15 #include "vm/object_store.h" |
| 16 #include "vm/os.h" | 16 #include "vm/os.h" |
| 17 #include "vm/parser.h" | 17 #include "vm/parser.h" |
| 18 #include "vm/resolver.h" | 18 #include "vm/resolver.h" |
| 19 #include "vm/stub_code.h" | 19 #include "vm/stub_code.h" |
| 20 | 20 |
| 21 namespace dart { | 21 namespace dart { |
| 22 | 22 |
| 23 DEFINE_FLAG(bool, eliminate_type_checks, true, |
| 24 "Eliminate type checks when allowed by static type analysis"); |
| 25 DEFINE_FLAG(bool, print_ast, false, "Print abstract syntax tree."); |
| 23 DEFINE_FLAG(bool, print_flow_graph, false, "Print the IR flow graph."); | 26 DEFINE_FLAG(bool, print_flow_graph, false, "Print the IR flow graph."); |
| 24 DECLARE_FLAG(bool, enable_type_checks); | 27 DECLARE_FLAG(bool, enable_type_checks); |
| 25 DEFINE_FLAG(bool, print_ast, false, "Print abstract syntax tree."); | |
| 26 | 28 |
| 27 | 29 |
| 28 FlowGraphBuilder::FlowGraphBuilder(const ParsedFunction& parsed_function) | 30 FlowGraphBuilder::FlowGraphBuilder(const ParsedFunction& parsed_function) |
| 29 : parsed_function_(parsed_function), | 31 : parsed_function_(parsed_function), |
| 30 preorder_block_entries_(), | 32 preorder_block_entries_(), |
| 31 postorder_block_entries_(), | 33 postorder_block_entries_(), |
| 32 context_level_(0), | 34 context_level_(0), |
| 33 last_used_try_index_(CatchClauseNode::kInvalidTryIndex), | 35 last_used_try_index_(CatchClauseNode::kInvalidTryIndex), |
| 34 try_index_(CatchClauseNode::kInvalidTryIndex), | 36 try_index_(CatchClauseNode::kInvalidTryIndex), |
| 35 graph_entry_(NULL) { } | 37 graph_entry_(NULL) { } |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 void EffectGraphVisitor::VisitTypeNode(TypeNode* node) { UNREACHABLE(); } | 306 void EffectGraphVisitor::VisitTypeNode(TypeNode* node) { UNREACHABLE(); } |
| 305 | 307 |
| 306 | 308 |
| 307 // Returns true if the type check can be skipped, for example, if the | 309 // Returns true if the type check can be skipped, for example, if the |
| 308 // destination type is Dynamic or if the static type of the value is a subtype | 310 // destination type is Dynamic or if the static type of the value is a subtype |
| 309 // of the destination type. | 311 // of the destination type. |
| 310 static bool CanSkipTypeCheck(Value* value, const AbstractType& dst_type) { | 312 static bool CanSkipTypeCheck(Value* value, const AbstractType& dst_type) { |
| 311 ASSERT(FLAG_enable_type_checks); | 313 ASSERT(FLAG_enable_type_checks); |
| 312 ASSERT(!dst_type.IsNull()); | 314 ASSERT(!dst_type.IsNull()); |
| 313 ASSERT(dst_type.IsFinalized()); | 315 ASSERT(dst_type.IsFinalized()); |
| 316 if (!FLAG_eliminate_type_checks) { |
| 317 return false; |
| 318 } |
| 314 | 319 |
| 315 // Any expression is assignable to the Dynamic type and to the Object type. | 320 // Any expression is assignable to the Dynamic type and to the Object type. |
| 316 // Skip the test. | 321 // Skip the test. |
| 317 if (!dst_type.IsMalformed() && | 322 if (!dst_type.IsMalformed() && |
| 318 (dst_type.IsDynamicType() || dst_type.IsObjectType())) { | 323 (dst_type.IsDynamicType() || dst_type.IsObjectType())) { |
| 319 return true; | 324 return true; |
| 320 } | 325 } |
| 321 | 326 |
| 322 // It is a compile-time error to explicitly return a value (including null) | 327 // It is a compile-time error to explicitly return a value (including null) |
| 323 // from a void function. However, functions that do not explicitly return a | 328 // from a void function. However, functions that do not explicitly return a |
| (...skipping 2070 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2394 char* chars = reinterpret_cast<char*>( | 2399 char* chars = reinterpret_cast<char*>( |
| 2395 Isolate::Current()->current_zone()->Allocate(len)); | 2400 Isolate::Current()->current_zone()->Allocate(len)); |
| 2396 OS::SNPrint(chars, len, kFormat, function_name, reason); | 2401 OS::SNPrint(chars, len, kFormat, function_name, reason); |
| 2397 const Error& error = Error::Handle( | 2402 const Error& error = Error::Handle( |
| 2398 LanguageError::New(String::Handle(String::New(chars)))); | 2403 LanguageError::New(String::Handle(String::New(chars)))); |
| 2399 Isolate::Current()->long_jump_base()->Jump(1, error); | 2404 Isolate::Current()->long_jump_base()->Jump(1, error); |
| 2400 } | 2405 } |
| 2401 | 2406 |
| 2402 | 2407 |
| 2403 } // namespace dart | 2408 } // namespace dart |
| OLD | NEW |