OLD | NEW |
---|---|
1 // Copyright 2015 the V8 project authors. All rights reserved. | 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 | 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 #include "src/signature.h" | 5 #include "src/signature.h" |
6 | 6 |
7 #include "src/handles.h" | 7 #include "src/handles.h" |
8 #include "src/v8.h" | 8 #include "src/v8.h" |
9 #include "src/zone-containers.h" | 9 #include "src/zone-containers.h" |
10 | 10 |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
188 sig.AddParam(static_cast<LocalType>(e->params_[i])); | 188 sig.AddParam(static_cast<LocalType>(e->params_[i])); |
189 } | 189 } |
190 e->signature_index_ = mb->AddSignature(sig.Build()); | 190 e->signature_index_ = mb->AddSignature(sig.Build()); |
191 e->name_.insert(e->name_.begin(), name_.begin(), name_.end()); | 191 e->name_.insert(e->name_.begin(), name_.begin(), name_.end()); |
192 return e; | 192 return e; |
193 } | 193 } |
194 | 194 |
195 | 195 |
196 void WasmFunctionBuilder::IndexVars(WasmFunctionEncoder* e, | 196 void WasmFunctionBuilder::IndexVars(WasmFunctionEncoder* e, |
197 uint16_t* var_index) const { | 197 uint16_t* var_index) const { |
198 // TODO(titzer): all of this is unnecessary now. | |
198 uint16_t param = 0; | 199 uint16_t param = 0; |
199 uint16_t i32 = 0; | 200 uint16_t i32 = 0; |
200 uint16_t i64 = 0; | 201 uint16_t i64 = 0; |
201 uint16_t f32 = 0; | 202 uint16_t f32 = 0; |
202 uint16_t f64 = 0; | 203 uint16_t f64 = 0; |
203 for (size_t i = 0; i < locals_.size(); i++) { | 204 for (size_t i = 0; i < locals_.size(); i++) { |
204 if (locals_.at(i).param_) { | 205 if (locals_.at(i).param_) { |
205 param++; | 206 param++; |
206 } else if (locals_.at(i).type_ == kAstI32) { | 207 } else if (locals_.at(i).type_ == kAstI32) { |
207 i32++; | 208 i32++; |
208 } else if (locals_.at(i).type_ == kAstI64) { | 209 } else if (locals_.at(i).type_ == kAstI64) { |
209 i64++; | 210 i64++; |
210 } else if (locals_.at(i).type_ == kAstF32) { | 211 } else if (locals_.at(i).type_ == kAstF32) { |
211 f32++; | 212 f32++; |
212 } else if (locals_.at(i).type_ == kAstF64) { | 213 } else if (locals_.at(i).type_ == kAstF64) { |
213 f64++; | 214 f64++; |
214 } | 215 } |
215 } | 216 } |
216 e->local_i32_count_ = i32; | 217 e->local_decls_.AddLocals(i32, kAstI32); |
217 e->local_i64_count_ = i64; | 218 e->local_decls_.AddLocals(i64, kAstI64); |
218 e->local_f32_count_ = f32; | 219 e->local_decls_.AddLocals(f32, kAstF32); |
219 e->local_f64_count_ = f64; | 220 e->local_decls_.AddLocals(f64, kAstF64); |
220 f64 = param + i32 + i64 + f32; | 221 f64 = param + i32 + i64 + f32; |
221 f32 = param + i32 + i64; | 222 f32 = param + i32 + i64; |
222 i64 = param + i32; | 223 i64 = param + i32; |
223 i32 = param; | 224 i32 = param; |
224 param = 0; | 225 param = 0; |
225 for (size_t i = 0; i < locals_.size(); i++) { | 226 for (size_t i = 0; i < locals_.size(); i++) { |
226 if (locals_.at(i).param_) { | 227 if (locals_.at(i).param_) { |
227 e->params_.push_back(locals_.at(i).type_); | 228 e->params_.push_back(locals_.at(i).type_); |
228 var_index[i] = param++; | 229 var_index[i] = param++; |
229 } else if (locals_.at(i).type_ == kAstI32) { | 230 } else if (locals_.at(i).type_ == kAstI32) { |
(...skipping 13 matching lines...) Expand all Loading... | |
243 bool exported, bool external) | 244 bool exported, bool external) |
244 : params_(zone), | 245 : params_(zone), |
245 exported_(exported), | 246 exported_(exported), |
246 external_(external), | 247 external_(external), |
247 body_(zone), | 248 body_(zone), |
248 name_(zone) {} | 249 name_(zone) {} |
249 | 250 |
250 | 251 |
251 uint32_t WasmFunctionEncoder::HeaderSize() const { | 252 uint32_t WasmFunctionEncoder::HeaderSize() const { |
252 uint32_t size = 3; | 253 uint32_t size = 3; |
253 if (HasLocals()) size += 8; | |
254 if (!external_) size += 2; | 254 if (!external_) size += 2; |
255 if (HasName()) size += 4; | 255 if (HasName()) size += 4; |
256 return size; | 256 return size; |
257 } | 257 } |
258 | 258 |
259 | 259 |
260 uint32_t WasmFunctionEncoder::BodySize(void) const { | 260 uint32_t WasmFunctionEncoder::BodySize(void) const { |
261 return external_ ? 0 : static_cast<uint32_t>(body_.size()); | 261 return external_ ? 0 |
262 : static_cast<uint32_t>(local_decls_.Size() + body_.size()); | |
262 } | 263 } |
263 | 264 |
264 | 265 |
265 uint32_t WasmFunctionEncoder::NameSize() const { | 266 uint32_t WasmFunctionEncoder::NameSize() const { |
266 return HasName() ? static_cast<uint32_t>(name_.size()) : 0; | 267 return HasName() ? static_cast<uint32_t>(name_.size()) : 0; |
267 } | 268 } |
268 | 269 |
269 | 270 |
270 void WasmFunctionEncoder::Serialize(byte* buffer, byte** header, | 271 void WasmFunctionEncoder::Serialize(byte* buffer, byte** header, |
271 byte** body) const { | 272 byte** body) const { |
272 uint8_t decl_bits = (exported_ ? kDeclFunctionExport : 0) | | 273 uint8_t decl_bits = (exported_ ? kDeclFunctionExport : 0) | |
273 (external_ ? kDeclFunctionImport : 0) | | 274 (external_ ? kDeclFunctionImport : 0) | |
274 (HasLocals() ? kDeclFunctionLocals : 0) | | |
275 (HasName() ? kDeclFunctionName : 0); | 275 (HasName() ? kDeclFunctionName : 0); |
276 | 276 |
277 EmitUint8(header, decl_bits); | 277 EmitUint8(header, decl_bits); |
278 EmitUint16(header, signature_index_); | 278 EmitUint16(header, signature_index_); |
279 | 279 |
280 if (HasName()) { | 280 if (HasName()) { |
281 uint32_t name_offset = static_cast<uint32_t>(*body - buffer); | 281 uint32_t name_offset = static_cast<uint32_t>(*body - buffer); |
282 EmitUint32(header, name_offset); | 282 EmitUint32(header, name_offset); |
283 std::memcpy(*body, &name_[0], name_.size()); | 283 std::memcpy(*body, &name_[0], name_.size()); |
284 (*body) += name_.size(); | 284 (*body) += name_.size(); |
285 } | 285 } |
286 | 286 |
287 if (HasLocals()) { | |
288 EmitUint16(header, local_i32_count_); | |
289 EmitUint16(header, local_i64_count_); | |
290 EmitUint16(header, local_f32_count_); | |
291 EmitUint16(header, local_f64_count_); | |
292 } | |
293 | |
294 if (!external_) { | 287 if (!external_) { |
295 EmitUint16(header, static_cast<uint16_t>(body_.size())); | 288 size_t size = body_.size() + local_decls_.Size(); |
289 EmitUint16(header, static_cast<uint16_t>(size)); | |
bradnelson
2016/03/02 21:51:15
I assume this will change to a leb in a later chan
titzer
2016/03/02 22:43:41
Yeah, we'll just update everything to be LEB in on
| |
290 (*header) += local_decls_.Emit(*header); | |
296 if (body_.size() > 0) { | 291 if (body_.size() > 0) { |
297 std::memcpy(*header, &body_[0], body_.size()); | 292 std::memcpy(*header, &body_[0], body_.size()); |
298 (*header) += body_.size(); | 293 (*header) += body_.size(); |
299 } | 294 } |
300 } | 295 } |
301 } | 296 } |
302 | 297 |
303 | 298 |
304 WasmDataSegmentEncoder::WasmDataSegmentEncoder(Zone* zone, const byte* data, | 299 WasmDataSegmentEncoder::WasmDataSegmentEncoder(Zone* zone, const byte* data, |
305 uint32_t size, uint32_t dest) | 300 uint32_t size, uint32_t dest) |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
602 next = next | 0x80; | 597 next = next | 0x80; |
603 } | 598 } |
604 output.push_back(next); | 599 output.push_back(next); |
605 shift += 7; | 600 shift += 7; |
606 } while ((next & 0x80) != 0); | 601 } while ((next & 0x80) != 0); |
607 return output; | 602 return output; |
608 } | 603 } |
609 } // namespace wasm | 604 } // namespace wasm |
610 } // namespace internal | 605 } // namespace internal |
611 } // namespace v8 | 606 } // namespace v8 |
OLD | NEW |