| 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 // Class for intrinsifying functions. | 4 // Class for intrinsifying functions. |
| 5 | 5 |
| 6 #include "vm/intrinsifier.h" | 6 #include "vm/intrinsifier.h" |
| 7 #include "vm/flags.h" | 7 #include "vm/flags.h" |
| 8 #include "vm/object.h" | 8 #include "vm/object.h" |
| 9 #include "vm/symbols.h" | 9 #include "vm/symbols.h" |
| 10 | 10 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 } | 91 } |
| 92 | 92 |
| 93 | 93 |
| 94 void Intrinsifier::InitializeState() { | 94 void Intrinsifier::InitializeState() { |
| 95 Isolate* isolate = Isolate::Current(); | 95 Isolate* isolate = Isolate::Current(); |
| 96 Library& lib = Library::Handle(isolate); | 96 Library& lib = Library::Handle(isolate); |
| 97 Class& cls = Class::Handle(isolate); | 97 Class& cls = Class::Handle(isolate); |
| 98 Function& func = Function::Handle(isolate); | 98 Function& func = Function::Handle(isolate); |
| 99 String& str = String::Handle(isolate); | 99 String& str = String::Handle(isolate); |
| 100 Error& error = Error::Handle(isolate); | 100 Error& error = Error::Handle(isolate); |
| 101 bool set_intrinsic = true; | |
| 102 | 101 |
| 103 #define SETUP_FUNCTION(class_name, function_name, destination, fp) \ | 102 #define SETUP_FUNCTION(class_name, function_name, destination, fp) \ |
| 104 if (strcmp(#class_name, "::") == 0) { \ | 103 if (strcmp(#class_name, "::") == 0) { \ |
| 105 str = String::New(#function_name); \ | 104 str = String::New(#function_name); \ |
| 106 func = lib.LookupFunctionAllowPrivate(str); \ | 105 func = lib.LookupFunctionAllowPrivate(str); \ |
| 107 } else { \ | 106 } else { \ |
| 108 str = String::New(#class_name); \ | 107 str = String::New(#class_name); \ |
| 109 cls = lib.LookupClassAllowPrivate(str); \ | 108 cls = lib.LookupClassAllowPrivate(str); \ |
| 110 ASSERT(!cls.IsNull()); \ | 109 ASSERT(!cls.IsNull()); \ |
| 111 error = cls.EnsureIsFinalized(isolate); \ | 110 error = cls.EnsureIsFinalized(isolate); \ |
| 112 ASSERT(error.IsNull()); \ | 111 ASSERT(error.IsNull()); \ |
| 113 if (#function_name[0] == '.') { \ | 112 if (#function_name[0] == '.') { \ |
| 114 str = String::New(#class_name#function_name); \ | 113 str = String::New(#class_name#function_name); \ |
| 115 } else { \ | 114 } else { \ |
| 116 str = String::New(#function_name); \ | 115 str = String::New(#function_name); \ |
| 117 } \ | 116 } \ |
| 118 func = cls.LookupFunctionAllowPrivate(str); \ | 117 func = cls.LookupFunctionAllowPrivate(str); \ |
| 119 } \ | 118 } \ |
| 120 ASSERT(!func.IsNull()); \ | 119 ASSERT(!func.IsNull()); \ |
| 121 func.set_is_intrinsic(set_intrinsic); \ | 120 func.set_is_intrinsic(true); |
| 122 | 121 |
| 123 // Set up all core lib functions that can be intrisified. | 122 // Set up all core lib functions that can be intrisified. |
| 124 lib = Library::CoreLibrary(); | 123 lib = Library::CoreLibrary(); |
| 125 CORE_LIB_INTRINSIC_LIST(SETUP_FUNCTION); | 124 CORE_LIB_INTRINSIC_LIST(SETUP_FUNCTION); |
| 126 | 125 |
| 127 // Integer intrinsics are in the core library, but we don't want to intrinsify | 126 // Integer intrinsics are in the core library, but we don't want to intrinsify |
| 128 // if we are looking for javascript integer overflow. | 127 // if we are looking for javascript integer overflow. |
| 129 set_intrinsic = !FLAG_throw_on_javascript_int_overflow; | 128 if (!FLAG_throw_on_javascript_int_overflow) { |
| 130 CORE_INTEGER_LIB_INTRINSIC_LIST(SETUP_FUNCTION); | 129 CORE_INTEGER_LIB_INTRINSIC_LIST(SETUP_FUNCTION); |
| 131 set_intrinsic = true; | 130 } |
| 132 | 131 |
| 133 // Set up all math lib functions that can be intrisified. | 132 // Set up all math lib functions that can be intrisified. |
| 134 lib = Library::MathLibrary(); | 133 lib = Library::MathLibrary(); |
| 135 MATH_LIB_INTRINSIC_LIST(SETUP_FUNCTION); | 134 MATH_LIB_INTRINSIC_LIST(SETUP_FUNCTION); |
| 136 | 135 |
| 137 // Set up all dart:typed_data lib functions that can be intrisified. | 136 // Set up all dart:typed_data lib functions that can be intrisified. |
| 138 lib = Library::TypedDataLibrary(); | 137 lib = Library::TypedDataLibrary(); |
| 139 TYPED_DATA_LIB_INTRINSIC_LIST(SETUP_FUNCTION); | 138 TYPED_DATA_LIB_INTRINSIC_LIST(SETUP_FUNCTION); |
| 140 | 139 |
| 141 #undef SETUP_FUNCTION | 140 #undef SETUP_FUNCTION |
| (...skipping 11 matching lines...) Expand all Loading... |
| 153 #define FIND_INTRINSICS(test_class_name, test_function_name, destination, fp) \ | 152 #define FIND_INTRINSICS(test_class_name, test_function_name, destination, fp) \ |
| 154 if (TestFunction(lib, function, \ | 153 if (TestFunction(lib, function, \ |
| 155 class_name, function_name, \ | 154 class_name, function_name, \ |
| 156 #test_class_name, #test_function_name)) { \ | 155 #test_class_name, #test_function_name)) { \ |
| 157 ASSERT(function.CheckSourceFingerprint(fp)); \ | 156 ASSERT(function.CheckSourceFingerprint(fp)); \ |
| 158 return destination(assembler); \ | 157 return destination(assembler); \ |
| 159 } \ | 158 } \ |
| 160 | 159 |
| 161 if (lib.raw() == Library::CoreLibrary()) { | 160 if (lib.raw() == Library::CoreLibrary()) { |
| 162 CORE_LIB_INTRINSIC_LIST(FIND_INTRINSICS); | 161 CORE_LIB_INTRINSIC_LIST(FIND_INTRINSICS); |
| 163 CORE_INTEGER_LIB_INTRINSIC_LIST(FIND_INTRINSICS); | 162 if (!FLAG_throw_on_javascript_int_overflow) { |
| 163 CORE_INTEGER_LIB_INTRINSIC_LIST(FIND_INTRINSICS); |
| 164 } |
| 164 } else if (lib.raw() == Library::TypedDataLibrary()) { | 165 } else if (lib.raw() == Library::TypedDataLibrary()) { |
| 165 TYPED_DATA_LIB_INTRINSIC_LIST(FIND_INTRINSICS); | 166 TYPED_DATA_LIB_INTRINSIC_LIST(FIND_INTRINSICS); |
| 166 } else if (lib.raw() == Library::MathLibrary()) { | 167 } else if (lib.raw() == Library::MathLibrary()) { |
| 167 MATH_LIB_INTRINSIC_LIST(FIND_INTRINSICS); | 168 MATH_LIB_INTRINSIC_LIST(FIND_INTRINSICS); |
| 168 } | 169 } |
| 169 return false; | 170 return false; |
| 170 | 171 |
| 171 #undef FIND_INTRINSICS | 172 #undef FIND_INTRINSICS |
| 172 } | 173 } |
| 173 | 174 |
| 174 } // namespace dart | 175 } // namespace dart |
| OLD | NEW |