Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 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/compiler.h" |
| 8 | #include "src/zone.h" |
| 9 | |
| 10 | #include "src/compiler/common-operator.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 11 | #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 | |
| 22 | using namespace v8::internal; |
| 23 | using namespace v8::internal::compiler; |
| 24 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 25 | static Operator dummy_operator(IrOpcode::kParameter, Operator::kNoWrite, |
| 26 | "dummy", 0, 0, 0, 0, 0, 0); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 27 | |
| 28 | // So we can get a real JS function. |
| 29 | static 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 | |
| 43 | TEST(TestLinkageCreate) { |
| 44 | InitializedHandleScope handles; |
| 45 | Handle<JSFunction> function = Compile("a + b"); |
| 46 | CompilationInfoWithZone info(function); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 47 | Linkage linkage(info.zone(), &info); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | |
| 51 | TEST(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 Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 62 | Linkage linkage(info.zone(), &info); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 63 | |
| 64 | CallDescriptor* descriptor = linkage.GetIncomingDescriptor(); |
| 65 | CHECK_NE(NULL, descriptor); |
| 66 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 67 | CHECK_EQ(1 + i, static_cast<int>(descriptor->JSParameterCount())); |
| 68 | CHECK_EQ(1, static_cast<int>(descriptor->ReturnCount())); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 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 | CompilationInfoWithZone info(static_cast<HydrogenCodeStub*>(NULL), isolate); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 78 | Linkage linkage(info.zone(), &info); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 79 | // 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 | |
| 85 | TEST(TestLinkageJSCall) { |
| 86 | HandleAndZoneScope handles; |
| 87 | Handle<JSFunction> function = Compile("a + c"); |
| 88 | CompilationInfoWithZone info(function); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 89 | Linkage linkage(info.zone(), &info); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 90 | |
| 91 | for (int i = 0; i < 32; i++) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 92 | CallDescriptor* descriptor = |
| 93 | linkage.GetJSCallDescriptor(i, CallDescriptor::kNoFlags); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 94 | CHECK_NE(NULL, descriptor); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 95 | CHECK_EQ(i, static_cast<int>(descriptor->JSParameterCount())); |
| 96 | CHECK_EQ(1, static_cast<int>(descriptor->ReturnCount())); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 97 | CHECK_EQ(Operator::kNoProperties, descriptor->properties()); |
| 98 | CHECK_EQ(true, descriptor->IsJSFunctionCall()); |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | |
| 103 | TEST(TestLinkageRuntimeCall) { |
| 104 | // TODO(titzer): test linkage creation for outgoing runtime calls. |
| 105 | } |
| 106 | |
| 107 | |
| 108 | TEST(TestLinkageStubCall) { |
| 109 | // TODO(titzer): test linkage creation for outgoing stub calls. |
| 110 | } |
| 111 | |
| 112 | |
| 113 | #endif // V8_TURBOFAN_TARGET |