2022-09-21 13:28:42 +02:00
|
|
|
// Copyright 2022 the V8 project authors. All rights reserved.
|
2014-09-29 13:20:04 +04:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2022-09-21 13:28:42 +02:00
|
|
|
#ifndef V8_COMMON_CALL_TESTER_H_
|
|
|
|
#define V8_COMMON_CALL_TESTER_H_
|
2014-09-29 13:20:04 +04:00
|
|
|
|
2019-08-01 08:38:30 +02:00
|
|
|
#include "src/execution/simulator.h"
|
|
|
|
#include "src/handles/handles.h"
|
2018-03-07 08:54:53 +01:00
|
|
|
#include "src/objects/code.h"
|
2022-09-21 13:28:42 +02:00
|
|
|
#include "test/common/c-signature.h"
|
2015-08-23 06:09:40 -07:00
|
|
|
|
2014-09-29 13:20:04 +04:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
namespace compiler {
|
|
|
|
|
2015-08-23 06:09:40 -07:00
|
|
|
template <typename R>
|
2014-09-29 13:20:04 +04:00
|
|
|
class CallHelper {
|
|
|
|
public:
|
2016-04-07 14:06:55 -07:00
|
|
|
explicit CallHelper(Isolate* isolate, MachineSignature* csig)
|
2015-08-23 06:09:40 -07:00
|
|
|
: csig_(csig), isolate_(isolate) {
|
2014-10-10 14:49:02 +04:00
|
|
|
USE(isolate_);
|
|
|
|
}
|
2018-12-04 08:20:37 +01:00
|
|
|
virtual ~CallHelper() = default;
|
2014-09-29 13:20:04 +04:00
|
|
|
|
2017-08-01 11:36:44 -05:00
|
|
|
template <typename... Params>
|
|
|
|
R Call(Params... args) {
|
|
|
|
CSignature::VerifyParams<Params...>(csig_);
|
2018-07-25 19:30:07 +02:00
|
|
|
Address entry = Generate();
|
2018-03-07 08:54:53 +01:00
|
|
|
auto fn = GeneratedCode<R, Params...>::FromAddress(isolate_, entry);
|
|
|
|
return fn.Call(args...);
|
2016-01-20 09:45:45 -08:00
|
|
|
}
|
|
|
|
|
2015-08-23 06:09:40 -07:00
|
|
|
protected:
|
2016-04-07 14:06:55 -07:00
|
|
|
MachineSignature* csig_;
|
2015-08-23 06:09:40 -07:00
|
|
|
|
2018-07-25 19:30:07 +02:00
|
|
|
virtual Address Generate() = 0;
|
2014-09-29 13:20:04 +04:00
|
|
|
|
|
|
|
private:
|
|
|
|
Isolate* isolate_;
|
|
|
|
};
|
|
|
|
|
2019-03-12 09:01:49 +01:00
|
|
|
template <>
|
|
|
|
template <typename... Params>
|
2023-10-05 08:46:07 +02:00
|
|
|
Tagged<Object> CallHelper<Tagged<Object>>::Call(Params... args) {
|
2019-03-12 09:01:49 +01:00
|
|
|
CSignature::VerifyParams<Params...>(csig_);
|
|
|
|
Address entry = Generate();
|
|
|
|
auto fn = GeneratedCode<Address, Params...>::FromAddress(isolate_, entry);
|
2023-10-05 08:46:07 +02:00
|
|
|
return Tagged<Object>(fn.Call(args...));
|
2019-03-12 09:01:49 +01:00
|
|
|
}
|
|
|
|
|
2015-10-06 08:42:38 +02:00
|
|
|
// A call helper that calls the given code object assuming C calling convention.
|
|
|
|
template <typename T>
|
|
|
|
class CodeRunner : public CallHelper<T> {
|
|
|
|
public:
|
2023-10-05 08:46:07 +02:00
|
|
|
CodeRunner(Isolate* isolate, Handle<InstructionStream> istream,
|
2023-03-30 12:11:08 +02:00
|
|
|
MachineSignature* csig)
|
2023-10-05 08:46:07 +02:00
|
|
|
: CallHelper<T>(isolate, csig), istream_(istream) {}
|
2024-08-14 20:41:00 +02:00
|
|
|
CodeRunner(Isolate* isolate, DirectHandle<Code> code, MachineSignature* csig)
|
2023-10-05 08:46:07 +02:00
|
|
|
: CallHelper<T>(isolate, csig),
|
|
|
|
istream_(code->instruction_stream(), isolate) {}
|
2018-12-04 08:20:37 +01:00
|
|
|
~CodeRunner() override = default;
|
2015-10-06 08:42:38 +02:00
|
|
|
|
2023-10-05 08:46:07 +02:00
|
|
|
Address Generate() override { return istream_->instruction_start(); }
|
2015-10-06 08:42:38 +02:00
|
|
|
|
|
|
|
private:
|
2023-10-05 08:46:07 +02:00
|
|
|
Handle<InstructionStream> istream_;
|
2015-10-06 08:42:38 +02:00
|
|
|
};
|
|
|
|
|
2014-09-29 13:20:04 +04:00
|
|
|
} // namespace compiler
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|
|
|
|
|
2022-09-21 13:28:42 +02:00
|
|
|
#endif // V8_COMMON_CALL_TESTER_H_
|