2022-08-22 15:42:07 +00:00
|
|
|
// Copyright 2022 the V8 project authors. All rights reserved.
|
2014-07-30 13:54:45 +00:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2022-08-22 15:42:07 +00:00
|
|
|
#ifndef V8_COMMON_CALL_TESTER_H_
|
|
|
|
#define V8_COMMON_CALL_TESTER_H_
|
2014-07-30 13:54:45 +00:00
|
|
|
|
|
|
|
#include "src/execution/simulator.h"
|
2017-05-04 14:19:04 +00:00
|
|
|
#include "src/handles/handles.h"
|
2018-01-08 15:31:30 +00:00
|
|
|
#include "src/objects/code.h"
|
2022-08-22 15:42:07 +00:00
|
|
|
#include "test/common/c-signature.h"
|
2015-06-01 15:54:53 +00:00
|
|
|
|
2014-07-30 13:54:45 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
namespace compiler {
|
|
|
|
|
2015-05-29 14:05:39 +00:00
|
|
|
template <typename R>
|
2014-07-30 13:54:45 +00:00
|
|
|
class CallHelper {
|
|
|
|
public:
|
2016-02-18 09:55:25 +00:00
|
|
|
explicit CallHelper(Isolate* isolate, MachineSignature* csig)
|
2015-06-02 15:00:55 +00:00
|
|
|
: csig_(csig), isolate_(isolate) {
|
2014-09-03 10:13:21 +00:00
|
|
|
USE(isolate_);
|
|
|
|
}
|
2018-09-17 11:30:48 +00:00
|
|
|
virtual ~CallHelper() = default;
|
2014-07-30 13:54:45 +00:00
|
|
|
|
2017-05-04 14:19:04 +00:00
|
|
|
template <typename... Params>
|
|
|
|
R Call(Params... args) {
|
|
|
|
CSignature::VerifyParams<Params...>(csig_);
|
2018-04-13 22:28:05 +00:00
|
|
|
Address entry = Generate();
|
2018-01-09 09:50:34 +00:00
|
|
|
auto fn = GeneratedCode<R, Params...>::FromAddress(isolate_, entry);
|
|
|
|
return fn.Call(args...);
|
2015-10-30 21:32:35 +00:00
|
|
|
}
|
|
|
|
|
2014-07-30 13:54:45 +00:00
|
|
|
protected:
|
2016-02-18 09:55:25 +00:00
|
|
|
MachineSignature* csig_;
|
2015-05-29 14:05:39 +00:00
|
|
|
|
2018-04-13 22:28:05 +00:00
|
|
|
virtual Address Generate() = 0;
|
2014-07-30 13:54:45 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
Isolate* isolate_;
|
|
|
|
};
|
|
|
|
|
2018-12-25 00:19:47 +00:00
|
|
|
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...));
|
|
|
|
}
|
|
|
|
|
2015-08-11 15:23:04 +00:00
|
|
|
// A call helper that calls the given code object assuming C calling convention.
|
|
|
|
template <typename T>
|
|
|
|
class CodeRunner : public CallHelper<T> {
|
|
|
|
public:
|
2016-02-18 09:55:25 +00:00
|
|
|
CodeRunner(Isolate* isolate, Handle<Code> code, MachineSignature* csig)
|
2015-08-11 15:23:04 +00:00
|
|
|
: CallHelper<T>(isolate, csig), code_(code) {}
|
2021-12-15 10:51:04 +00:00
|
|
|
#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
|
2018-09-17 11:30:48 +00:00
|
|
|
~CodeRunner() override = default;
|
2015-08-11 15:23:04 +00:00
|
|
|
|
2018-04-13 22:28:05 +00:00
|
|
|
Address Generate() override { return code_->entry(); }
|
2015-08-11 15:23:04 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
Handle<Code> code_;
|
|
|
|
};
|
|
|
|
|
2014-07-30 13:54:45 +00:00
|
|
|
} // namespace compiler
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|
|
|
|
|
2022-08-22 15:42:07 +00:00
|
|
|
#endif // V8_COMMON_CALL_TESTER_H_
|