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 = isolate->factory() 33 ->NewStringFromUtf8(CStrVector(source)) 34 .ToHandleChecked(); 35 Handle<SharedFunctionInfo> shared_function = Compiler::CompileScript( 36 source_code, Handle<String>(), 0, 0, false, 37 Handle<Context>(isolate->native_context()), NULL, NULL, 38 v8::ScriptCompiler::kNoCompileOptions, NOT_NATIVES_CODE); 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 Linkage linkage(&info); 49 } 50 51 52 TEST(TestLinkageJSFunctionIncoming) { 53 InitializedHandleScope handles; 54 55 const char* sources[] = {"(function() { })", "(function(a) { })", 56 "(function(a,b) { })", "(function(a,b,c) { })"}; 57 58 for (int i = 0; i < 3; i++) { 59 i::HandleScope handles(CcTest::i_isolate()); 60 Handle<JSFunction> function = v8::Utils::OpenHandle( 61 *v8::Handle<v8::Function>::Cast(CompileRun(sources[i]))); 62 CompilationInfoWithZone info(function); 63 Linkage linkage(&info); 64 65 CallDescriptor* descriptor = linkage.GetIncomingDescriptor(); 66 CHECK_NE(NULL, descriptor); 67 68 CHECK_EQ(1 + i, descriptor->JSParameterCount()); 69 CHECK_EQ(1, 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 CompilationInfoWithZone info(static_cast<HydrogenCodeStub*>(NULL), isolate); 79 Linkage linkage(&info); 80 // TODO(titzer): test linkage creation with a bonafide code stub. 81 // this just checks current behavior. 82 CHECK_EQ(NULL, linkage.GetIncomingDescriptor()); 83 } 84 85 86 TEST(TestLinkageJSCall) { 87 HandleAndZoneScope handles; 88 Handle<JSFunction> function = Compile("a + c"); 89 CompilationInfoWithZone info(function); 90 Linkage linkage(&info); 91 92 for (int i = 0; i < 32; i++) { 93 CallDescriptor* descriptor = linkage.GetJSCallDescriptor(i); 94 CHECK_NE(NULL, descriptor); 95 CHECK_EQ(i, descriptor->JSParameterCount()); 96 CHECK_EQ(1, descriptor->ReturnCount()); 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 114