Chromium Code Reviews| 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/macro-assembler.h" | 9 #include "src/macro-assembler.h" |
| 10 #include "src/objects.h" | 10 #include "src/objects.h" |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 180 case WasmSection::Code::FunctionBodies: { | 180 case WasmSection::Code::FunctionBodies: { |
| 181 const byte* pos = pc_; | 181 const byte* pos = pc_; |
| 182 uint32_t functions_count = consume_u32v("functions count"); | 182 uint32_t functions_count = consume_u32v("functions count"); |
| 183 if (functions_count != module->functions.size()) { | 183 if (functions_count != module->functions.size()) { |
| 184 error(pos, pos, "function body count %u mismatch (%u expected)", | 184 error(pos, pos, "function body count %u mismatch (%u expected)", |
| 185 functions_count, | 185 functions_count, |
| 186 static_cast<uint32_t>(module->functions.size())); | 186 static_cast<uint32_t>(module->functions.size())); |
| 187 break; | 187 break; |
| 188 } | 188 } |
| 189 for (uint32_t i = 0; i < functions_count; ++i) { | 189 for (uint32_t i = 0; i < functions_count; ++i) { |
| 190 if (failed()) break; | |
|
titzer
2016/09/22 09:53:11
Can we change all these loops to be for(x, ok() &&
ahaas
2016/09/22 12:35:09
Done.
| |
| 190 WasmFunction* function = &module->functions[i]; | 191 WasmFunction* function = &module->functions[i]; |
| 191 uint32_t size = consume_u32v("body size"); | 192 uint32_t size = consume_u32v("body size"); |
| 192 function->code_start_offset = pc_offset(); | 193 function->code_start_offset = pc_offset(); |
| 193 function->code_end_offset = pc_offset() + size; | 194 function->code_end_offset = pc_offset() + size; |
| 194 | 195 |
| 195 TRACE(" +%d %-20s: (%d bytes)\n", pc_offset(), "function body", | 196 TRACE(" +%d %-20s: (%d bytes)\n", pc_offset(), "function body", |
| 196 size); | 197 size); |
| 197 pc_ += size; | 198 pc_ += size; |
| 198 if (pc_ > limit_) { | 199 if (pc_ > limit_) { |
| 199 error(pc_, "function body extends beyond end of file"); | 200 error(pc_, "function body extends beyond end of file"); |
| 200 } | 201 } |
| 201 } | 202 } |
| 202 break; | 203 break; |
| 203 } | 204 } |
| 204 case WasmSection::Code::Names: { | 205 case WasmSection::Code::Names: { |
| 205 const byte* pos = pc_; | 206 const byte* pos = pc_; |
| 206 uint32_t functions_count = consume_u32v("functions count"); | 207 uint32_t functions_count = consume_u32v("functions count"); |
| 207 if (functions_count != module->functions.size()) { | 208 if (functions_count != module->functions.size()) { |
| 208 error(pos, pos, "function name count %u mismatch (%u expected)", | 209 error(pos, pos, "function name count %u mismatch (%u expected)", |
| 209 functions_count, | 210 functions_count, |
| 210 static_cast<uint32_t>(module->functions.size())); | 211 static_cast<uint32_t>(module->functions.size())); |
| 211 break; | 212 break; |
| 212 } | 213 } |
| 213 | 214 |
| 214 for (uint32_t i = 0; i < functions_count; ++i) { | 215 for (uint32_t i = 0; i < functions_count; ++i) { |
| 216 if (failed()) break; | |
| 215 WasmFunction* function = &module->functions[i]; | 217 WasmFunction* function = &module->functions[i]; |
| 216 function->name_offset = | 218 function->name_offset = |
| 217 consume_string(&function->name_length, false); | 219 consume_string(&function->name_length, false); |
| 218 | 220 |
| 219 uint32_t local_names_count = consume_u32v("local names count"); | 221 uint32_t local_names_count = consume_u32v("local names count"); |
| 220 for (uint32_t j = 0; j < local_names_count; j++) { | 222 for (uint32_t j = 0; j < local_names_count; j++) { |
| 223 if (failed()) break; | |
| 221 uint32_t unused = 0; | 224 uint32_t unused = 0; |
| 222 uint32_t offset = consume_string(&unused, false); | 225 uint32_t offset = consume_string(&unused, false); |
| 223 USE(unused); | 226 USE(unused); |
| 224 USE(offset); | 227 USE(offset); |
| 225 } | 228 } |
| 226 } | 229 } |
| 227 break; | 230 break; |
| 228 } | 231 } |
| 229 case WasmSection::Code::Globals: { | 232 case WasmSection::Code::Globals: { |
| 230 uint32_t globals_count = consume_u32v("globals count"); | 233 uint32_t globals_count = consume_u32v("globals count"); |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 512 void DecodeFunctionTableInModule(WasmModule* module, | 515 void DecodeFunctionTableInModule(WasmModule* module, |
| 513 WasmIndirectFunctionTable* table) { | 516 WasmIndirectFunctionTable* table) { |
| 514 table->size = consume_u32v("function table entry count"); | 517 table->size = consume_u32v("function table entry count"); |
| 515 table->max_size = table->size; | 518 table->max_size = table->size; |
| 516 | 519 |
| 517 if (table->max_size != table->size) { | 520 if (table->max_size != table->size) { |
| 518 error("invalid table maximum size"); | 521 error("invalid table maximum size"); |
| 519 } | 522 } |
| 520 | 523 |
| 521 for (uint32_t i = 0; i < table->size; ++i) { | 524 for (uint32_t i = 0; i < table->size; ++i) { |
| 525 if (failed()) break; | |
| 522 uint16_t index = consume_u32v(); | 526 uint16_t index = consume_u32v(); |
| 523 if (index >= module->functions.size()) { | 527 if (index >= module->functions.size()) { |
| 524 error(pc_ - sizeof(index), "invalid function index"); | 528 error(pc_ - sizeof(index), "invalid function index"); |
| 525 break; | 529 break; |
| 526 } | 530 } |
| 527 table->values.push_back(index); | 531 table->values.push_back(index); |
| 528 } | 532 } |
| 529 } | 533 } |
| 530 | 534 |
| 531 // Calculate individual global offsets and total size of globals table. | 535 // Calculate individual global offsets and total size of globals table. |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 821 decoder.consume_bytes(size); | 825 decoder.consume_bytes(size); |
| 822 } | 826 } |
| 823 if (decoder.more()) decoder.error("unexpected additional bytes"); | 827 if (decoder.more()) decoder.error("unexpected additional bytes"); |
| 824 | 828 |
| 825 return decoder.toResult(std::move(table)); | 829 return decoder.toResult(std::move(table)); |
| 826 } | 830 } |
| 827 | 831 |
| 828 } // namespace wasm | 832 } // namespace wasm |
| 829 } // namespace internal | 833 } // namespace internal |
| 830 } // namespace v8 | 834 } // namespace v8 |
| OLD | NEW |