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.
|
|
|
|
|
2017-02-23 11:46:29 +00:00
|
|
|
#include "src/api.h"
|
2016-09-20 16:07:25 +00:00
|
|
|
#include "src/code-factory.h"
|
2015-02-12 12:57:07 +00:00
|
|
|
#include "src/code-stubs.h"
|
2014-07-30 13:54:45 +00:00
|
|
|
#include "src/compiler.h"
|
|
|
|
#include "src/compiler/common-operator.h"
|
|
|
|
#include "src/compiler/graph.h"
|
|
|
|
#include "src/compiler/linkage.h"
|
|
|
|
#include "src/compiler/machine-operator.h"
|
|
|
|
#include "src/compiler/node.h"
|
|
|
|
#include "src/compiler/operator.h"
|
|
|
|
#include "src/compiler/pipeline.h"
|
|
|
|
#include "src/compiler/schedule.h"
|
2017-02-23 11:46:29 +00:00
|
|
|
#include "src/objects-inl.h"
|
2018-04-04 20:30:34 +00:00
|
|
|
#include "src/optimized-compilation-info.h"
|
2016-09-20 16:07:25 +00:00
|
|
|
#include "src/parsing/parse-info.h"
|
|
|
|
#include "src/zone/zone.h"
|
2014-07-30 13:54:45 +00:00
|
|
|
#include "test/cctest/cctest.h"
|
|
|
|
|
2015-10-30 09:16:26 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
namespace compiler {
|
2014-07-30 13:54:45 +00:00
|
|
|
|
2014-10-29 14:40:47 +00:00
|
|
|
static Operator dummy_operator(IrOpcode::kParameter, Operator::kNoWrite,
|
|
|
|
"dummy", 0, 0, 0, 0, 0, 0);
|
2014-07-30 13:54:45 +00:00
|
|
|
|
|
|
|
// So we can get a real JS function.
|
|
|
|
static Handle<JSFunction> Compile(const char* source) {
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
Handle<String> source_code = isolate->factory()
|
|
|
|
->NewStringFromUtf8(CStrVector(source))
|
|
|
|
.ToHandleChecked();
|
2017-10-04 22:48:12 +00:00
|
|
|
Handle<SharedFunctionInfo> shared =
|
|
|
|
Compiler::GetSharedFunctionInfoForScript(
|
2018-07-17 15:08:58 +00:00
|
|
|
isolate, source_code, Compiler::ScriptDetails(),
|
|
|
|
v8::ScriptOriginOptions(), nullptr, nullptr,
|
|
|
|
v8::ScriptCompiler::kNoCompileOptions,
|
2018-02-21 14:35:23 +00:00
|
|
|
ScriptCompiler::kNoCacheNoReason, NOT_NATIVES_CODE)
|
2017-10-04 22:48:12 +00:00
|
|
|
.ToHandleChecked();
|
2014-07-30 13:54:45 +00:00
|
|
|
return isolate->factory()->NewFunctionFromSharedFunctionInfo(
|
2016-03-08 12:07:27 +00:00
|
|
|
shared, isolate->native_context());
|
2014-07-30 13:54:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(TestLinkageCreate) {
|
2015-03-24 14:17:05 +00:00
|
|
|
HandleAndZoneScope handles;
|
2014-07-30 13:54:45 +00:00
|
|
|
Handle<JSFunction> function = Compile("a + b");
|
2018-06-23 09:05:50 +00:00
|
|
|
Handle<SharedFunctionInfo> shared(function->shared(), handles.main_isolate());
|
2018-04-04 20:30:34 +00:00
|
|
|
OptimizedCompilationInfo info(handles.main_zone(), function->GetIsolate(),
|
|
|
|
shared, function);
|
2018-02-09 19:19:25 +00:00
|
|
|
auto call_descriptor = Linkage::ComputeIncoming(info.zone(), &info);
|
|
|
|
CHECK(call_descriptor);
|
2014-07-30 13:54:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(TestLinkageJSFunctionIncoming) {
|
|
|
|
const char* sources[] = {"(function() { })", "(function(a) { })",
|
|
|
|
"(function(a,b) { })", "(function(a,b,c) { })"};
|
|
|
|
|
|
|
|
for (int i = 0; i < 3; i++) {
|
2015-03-24 14:17:05 +00:00
|
|
|
HandleAndZoneScope handles;
|
2015-10-23 12:26:49 +00:00
|
|
|
Handle<JSFunction> function =
|
|
|
|
Handle<JSFunction>::cast(v8::Utils::OpenHandle(
|
2015-10-28 13:09:46 +00:00
|
|
|
*v8::Local<v8::Function>::Cast(CompileRun(sources[i]))));
|
2018-06-23 09:05:50 +00:00
|
|
|
Handle<SharedFunctionInfo> shared(function->shared(),
|
|
|
|
handles.main_isolate());
|
2018-04-04 20:30:34 +00:00
|
|
|
OptimizedCompilationInfo info(handles.main_zone(), function->GetIsolate(),
|
|
|
|
shared, function);
|
2018-02-09 19:19:25 +00:00
|
|
|
auto call_descriptor = Linkage::ComputeIncoming(info.zone(), &info);
|
|
|
|
CHECK(call_descriptor);
|
2014-07-30 13:54:45 +00:00
|
|
|
|
2018-02-09 19:19:25 +00:00
|
|
|
CHECK_EQ(1 + i, static_cast<int>(call_descriptor->JSParameterCount()));
|
|
|
|
CHECK_EQ(1, static_cast<int>(call_descriptor->ReturnCount()));
|
|
|
|
CHECK_EQ(Operator::kNoProperties, call_descriptor->properties());
|
|
|
|
CHECK_EQ(true, call_descriptor->IsJSFunctionCall());
|
2014-07-30 13:54:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(TestLinkageJSCall) {
|
|
|
|
HandleAndZoneScope handles;
|
|
|
|
Handle<JSFunction> function = Compile("a + c");
|
2018-06-23 09:05:50 +00:00
|
|
|
Handle<SharedFunctionInfo> shared(function->shared(), handles.main_isolate());
|
2018-04-04 20:30:34 +00:00
|
|
|
OptimizedCompilationInfo info(handles.main_zone(), function->GetIsolate(),
|
|
|
|
shared, function);
|
2014-07-30 13:54:45 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < 32; i++) {
|
2018-02-09 19:19:25 +00:00
|
|
|
auto call_descriptor = Linkage::GetJSCallDescriptor(
|
2015-02-11 14:12:03 +00:00
|
|
|
info.zone(), false, i, CallDescriptor::kNoFlags);
|
2018-02-09 19:19:25 +00:00
|
|
|
CHECK(call_descriptor);
|
|
|
|
CHECK_EQ(i, static_cast<int>(call_descriptor->JSParameterCount()));
|
|
|
|
CHECK_EQ(1, static_cast<int>(call_descriptor->ReturnCount()));
|
|
|
|
CHECK_EQ(Operator::kNoProperties, call_descriptor->properties());
|
|
|
|
CHECK_EQ(true, call_descriptor->IsJSFunctionCall());
|
2014-07-30 13:54:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(TestLinkageRuntimeCall) {
|
|
|
|
// TODO(titzer): test linkage creation for outgoing runtime calls.
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(TestLinkageStubCall) {
|
2016-01-20 15:17:39 +00:00
|
|
|
Isolate* isolate = CcTest::InitIsolateOnce();
|
2016-10-17 12:12:30 +00:00
|
|
|
Zone zone(isolate->allocator(), ZONE_NAME);
|
2017-06-12 06:27:15 +00:00
|
|
|
Callable callable = Builtins::CallableFor(isolate, Builtins::kToNumber);
|
2018-04-04 20:30:34 +00:00
|
|
|
OptimizedCompilationInfo info(ArrayVector("test"), &zone, Code::STUB);
|
2018-02-09 19:19:25 +00:00
|
|
|
auto call_descriptor = Linkage::GetStubCallDescriptor(
|
2018-06-18 15:14:29 +00:00
|
|
|
&zone, callable.descriptor(), 0, CallDescriptor::kNoFlags,
|
2016-06-09 15:36:12 +00:00
|
|
|
Operator::kNoProperties);
|
2018-02-09 19:19:25 +00:00
|
|
|
CHECK(call_descriptor);
|
|
|
|
CHECK_EQ(0, static_cast<int>(call_descriptor->StackParameterCount()));
|
|
|
|
CHECK_EQ(1, static_cast<int>(call_descriptor->ReturnCount()));
|
|
|
|
CHECK_EQ(Operator::kNoProperties, call_descriptor->properties());
|
|
|
|
CHECK_EQ(false, call_descriptor->IsJSFunctionCall());
|
2014-07-30 13:54:45 +00:00
|
|
|
// TODO(titzer): test linkage creation for outgoing stub calls.
|
|
|
|
}
|
2015-10-30 09:16:26 +00:00
|
|
|
|
|
|
|
} // namespace compiler
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|