OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_COMPILER_MACHINE_NODE_FACTORY_H_ | 5 #ifndef V8_COMPILER_MACHINE_NODE_FACTORY_H_ |
6 #define V8_COMPILER_MACHINE_NODE_FACTORY_H_ | 6 #define V8_COMPILER_MACHINE_NODE_FACTORY_H_ |
7 | 7 |
8 #ifdef USE_SIMULATOR | 8 #ifdef USE_SIMULATOR |
9 #define MACHINE_ASSEMBLER_SUPPORTS_CALL_C 0 | 9 #define MACHINE_ASSEMBLER_SUPPORTS_CALL_C 0 |
10 #else | 10 #else |
11 #define MACHINE_ASSEMBLER_SUPPORTS_CALL_C 1 | 11 #define MACHINE_ASSEMBLER_SUPPORTS_CALL_C 1 |
12 #endif | 12 #endif |
13 | 13 |
14 #include "src/v8.h" | 14 #include "src/v8.h" |
15 | 15 |
16 #include "src/compiler/machine-operator.h" | 16 #include "src/compiler/machine-operator.h" |
17 #include "src/compiler/node.h" | 17 #include "src/compiler/node.h" |
18 | 18 |
19 namespace v8 { | 19 namespace v8 { |
20 namespace internal { | 20 namespace internal { |
21 namespace compiler { | 21 namespace compiler { |
22 | 22 |
23 class MachineCallDescriptorBuilder : public ZoneObject { | |
24 public: | |
25 MachineCallDescriptorBuilder(MachineType return_type, int parameter_count, | |
26 const MachineType* parameter_types) | |
27 : return_type_(return_type), | |
28 parameter_count_(parameter_count), | |
29 parameter_types_(parameter_types) {} | |
30 | |
31 int parameter_count() const { return parameter_count_; } | |
32 const MachineType* parameter_types() const { return parameter_types_; } | |
33 | |
34 CallDescriptor* BuildCallDescriptor(Zone* zone) { | |
35 return Linkage::GetSimplifiedCDescriptor(zone, parameter_count_, | |
36 return_type_, parameter_types_); | |
37 } | |
38 | |
39 private: | |
40 const MachineType return_type_; | |
41 const int parameter_count_; | |
42 const MachineType* const parameter_types_; | |
43 }; | |
44 | |
45 | |
46 #define ZONE() static_cast<NodeFactory*>(this)->zone() | 23 #define ZONE() static_cast<NodeFactory*>(this)->zone() |
47 #define COMMON() static_cast<NodeFactory*>(this)->common() | 24 #define COMMON() static_cast<NodeFactory*>(this)->common() |
48 #define MACHINE() static_cast<NodeFactory*>(this)->machine() | 25 #define MACHINE() static_cast<NodeFactory*>(this)->machine() |
| 26 #define MACHINE_SIG() static_cast<NodeFactory*>(this)->machine_sig() |
49 #define NEW_NODE_0(op) static_cast<NodeFactory*>(this)->NewNode(op) | 27 #define NEW_NODE_0(op) static_cast<NodeFactory*>(this)->NewNode(op) |
50 #define NEW_NODE_1(op, a) static_cast<NodeFactory*>(this)->NewNode(op, a) | 28 #define NEW_NODE_1(op, a) static_cast<NodeFactory*>(this)->NewNode(op, a) |
51 #define NEW_NODE_2(op, a, b) static_cast<NodeFactory*>(this)->NewNode(op, a, b) | 29 #define NEW_NODE_2(op, a, b) static_cast<NodeFactory*>(this)->NewNode(op, a, b) |
52 #define NEW_NODE_3(op, a, b, c) \ | 30 #define NEW_NODE_3(op, a, b, c) \ |
53 static_cast<NodeFactory*>(this)->NewNode(op, a, b, c) | 31 static_cast<NodeFactory*>(this)->NewNode(op, a, b, c) |
54 | 32 |
55 template <typename NodeFactory> | 33 template <typename NodeFactory> |
56 class MachineNodeFactory { | 34 class MachineNodeFactory { |
57 public: | 35 public: |
58 // Constants. | 36 // Constants. |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 return NEW_NODE_1(MACHINE()->TruncateFloat64ToInt32(), a); | 340 return NEW_NODE_1(MACHINE()->TruncateFloat64ToInt32(), a); |
363 } | 341 } |
364 Node* TruncateInt64ToInt32(Node* a) { | 342 Node* TruncateInt64ToInt32(Node* a) { |
365 return NEW_NODE_1(MACHINE()->TruncateInt64ToInt32(), a); | 343 return NEW_NODE_1(MACHINE()->TruncateInt64ToInt32(), a); |
366 } | 344 } |
367 | 345 |
368 #ifdef MACHINE_ASSEMBLER_SUPPORTS_CALL_C | 346 #ifdef MACHINE_ASSEMBLER_SUPPORTS_CALL_C |
369 // Call to C. | 347 // Call to C. |
370 Node* CallC(Node* function_address, MachineType return_type, | 348 Node* CallC(Node* function_address, MachineType return_type, |
371 MachineType* arg_types, Node** args, int n_args) { | 349 MachineType* arg_types, Node** args, int n_args) { |
372 CallDescriptor* descriptor = Linkage::GetSimplifiedCDescriptor( | 350 CallDescriptor* descriptor = |
373 ZONE(), n_args, return_type, arg_types); | 351 Linkage::GetSimplifiedCDescriptor(ZONE(), MACHINE_SIG()); |
374 Node** passed_args = | 352 Node** passed_args = |
375 static_cast<Node**>(alloca((n_args + 1) * sizeof(args[0]))); | 353 static_cast<Node**>(alloca((n_args + 1) * sizeof(args[0]))); |
376 passed_args[0] = function_address; | 354 passed_args[0] = function_address; |
377 for (int i = 0; i < n_args; ++i) { | 355 for (int i = 0; i < n_args; ++i) { |
378 passed_args[i + 1] = args[i]; | 356 passed_args[i + 1] = args[i]; |
379 } | 357 } |
380 return NEW_NODE_2(COMMON()->Call(descriptor), n_args + 1, passed_args); | 358 return NEW_NODE_2(COMMON()->Call(descriptor), n_args + 1, passed_args); |
381 } | 359 } |
382 #endif | 360 #endif |
383 }; | 361 }; |
384 | 362 |
385 #undef NEW_NODE_0 | 363 #undef NEW_NODE_0 |
386 #undef NEW_NODE_1 | 364 #undef NEW_NODE_1 |
387 #undef NEW_NODE_2 | 365 #undef NEW_NODE_2 |
388 #undef NEW_NODE_3 | 366 #undef NEW_NODE_3 |
389 #undef MACHINE | 367 #undef MACHINE |
390 #undef COMMON | 368 #undef COMMON |
391 #undef ZONE | 369 #undef ZONE |
392 | 370 |
393 } // namespace compiler | 371 } // namespace compiler |
394 } // namespace internal | 372 } // namespace internal |
395 } // namespace v8 | 373 } // namespace v8 |
396 | 374 |
397 #endif // V8_COMPILER_MACHINE_NODE_FACTORY_H_ | 375 #endif // V8_COMPILER_MACHINE_NODE_FACTORY_H_ |
OLD | NEW |