| 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 1184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1195 for (uint32_t i = 0; i < functions_count && decoder.ok(); ++i) { | 1195 for (uint32_t i = 0; i < functions_count && decoder.ok(); ++i) { |
| 1196 uint32_t size = decoder.consume_u32v("table size"); | 1196 uint32_t size = decoder.consume_u32v("table size"); |
| 1197 if (size == 0) { | 1197 if (size == 0) { |
| 1198 table.push_back(std::vector<AsmJsOffsetEntry>()); | 1198 table.push_back(std::vector<AsmJsOffsetEntry>()); |
| 1199 continue; | 1199 continue; |
| 1200 } | 1200 } |
| 1201 if (!decoder.checkAvailable(size)) { | 1201 if (!decoder.checkAvailable(size)) { |
| 1202 decoder.error("illegal asm function offset table size"); | 1202 decoder.error("illegal asm function offset table size"); |
| 1203 } | 1203 } |
| 1204 const byte* table_end = decoder.pc() + size; | 1204 const byte* table_end = decoder.pc() + size; |
| 1205 uint32_t locals_size = decoder.consume_u32("locals size"); | 1205 uint32_t locals_size = decoder.consume_u32v("locals size"); |
| 1206 int function_start_position = decoder.consume_u32v("function start pos"); |
| 1206 int last_byte_offset = locals_size; | 1207 int last_byte_offset = locals_size; |
| 1207 int last_asm_position = 0; | 1208 int last_asm_position = function_start_position; |
| 1208 std::vector<AsmJsOffsetEntry> func_asm_offsets; | 1209 std::vector<AsmJsOffsetEntry> func_asm_offsets; |
| 1209 func_asm_offsets.reserve(size / 4); // conservative estimation | 1210 func_asm_offsets.reserve(size / 4); // conservative estimation |
| 1211 // Add an entry for the stack check, associated with position 0. |
| 1212 func_asm_offsets.push_back( |
| 1213 {0, function_start_position, function_start_position}); |
| 1210 while (decoder.ok() && decoder.pc() < table_end) { | 1214 while (decoder.ok() && decoder.pc() < table_end) { |
| 1211 last_byte_offset += decoder.consume_u32v("byte offset delta"); | 1215 last_byte_offset += decoder.consume_u32v("byte offset delta"); |
| 1212 int call_position = | 1216 int call_position = |
| 1213 last_asm_position + decoder.consume_i32v("call position delta"); | 1217 last_asm_position + decoder.consume_i32v("call position delta"); |
| 1214 int to_number_position = | 1218 int to_number_position = |
| 1215 call_position + decoder.consume_i32v("to_number position delta"); | 1219 call_position + decoder.consume_i32v("to_number position delta"); |
| 1216 last_asm_position = to_number_position; | 1220 last_asm_position = to_number_position; |
| 1217 func_asm_offsets.push_back( | 1221 func_asm_offsets.push_back( |
| 1218 {last_byte_offset, call_position, to_number_position}); | 1222 {last_byte_offset, call_position, to_number_position}); |
| 1219 } | 1223 } |
| 1220 if (decoder.pc() != table_end) { | 1224 if (decoder.pc() != table_end) { |
| 1221 decoder.error("broken asm offset table"); | 1225 decoder.error("broken asm offset table"); |
| 1222 } | 1226 } |
| 1223 table.push_back(std::move(func_asm_offsets)); | 1227 table.push_back(std::move(func_asm_offsets)); |
| 1224 } | 1228 } |
| 1225 if (decoder.more()) decoder.error("unexpected additional bytes"); | 1229 if (decoder.more()) decoder.error("unexpected additional bytes"); |
| 1226 | 1230 |
| 1227 return decoder.toResult(std::move(table)); | 1231 return decoder.toResult(std::move(table)); |
| 1228 } | 1232 } |
| 1229 | 1233 |
| 1230 } // namespace wasm | 1234 } // namespace wasm |
| 1231 } // namespace internal | 1235 } // namespace internal |
| 1232 } // namespace v8 | 1236 } // namespace v8 |
| OLD | NEW |