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_CODE_STUBS_UTILS_H_ 6 #define V8_CODE_STUBS_UTILS_H_ 7 8 namespace v8 { 9 namespace internal { 10 11 namespace compiler { 12 class CodeAssemblerState; 13 } // namespace compiler 14 15 // ---------------------------------------------------------------------------- 16 // Support macro for defining code stubs with Turbofan. 17 // ---------------------------------------------------------------------------- 18 // 19 // A code stub generator is defined by writing: 20 // 21 // TF_STUB(name, code_assember_base_class) { 22 // ... 23 // } 24 // 25 // In the body of the generator function the arguments can be accessed 26 // as "Parameter(n)". 27 #define TF_STUB(StubName, AssemblerBase) \ 28 class StubName##Assembler : public AssemblerBase { \ 29 public: \ 30 typedef StubName::Descriptor Descriptor; \ 31 \ 32 explicit StubName##Assembler(compiler::CodeAssemblerState* state) \ 33 : AssemblerBase(state) {} \ 34 void Generate##StubName##Impl(const StubName* stub); \ 35 \ 36 Node* Parameter(Descriptor::ParameterIndices index) { \ 37 return CodeAssembler::Parameter(static_cast<int>(index)); \ 38 } \ 39 }; \ 40 void StubName::GenerateAssembly(compiler::CodeAssemblerState* state) const { \ 41 StubName##Assembler assembler(state); \ 42 assembler.Generate##StubName##Impl(this); \ 43 } \ 44 void StubName##Assembler::Generate##StubName##Impl(const StubName* stub) 45 46 } // namespace internal 47 } // namespace v8 48 49 #endif // V8_CODE_STUBS_UTILS_H_ 50