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/zone-containers.h" | 9 #include "src/zone/zone-containers.h" |
10 | 10 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 signature_index_(0), | 52 signature_index_(0), |
53 exported_(0), | 53 exported_(0), |
54 func_index_(static_cast<uint32_t>(builder->functions_.size())), | 54 func_index_(static_cast<uint32_t>(builder->functions_.size())), |
55 body_(builder->zone()), | 55 body_(builder->zone()), |
56 name_(builder->zone()), | 56 name_(builder->zone()), |
57 exported_name_(builder->zone()), | 57 exported_name_(builder->zone()), |
58 i32_temps_(builder->zone()), | 58 i32_temps_(builder->zone()), |
59 i64_temps_(builder->zone()), | 59 i64_temps_(builder->zone()), |
60 f32_temps_(builder->zone()), | 60 f32_temps_(builder->zone()), |
61 f64_temps_(builder->zone()), | 61 f64_temps_(builder->zone()), |
62 direct_calls_(builder->zone()) {} | 62 direct_calls_(builder->zone()), |
| 63 asm_offsets_(builder->zone(), 8) {} |
63 | 64 |
64 void WasmFunctionBuilder::EmitVarInt(uint32_t val) { | 65 void WasmFunctionBuilder::EmitVarInt(uint32_t val) { |
65 byte buffer[8]; | 66 byte buffer[8]; |
66 byte* ptr = buffer; | 67 byte* ptr = buffer; |
67 LEBHelper::write_u32v(&ptr, val); | 68 LEBHelper::write_u32v(&ptr, val); |
68 for (byte* p = buffer; p < ptr; p++) { | 69 for (byte* p = buffer; p < ptr; p++) { |
69 body_.push_back(*p); | 70 body_.push_back(*p); |
70 } | 71 } |
71 } | 72 } |
72 | 73 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 exported_ = true; | 147 exported_ = true; |
147 exported_name_.resize(name.length()); | 148 exported_name_.resize(name.length()); |
148 memcpy(exported_name_.data(), name.start(), name.length()); | 149 memcpy(exported_name_.data(), name.start(), name.length()); |
149 } | 150 } |
150 | 151 |
151 void WasmFunctionBuilder::SetName(Vector<const char> name) { | 152 void WasmFunctionBuilder::SetName(Vector<const char> name) { |
152 name_.resize(name.length()); | 153 name_.resize(name.length()); |
153 memcpy(name_.data(), name.start(), name.length()); | 154 memcpy(name_.data(), name.start(), name.length()); |
154 } | 155 } |
155 | 156 |
| 157 void WasmFunctionBuilder::AddAsmWasmOffset(int asm_position) { |
| 158 // We only want to emit one mapping per byte offset: |
| 159 DCHECK(asm_offsets_.size() == 0 || body_.size() > last_asm_byte_offset_); |
| 160 |
| 161 DCHECK_LE(body_.size(), kMaxUInt32); |
| 162 uint32_t byte_offset = static_cast<uint32_t>(body_.size()); |
| 163 asm_offsets_.write_u32v(byte_offset - last_asm_byte_offset_); |
| 164 last_asm_byte_offset_ = byte_offset; |
| 165 |
| 166 DCHECK_GE(asm_position, 0); |
| 167 asm_offsets_.write_i32v(asm_position - last_asm_source_position_); |
| 168 last_asm_source_position_ = asm_position; |
| 169 } |
| 170 |
156 void WasmFunctionBuilder::WriteSignature(ZoneBuffer& buffer) const { | 171 void WasmFunctionBuilder::WriteSignature(ZoneBuffer& buffer) const { |
157 buffer.write_u32v(signature_index_); | 172 buffer.write_u32v(signature_index_); |
158 } | 173 } |
159 | 174 |
160 void WasmFunctionBuilder::WriteExport(ZoneBuffer& buffer) const { | 175 void WasmFunctionBuilder::WriteExport(ZoneBuffer& buffer) const { |
161 if (exported_) { | 176 if (exported_) { |
162 const ZoneVector<char>* exported_name = | 177 const ZoneVector<char>* exported_name = |
163 exported_name_.size() == 0 ? &name_ : &exported_name_; | 178 exported_name_.size() == 0 ? &name_ : &exported_name_; |
164 buffer.write_size(exported_name->size()); | 179 buffer.write_size(exported_name->size()); |
165 buffer.write(reinterpret_cast<const byte*>(exported_name->data()), | 180 buffer.write(reinterpret_cast<const byte*>(exported_name->data()), |
(...skipping 15 matching lines...) Expand all Loading... |
181 size_t base = buffer.offset(); | 196 size_t base = buffer.offset(); |
182 buffer.write(&body_[0], body_.size()); | 197 buffer.write(&body_[0], body_.size()); |
183 for (DirectCallIndex call : direct_calls_) { | 198 for (DirectCallIndex call : direct_calls_) { |
184 buffer.patch_u32v( | 199 buffer.patch_u32v( |
185 base + call.offset, | 200 base + call.offset, |
186 call.direct_index + static_cast<uint32_t>(builder_->imports_.size())); | 201 call.direct_index + static_cast<uint32_t>(builder_->imports_.size())); |
187 } | 202 } |
188 } | 203 } |
189 } | 204 } |
190 | 205 |
| 206 void WasmFunctionBuilder::WriteAsmWasmOffsetTable(ZoneBuffer& buffer) const { |
| 207 if (asm_offsets_.size() == 0) { |
| 208 buffer.write_size(0); |
| 209 return; |
| 210 } |
| 211 buffer.write_size(asm_offsets_.size() + kInt32Size); |
| 212 // Offset of the recorded byte offsets. |
| 213 DCHECK_GE(kMaxUInt32, locals_.Size()); |
| 214 buffer.write_u32(static_cast<uint32_t>(locals_.Size())); |
| 215 buffer.write(asm_offsets_.begin(), asm_offsets_.size()); |
| 216 } |
| 217 |
191 WasmModuleBuilder::WasmModuleBuilder(Zone* zone) | 218 WasmModuleBuilder::WasmModuleBuilder(Zone* zone) |
192 : zone_(zone), | 219 : zone_(zone), |
193 signatures_(zone), | 220 signatures_(zone), |
194 imports_(zone), | 221 imports_(zone), |
195 functions_(zone), | 222 functions_(zone), |
196 data_segments_(zone), | 223 data_segments_(zone), |
197 indirect_functions_(zone), | 224 indirect_functions_(zone), |
198 globals_(zone), | 225 globals_(zone), |
199 signature_map_(zone), | 226 signature_map_(zone), |
200 start_function_index_(-1) {} | 227 start_function_index_(-1) {} |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 buffer.write_size(function->name_.size()); | 514 buffer.write_size(function->name_.size()); |
488 if (function->name_.size() > 0) { | 515 if (function->name_.size() > 0) { |
489 buffer.write(reinterpret_cast<const byte*>(&function->name_[0]), | 516 buffer.write(reinterpret_cast<const byte*>(&function->name_[0]), |
490 function->name_.size()); | 517 function->name_.size()); |
491 } | 518 } |
492 buffer.write_u8(0); | 519 buffer.write_u8(0); |
493 } | 520 } |
494 FixupSection(buffer, start); | 521 FixupSection(buffer, start); |
495 } | 522 } |
496 } | 523 } |
| 524 |
| 525 void WasmModuleBuilder::WriteAsmJsOffsetTable(ZoneBuffer& buffer) const { |
| 526 // == Emit asm.js offset table =============================================== |
| 527 buffer.write_size(functions_.size()); |
| 528 // Emit the offset table per function. |
| 529 for (auto function : functions_) { |
| 530 function->WriteAsmWasmOffsetTable(buffer); |
| 531 } |
| 532 } |
497 } // namespace wasm | 533 } // namespace wasm |
498 } // namespace internal | 534 } // namespace internal |
499 } // namespace v8 | 535 } // namespace v8 |
OLD | NEW |