2016-03-22 11:35:09 +00:00
|
|
|
// Copyright 2015 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.
|
|
|
|
|
2019-05-24 13:51:59 +00:00
|
|
|
#include "src/init/v8.h"
|
2016-03-22 11:35:09 +00:00
|
|
|
|
2019-05-17 12:13:44 +00:00
|
|
|
#include "src/api/api-inl.h"
|
2019-02-14 21:10:30 +00:00
|
|
|
#include "src/heap/heap-inl.h"
|
2016-03-22 11:35:09 +00:00
|
|
|
#include "src/interpreter/interpreter-intrinsics.h"
|
2019-05-23 08:51:46 +00:00
|
|
|
#include "src/objects/objects-inl.h"
|
2016-03-22 11:35:09 +00:00
|
|
|
#include "test/cctest/interpreter/interpreter-tester.h"
|
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
namespace interpreter {
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class InvokeIntrinsicHelper {
|
|
|
|
public:
|
|
|
|
InvokeIntrinsicHelper(Isolate* isolate, Zone* zone,
|
|
|
|
Runtime::FunctionId function_id)
|
|
|
|
: isolate_(isolate),
|
|
|
|
zone_(zone),
|
|
|
|
factory_(isolate->factory()),
|
|
|
|
function_id_(function_id) {}
|
|
|
|
|
|
|
|
template <class... A>
|
|
|
|
Handle<Object> Invoke(A... args) {
|
|
|
|
CHECK(IntrinsicsHelper::IsSupported(function_id_));
|
2020-03-19 14:33:26 +00:00
|
|
|
int parameter_count = sizeof...(args);
|
|
|
|
// Move the parameter to locals, since the order of the
|
|
|
|
// arguments in the stack is reversed.
|
|
|
|
BytecodeArrayBuilder builder(zone_, parameter_count + 1, parameter_count,
|
|
|
|
nullptr);
|
|
|
|
for (int i = 0; i < parameter_count; i++) {
|
|
|
|
builder.MoveRegister(builder.Parameter(i), builder.Local(i));
|
|
|
|
}
|
|
|
|
RegisterList reg_list =
|
|
|
|
InterpreterTester::NewRegisterList(0, parameter_count);
|
2016-09-30 09:02:59 +00:00
|
|
|
builder.CallRuntime(function_id_, reg_list).Return();
|
2016-08-18 13:42:05 +00:00
|
|
|
InterpreterTester tester(isolate_, builder.ToBytecodeArray(isolate_));
|
2016-05-27 22:29:01 +00:00
|
|
|
auto callable = tester.GetCallable<A...>();
|
2016-03-22 11:35:09 +00:00
|
|
|
return callable(args...).ToHandleChecked();
|
|
|
|
}
|
|
|
|
|
|
|
|
Handle<Object> NewObject(const char* script) {
|
|
|
|
return v8::Utils::OpenHandle(*CompileRun(script));
|
|
|
|
}
|
|
|
|
|
|
|
|
Handle<Object> Undefined() { return factory_->undefined_value(); }
|
|
|
|
Handle<Object> Null() { return factory_->null_value(); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
Isolate* isolate_;
|
|
|
|
Zone* zone_;
|
|
|
|
Factory* factory_;
|
|
|
|
Runtime::FunctionId function_id_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
} // namespace interpreter
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|