13695b2e0b44861fed1b26e201653958f3bb50d2
[platform/upstream/nodejs.git] / deps / v8 / test / cctest / compiler / test-linkage.cc
1 // 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/code-stubs.h"
8 #include "src/compiler.h"
9 #include "src/zone.h"
10
11 #include "src/compiler/common-operator.h"
12 #include "src/compiler/graph.h"
13 #include "src/compiler/linkage.h"
14 #include "src/compiler/machine-operator.h"
15 #include "src/compiler/node.h"
16 #include "src/compiler/operator.h"
17 #include "src/compiler/pipeline.h"
18 #include "src/compiler/schedule.h"
19 #include "test/cctest/cctest.h"
20
21 #if V8_TURBOFAN_TARGET
22
23 using namespace v8::internal;
24 using namespace v8::internal::compiler;
25
26 static Operator dummy_operator(IrOpcode::kParameter, Operator::kNoWrite,
27                                "dummy", 0, 0, 0, 0, 0, 0);
28
29 // So we can get a real JS function.
30 static Handle<JSFunction> Compile(const char* source) {
31   Isolate* isolate = CcTest::i_isolate();
32   Handle<String> source_code = isolate->factory()
33                                    ->NewStringFromUtf8(CStrVector(source))
34                                    .ToHandleChecked();
35   Handle<SharedFunctionInfo> shared_function = Compiler::CompileScript(
36       source_code, Handle<String>(), 0, 0, false, false,
37       Handle<Context>(isolate->native_context()), NULL, NULL,
38       v8::ScriptCompiler::kNoCompileOptions, NOT_NATIVES_CODE, false);
39   return isolate->factory()->NewFunctionFromSharedFunctionInfo(
40       shared_function, isolate->native_context());
41 }
42
43
44 TEST(TestLinkageCreate) {
45   InitializedHandleScope handles;
46   Handle<JSFunction> function = Compile("a + b");
47   CompilationInfoWithZone info(function);
48   CallDescriptor* descriptor = Linkage::ComputeIncoming(info.zone(), &info);
49   CHECK(descriptor);
50 }
51
52
53 TEST(TestLinkageJSFunctionIncoming) {
54   InitializedHandleScope handles;
55
56   const char* sources[] = {"(function() { })", "(function(a) { })",
57                            "(function(a,b) { })", "(function(a,b,c) { })"};
58
59   for (int i = 0; i < 3; i++) {
60     i::HandleScope handles(CcTest::i_isolate());
61     Handle<JSFunction> function = v8::Utils::OpenHandle(
62         *v8::Handle<v8::Function>::Cast(CompileRun(sources[i])));
63     CompilationInfoWithZone info(function);
64     CallDescriptor* descriptor = Linkage::ComputeIncoming(info.zone(), &info);
65     CHECK(descriptor);
66
67     CHECK_EQ(1 + i, static_cast<int>(descriptor->JSParameterCount()));
68     CHECK_EQ(1, static_cast<int>(descriptor->ReturnCount()));
69     CHECK_EQ(Operator::kNoProperties, descriptor->properties());
70     CHECK_EQ(true, descriptor->IsJSFunctionCall());
71   }
72 }
73
74
75 TEST(TestLinkageCodeStubIncoming) {
76   Isolate* isolate = CcTest::InitIsolateOnce();
77   ToNumberStub stub(isolate);
78   CompilationInfoWithZone info(&stub, isolate);
79   CallDescriptor* descriptor = Linkage::ComputeIncoming(info.zone(), &info);
80   CHECK(descriptor);
81   CHECK_EQ(1, static_cast<int>(descriptor->JSParameterCount()));
82   CHECK_EQ(1, static_cast<int>(descriptor->ReturnCount()));
83   CHECK_EQ(Operator::kNoProperties, descriptor->properties());
84   CHECK_EQ(false, descriptor->IsJSFunctionCall());
85 }
86
87
88 TEST(TestLinkageJSCall) {
89   HandleAndZoneScope handles;
90   Handle<JSFunction> function = Compile("a + c");
91   CompilationInfoWithZone info(function);
92
93   for (int i = 0; i < 32; i++) {
94     CallDescriptor* descriptor = Linkage::GetJSCallDescriptor(
95         info.zone(), false, i, CallDescriptor::kNoFlags);
96     CHECK(descriptor);
97     CHECK_EQ(i, static_cast<int>(descriptor->JSParameterCount()));
98     CHECK_EQ(1, static_cast<int>(descriptor->ReturnCount()));
99     CHECK_EQ(Operator::kNoProperties, descriptor->properties());
100     CHECK_EQ(true, descriptor->IsJSFunctionCall());
101   }
102 }
103
104
105 TEST(TestLinkageRuntimeCall) {
106   // TODO(titzer): test linkage creation for outgoing runtime calls.
107 }
108
109
110 TEST(TestLinkageStubCall) {
111   // TODO(titzer): test linkage creation for outgoing stub calls.
112 }
113
114
115 #endif  // V8_TURBOFAN_TARGET