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/wasm/module-decoder.h" | 5 #include "src/wasm/module-decoder.h" |
6 | 6 |
7 #include "src/base/functional.h" | 7 #include "src/base/functional.h" |
8 #include "src/base/platform/platform.h" | 8 #include "src/base/platform/platform.h" |
9 #include "src/flags.h" | 9 #include "src/flags.h" |
10 #include "src/macro-assembler.h" | 10 #include "src/macro-assembler.h" |
(...skipping 1186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1197 Decoder decoder(tables_start, tables_end); | 1197 Decoder decoder(tables_start, tables_end); |
1198 uint32_t functions_count = decoder.consume_u32v("functions count"); | 1198 uint32_t functions_count = decoder.consume_u32v("functions count"); |
1199 // Reserve space for the entries, taking care of invalid input. | 1199 // Reserve space for the entries, taking care of invalid input. |
1200 if (functions_count < static_cast<unsigned>(tables_end - tables_start)) { | 1200 if (functions_count < static_cast<unsigned>(tables_end - tables_start)) { |
1201 table.reserve(functions_count); | 1201 table.reserve(functions_count); |
1202 } | 1202 } |
1203 | 1203 |
1204 for (uint32_t i = 0; i < functions_count && decoder.ok(); ++i) { | 1204 for (uint32_t i = 0; i < functions_count && decoder.ok(); ++i) { |
1205 uint32_t size = decoder.consume_u32v("table size"); | 1205 uint32_t size = decoder.consume_u32v("table size"); |
1206 if (size == 0) { | 1206 if (size == 0) { |
1207 table.push_back(std::vector<std::pair<int, int>>()); | 1207 table.push_back(std::vector<AsmJsOffsetEntry>()); |
1208 continue; | 1208 continue; |
1209 } | 1209 } |
1210 if (!decoder.checkAvailable(size)) { | 1210 if (!decoder.checkAvailable(size)) { |
1211 decoder.error("illegal asm function offset table size"); | 1211 decoder.error("illegal asm function offset table size"); |
1212 } | 1212 } |
1213 const byte* table_end = decoder.pc() + size; | 1213 const byte* table_end = decoder.pc() + size; |
1214 uint32_t locals_size = decoder.consume_u32("locals size"); | 1214 uint32_t locals_size = decoder.consume_u32("locals size"); |
1215 int last_byte_offset = locals_size; | 1215 int last_byte_offset = locals_size; |
1216 int last_asm_position = 0; | 1216 int last_asm_position = 0; |
1217 std::vector<std::pair<int, int>> func_asm_offsets; | 1217 std::vector<AsmJsOffsetEntry> func_asm_offsets; |
1218 func_asm_offsets.reserve(size / 4); // conservative estimation | 1218 func_asm_offsets.reserve(size / 4); // conservative estimation |
1219 while (decoder.ok() && decoder.pc() < table_end) { | 1219 while (decoder.ok() && decoder.pc() < table_end) { |
1220 last_byte_offset += decoder.consume_u32v("byte offset delta"); | 1220 last_byte_offset += decoder.consume_u32v("byte offset delta"); |
1221 last_asm_position += decoder.consume_i32v("asm position delta"); | 1221 int call_position = |
1222 func_asm_offsets.push_back({last_byte_offset, last_asm_position}); | 1222 last_asm_position + decoder.consume_i32v("call position delta"); |
| 1223 int to_number_position = |
| 1224 call_position + decoder.consume_i32v("to_number position delta"); |
| 1225 last_asm_position = to_number_position; |
| 1226 func_asm_offsets.push_back( |
| 1227 {last_byte_offset, call_position, to_number_position}); |
1223 } | 1228 } |
1224 if (decoder.pc() != table_end) { | 1229 if (decoder.pc() != table_end) { |
1225 decoder.error("broken asm offset table"); | 1230 decoder.error("broken asm offset table"); |
1226 } | 1231 } |
1227 table.push_back(std::move(func_asm_offsets)); | 1232 table.push_back(std::move(func_asm_offsets)); |
1228 } | 1233 } |
1229 if (decoder.more()) decoder.error("unexpected additional bytes"); | 1234 if (decoder.more()) decoder.error("unexpected additional bytes"); |
1230 | 1235 |
1231 return decoder.toResult(std::move(table)); | 1236 return decoder.toResult(std::move(table)); |
1232 } | 1237 } |
1233 | 1238 |
1234 } // namespace wasm | 1239 } // namespace wasm |
1235 } // namespace internal | 1240 } // namespace internal |
1236 } // namespace v8 | 1241 } // namespace v8 |
OLD | NEW |