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