// Copyright 2014 the V8 project authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef V8_CCTEST_COMPILER_CALL_TESTER_H_ #define V8_CCTEST_COMPILER_CALL_TESTER_H_ #include "src/execution/simulator.h" #include "src/handles/handles.h" #include "src/objects/code.h" #include "test/cctest/compiler/c-signature.h" namespace v8 { namespace internal { namespace compiler { template class CallHelper { public: explicit CallHelper(Isolate* isolate, MachineSignature* csig) : csig_(csig), isolate_(isolate) { USE(isolate_); } virtual ~CallHelper() = default; template R Call(Params... args) { CSignature::VerifyParams(csig_); Address entry = Generate(); auto fn = GeneratedCode::FromAddress(isolate_, entry); return fn.Call(args...); } protected: MachineSignature* csig_; virtual Address Generate() = 0; private: Isolate* isolate_; }; template <> template Object CallHelper::Call(Params... args) { CSignature::VerifyParams(csig_); Address entry = Generate(); auto fn = GeneratedCode::FromAddress(isolate_, entry); return Object(fn.Call(args...)); } // A call helper that calls the given code object assuming C calling convention. template class CodeRunner : public CallHelper { public: CodeRunner(Isolate* isolate, Handle code, MachineSignature* csig) : CallHelper(isolate, csig), code_(code) {} ~CodeRunner() override = default; Address Generate() override { return code_->entry(); } private: Handle code_; }; } // namespace compiler } // namespace internal } // namespace v8 #endif // V8_CCTEST_COMPILER_CALL_TESTER_H_