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 "include/cppgc/source-location.h" 9#include "src/builtins/builtins-descriptors.h" 10 11namespace v8 { 12namespace internal { 13 14namespace compiler { 15class CodeAssemblerState; 16} // namespace compiler 17 18// ---------------------------------------------------------------------------- 19// Support macro for defining builtins with Turbofan. 20// ---------------------------------------------------------------------------- 21// 22// A builtin function is defined by writing: 23// 24// TF_BUILTIN(name, code_assember_base_class) { 25// ... 26// } 27// 28// In the body of the builtin function the arguments can be accessed 29// as "Parameter(n)". 30#define TF_BUILTIN(Name, AssemblerBase) \ 31 class Name##Assembler : public AssemblerBase { \ 32 public: \ 33 using Descriptor = Builtin_##Name##_InterfaceDescriptor; \ 34 \ 35 explicit Name##Assembler(compiler::CodeAssemblerState* state) \ 36 : AssemblerBase(state) {} \ 37 void Generate##Name##Impl(); \ 38 \ 39 template <class T> \ 40 TNode<T> Parameter( \ 41 Descriptor::ParameterIndices index, \ 42 cppgc::SourceLocation loc = cppgc::SourceLocation::Current()) { \ 43 return CodeAssembler::Parameter<T>(static_cast<int>(index), loc); \ 44 } \ 45 \ 46 template <class T> \ 47 TNode<T> UncheckedParameter(Descriptor::ParameterIndices index) { \ 48 return CodeAssembler::UncheckedParameter<T>(static_cast<int>(index)); \ 49 } \ 50 }; \ 51 void Builtins::Generate_##Name(compiler::CodeAssemblerState* state) { \ 52 Name##Assembler assembler(state); \ 53 state->SetInitialDebugInformation(#Name, __FILE__, __LINE__); \ 54 if (Builtins::KindOf(Builtin::k##Name) == Builtins::TFJ) { \ 55 assembler.PerformStackCheck(assembler.GetJSContextParameter()); \ 56 } \ 57 assembler.Generate##Name##Impl(); \ 58 } \ 59 void Name##Assembler::Generate##Name##Impl() 60 61} // namespace internal 62} // namespace v8 63 64#endif // V8_BUILTINS_BUILTINS_UTILS_GEN_H_ 65