blob: 117caf22d82618dcd011103da40db0002f307563 [file] [log] [blame]
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001// Copyright 2014 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "src/v8.h"
6
7#include "src/compiler.h"
8#include "src/zone.h"
9
10#include "src/compiler/common-operator.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +000011#include "src/compiler/graph.h"
12#include "src/compiler/linkage.h"
13#include "src/compiler/machine-operator.h"
14#include "src/compiler/node.h"
15#include "src/compiler/operator.h"
16#include "src/compiler/pipeline.h"
17#include "src/compiler/schedule.h"
18#include "test/cctest/cctest.h"
19
20#if V8_TURBOFAN_TARGET
21
22using namespace v8::internal;
23using namespace v8::internal::compiler;
24
Emily Bernierd0a1eb72015-03-24 16:35:39 -040025static Operator dummy_operator(IrOpcode::kParameter, Operator::kNoWrite,
26 "dummy", 0, 0, 0, 0, 0, 0);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000027
28// So we can get a real JS function.
29static Handle<JSFunction> Compile(const char* source) {
30 Isolate* isolate = CcTest::i_isolate();
31 Handle<String> source_code = isolate->factory()
32 ->NewStringFromUtf8(CStrVector(source))
33 .ToHandleChecked();
34 Handle<SharedFunctionInfo> shared_function = Compiler::CompileScript(
35 source_code, Handle<String>(), 0, 0, false,
36 Handle<Context>(isolate->native_context()), NULL, NULL,
37 v8::ScriptCompiler::kNoCompileOptions, NOT_NATIVES_CODE);
38 return isolate->factory()->NewFunctionFromSharedFunctionInfo(
39 shared_function, isolate->native_context());
40}
41
42
43TEST(TestLinkageCreate) {
44 InitializedHandleScope handles;
45 Handle<JSFunction> function = Compile("a + b");
46 CompilationInfoWithZone info(function);
Emily Bernierd0a1eb72015-03-24 16:35:39 -040047 Linkage linkage(info.zone(), &info);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000048}
49
50
51TEST(TestLinkageJSFunctionIncoming) {
52 InitializedHandleScope handles;
53
54 const char* sources[] = {"(function() { })", "(function(a) { })",
55 "(function(a,b) { })", "(function(a,b,c) { })"};
56
57 for (int i = 0; i < 3; i++) {
58 i::HandleScope handles(CcTest::i_isolate());
59 Handle<JSFunction> function = v8::Utils::OpenHandle(
60 *v8::Handle<v8::Function>::Cast(CompileRun(sources[i])));
61 CompilationInfoWithZone info(function);
Emily Bernierd0a1eb72015-03-24 16:35:39 -040062 Linkage linkage(info.zone(), &info);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000063
64 CallDescriptor* descriptor = linkage.GetIncomingDescriptor();
65 CHECK_NE(NULL, descriptor);
66
Emily Bernierd0a1eb72015-03-24 16:35:39 -040067 CHECK_EQ(1 + i, static_cast<int>(descriptor->JSParameterCount()));
68 CHECK_EQ(1, static_cast<int>(descriptor->ReturnCount()));
Ben Murdochb8a8cc12014-11-26 15:28:44 +000069 CHECK_EQ(Operator::kNoProperties, descriptor->properties());
70 CHECK_EQ(true, descriptor->IsJSFunctionCall());
71 }
72}
73
74
75TEST(TestLinkageCodeStubIncoming) {
76 Isolate* isolate = CcTest::InitIsolateOnce();
77 CompilationInfoWithZone info(static_cast<HydrogenCodeStub*>(NULL), isolate);
Emily Bernierd0a1eb72015-03-24 16:35:39 -040078 Linkage linkage(info.zone(), &info);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000079 // TODO(titzer): test linkage creation with a bonafide code stub.
80 // this just checks current behavior.
81 CHECK_EQ(NULL, linkage.GetIncomingDescriptor());
82}
83
84
85TEST(TestLinkageJSCall) {
86 HandleAndZoneScope handles;
87 Handle<JSFunction> function = Compile("a + c");
88 CompilationInfoWithZone info(function);
Emily Bernierd0a1eb72015-03-24 16:35:39 -040089 Linkage linkage(info.zone(), &info);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000090
91 for (int i = 0; i < 32; i++) {
Emily Bernierd0a1eb72015-03-24 16:35:39 -040092 CallDescriptor* descriptor =
93 linkage.GetJSCallDescriptor(i, CallDescriptor::kNoFlags);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000094 CHECK_NE(NULL, descriptor);
Emily Bernierd0a1eb72015-03-24 16:35:39 -040095 CHECK_EQ(i, static_cast<int>(descriptor->JSParameterCount()));
96 CHECK_EQ(1, static_cast<int>(descriptor->ReturnCount()));
Ben Murdochb8a8cc12014-11-26 15:28:44 +000097 CHECK_EQ(Operator::kNoProperties, descriptor->properties());
98 CHECK_EQ(true, descriptor->IsJSFunctionCall());
99 }
100}
101
102
103TEST(TestLinkageRuntimeCall) {
104 // TODO(titzer): test linkage creation for outgoing runtime calls.
105}
106
107
108TEST(TestLinkageStubCall) {
109 // TODO(titzer): test linkage creation for outgoing stub calls.
110}
111
112
113#endif // V8_TURBOFAN_TARGET