2014-07-30 13:54:45 +00:00
|
|
|
// 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_
|
|
|
|
|
2017-05-04 14:19:04 +00:00
|
|
|
#include "src/handles.h"
|
2018-01-08 15:31:30 +00:00
|
|
|
#include "src/objects/code.h"
|
2014-07-30 13:54:45 +00:00
|
|
|
#include "src/simulator.h"
|
2015-06-01 15:54:53 +00:00
|
|
|
#include "test/cctest/compiler/c-signature.h"
|
|
|
|
|
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_;
|
|
|
|
};
|
|
|
|
|
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) {}
|
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
|
|
|
|
|
|
|
|
#endif // V8_CCTEST_COMPILER_CALL_TESTER_H_
|