OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_BUILTINS_BUILTINS_UTILS_H_ | 5 #ifndef V8_BUILTINS_BUILTINS_UTILS_H_ |
6 #define V8_BUILTINS_BUILTINS_UTILS_H_ | 6 #define V8_BUILTINS_BUILTINS_UTILS_H_ |
7 | 7 |
8 #include "src/arguments.h" | 8 #include "src/arguments.h" |
9 #include "src/base/logging.h" | 9 #include "src/base/logging.h" |
10 #include "src/builtins/builtins.h" | 10 #include "src/builtins/builtins.h" |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 return Builtin_Impl_Stats_##name(args_length, args_object, isolate); \ | 95 return Builtin_Impl_Stats_##name(args_length, args_object, isolate); \ |
96 } \ | 96 } \ |
97 BuiltinArguments args(args_length, args_object); \ | 97 BuiltinArguments args(args_length, args_object); \ |
98 return Builtin_Impl_##name(args, isolate); \ | 98 return Builtin_Impl_##name(args, isolate); \ |
99 } \ | 99 } \ |
100 \ | 100 \ |
101 MUST_USE_RESULT static Object* Builtin_Impl_##name(BuiltinArguments args, \ | 101 MUST_USE_RESULT static Object* Builtin_Impl_##name(BuiltinArguments args, \ |
102 Isolate* isolate) | 102 Isolate* isolate) |
103 | 103 |
104 // ---------------------------------------------------------------------------- | 104 // ---------------------------------------------------------------------------- |
| 105 // Support macro for defining builtins with Turbofan. |
| 106 // ---------------------------------------------------------------------------- |
| 107 // |
| 108 // A builtin function is defined by writing: |
| 109 // |
| 110 // TF_BUILTIN(name, code_assember_base_class) { |
| 111 // ... |
| 112 // } |
| 113 // |
| 114 // In the body of the builtin function the arguments can be accessed |
| 115 // as "Parameter(n)". |
| 116 #define TF_BUILTIN(Name, AssemblerBase) \ |
| 117 class Name##Assembler : public AssemblerBase { \ |
| 118 public: \ |
| 119 explicit Name##Assembler(compiler::CodeAssemblerState* state) \ |
| 120 : AssemblerBase(state) {} \ |
| 121 void Generate##Name(); \ |
| 122 }; \ |
| 123 void Builtins::Generate_##Name(compiler::CodeAssemblerState* state) { \ |
| 124 Name##Assembler assembler(state); \ |
| 125 assembler.Generate##Name(); \ |
| 126 } \ |
| 127 void Name##Assembler::Generate##Name() |
| 128 |
| 129 // ---------------------------------------------------------------------------- |
105 | 130 |
106 #define CHECK_RECEIVER(Type, name, method) \ | 131 #define CHECK_RECEIVER(Type, name, method) \ |
107 if (!args.receiver()->Is##Type()) { \ | 132 if (!args.receiver()->Is##Type()) { \ |
108 THROW_NEW_ERROR_RETURN_FAILURE( \ | 133 THROW_NEW_ERROR_RETURN_FAILURE( \ |
109 isolate, \ | 134 isolate, \ |
110 NewTypeError(MessageTemplate::kIncompatibleMethodReceiver, \ | 135 NewTypeError(MessageTemplate::kIncompatibleMethodReceiver, \ |
111 isolate->factory()->NewStringFromAsciiChecked(method), \ | 136 isolate->factory()->NewStringFromAsciiChecked(method), \ |
112 args.receiver())); \ | 137 args.receiver())); \ |
113 } \ | 138 } \ |
114 Handle<Type> name = Handle<Type>::cast(args.receiver()) | 139 Handle<Type> name = Handle<Type>::cast(args.receiver()) |
(...skipping 10 matching lines...) Expand all Loading... |
125 isolate->factory()->NewStringFromAsciiChecked(method))); \ | 150 isolate->factory()->NewStringFromAsciiChecked(method))); \ |
126 } \ | 151 } \ |
127 Handle<String> name; \ | 152 Handle<String> name; \ |
128 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( \ | 153 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( \ |
129 isolate, name, Object::ToString(isolate, args.receiver())) | 154 isolate, name, Object::ToString(isolate, args.receiver())) |
130 | 155 |
131 } // namespace internal | 156 } // namespace internal |
132 } // namespace v8 | 157 } // namespace v8 |
133 | 158 |
134 #endif // V8_BUILTINS_BUILTINS_UTILS_H_ | 159 #endif // V8_BUILTINS_BUILTINS_UTILS_H_ |
OLD | NEW |