| OLD | NEW | 
|    1 // Copyright (c) 2011, 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/compiler.h" |    5 #include "vm/compiler.h" | 
|    6  |    6  | 
|    7 #include "vm/assembler.h" |    7 #include "vm/assembler.h" | 
|    8 #include "vm/ast_printer.h" |    8 #include "vm/ast_printer.h" | 
|    9 #include "vm/code_generator.h" |    9 #include "vm/code_generator.h" | 
|   10 #include "vm/code_index_table.h" |   10 #include "vm/code_index_table.h" | 
|   11 #include "vm/code_patcher.h" |   11 #include "vm/code_patcher.h" | 
|   12 #include "vm/dart_entry.h" |   12 #include "vm/dart_entry.h" | 
|   13 #include "vm/disassembler.h" |   13 #include "vm/disassembler.h" | 
|   14 #include "vm/exceptions.h" |   14 #include "vm/exceptions.h" | 
|   15 #include "vm/flags.h" |   15 #include "vm/flags.h" | 
 |   16 #include "vm/flow_graph_builder.h" | 
|   16 #include "vm/longjump.h" |   17 #include "vm/longjump.h" | 
|   17 #include "vm/object.h" |   18 #include "vm/object.h" | 
|   18 #include "vm/object_store.h" |   19 #include "vm/object_store.h" | 
|   19 #include "vm/opt_code_generator.h" |   20 #include "vm/opt_code_generator.h" | 
|   20 #include "vm/os.h" |   21 #include "vm/os.h" | 
|   21 #include "vm/parser.h" |   22 #include "vm/parser.h" | 
|   22 #include "vm/scanner.h" |   23 #include "vm/scanner.h" | 
|   23 #include "vm/timer.h" |   24 #include "vm/timer.h" | 
|   24  |   25  | 
|   25 namespace dart { |   26 namespace dart { | 
|   26  |   27  | 
|   27 DEFINE_FLAG(bool, disassemble, false, "Disassemble dart code."); |   28 DEFINE_FLAG(bool, disassemble, false, "Disassemble dart code."); | 
|   28 DEFINE_FLAG(bool, trace_compiler, false, "Trace compiler operations."); |   29 DEFINE_FLAG(bool, trace_compiler, false, "Trace compiler operations."); | 
|   29 DEFINE_FLAG(int, deoptimization_counter_threshold, 5, |   30 DEFINE_FLAG(int, deoptimization_counter_threshold, 5, | 
|   30     "How many times we allow deoptimization before we disallow" |   31     "How many times we allow deoptimization before we disallow" | 
|   31     " certain optimizations"); |   32     " certain optimizations"); | 
 |   33 DEFINE_FLAG(bool, use_new_compiler, false, | 
 |   34     "Try to use the new compiler backend."); | 
|   32  |   35  | 
|   33  |   36  | 
|   34 // Compile a function. Should call only if the function has not been compiled. |   37 // Compile a function. Should call only if the function has not been compiled. | 
|   35 //   Arg0: function object. |   38 //   Arg0: function object. | 
|   36 DEFINE_RUNTIME_ENTRY(CompileFunction, 1) { |   39 DEFINE_RUNTIME_ENTRY(CompileFunction, 1) { | 
|   37   ASSERT(arguments.Count() == kCompileFunctionRuntimeEntry.argument_count()); |   40   ASSERT(arguments.Count() == kCompileFunctionRuntimeEntry.argument_count()); | 
|   38   const Function& function = Function::CheckedHandle(arguments.At(0)); |   41   const Function& function = Function::CheckedHandle(arguments.At(0)); | 
|   39   ASSERT(!function.HasCode()); |   42   ASSERT(!function.HasCode()); | 
|   40   const Error& error = Error::Handle(Compiler::CompileFunction(function)); |   43   const Error& error = Error::Handle(Compiler::CompileFunction(function)); | 
|   41   if (!error.IsNull()) { |   44   if (!error.IsNull()) { | 
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  106     TIMERSCOPE(time_compilation); |  109     TIMERSCOPE(time_compilation); | 
|  107     ParsedFunction parsed_function(function); |  110     ParsedFunction parsed_function(function); | 
|  108     const char* function_fullname = function.ToFullyQualifiedCString(); |  111     const char* function_fullname = function.ToFullyQualifiedCString(); | 
|  109     if (FLAG_trace_compiler) { |  112     if (FLAG_trace_compiler) { | 
|  110       OS::Print("Compiling %sfunction: '%s' @ token %d\n", |  113       OS::Print("Compiling %sfunction: '%s' @ token %d\n", | 
|  111                 (optimized ? "optimized " : ""), |  114                 (optimized ? "optimized " : ""), | 
|  112                 function_fullname, |  115                 function_fullname, | 
|  113                 function.token_index()); |  116                 function.token_index()); | 
|  114     } |  117     } | 
|  115     Parser::ParseFunction(&parsed_function); |  118     Parser::ParseFunction(&parsed_function); | 
 |  119     if (FLAG_use_new_compiler) { | 
 |  120       FlowGraphBuilder graph_builder(parsed_function); | 
 |  121       graph_builder.BuildGraph(); | 
 |  122       // Currently, always fails and falls through to the old compiler. | 
 |  123     } | 
|  116     CodeIndexTable* code_index_table = isolate->code_index_table(); |  124     CodeIndexTable* code_index_table = isolate->code_index_table(); | 
|  117     ASSERT(code_index_table != NULL); |  125     ASSERT(code_index_table != NULL); | 
|  118     Assembler assembler; |  126     Assembler assembler; | 
|  119     if (optimized) { |  127     if (optimized) { | 
|  120       // Transition to optimized code only from unoptimized code ... for now. |  128       // Transition to optimized code only from unoptimized code ... for now. | 
|  121       ASSERT(function.HasCode()); |  129       ASSERT(function.HasCode()); | 
|  122       ASSERT(!Code::Handle(function.code()).is_optimized()); |  130       ASSERT(!Code::Handle(function.code()).is_optimized()); | 
|  123       // Do not use type feedback to optimize a function that was deoptimized. |  131       // Do not use type feedback to optimize a function that was deoptimized. | 
|  124       if (parsed_function.function().deoptimization_counter() < |  132       if (parsed_function.function().deoptimization_counter() < | 
|  125           FLAG_deoptimization_counter_threshold) { |  133           FLAG_deoptimization_counter_threshold) { | 
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  333   } else { |  341   } else { | 
|  334     result = isolate->object_store()->sticky_error(); |  342     result = isolate->object_store()->sticky_error(); | 
|  335     isolate->object_store()->clear_sticky_error(); |  343     isolate->object_store()->clear_sticky_error(); | 
|  336   } |  344   } | 
|  337   isolate->set_long_jump_base(base); |  345   isolate->set_long_jump_base(base); | 
|  338   return result.raw(); |  346   return result.raw(); | 
|  339 } |  347 } | 
|  340  |  348  | 
|  341  |  349  | 
|  342 }  // namespace dart |  350 }  // namespace dart | 
| OLD | NEW |