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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 name.start(), name.start() + name.length(), builder_->zone())); | 145 name.start(), name.start() + name.length(), builder_->zone())); |
146 } | 146 } |
147 | 147 |
148 void WasmFunctionBuilder::SetName(Vector<const char> name) { | 148 void WasmFunctionBuilder::SetName(Vector<const char> name) { |
149 name_.resize(name.length()); | 149 name_.resize(name.length()); |
150 memcpy(name_.data(), name.start(), name.length()); | 150 memcpy(name_.data(), name.start(), name.length()); |
151 } | 151 } |
152 | 152 |
153 void WasmFunctionBuilder::AddAsmWasmOffset(int call_position, | 153 void WasmFunctionBuilder::AddAsmWasmOffset(int call_position, |
154 int to_number_position) { | 154 int to_number_position) { |
155 // We only want to emit one mapping per byte offset: | 155 // We only want to emit one mapping per byte offset. |
156 DCHECK(asm_offsets_.size() == 0 || body_.size() > last_asm_byte_offset_); | 156 DCHECK(asm_offsets_.size() == 0 || body_.size() > last_asm_byte_offset_); |
157 | 157 |
158 DCHECK_LE(body_.size(), kMaxUInt32); | 158 DCHECK_LE(body_.size(), kMaxUInt32); |
159 uint32_t byte_offset = static_cast<uint32_t>(body_.size()); | 159 uint32_t byte_offset = static_cast<uint32_t>(body_.size()); |
160 asm_offsets_.write_u32v(byte_offset - last_asm_byte_offset_); | 160 asm_offsets_.write_u32v(byte_offset - last_asm_byte_offset_); |
161 last_asm_byte_offset_ = byte_offset; | 161 last_asm_byte_offset_ = byte_offset; |
162 | 162 |
163 DCHECK_GE(call_position, 0); | 163 DCHECK_GE(call_position, 0); |
164 asm_offsets_.write_i32v(call_position - last_asm_source_position_); | 164 asm_offsets_.write_i32v(call_position - last_asm_source_position_); |
165 | 165 |
166 DCHECK_GE(to_number_position, 0); | 166 DCHECK_GE(to_number_position, 0); |
167 asm_offsets_.write_i32v(to_number_position - call_position); | 167 asm_offsets_.write_i32v(to_number_position - call_position); |
168 last_asm_source_position_ = to_number_position; | 168 last_asm_source_position_ = to_number_position; |
169 } | 169 } |
170 | 170 |
| 171 void WasmFunctionBuilder::SetAsmFunctionStartPosition(int position) { |
| 172 DCHECK_EQ(0, asm_func_start_source_position_); |
| 173 DCHECK_LE(0, position); |
| 174 // Must be called before emitting any asm.js source position. |
| 175 DCHECK_EQ(0, asm_offsets_.size()); |
| 176 asm_func_start_source_position_ = position; |
| 177 last_asm_source_position_ = position; |
| 178 } |
| 179 |
171 void WasmFunctionBuilder::WriteSignature(ZoneBuffer& buffer) const { | 180 void WasmFunctionBuilder::WriteSignature(ZoneBuffer& buffer) const { |
172 buffer.write_u32v(signature_index_); | 181 buffer.write_u32v(signature_index_); |
173 } | 182 } |
174 | 183 |
175 void WasmFunctionBuilder::WriteExports(ZoneBuffer& buffer) const { | 184 void WasmFunctionBuilder::WriteExports(ZoneBuffer& buffer) const { |
176 for (auto name : exported_names_) { | 185 for (auto name : exported_names_) { |
177 buffer.write_size(name.size()); | 186 buffer.write_size(name.size()); |
178 buffer.write(reinterpret_cast<const byte*>(name.data()), name.size()); | 187 buffer.write(reinterpret_cast<const byte*>(name.data()), name.size()); |
179 buffer.write_u8(kExternalFunction); | 188 buffer.write_u8(kExternalFunction); |
180 buffer.write_u32v(func_index_ + | 189 buffer.write_u32v(func_index_ + |
(...skipping 13 matching lines...) Expand all Loading... |
194 buffer.write(&body_[0], body_.size()); | 203 buffer.write(&body_[0], body_.size()); |
195 for (DirectCallIndex call : direct_calls_) { | 204 for (DirectCallIndex call : direct_calls_) { |
196 buffer.patch_u32v( | 205 buffer.patch_u32v( |
197 base + call.offset, | 206 base + call.offset, |
198 call.direct_index + static_cast<uint32_t>(builder_->imports_.size())); | 207 call.direct_index + static_cast<uint32_t>(builder_->imports_.size())); |
199 } | 208 } |
200 } | 209 } |
201 } | 210 } |
202 | 211 |
203 void WasmFunctionBuilder::WriteAsmWasmOffsetTable(ZoneBuffer& buffer) const { | 212 void WasmFunctionBuilder::WriteAsmWasmOffsetTable(ZoneBuffer& buffer) const { |
204 if (asm_offsets_.size() == 0) { | 213 if (asm_func_start_source_position_ == 0 && asm_offsets_.size() == 0) { |
205 buffer.write_size(0); | 214 buffer.write_size(0); |
206 return; | 215 return; |
207 } | 216 } |
208 buffer.write_size(asm_offsets_.size() + kInt32Size); | 217 size_t locals_enc_size = LEBHelper::sizeof_u32v(locals_.Size()); |
| 218 size_t func_start_size = |
| 219 LEBHelper::sizeof_u32v(asm_func_start_source_position_); |
| 220 buffer.write_size(asm_offsets_.size() + locals_enc_size + func_start_size); |
209 // Offset of the recorded byte offsets. | 221 // Offset of the recorded byte offsets. |
210 DCHECK_GE(kMaxUInt32, locals_.Size()); | 222 DCHECK_GE(kMaxUInt32, locals_.Size()); |
211 buffer.write_u32(static_cast<uint32_t>(locals_.Size())); | 223 buffer.write_u32v(static_cast<uint32_t>(locals_.Size())); |
| 224 // Start position of the function. |
| 225 buffer.write_u32v(asm_func_start_source_position_); |
212 buffer.write(asm_offsets_.begin(), asm_offsets_.size()); | 226 buffer.write(asm_offsets_.begin(), asm_offsets_.size()); |
213 } | 227 } |
214 | 228 |
215 WasmModuleBuilder::WasmModuleBuilder(Zone* zone) | 229 WasmModuleBuilder::WasmModuleBuilder(Zone* zone) |
216 : zone_(zone), | 230 : zone_(zone), |
217 signatures_(zone), | 231 signatures_(zone), |
218 imports_(zone), | 232 imports_(zone), |
219 functions_(zone), | 233 functions_(zone), |
220 data_segments_(zone), | 234 data_segments_(zone), |
221 indirect_functions_(zone), | 235 indirect_functions_(zone), |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
535 // Emit the offset table per function. | 549 // Emit the offset table per function. |
536 for (auto function : functions_) { | 550 for (auto function : functions_) { |
537 function->WriteAsmWasmOffsetTable(buffer); | 551 function->WriteAsmWasmOffsetTable(buffer); |
538 } | 552 } |
539 // Append a 0 to indicate that this is an encoded table. | 553 // Append a 0 to indicate that this is an encoded table. |
540 buffer.write_u8(0); | 554 buffer.write_u8(0); |
541 } | 555 } |
542 } // namespace wasm | 556 } // namespace wasm |
543 } // namespace internal | 557 } // namespace internal |
544 } // namespace v8 | 558 } // namespace v8 |
OLD | NEW |