1 // Copyright 2017 the V8 project authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef V8_BUILTINS_BUILTINS_UTILS_GEN_H_ 6 #define V8_BUILTINS_BUILTINS_UTILS_GEN_H_ 7 8 #include "src/builtins/builtins-descriptors.h" 9 10 namespace v8 { 11 namespace internal { 12 13 namespace compiler { 14 class CodeAssemblerState; 15 } // namespace compiler 16 17 // ---------------------------------------------------------------------------- 18 // Support macro for defining builtins with Turbofan. 19 // ---------------------------------------------------------------------------- 20 // 21 // A builtin function is defined by writing: 22 // 23 // TF_BUILTIN(name, code_assember_base_class) { 24 // ... 25 // } 26 // 27 // In the body of the builtin function the arguments can be accessed 28 // as "Parameter(n)". 29 #define TF_BUILTIN(Name, AssemblerBase) \ 30 class Name##Assembler : public AssemblerBase { \ 31 public: \ 32 typedef Builtin_##Name##_InterfaceDescriptor Descriptor; \ 33 \ 34 explicit Name##Assembler(compiler::CodeAssemblerState* state) \ 35 : AssemblerBase(state) {} \ 36 void Generate##Name##Impl(); \ 37 \ 38 Node* Parameter(Descriptor::ParameterIndices index) { \ 39 return CodeAssembler::Parameter(static_cast<int>(index)); \ 40 } \ 41 }; \ 42 void Builtins::Generate_##Name(compiler::CodeAssemblerState* state) { \ 43 Name##Assembler assembler(state); \ 44 state->SetInitialDebugInformation(#Name, __FILE__, __LINE__); \ 45 if (Builtins::KindOf(Builtins::k##Name) == Builtins::TFJ) { \ 46 assembler.PerformStackCheck(assembler.GetJSContextParameter()); \ 47 } \ 48 assembler.Generate##Name##Impl(); \ 49 } \ 50 void Name##Assembler::Generate##Name##Impl() 51 52 } // namespace internal 53 } // namespace v8 54 55 #endif // V8_BUILTINS_BUILTINS_UTILS_GEN_H_ 56