Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(634)

Side by Side Diff: src/compiler/machine-type.h

Issue 530783002: Convert Linkage to use MachineSignature. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Another try at size_t. Staunch the bleeding. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "src/globals.h" 8 #include "src/globals.h"
9 #include "src/zone.h"
9 10
10 namespace v8 { 11 namespace v8 {
11 namespace internal { 12 namespace internal {
12 13
13 class OStream; 14 class OStream;
14 15
15 namespace compiler { 16 namespace compiler {
16 17
17 // Machine-level types and representations. 18 // Machine-level types and representations.
18 // TODO(titzer): Use the real type system instead of MachineType. 19 // TODO(titzer): Use the real type system instead of MachineType.
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 case kRepFloat64: 102 case kRepFloat64:
102 return 8; 103 return 8;
103 case kRepTagged: 104 case kRepTagged:
104 return kPointerSize; 105 return kPointerSize;
105 default: 106 default:
106 UNREACHABLE(); 107 UNREACHABLE();
107 return kPointerSize; 108 return kPointerSize;
108 } 109 }
109 } 110 }
110 111
111 // Describes the inputs and outputs of a function or call in terms of machine 112 // Describes the inputs and outputs of a function or call.
112 // types. 113 template <typename T>
113 class MachineSignature { 114 class Signature : public ZoneObject {
114 public: 115 public:
115 MachineSignature(uint8_t return_count, uint16_t param_count, 116 Signature(size_t return_count, size_t parameter_count, T* reps)
116 MachineType* reps) 117 : return_count_(return_count),
117 : return_count_(return_count), param_count_(param_count), reps_(reps) {} 118 parameter_count_(parameter_count),
119 reps_(reps) {}
118 120
119 int GetReturnCount() const { return return_count_; } 121 size_t return_count() const { return return_count_; }
120 int GetParamCount() const { return param_count_; } 122 size_t parameter_count() const { return parameter_count_; }
121 123
122 MachineType GetParameterType(int index) const { 124 T GetParam(size_t index) const {
123 DCHECK(index >= 0 && index < param_count_); 125 DCHECK(index < parameter_count_);
124 return reps_[return_count_ + index]; 126 return reps_[return_count_ + index];
125 } 127 }
126 128
127 MachineType GetReturnType(int index = 0) const { 129 T GetReturn(size_t index = 0) const {
128 DCHECK(index >= 0 && index < return_count_); 130 DCHECK(index < return_count_);
129 return reps_[index]; 131 return reps_[index];
130 } 132 }
131 133
134 // For incrementally building signatures.
135 class Builder {
136 public:
137 Builder(Zone* zone, size_t return_count, size_t parameter_count)
138 : return_count_(return_count),
139 parameter_count_(parameter_count),
140 zone_(zone),
141 rcursor_(0),
142 pcursor_(0),
143 buffer_(zone->NewArray<T>(
144 static_cast<int>(return_count + parameter_count))) {}
145
146 const size_t return_count_;
147 const size_t parameter_count_;
148
149 void AddReturn(T val) {
150 DCHECK(rcursor_ < return_count_);
151 buffer_[rcursor_++] = val;
152 }
153 void AddParam(T val) {
154 DCHECK(pcursor_ < parameter_count_);
155 buffer_[return_count_ + pcursor_++] = val;
156 }
157 Signature<T>* Build() {
158 DCHECK(rcursor_ == return_count_);
159 DCHECK(pcursor_ == parameter_count_);
160 return new (zone_) Signature<T>(return_count_, parameter_count_, buffer_);
161 }
162
163 private:
164 Zone* zone_;
165 size_t rcursor_;
166 size_t pcursor_;
167 T* buffer_;
168 };
169
132 protected: 170 protected:
133 uint8_t return_count_; 171 size_t return_count_;
134 uint16_t param_count_; 172 size_t parameter_count_;
135 MachineType* reps_; 173 T* reps_;
136 }; 174 };
175
176 typedef Signature<MachineType> MachineSignature;
137 } // namespace compiler 177 } // namespace compiler
138 } // namespace internal 178 } // namespace internal
139 } // namespace v8 179 } // namespace v8
140 180
141 #endif // V8_COMPILER_MACHINE_TYPE_H_ 181 #endif // V8_COMPILER_MACHINE_TYPE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698