4392e0a4ad
This changeset include: 1. [prepare for migrate] move `cctest/compiler/value-helper.h`, `cctest/compiler/c-signature.h`, and `cctest/compiler/call-tester.h` to `test/common` directory because both `test-codegen` and a lot of cctest file include it. 2. [prepare for migrate] separate the tester helper part of `test-codegen` into a new `codegen-tester` file. 3. finally, migrate test-codegen.cc to `codegen-unittest.cc` Bug: v8:12781 Change-Id: Ia2f52c1d3b6b62501066dc1c4308a2c09d699e92 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3831146 Reviewed-by: Clemens Backes <clemensb@chromium.org> Commit-Queue: Clemens Backes <clemensb@chromium.org> Cr-Commit-Position: refs/heads/main@{#82630}
75 lines
2.0 KiB
C++
75 lines
2.0 KiB
C++
// Copyright 2022 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_COMMON_CALL_TESTER_H_
|
|
#define V8_COMMON_CALL_TESTER_H_
|
|
|
|
#include "src/execution/simulator.h"
|
|
#include "src/handles/handles.h"
|
|
#include "src/objects/code.h"
|
|
#include "test/common/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_COMMON_CALL_TESTER_H_
|