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_TYPE_H_ | 5 #ifndef V8_COMPILER_MACHINE_TYPE_H_ |
6 #define V8_COMPILER_MACHINE_TYPE_H_ | 6 #define V8_COMPILER_MACHINE_TYPE_H_ |
7 | 7 |
8 #include <iosfwd> | 8 #include <iosfwd> |
9 | 9 |
10 #include "src/base/bits.h" | 10 #include "src/base/bits.h" |
11 #include "src/globals.h" | 11 #include "src/globals.h" |
| 12 #include "src/signature.h" |
12 #include "src/zone.h" | 13 #include "src/zone.h" |
13 | 14 |
14 namespace v8 { | 15 namespace v8 { |
15 namespace internal { | 16 namespace internal { |
16 namespace compiler { | 17 namespace compiler { |
17 | 18 |
18 // Machine-level types and representations. | 19 // Machine-level types and representations. |
19 // TODO(titzer): Use the real type system instead of MachineType. | 20 // TODO(titzer): Use the real type system instead of MachineType. |
20 enum MachineType { | 21 enum MachineType { |
21 // Representations. | 22 // Representations. |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 return -1; | 105 return -1; |
105 } | 106 } |
106 | 107 |
107 // Gets the element size in bytes of the machine type. | 108 // Gets the element size in bytes of the machine type. |
108 inline int ElementSizeOf(MachineType machine_type) { | 109 inline int ElementSizeOf(MachineType machine_type) { |
109 const int shift = ElementSizeLog2Of(machine_type); | 110 const int shift = ElementSizeLog2Of(machine_type); |
110 DCHECK_NE(-1, shift); | 111 DCHECK_NE(-1, shift); |
111 return 1 << shift; | 112 return 1 << shift; |
112 } | 113 } |
113 | 114 |
114 // Describes the inputs and outputs of a function or call. | |
115 template <typename T> | |
116 class Signature : public ZoneObject { | |
117 public: | |
118 Signature(size_t return_count, size_t parameter_count, T* reps) | |
119 : return_count_(return_count), | |
120 parameter_count_(parameter_count), | |
121 reps_(reps) {} | |
122 | |
123 size_t return_count() const { return return_count_; } | |
124 size_t parameter_count() const { return parameter_count_; } | |
125 | |
126 T GetParam(size_t index) const { | |
127 DCHECK(index < parameter_count_); | |
128 return reps_[return_count_ + index]; | |
129 } | |
130 | |
131 T GetReturn(size_t index = 0) const { | |
132 DCHECK(index < return_count_); | |
133 return reps_[index]; | |
134 } | |
135 | |
136 // For incrementally building signatures. | |
137 class Builder { | |
138 public: | |
139 Builder(Zone* zone, size_t return_count, size_t parameter_count) | |
140 : return_count_(return_count), | |
141 parameter_count_(parameter_count), | |
142 zone_(zone), | |
143 rcursor_(0), | |
144 pcursor_(0), | |
145 buffer_(zone->NewArray<T>( | |
146 static_cast<int>(return_count + parameter_count))) {} | |
147 | |
148 const size_t return_count_; | |
149 const size_t parameter_count_; | |
150 | |
151 void AddReturn(T val) { | |
152 DCHECK(rcursor_ < return_count_); | |
153 buffer_[rcursor_++] = val; | |
154 } | |
155 void AddParam(T val) { | |
156 DCHECK(pcursor_ < parameter_count_); | |
157 buffer_[return_count_ + pcursor_++] = val; | |
158 } | |
159 Signature<T>* Build() { | |
160 DCHECK(rcursor_ == return_count_); | |
161 DCHECK(pcursor_ == parameter_count_); | |
162 return new (zone_) Signature<T>(return_count_, parameter_count_, buffer_); | |
163 } | |
164 | |
165 private: | |
166 Zone* zone_; | |
167 size_t rcursor_; | |
168 size_t pcursor_; | |
169 T* buffer_; | |
170 }; | |
171 | |
172 protected: | |
173 size_t return_count_; | |
174 size_t parameter_count_; | |
175 T* reps_; | |
176 }; | |
177 | |
178 typedef Signature<MachineType> MachineSignature; | 115 typedef Signature<MachineType> MachineSignature; |
179 } // namespace compiler | 116 } // namespace compiler |
180 } // namespace internal | 117 } // namespace internal |
181 } // namespace v8 | 118 } // namespace v8 |
182 | 119 |
183 #endif // V8_COMPILER_MACHINE_TYPE_H_ | 120 #endif // V8_COMPILER_MACHINE_TYPE_H_ |
OLD | NEW |