OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 // Class for intrinsifying functions. |
| 5 |
| 6 #include "vm/intrinsifier.h" |
| 7 #include "vm/flags.h" |
| 8 #include "vm/object.h" |
| 9 |
| 10 namespace dart { |
| 11 |
| 12 DEFINE_FLAG(bool, intrinsify, true, "Instrinsify when possible"); |
| 13 |
| 14 |
| 15 static bool CompareNames(const char* test_name, const char* name) { |
| 16 if (strcmp(test_name, name) == 0) { |
| 17 return true; |
| 18 } |
| 19 if ((name[0] == '_') && (test_name[0] == '_')) { |
| 20 // Check if the private class is member of corelib and matches the |
| 21 // test_class_name. |
| 22 const Library& core_lib = Library::Handle(Library::CoreLibrary()); |
| 23 const Library& core_impl_lib = Library::Handle(Library::CoreImplLibrary()); |
| 24 String& test_str = String::Handle(String::New(test_name)); |
| 25 String& test_str_with_key = String::Handle(); |
| 26 test_str_with_key = |
| 27 String::Concat(test_str, String::Handle(core_lib.private_key())); |
| 28 if (strcmp(test_str_with_key.ToCString(), name) == 0) { |
| 29 return true; |
| 30 } |
| 31 test_str_with_key = |
| 32 String::Concat(test_str, String::Handle(core_impl_lib.private_key())); |
| 33 if (strcmp(test_str_with_key.ToCString(), name) == 0) { |
| 34 return true; |
| 35 } |
| 36 } |
| 37 return false; |
| 38 } |
| 39 |
| 40 |
| 41 // Returns true if the function matches function_name and class_name, with |
| 42 // special recognition of corelib private classes. |
| 43 static bool TestFunction(const Function& function, |
| 44 const char* function_class_name, |
| 45 const char* function_name, |
| 46 const char* test_class_name, |
| 47 const char* test_function_name) { |
| 48 return CompareNames(test_class_name, function_class_name) && |
| 49 CompareNames(test_function_name, function_name); |
| 50 } |
| 51 |
| 52 |
| 53 bool Intrinsifier::Intrinsify(const Function& function, Assembler* assembler) { |
| 54 if (!FLAG_intrinsify) return false; |
| 55 const char* function_name = String::Handle(function.name()).ToCString(); |
| 56 const Class& function_class = Class::Handle(function.owner()); |
| 57 const char* class_name = String::Handle(function_class.Name()).ToCString(); |
| 58 // Only core library methods can be intrinsified. |
| 59 const Library& core_lib = Library::Handle(Library::CoreLibrary()); |
| 60 const Library& core_impl_lib = Library::Handle(Library::CoreImplLibrary()); |
| 61 if ((function_class.library() != core_lib.raw()) && |
| 62 (function_class.library() != core_impl_lib.raw())) { |
| 63 return false; |
| 64 } |
| 65 #define FIND_INTRINSICS(test_class_name, test_function_name, destination) \ |
| 66 if (TestFunction(function, \ |
| 67 class_name, function_name, \ |
| 68 #test_class_name, #test_function_name)) { \ |
| 69 return destination(assembler); \ |
| 70 } \ |
| 71 |
| 72 INTRINSIC_LIST(FIND_INTRINSICS); |
| 73 #undef FIND_INTRINSICS |
| 74 return false; |
| 75 } |
| 76 |
| 77 } // namespace dart |
OLD | NEW |