| 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/macro-assembler.h" | 5 #include "src/macro-assembler.h" |
| 6 #include "src/objects.h" | 6 #include "src/objects.h" |
| 7 #include "src/v8.h" | 7 #include "src/v8.h" |
| 8 | 8 |
| 9 #include "src/wasm/decoder.h" | 9 #include "src/wasm/decoder.h" |
| 10 #include "src/wasm/module-decoder.h" | 10 #include "src/wasm/module-decoder.h" |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 } | 245 } |
| 246 | 246 |
| 247 // Decodes a single anonymous function starting at {start_}. | 247 // Decodes a single anonymous function starting at {start_}. |
| 248 FunctionResult DecodeSingleFunction(ModuleEnv* module_env, | 248 FunctionResult DecodeSingleFunction(ModuleEnv* module_env, |
| 249 WasmFunction* function) { | 249 WasmFunction* function) { |
| 250 pc_ = start_; | 250 pc_ = start_; |
| 251 function->sig = consume_sig(); // read signature | 251 function->sig = consume_sig(); // read signature |
| 252 function->name_offset = 0; // ---- name | 252 function->name_offset = 0; // ---- name |
| 253 function->code_start_offset = off(pc_ + 8); // ---- code start | 253 function->code_start_offset = off(pc_ + 8); // ---- code start |
| 254 function->code_end_offset = off(limit_); // ---- code end | 254 function->code_end_offset = off(limit_); // ---- code end |
| 255 function->local_int32_count = consume_u16(); // read u16 | 255 function->local_i32_count = consume_u16(); // read u16 |
| 256 function->local_int64_count = consume_u16(); // read u16 | 256 function->local_i64_count = consume_u16(); // read u16 |
| 257 function->local_float32_count = consume_u16(); // read u16 | 257 function->local_f32_count = consume_u16(); // read u16 |
| 258 function->local_float64_count = consume_u16(); // read u16 | 258 function->local_f64_count = consume_u16(); // read u16 |
| 259 function->exported = false; // ---- exported | 259 function->exported = false; // ---- exported |
| 260 function->external = false; // ---- external | 260 function->external = false; // ---- external |
| 261 | 261 |
| 262 if (ok()) VerifyFunctionBody(0, module_env, function); | 262 if (ok()) VerifyFunctionBody(0, module_env, function); |
| 263 | 263 |
| 264 FunctionResult result; | 264 FunctionResult result; |
| 265 result.CopyFrom(result_); // Copy error code and location. | 265 result.CopyFrom(result_); // Copy error code and location. |
| 266 result.val = function; | 266 result.val = function; |
| 267 return result; | 267 return result; |
| 268 } | 268 } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 | 317 |
| 318 function->exported = decl_bits & kDeclFunctionExport; | 318 function->exported = decl_bits & kDeclFunctionExport; |
| 319 | 319 |
| 320 // Imported functions have no locals or body. | 320 // Imported functions have no locals or body. |
| 321 if (decl_bits & kDeclFunctionImport) { | 321 if (decl_bits & kDeclFunctionImport) { |
| 322 function->external = true; | 322 function->external = true; |
| 323 return; | 323 return; |
| 324 } | 324 } |
| 325 | 325 |
| 326 if (decl_bits & kDeclFunctionLocals) { | 326 if (decl_bits & kDeclFunctionLocals) { |
| 327 function->local_int32_count = consume_u16("int32 count"); | 327 function->local_i32_count = consume_u16("i32 count"); |
| 328 function->local_int64_count = consume_u16("int64 count"); | 328 function->local_i64_count = consume_u16("i64 count"); |
| 329 function->local_float32_count = consume_u16("float32 count"); | 329 function->local_f32_count = consume_u16("f32 count"); |
| 330 function->local_float64_count = consume_u16("float64 count"); | 330 function->local_f64_count = consume_u16("f64 count"); |
| 331 } | 331 } |
| 332 | 332 |
| 333 uint16_t size = consume_u16("body size"); | 333 uint16_t size = consume_u16("body size"); |
| 334 if (ok()) { | 334 if (ok()) { |
| 335 if ((pc_ + size) > limit_) { | 335 if ((pc_ + size) > limit_) { |
| 336 return error(pc_, limit_, | 336 return error(pc_, limit_, |
| 337 "expected %d bytes for function body, fell off end", size); | 337 "expected %d bytes for function body, fell off end", size); |
| 338 } | 338 } |
| 339 function->code_start_offset = static_cast<uint32_t>(pc_ - start_); | 339 function->code_start_offset = static_cast<uint32_t>(pc_ - start_); |
| 340 function->code_end_offset = function->code_start_offset + size; | 340 function->code_end_offset = function->code_start_offset + size; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 OFStream os(stdout); | 381 OFStream os(stdout); |
| 382 os << "Verifying WASM function:"; | 382 os << "Verifying WASM function:"; |
| 383 if (function->name_offset > 0) { | 383 if (function->name_offset > 0) { |
| 384 os << menv->module->GetName(function->name_offset); | 384 os << menv->module->GetName(function->name_offset); |
| 385 } | 385 } |
| 386 os << std::endl; | 386 os << std::endl; |
| 387 } | 387 } |
| 388 FunctionEnv fenv; | 388 FunctionEnv fenv; |
| 389 fenv.module = menv; | 389 fenv.module = menv; |
| 390 fenv.sig = function->sig; | 390 fenv.sig = function->sig; |
| 391 fenv.local_int32_count = function->local_int32_count; | 391 fenv.local_i32_count = function->local_i32_count; |
| 392 fenv.local_int64_count = function->local_int64_count; | 392 fenv.local_i64_count = function->local_i64_count; |
| 393 fenv.local_float32_count = function->local_float32_count; | 393 fenv.local_f32_count = function->local_f32_count; |
| 394 fenv.local_float64_count = function->local_float64_count; | 394 fenv.local_f64_count = function->local_f64_count; |
| 395 fenv.SumLocals(); | 395 fenv.SumLocals(); |
| 396 | 396 |
| 397 TreeResult result = | 397 TreeResult result = |
| 398 VerifyWasmCode(&fenv, start_, start_ + function->code_start_offset, | 398 VerifyWasmCode(&fenv, start_, start_ + function->code_start_offset, |
| 399 start_ + function->code_end_offset); | 399 start_ + function->code_end_offset); |
| 400 if (result.failed()) { | 400 if (result.failed()) { |
| 401 // Wrap the error message from the function decoder. | 401 // Wrap the error message from the function decoder. |
| 402 std::ostringstream str; | 402 std::ostringstream str; |
| 403 str << "in function #" << func_num << ": "; | 403 str << "in function #" << func_num << ": "; |
| 404 // TODO(titzer): add function name for the user? | 404 // TODO(titzer): add function name for the user? |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 557 if (function_start > function_end) return FunctionError("start > end"); | 557 if (function_start > function_end) return FunctionError("start > end"); |
| 558 if (size > kMaxFunctionSize) | 558 if (size > kMaxFunctionSize) |
| 559 return FunctionError("size > maximum function size"); | 559 return FunctionError("size > maximum function size"); |
| 560 WasmFunction* function = new WasmFunction(); | 560 WasmFunction* function = new WasmFunction(); |
| 561 ModuleDecoder decoder(zone, function_start, function_end, false); | 561 ModuleDecoder decoder(zone, function_start, function_end, false); |
| 562 return decoder.DecodeSingleFunction(module_env, function); | 562 return decoder.DecodeSingleFunction(module_env, function); |
| 563 } | 563 } |
| 564 } // namespace wasm | 564 } // namespace wasm |
| 565 } // namespace internal | 565 } // namespace internal |
| 566 } // namespace v8 | 566 } // namespace v8 |
| OLD | NEW |