OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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_CODE_STUB_ASSEMBLER_H_ |
| 6 #define V8_CODE_STUB_ASSEMBLER_H_ |
| 7 |
| 8 #include "src/compiler/code-assembler.h" |
| 9 #include "src/objects.h" |
| 10 |
| 11 namespace v8 { |
| 12 namespace internal { |
| 13 |
| 14 class CallInterfaceDescriptor; |
| 15 |
| 16 // Provides JavaScript-specific "macro-assembler" functionality on top of the |
| 17 // CodeAssembler. By factoring the JavaScript-isms out of the CodeAssembler, |
| 18 // it's possible to add JavaScript-specific useful CodeAssembler "macros" |
| 19 // without modifying files in the compiler directory (and requiring a review |
| 20 // from a compiler directory OWNER). |
| 21 class CodeStubAssembler : public compiler::CodeAssembler { |
| 22 public: |
| 23 // Create with CallStub linkage. |
| 24 // |result_size| specifies the number of results returned by the stub. |
| 25 // TODO(rmcilroy): move result_size to the CallInterfaceDescriptor. |
| 26 CodeStubAssembler(Isolate* isolate, Zone* zone, |
| 27 const CallInterfaceDescriptor& descriptor, |
| 28 Code::Flags flags, const char* name, |
| 29 size_t result_size = 1); |
| 30 |
| 31 // Create with JSCall linkage. |
| 32 CodeStubAssembler(Isolate* isolate, Zone* zone, int parameter_count, |
| 33 Code::Flags flags, const char* name); |
| 34 |
| 35 // Float64 operations. |
| 36 compiler::Node* Float64Ceil(compiler::Node* x); |
| 37 compiler::Node* Float64Floor(compiler::Node* x); |
| 38 compiler::Node* Float64Round(compiler::Node* x); |
| 39 compiler::Node* Float64Trunc(compiler::Node* x); |
| 40 |
| 41 // Smi conversions. |
| 42 compiler::Node* SmiToFloat64(compiler::Node* value); |
| 43 compiler::Node* SmiFromWord32(compiler::Node* value); |
| 44 compiler::Node* SmiToWord(compiler::Node* value) { return SmiUntag(value); } |
| 45 compiler::Node* SmiToWord32(compiler::Node* value); |
| 46 |
| 47 // Smi operations. |
| 48 compiler::Node* SmiAdd(compiler::Node* a, compiler::Node* b); |
| 49 compiler::Node* SmiAddWithOverflow(compiler::Node* a, compiler::Node* b); |
| 50 compiler::Node* SmiSub(compiler::Node* a, compiler::Node* b); |
| 51 compiler::Node* SmiSubWithOverflow(compiler::Node* a, compiler::Node* b); |
| 52 compiler::Node* SmiEqual(compiler::Node* a, compiler::Node* b); |
| 53 compiler::Node* SmiAboveOrEqual(compiler::Node* a, compiler::Node* b); |
| 54 compiler::Node* SmiLessThan(compiler::Node* a, compiler::Node* b); |
| 55 compiler::Node* SmiLessThanOrEqual(compiler::Node* a, compiler::Node* b); |
| 56 compiler::Node* SmiMin(compiler::Node* a, compiler::Node* b); |
| 57 |
| 58 // Check a value for smi-ness |
| 59 compiler::Node* WordIsSmi(compiler::Node* a); |
| 60 // Check that the value is a positive smi. |
| 61 compiler::Node* WordIsPositiveSmi(compiler::Node* a); |
| 62 |
| 63 void BranchIfSmiLessThan(compiler::Node* a, compiler::Node* b, Label* if_true, |
| 64 Label* if_false) { |
| 65 BranchIf(SmiLessThan(a, b), if_true, if_false); |
| 66 } |
| 67 |
| 68 void BranchIfSmiLessThanOrEqual(compiler::Node* a, compiler::Node* b, |
| 69 Label* if_true, Label* if_false) { |
| 70 BranchIf(SmiLessThanOrEqual(a, b), if_true, if_false); |
| 71 } |
| 72 |
| 73 void BranchIfFloat64IsNaN(compiler::Node* value, Label* if_true, |
| 74 Label* if_false) { |
| 75 BranchIfFloat64Equal(value, value, if_false, if_true); |
| 76 } |
| 77 |
| 78 // Load an object pointer from a buffer that isn't in the heap. |
| 79 compiler::Node* LoadBufferObject(compiler::Node* buffer, int offset, |
| 80 MachineType rep = MachineType::AnyTagged()); |
| 81 // Load a field from an object on the heap. |
| 82 compiler::Node* LoadObjectField(compiler::Node* object, int offset, |
| 83 MachineType rep = MachineType::AnyTagged()); |
| 84 // Load the floating point value of a HeapNumber. |
| 85 compiler::Node* LoadHeapNumberValue(compiler::Node* object); |
| 86 // Load the Map of an HeapObject. |
| 87 compiler::Node* LoadMap(compiler::Node* object); |
| 88 // Load the instance type of an HeapObject. |
| 89 compiler::Node* LoadInstanceType(compiler::Node* object); |
| 90 // Load the elements backing store of a JSObject. |
| 91 compiler::Node* LoadElements(compiler::Node* object); |
| 92 // Load the length of a fixed array base instance. |
| 93 compiler::Node* LoadFixedArrayBaseLength(compiler::Node* array); |
| 94 // Load the bit field of a Map. |
| 95 compiler::Node* LoadMapBitField(compiler::Node* map); |
| 96 // Load bit field 2 of a map. |
| 97 compiler::Node* LoadMapBitField2(compiler::Node* map); |
| 98 // Load bit field 3 of a map. |
| 99 compiler::Node* LoadMapBitField3(compiler::Node* map); |
| 100 // Load the instance type of a map. |
| 101 compiler::Node* LoadMapInstanceType(compiler::Node* map); |
| 102 // Load the instance descriptors of a map. |
| 103 compiler::Node* LoadMapDescriptors(compiler::Node* map); |
| 104 |
| 105 // Load the hash field of a name. |
| 106 compiler::Node* LoadNameHash(compiler::Node* name); |
| 107 // Load the instance size of a Map. |
| 108 compiler::Node* LoadMapInstanceSize(compiler::Node* map); |
| 109 |
| 110 // Load an array element from a FixedArray. |
| 111 compiler::Node* LoadFixedArrayElementInt32Index(compiler::Node* object, |
| 112 compiler::Node* int32_index, |
| 113 int additional_offset = 0); |
| 114 compiler::Node* LoadFixedArrayElementSmiIndex(compiler::Node* object, |
| 115 compiler::Node* smi_index, |
| 116 int additional_offset = 0); |
| 117 compiler::Node* LoadFixedArrayElementConstantIndex(compiler::Node* object, |
| 118 int index); |
| 119 |
| 120 // Store the floating point value of a HeapNumber. |
| 121 compiler::Node* StoreHeapNumberValue(compiler::Node* object, |
| 122 compiler::Node* value); |
| 123 // Store a field to an object on the heap. |
| 124 compiler::Node* StoreObjectFieldNoWriteBarrier( |
| 125 compiler::Node* object, int offset, compiler::Node* value, |
| 126 MachineRepresentation rep = MachineRepresentation::kTagged); |
| 127 // Store the Map of an HeapObject. |
| 128 compiler::Node* StoreMapNoWriteBarrier(compiler::Node* object, |
| 129 compiler::Node* map); |
| 130 // Store an array element to a FixedArray. |
| 131 compiler::Node* StoreFixedArrayElementInt32Index(compiler::Node* object, |
| 132 compiler::Node* index, |
| 133 compiler::Node* value); |
| 134 compiler::Node* StoreFixedArrayElementNoWriteBarrier(compiler::Node* object, |
| 135 compiler::Node* index, |
| 136 compiler::Node* value); |
| 137 |
| 138 // Allocate a HeapNumber without initializing its value. |
| 139 compiler::Node* AllocateHeapNumber(); |
| 140 // Allocate a HeapNumber with a specific value. |
| 141 compiler::Node* AllocateHeapNumberWithValue(compiler::Node* value); |
| 142 // Allocate a SeqOneByteString with the given length. |
| 143 compiler::Node* AllocateSeqOneByteString(int length); |
| 144 // Allocate a SeqTwoByteString with the given length. |
| 145 compiler::Node* AllocateSeqTwoByteString(int length); |
| 146 |
| 147 compiler::Node* TruncateTaggedToFloat64(compiler::Node* context, |
| 148 compiler::Node* value); |
| 149 compiler::Node* TruncateTaggedToWord32(compiler::Node* context, |
| 150 compiler::Node* value); |
| 151 // Truncate to int32 using JavaScript truncation mode. |
| 152 compiler::Node* TruncateFloat64ToInt32(compiler::Node* value); |
| 153 // Truncate the floating point value of a HeapNumber to an Int32. |
| 154 compiler::Node* TruncateHeapNumberValueToWord32(compiler::Node* object); |
| 155 |
| 156 // Conversions. |
| 157 compiler::Node* ChangeFloat64ToTagged(compiler::Node* value); |
| 158 compiler::Node* ChangeInt32ToTagged(compiler::Node* value); |
| 159 compiler::Node* ChangeUint32ToTagged(compiler::Node* value); |
| 160 |
| 161 // Type conversions. |
| 162 // Throws a TypeError for {method_name} if {value} is not coercible to Object, |
| 163 // or returns the {value} converted to a String otherwise. |
| 164 compiler::Node* ToThisString(compiler::Node* context, compiler::Node* value, |
| 165 char const* method_name); |
| 166 |
| 167 // String helpers. |
| 168 // Load a character from a String (might flatten a ConsString). |
| 169 compiler::Node* StringCharCodeAt(compiler::Node* string, |
| 170 compiler::Node* smi_index); |
| 171 // Return the single character string with only {code}. |
| 172 compiler::Node* StringFromCharCode(compiler::Node* code); |
| 173 |
| 174 // Returns a node that is true if the given bit is set in |word32|. |
| 175 template <typename T> |
| 176 compiler::Node* BitFieldDecode(compiler::Node* word32) { |
| 177 return BitFieldDecode(word32, T::kShift, T::kMask); |
| 178 } |
| 179 |
| 180 compiler::Node* BitFieldDecode(compiler::Node* word32, uint32_t shift, |
| 181 uint32_t mask); |
| 182 }; |
| 183 |
| 184 } // namespace internal |
| 185 } // namespace v8 |
| 186 |
| 187 #endif // V8_CODE_STUB_ASSEMBLER_H_ |
OLD | NEW |