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.
|
|
|
|
|
|
|
|
#include "src/v8.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"
|
2015-03-24 14:17:05 +00:00
|
|
|
#include "src/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"
|
|
|
|
|
|
|
|
#if V8_TURBOFAN_TARGET
|
|
|
|
|
|
|
|
using namespace v8::internal;
|
|
|
|
using namespace v8::internal::compiler;
|
|
|
|
|
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();
|
|
|
|
Handle<SharedFunctionInfo> shared_function = Compiler::CompileScript(
|
2015-05-18 13:54:41 +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(
|
|
|
|
shared_function, isolate->native_context());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
CompilationInfo info(&parse_info);
|
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;
|
2014-07-30 13:54:45 +00:00
|
|
|
Handle<JSFunction> function = v8::Utils::OpenHandle(
|
|
|
|
*v8::Handle<v8::Function>::Cast(CompileRun(sources[i])));
|
2015-03-24 14:17:05 +00:00
|
|
|
ParseInfo parse_info(handles.main_zone(), function);
|
|
|
|
CompilationInfo info(&parse_info);
|
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(TestLinkageCodeStubIncoming) {
|
|
|
|
Isolate* isolate = CcTest::InitIsolateOnce();
|
2015-03-23 17:30:38 +00:00
|
|
|
Zone zone;
|
2015-02-12 12:57:07 +00:00
|
|
|
ToNumberStub stub(isolate);
|
2015-03-23 17:30:38 +00:00
|
|
|
CompilationInfo info(&stub, isolate, &zone);
|
|
|
|
CallDescriptor* descriptor = Linkage::ComputeIncoming(&zone, &info);
|
2015-02-12 12:57:07 +00:00
|
|
|
CHECK(descriptor);
|
|
|
|
CHECK_EQ(1, static_cast<int>(descriptor->JSParameterCount()));
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
CompilationInfo info(&parse_info);
|
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) {
|
|
|
|
// TODO(titzer): test linkage creation for outgoing stub calls.
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif // V8_TURBOFAN_TARGET
|