OLD | NEW |
(Empty) | |
| 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" |
| 11 #include "src/compiler/generic-node-inl.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 SimpleOperator dummy_operator(IrOpcode::kParameter, Operator::kNoWrite, |
| 27 0, 0, "dummy"); |
| 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 = |
| 33 isolate->factory()->NewStringFromUtf8(CStrVector(source)) |
| 34 .ToHandleChecked(); |
| 35 Handle<SharedFunctionInfo> shared_function = |
| 36 Compiler::CompileScript(source_code, |
| 37 Handle<String>(), |
| 38 0, |
| 39 0, |
| 40 false, |
| 41 Handle<Context>(isolate->native_context()), |
| 42 NULL, NULL, |
| 43 v8::ScriptCompiler::kNoCompileOptions, |
| 44 NOT_NATIVES_CODE); |
| 45 return isolate->factory()->NewFunctionFromSharedFunctionInfo( |
| 46 shared_function, isolate->native_context()); |
| 47 } |
| 48 |
| 49 |
| 50 |
| 51 TEST(TestLinkageCreate) { |
| 52 InitializedHandleScope handles; |
| 53 Handle<JSFunction> function = Compile("a + b"); |
| 54 CompilationInfoWithZone info(function); |
| 55 Linkage linkage(&info); |
| 56 } |
| 57 |
| 58 |
| 59 TEST(TestLinkageJSFunctionIncoming) { |
| 60 InitializedHandleScope handles; |
| 61 |
| 62 const char* sources[] = { |
| 63 "(function() { })", |
| 64 "(function(a) { })", |
| 65 "(function(a,b) { })", |
| 66 "(function(a,b,c) { })" |
| 67 }; |
| 68 |
| 69 for (int i = 0; i < 3; i++) { |
| 70 i::HandleScope handles(CcTest::i_isolate()); |
| 71 Handle<JSFunction> function = v8::Utils::OpenHandle( |
| 72 *v8::Handle<v8::Function>::Cast(CompileRun(sources[i]))); |
| 73 CompilationInfoWithZone info(function); |
| 74 Linkage linkage(&info); |
| 75 |
| 76 CallDescriptor* descriptor = linkage.GetIncomingDescriptor(); |
| 77 CHECK_NE(NULL, descriptor); |
| 78 |
| 79 CHECK_EQ(1 + i, descriptor->ParameterCount()); |
| 80 CHECK_EQ(1, descriptor->ReturnCount()); |
| 81 CHECK_EQ(Operator::kNoProperties, descriptor->properties()); |
| 82 CHECK_EQ(true, descriptor->IsJSFunctionCall()); |
| 83 } |
| 84 } |
| 85 |
| 86 |
| 87 TEST(TestLinkageCodeStubIncoming) { |
| 88 Isolate* isolate = CcTest::InitIsolateOnce(); |
| 89 CompilationInfoWithZone info(static_cast<HydrogenCodeStub*>(NULL), isolate); |
| 90 Linkage linkage(&info); |
| 91 // TODO(titzer): test linkage creation with a bonafide code stub. |
| 92 // this just checks current behavior. |
| 93 CHECK_EQ(NULL, linkage.GetIncomingDescriptor()); |
| 94 } |
| 95 |
| 96 |
| 97 TEST(TestLinkageJSCall) { |
| 98 HandleAndZoneScope handles; |
| 99 Handle<JSFunction> function = Compile("a + c"); |
| 100 CompilationInfoWithZone info(function); |
| 101 Linkage linkage(&info); |
| 102 |
| 103 for (int i = 0; i < 32; i++) { |
| 104 CallDescriptor* descriptor = linkage.GetJSCallDescriptor(i); |
| 105 CHECK_NE(NULL, descriptor); |
| 106 CHECK_EQ(i, descriptor->ParameterCount()); |
| 107 CHECK_EQ(1, descriptor->ReturnCount()); |
| 108 CHECK_EQ(Operator::kNoProperties, descriptor->properties()); |
| 109 CHECK_EQ(true, descriptor->IsJSFunctionCall()); |
| 110 } |
| 111 } |
| 112 |
| 113 |
| 114 TEST(TestLinkageRuntimeCall) { |
| 115 // TODO(titzer): test linkage creation for outgoing runtime calls. |
| 116 } |
| 117 |
| 118 |
| 119 TEST(TestLinkageStubCall) { |
| 120 // TODO(titzer): test linkage creation for outgoing stub calls. |
| 121 } |
| 122 |
| 123 |
| 124 #endif // V8_TURBOFAN_TARGET |
OLD | NEW |