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.
|
|
|
|
|
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"
|
2015-11-26 16:22:34 +00:00
|
|
|
#include "src/parsing/parser.h"
|
2014-07-30 13:54:45 +00:00
|
|
|
#include "src/zone.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"
|
|
|
|
#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,
|
2015-02-06 17:52:20 +00:00
|
|
|
v8::ScriptCompiler::kNoCompileOptions, NOT_NATIVES_CODE, false);
|
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");
|
2015-03-24 14:17:05 +00:00
|
|
|
ParseInfo parse_info(handles.main_zone(), function);
|
2016-04-08 12:31:38 +00:00
|
|
|
CompilationInfo info(&parse_info, 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]))));
|
2015-03-24 14:17:05 +00:00
|
|
|
ParseInfo parse_info(handles.main_zone(), function);
|
2016-04-08 12:31:38 +00:00
|
|
|
CompilationInfo info(&parse_info, 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");
|
2015-03-24 14:17:05 +00:00
|
|
|
ParseInfo parse_info(handles.main_zone(), function);
|
2016-04-08 12:31:38 +00:00
|
|
|
CompilationInfo info(&parse_info, 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-04-01 10:00:30 +00:00
|
|
|
Zone zone(isolate->allocator());
|
2016-01-20 15:17:39 +00:00
|
|
|
ToNumberStub stub(isolate);
|
|
|
|
CompilationInfo info("test", isolate, &zone, Code::ComputeFlags(Code::STUB));
|
|
|
|
CallInterfaceDescriptor interface_descriptor =
|
|
|
|
stub.GetCallInterfaceDescriptor();
|
|
|
|
CallDescriptor* descriptor = Linkage::GetStubCallDescriptor(
|
|
|
|
isolate, &zone, interface_descriptor, stub.GetStackParameterCount(),
|
|
|
|
CallDescriptor::kNoFlags, Operator::kNoProperties);
|
|
|
|
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
|