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"
|
2016-08-31 08:49:14 +00:00
|
|
|
#include "src/compilation-info.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"
|
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();
|
2016-03-08 12:07:27 +00:00
|
|
|
Handle<SharedFunctionInfo> shared = Compiler::GetSharedFunctionInfoForScript(
|
2015-05-19 03:11:33 +00:00
|
|
|
source_code, Handle<String>(), 0, 0, v8::ScriptOriginOptions(),
|
|
|
|
Handle<Object>(), Handle<Context>(isolate->native_context()), NULL, NULL,
|
2017-01-19 06:59:20 +00:00
|
|
|
v8::ScriptCompiler::kNoCompileOptions, NOT_NATIVES_CODE);
|
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");
|
2017-07-21 09:32:32 +00:00
|
|
|
Handle<SharedFunctionInfo> shared(function->shared());
|
|
|
|
ParseInfo parse_info(shared);
|
2017-03-22 12:46:46 +00:00
|
|
|
CompilationInfo info(parse_info.zone(), &parse_info, function->GetIsolate(),
|
2017-07-21 09:32:32 +00:00
|
|
|
shared, function);
|
2015-02-11 14:12:03 +00:00
|
|
|
CallDescriptor* descriptor = Linkage::ComputeIncoming(info.zone(), &info);
|
|
|
|
CHECK(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]))));
|
2017-07-21 09:32:32 +00:00
|
|
|
Handle<SharedFunctionInfo> shared(function->shared());
|
|
|
|
ParseInfo parse_info(shared);
|
2017-03-22 12:46:46 +00:00
|
|
|
CompilationInfo info(parse_info.zone(), &parse_info, function->GetIsolate(),
|
2017-07-21 09:32:32 +00:00
|
|
|
shared, function);
|
2015-02-11 14:12:03 +00:00
|
|
|
CallDescriptor* descriptor = Linkage::ComputeIncoming(info.zone(), &info);
|
2015-01-30 09:29:25 +00:00
|
|
|
CHECK(descriptor);
|
2014-07-30 13:54:45 +00:00
|
|
|
|
2014-11-20 11:51:04 +00:00
|
|
|
CHECK_EQ(1 + i, static_cast<int>(descriptor->JSParameterCount()));
|
|
|
|
CHECK_EQ(1, static_cast<int>(descriptor->ReturnCount()));
|
2014-07-30 13:54:45 +00:00
|
|
|
CHECK_EQ(Operator::kNoProperties, descriptor->properties());
|
|
|
|
CHECK_EQ(true, descriptor->IsJSFunctionCall());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(TestLinkageJSCall) {
|
|
|
|
HandleAndZoneScope handles;
|
|
|
|
Handle<JSFunction> function = Compile("a + c");
|
2017-07-21 09:32:32 +00:00
|
|
|
Handle<SharedFunctionInfo> shared(function->shared());
|
|
|
|
ParseInfo parse_info(shared);
|
2017-03-22 12:46:46 +00:00
|
|
|
CompilationInfo info(parse_info.zone(), &parse_info, function->GetIsolate(),
|
2017-07-21 09:32:32 +00:00
|
|
|
shared, function);
|
2014-07-30 13:54:45 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < 32; i++) {
|
2015-02-11 14:12:03 +00:00
|
|
|
CallDescriptor* descriptor = Linkage::GetJSCallDescriptor(
|
|
|
|
info.zone(), false, i, CallDescriptor::kNoFlags);
|
2015-01-30 09:29:25 +00:00
|
|
|
CHECK(descriptor);
|
2014-11-20 11:51:04 +00:00
|
|
|
CHECK_EQ(i, static_cast<int>(descriptor->JSParameterCount()));
|
|
|
|
CHECK_EQ(1, static_cast<int>(descriptor->ReturnCount()));
|
2014-07-30 13:54:45 +00:00
|
|
|
CHECK_EQ(Operator::kNoProperties, descriptor->properties());
|
|
|
|
CHECK_EQ(true, descriptor->IsJSFunctionCall());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
2016-04-26 14:36:35 +00:00
|
|
|
CompilationInfo info(ArrayVector("test"), isolate, &zone,
|
|
|
|
Code::ComputeFlags(Code::STUB));
|
2016-01-20 15:17:39 +00:00
|
|
|
CallDescriptor* descriptor = Linkage::GetStubCallDescriptor(
|
2016-06-09 15:36:12 +00:00
|
|
|
isolate, &zone, callable.descriptor(), 0, CallDescriptor::kNoFlags,
|
|
|
|
Operator::kNoProperties);
|
2016-01-20 15:17:39 +00:00
|
|
|
CHECK(descriptor);
|
|
|
|
CHECK_EQ(0, static_cast<int>(descriptor->StackParameterCount()));
|
|
|
|
CHECK_EQ(1, static_cast<int>(descriptor->ReturnCount()));
|
|
|
|
CHECK_EQ(Operator::kNoProperties, descriptor->properties());
|
|
|
|
CHECK_EQ(false, 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
|