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 "test/cctest/compiler/graph-builder-tester.h" |
| 6 | |
| 7 | #include "src/compiler/linkage.h" |
| 8 | #include "src/compiler/pipeline.h" |
| 9 | |
| 10 | namespace v8 { |
| 11 | namespace internal { |
| 12 | namespace compiler { |
| 13 | |
| 14 | MachineCallHelper::MachineCallHelper(Zone* zone, MachineSignature* machine_sig) |
| 15 | : CallHelper(zone->isolate(), machine_sig), |
| 16 | parameters_(NULL), |
| 17 | graph_(NULL) {} |
| 18 | |
| 19 | |
| 20 | void MachineCallHelper::InitParameters(GraphBuilder* builder, |
| 21 | CommonOperatorBuilder* common) { |
| 22 | DCHECK_EQ(NULL, parameters_); |
| 23 | graph_ = builder->graph(); |
| 24 | int param_count = static_cast<int>(parameter_count()); |
| 25 | if (param_count == 0) return; |
| 26 | parameters_ = graph_->zone()->NewArray<Node*>(param_count); |
| 27 | for (int i = 0; i < param_count; ++i) { |
| 28 | parameters_[i] = builder->NewNode(common->Parameter(i), graph_->start()); |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | |
| 33 | byte* MachineCallHelper::Generate() { |
| 34 | DCHECK(parameter_count() == 0 || parameters_ != NULL); |
| 35 | if (!Pipeline::SupportedBackend()) return NULL; |
| 36 | if (code_.is_null()) { |
| 37 | Zone* zone = graph_->zone(); |
| 38 | CompilationInfo info(zone->isolate(), zone); |
| 39 | Linkage linkage(&info, |
| 40 | Linkage::GetSimplifiedCDescriptor(zone, machine_sig_)); |
| 41 | Pipeline pipeline(&info); |
| 42 | code_ = pipeline.GenerateCodeForMachineGraph(&linkage, graph_); |
| 43 | } |
| 44 | return code_.ToHandleChecked()->entry(); |
| 45 | } |
| 46 | |
| 47 | |
| 48 | Node* MachineCallHelper::Parameter(size_t index) { |
| 49 | DCHECK_NE(NULL, parameters_); |
| 50 | DCHECK(index < parameter_count()); |
| 51 | return parameters_[index]; |
| 52 | } |
| 53 | |
| 54 | } // namespace compiler |
| 55 | } // namespace internal |
| 56 | } // namespace v8 |