a7db5fcbad
... in order to avoid Code <-> CodeT conversions in builtins. This CL changes the meaning of RelocInfo::CODE_TARGET which now expects CodeT objects as a code target. In order to reduce code churn this CL makes BUILTIN_CODE and friends return CodeT instead of Code. In the follow-up CLs BUILTIN_CODET and friends will be removed. Bug: v8:11880 Change-Id: Ib8f60973e55c60fc62ba84707471da388f8201b4 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3338483 Reviewed-by: Patrick Thier <pthier@chromium.org> Reviewed-by: Nico Hartmann <nicohartmann@chromium.org> Reviewed-by: Leszek Swirski <leszeks@chromium.org> Commit-Queue: Igor Sheludko <ishell@chromium.org> Cr-Commit-Position: refs/heads/main@{#78393}
76 lines
2.0 KiB
C++
76 lines
2.0 KiB
C++
// 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 <typename R>
|
|
class CallHelper {
|
|
public:
|
|
explicit CallHelper(Isolate* isolate, MachineSignature* csig)
|
|
: csig_(csig), isolate_(isolate) {
|
|
USE(isolate_);
|
|
}
|
|
virtual ~CallHelper() = default;
|
|
|
|
template <typename... Params>
|
|
R Call(Params... args) {
|
|
CSignature::VerifyParams<Params...>(csig_);
|
|
Address entry = Generate();
|
|
auto fn = GeneratedCode<R, Params...>::FromAddress(isolate_, entry);
|
|
return fn.Call(args...);
|
|
}
|
|
|
|
protected:
|
|
MachineSignature* csig_;
|
|
|
|
virtual Address Generate() = 0;
|
|
|
|
private:
|
|
Isolate* isolate_;
|
|
};
|
|
|
|
template <>
|
|
template <typename... Params>
|
|
Object CallHelper<Object>::Call(Params... args) {
|
|
CSignature::VerifyParams<Params...>(csig_);
|
|
Address entry = Generate();
|
|
auto fn = GeneratedCode<Address, Params...>::FromAddress(isolate_, entry);
|
|
return Object(fn.Call(args...));
|
|
}
|
|
|
|
// A call helper that calls the given code object assuming C calling convention.
|
|
template <typename T>
|
|
class CodeRunner : public CallHelper<T> {
|
|
public:
|
|
CodeRunner(Isolate* isolate, Handle<Code> code, MachineSignature* csig)
|
|
: CallHelper<T>(isolate, csig), code_(code) {}
|
|
#ifdef V8_EXTERNAL_CODE_SPACE
|
|
CodeRunner(Isolate* isolate, Handle<CodeT> code, MachineSignature* csig)
|
|
: CallHelper<T>(isolate, csig), code_(FromCodeT(*code), isolate) {}
|
|
#endif // V8_EXTERNAL_CODE_SPACE
|
|
~CodeRunner() override = default;
|
|
|
|
Address Generate() override { return code_->entry(); }
|
|
|
|
private:
|
|
Handle<Code> code_;
|
|
};
|
|
|
|
|
|
} // namespace compiler
|
|
} // namespace internal
|
|
} // namespace v8
|
|
|
|
#endif // V8_CCTEST_COMPILER_CALL_TESTER_H_
|