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.
7 #include "src/code-stubs.h"
8 #include "src/compiler.h"
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"
21 #if V8_TURBOFAN_TARGET
23 using namespace v8::internal;
24 using namespace v8::internal::compiler;
26 static Operator dummy_operator(IrOpcode::kParameter, Operator::kNoWrite,
27 "dummy", 0, 0, 0, 0, 0, 0);
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))
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());
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);
53 TEST(TestLinkageJSFunctionIncoming) {
54 InitializedHandleScope handles;
56 const char* sources[] = {"(function() { })", "(function(a) { })",
57 "(function(a,b) { })", "(function(a,b,c) { })"};
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);
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());
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);
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());
88 TEST(TestLinkageJSCall) {
89 HandleAndZoneScope handles;
90 Handle<JSFunction> function = Compile("a + c");
91 CompilationInfoWithZone info(function);
93 for (int i = 0; i < 32; i++) {
94 CallDescriptor* descriptor = Linkage::GetJSCallDescriptor(
95 info.zone(), false, i, CallDescriptor::kNoFlags);
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());
105 TEST(TestLinkageRuntimeCall) {
106 // TODO(titzer): test linkage creation for outgoing runtime calls.
110 TEST(TestLinkageStubCall) {
111 // TODO(titzer): test linkage creation for outgoing stub calls.
115 #endif // V8_TURBOFAN_TARGET