| 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 316 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 327             SetHasMemory(module); | 327             SetHasMemory(module); | 
| 328             break; | 328             break; | 
| 329           } | 329           } | 
| 330           case kExternalGlobal: { | 330           case kExternalGlobal: { | 
| 331             // ===== Imported global ========================================= | 331             // ===== Imported global ========================================= | 
| 332             import->index = static_cast<uint32_t>(module->globals.size()); | 332             import->index = static_cast<uint32_t>(module->globals.size()); | 
| 333             module->globals.push_back( | 333             module->globals.push_back( | 
| 334                 {kWasmStmt, false, WasmInitExpr(), 0, true, false}); | 334                 {kWasmStmt, false, WasmInitExpr(), 0, true, false}); | 
| 335             WasmGlobal* global = &module->globals.back(); | 335             WasmGlobal* global = &module->globals.back(); | 
| 336             global->type = consume_value_type(); | 336             global->type = consume_value_type(); | 
| 337             global->mutability = consume_u8("mutability") != 0; | 337             global->mutability = consume_mutability(); | 
| 338             if (global->mutability) { | 338             if (global->mutability) { | 
| 339               error("mutable globals cannot be imported"); | 339               error("mutable globals cannot be imported"); | 
| 340             } | 340             } | 
| 341             break; | 341             break; | 
| 342           } | 342           } | 
| 343           default: | 343           default: | 
| 344             error(pos, pos, "unknown import kind 0x%02x", import->kind); | 344             error(pos, pos, "unknown import kind 0x%02x", import->kind); | 
| 345             break; | 345             break; | 
| 346         } | 346         } | 
| 347       } | 347       } | 
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 689       error("At most one memory object is supported"); | 689       error("At most one memory object is supported"); | 
| 690     } else { | 690     } else { | 
| 691       module->has_memory = true; | 691       module->has_memory = true; | 
| 692     } | 692     } | 
| 693   } | 693   } | 
| 694 | 694 | 
| 695   // Decodes a single global entry inside a module starting at {pc_}. | 695   // Decodes a single global entry inside a module starting at {pc_}. | 
| 696   void DecodeGlobalInModule(WasmModule* module, uint32_t index, | 696   void DecodeGlobalInModule(WasmModule* module, uint32_t index, | 
| 697                             WasmGlobal* global) { | 697                             WasmGlobal* global) { | 
| 698     global->type = consume_value_type(); | 698     global->type = consume_value_type(); | 
| 699     global->mutability = consume_u8("mutability") != 0; | 699     global->mutability = consume_mutability(); | 
| 700     const byte* pos = pc(); | 700     const byte* pos = pc(); | 
| 701     global->init = consume_init_expr(module, kWasmStmt); | 701     global->init = consume_init_expr(module, kWasmStmt); | 
| 702     switch (global->init.kind) { | 702     switch (global->init.kind) { | 
| 703       case WasmInitExpr::kGlobalIndex: { | 703       case WasmInitExpr::kGlobalIndex: { | 
| 704         uint32_t other_index = global->init.val.global_index; | 704         uint32_t other_index = global->init.val.global_index; | 
| 705         if (other_index >= index) { | 705         if (other_index >= index) { | 
| 706           error(pos, pos, | 706           error(pos, pos, | 
| 707                 "invalid global index in init expression, " | 707                 "invalid global index in init expression, " | 
| 708                 "index %u, other_index %u", | 708                 "index %u, other_index %u", | 
| 709                 index, other_index); | 709                 index, other_index); | 
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 981       expr.kind = WasmInitExpr::kNone; | 981       expr.kind = WasmInitExpr::kNone; | 
| 982     } | 982     } | 
| 983     if (expected != kWasmStmt && TypeOf(module, expr) != kWasmI32) { | 983     if (expected != kWasmStmt && TypeOf(module, expr) != kWasmI32) { | 
| 984       error(pos, pos, "type error in init expression, expected %s, got %s", | 984       error(pos, pos, "type error in init expression, expected %s, got %s", | 
| 985             WasmOpcodes::TypeName(expected), | 985             WasmOpcodes::TypeName(expected), | 
| 986             WasmOpcodes::TypeName(TypeOf(module, expr))); | 986             WasmOpcodes::TypeName(TypeOf(module, expr))); | 
| 987     } | 987     } | 
| 988     return expr; | 988     return expr; | 
| 989   } | 989   } | 
| 990 | 990 | 
|  | 991   // Read a mutability flag | 
|  | 992   bool consume_mutability() { | 
|  | 993     byte val = consume_u8("mutability"); | 
|  | 994     if (val > 1) error(pc_ - 1, "invalid mutability"); | 
|  | 995     return val != 0; | 
|  | 996   } | 
|  | 997 | 
| 991   // Reads a single 8-bit integer, interpreting it as a local type. | 998   // Reads a single 8-bit integer, interpreting it as a local type. | 
| 992   ValueType consume_value_type() { | 999   ValueType consume_value_type() { | 
| 993     byte val = consume_u8("value type"); | 1000     byte val = consume_u8("value type"); | 
| 994     ValueTypeCode t = static_cast<ValueTypeCode>(val); | 1001     ValueTypeCode t = static_cast<ValueTypeCode>(val); | 
| 995     switch (t) { | 1002     switch (t) { | 
| 996       case kLocalI32: | 1003       case kLocalI32: | 
| 997         return kWasmI32; | 1004         return kWasmI32; | 
| 998       case kLocalI64: | 1005       case kLocalI64: | 
| 999         return kWasmI64; | 1006         return kWasmI64; | 
| 1000       case kLocalF32: | 1007       case kLocalF32: | 
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1239     table.push_back(std::move(func_asm_offsets)); | 1246     table.push_back(std::move(func_asm_offsets)); | 
| 1240   } | 1247   } | 
| 1241   if (decoder.more()) decoder.error("unexpected additional bytes"); | 1248   if (decoder.more()) decoder.error("unexpected additional bytes"); | 
| 1242 | 1249 | 
| 1243   return decoder.toResult(std::move(table)); | 1250   return decoder.toResult(std::move(table)); | 
| 1244 } | 1251 } | 
| 1245 | 1252 | 
| 1246 }  // namespace wasm | 1253 }  // namespace wasm | 
| 1247 }  // namespace internal | 1254 }  // namespace internal | 
| 1248 }  // namespace v8 | 1255 }  // namespace v8 | 
| OLD | NEW | 
|---|