Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 1 | // Copyright 2015 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 | #ifndef V8_COMPILER_CODE_STUB_ASSEMBLER_H_ |
| 6 | #define V8_COMPILER_CODE_STUB_ASSEMBLER_H_ |
| 7 | |
| 8 | // Clients of this interface shouldn't depend on lots of compiler internals. |
| 9 | // Do not include anything from src/compiler here! |
| 10 | #include "src/allocation.h" |
| 11 | #include "src/builtins.h" |
| 12 | #include "src/runtime/runtime.h" |
| 13 | |
| 14 | namespace v8 { |
| 15 | namespace internal { |
| 16 | |
| 17 | class CallInterfaceDescriptor; |
| 18 | class Isolate; |
| 19 | class Zone; |
| 20 | |
| 21 | namespace compiler { |
| 22 | |
| 23 | class CallDescriptor; |
| 24 | class Graph; |
| 25 | class Node; |
| 26 | class Operator; |
| 27 | class RawMachineAssembler; |
| 28 | class Schedule; |
| 29 | |
| 30 | class CodeStubAssembler { |
| 31 | public: |
| 32 | CodeStubAssembler(Isolate* isolate, Zone* zone, |
| 33 | const CallInterfaceDescriptor& descriptor, Code::Kind kind, |
| 34 | const char* name); |
| 35 | virtual ~CodeStubAssembler(); |
| 36 | |
| 37 | Handle<Code> GenerateCode(); |
| 38 | |
| 39 | // Constants. |
| 40 | Node* Int32Constant(int value); |
| 41 | Node* IntPtrConstant(intptr_t value); |
| 42 | Node* NumberConstant(double value); |
| 43 | Node* HeapConstant(Handle<HeapObject> object); |
| 44 | Node* BooleanConstant(bool value); |
| 45 | |
| 46 | Node* Parameter(int value); |
| 47 | void Return(Node* value); |
| 48 | |
| 49 | // Tag and untag Smi values. |
| 50 | Node* SmiTag(Node* value); |
| 51 | Node* SmiUntag(Node* value); |
| 52 | |
| 53 | // Basic arithmetic operations. |
| 54 | Node* IntPtrAdd(Node* a, Node* b); |
| 55 | Node* IntPtrSub(Node* a, Node* b); |
| 56 | Node* WordShl(Node* value, int shift); |
| 57 | |
| 58 | // Load a field from an object on the heap. |
| 59 | Node* LoadObjectField(Node* object, int offset); |
| 60 | |
| 61 | // Call runtime function. |
| 62 | Node* CallRuntime(Runtime::FunctionId function_id, Node* context, Node* arg1); |
| 63 | Node* CallRuntime(Runtime::FunctionId function_id, Node* context, Node* arg1, |
| 64 | Node* arg2); |
| 65 | |
| 66 | Node* TailCallRuntime(Runtime::FunctionId function_id, Node* context, |
| 67 | Node* arg1); |
| 68 | Node* TailCallRuntime(Runtime::FunctionId function_id, Node* context, |
| 69 | Node* arg1, Node* arg2); |
| 70 | |
| 71 | private: |
| 72 | friend class CodeStubAssemblerTester; |
| 73 | |
| 74 | Node* CallN(CallDescriptor* descriptor, Node* code_target, Node** args); |
| 75 | Node* TailCallN(CallDescriptor* descriptor, Node* code_target, Node** args); |
| 76 | |
| 77 | Node* SmiShiftBitsConstant(); |
| 78 | |
| 79 | // Private helpers which delegate to RawMachineAssembler. |
| 80 | Graph* graph(); |
| 81 | Isolate* isolate(); |
| 82 | Zone* zone(); |
| 83 | |
| 84 | base::SmartPointer<RawMachineAssembler> raw_assembler_; |
| 85 | Code::Kind kind_; |
| 86 | const char* name_; |
| 87 | bool code_generated_; |
| 88 | |
| 89 | DISALLOW_COPY_AND_ASSIGN(CodeStubAssembler); |
| 90 | }; |
| 91 | |
| 92 | } // namespace compiler |
| 93 | } // namespace internal |
| 94 | } // namespace v8 |
| 95 | |
| 96 | #endif // V8_COMPILER_CODE_STUB_ASSEMBLER_H_ |