| 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 #ifndef V8_WASM_AST_DECODER_H_ |    5 #ifndef V8_WASM_AST_DECODER_H_ | 
|    6 #define V8_WASM_AST_DECODER_H_ |    6 #define V8_WASM_AST_DECODER_H_ | 
|    7  |    7  | 
|    8 #include "src/signature.h" |    8 #include "src/signature.h" | 
|    9 #include "src/wasm/decoder.h" |    9 #include "src/wasm/decoder.h" | 
|   10 #include "src/wasm/wasm-opcodes.h" |   10 #include "src/wasm/wasm-opcodes.h" | 
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   90     machine_type = MachineType::None(); |   90     machine_type = MachineType::None(); | 
|   91   } |   91   } | 
|   92 }; |   92 }; | 
|   93  |   93  | 
|   94 struct Block; |   94 struct Block; | 
|   95 struct BreakDepthOperand { |   95 struct BreakDepthOperand { | 
|   96   uint32_t depth; |   96   uint32_t depth; | 
|   97   Block* target; |   97   Block* target; | 
|   98   int length; |   98   int length; | 
|   99   inline BreakDepthOperand(Decoder* decoder, const byte* pc) { |   99   inline BreakDepthOperand(Decoder* decoder, const byte* pc) { | 
|  100     depth = decoder->checked_read_u8(pc, 1, "break depth"); |  100     depth = decoder->checked_read_u32v(pc, 1, &length, "break depth"); | 
|  101     length = 1; |  | 
|  102     target = nullptr; |  101     target = nullptr; | 
|  103   } |  102   } | 
|  104 }; |  103 }; | 
|  105  |  104  | 
|  106 struct BlockCountOperand { |  105 struct BlockCountOperand { | 
|  107   uint32_t count; |  106   uint32_t count; | 
|  108   int length; |  107   int length; | 
|  109   inline BlockCountOperand(Decoder* decoder, const byte* pc) { |  108   inline BlockCountOperand(Decoder* decoder, const byte* pc) { | 
|  110     count = decoder->checked_read_u8(pc, 1, "block count"); |  109     count = decoder->checked_read_u32v(pc, 1, &length, "block count"); | 
|  111     length = 1; |  | 
|  112   } |  110   } | 
|  113 }; |  111 }; | 
|  114  |  112  | 
|  115 struct SignatureIndexOperand { |  113 struct SignatureIndexOperand { | 
|  116   uint32_t index; |  114   uint32_t index; | 
|  117   FunctionSig* sig; |  115   FunctionSig* sig; | 
|  118   int length; |  116   int length; | 
|  119   inline SignatureIndexOperand(Decoder* decoder, const byte* pc) { |  117   inline SignatureIndexOperand(Decoder* decoder, const byte* pc) { | 
|  120     index = decoder->checked_read_u32v(pc, 1, &length, "signature index"); |  118     index = decoder->checked_read_u32v(pc, 1, &length, "signature index"); | 
|  121     sig = nullptr; |  119     sig = nullptr; | 
| (...skipping 18 matching lines...) Expand all  Loading... | 
|  140     index = decoder->checked_read_u32v(pc, 1, &length, "import index"); |  138     index = decoder->checked_read_u32v(pc, 1, &length, "import index"); | 
|  141     sig = nullptr; |  139     sig = nullptr; | 
|  142   } |  140   } | 
|  143 }; |  141 }; | 
|  144  |  142  | 
|  145 struct BranchTableOperand { |  143 struct BranchTableOperand { | 
|  146   uint32_t table_count; |  144   uint32_t table_count; | 
|  147   const byte* table; |  145   const byte* table; | 
|  148   int length; |  146   int length; | 
|  149   inline BranchTableOperand(Decoder* decoder, const byte* pc) { |  147   inline BranchTableOperand(Decoder* decoder, const byte* pc) { | 
|  150     table_count = decoder->checked_read_u16(pc, 1, "expected #entries"); |  148     int varint_length; | 
|  151     length = 2 + table_count * 2 + 2; |  149     table_count = | 
 |  150         decoder->checked_read_u32v(pc, 1, &varint_length, "expected #entries"); | 
 |  151     length = varint_length + (table_count + 1) * sizeof(uint32_t); | 
|  152  |  152  | 
|  153     if (decoder->check(pc, 3, table_count * 2 + 2, |  153     uint32_t table_start = 1 + varint_length; | 
 |  154     if (decoder->check(pc, table_start, (table_count + 1) * sizeof(uint32_t), | 
|  154                        "expected <table entries>")) { |  155                        "expected <table entries>")) { | 
|  155       table = pc + 3; |  156       table = pc + table_start; | 
|  156     } else { |  157     } else { | 
|  157       table = nullptr; |  158       table = nullptr; | 
|  158     } |  159     } | 
|  159   } |  160   } | 
|  160   inline uint16_t read_entry(Decoder* decoder, int i) { |  161   inline uint32_t read_entry(Decoder* decoder, int i) { | 
|  161     DCHECK(i >= 0 && static_cast<uint32_t>(i) <= table_count); |  162     DCHECK(i >= 0 && static_cast<uint32_t>(i) <= table_count); | 
|  162     return table ? decoder->read_u16(table + i * sizeof(uint16_t)) : 0; |  163     return table ? decoder->read_u32(table + i * sizeof(uint32_t)) : 0; | 
|  163   } |  164   } | 
|  164 }; |  165 }; | 
|  165  |  166  | 
|  166 struct MemoryAccessOperand { |  167 struct MemoryAccessOperand { | 
|  167   bool aligned; |  168   bool aligned; | 
|  168   uint32_t offset; |  169   uint32_t offset; | 
|  169   int length; |  170   int length; | 
|  170   inline MemoryAccessOperand(Decoder* decoder, const byte* pc) { |  171   inline MemoryAccessOperand(Decoder* decoder, const byte* pc) { | 
|  171     byte bitfield = decoder->checked_read_u8(pc, 1, "memory access byte"); |  172     byte bitfield = decoder->checked_read_u8(pc, 1, "memory access byte"); | 
|  172     aligned = MemoryAccess::AlignmentField::decode(bitfield); |  173     aligned = MemoryAccess::AlignmentField::decode(bitfield); | 
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  228 int OpcodeLength(const byte* pc, const byte* end); |  229 int OpcodeLength(const byte* pc, const byte* end); | 
|  229  |  230  | 
|  230 // Computes the arity (number of sub-nodes) of the opcode at the given address. |  231 // Computes the arity (number of sub-nodes) of the opcode at the given address. | 
|  231 int OpcodeArity(ModuleEnv* module, FunctionSig* sig, const byte* pc, |  232 int OpcodeArity(ModuleEnv* module, FunctionSig* sig, const byte* pc, | 
|  232                 const byte* end); |  233                 const byte* end); | 
|  233 }  // namespace wasm |  234 }  // namespace wasm | 
|  234 }  // namespace internal |  235 }  // namespace internal | 
|  235 }  // namespace v8 |  236 }  // namespace v8 | 
|  236  |  237  | 
|  237 #endif  // V8_WASM_AST_DECODER_H_ |  238 #endif  // V8_WASM_AST_DECODER_H_ | 
| OLD | NEW |