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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 struct ImportIndexOperand { | 135 struct ImportIndexOperand { |
136 uint32_t index; | 136 uint32_t index; |
137 FunctionSig* sig; | 137 FunctionSig* sig; |
138 int length; | 138 int length; |
139 inline ImportIndexOperand(Decoder* decoder, const byte* pc) { | 139 inline ImportIndexOperand(Decoder* decoder, const byte* pc) { |
140 index = decoder->checked_read_u32v(pc, 1, &length, "import index"); | 140 index = decoder->checked_read_u32v(pc, 1, &length, "import index"); |
141 sig = nullptr; | 141 sig = nullptr; |
142 } | 142 } |
143 }; | 143 }; |
144 | 144 |
145 struct TableSwitchOperand { | 145 struct BranchTableOperand { |
146 uint32_t case_count; | |
147 uint32_t table_count; | 146 uint32_t table_count; |
148 const byte* table; | 147 const byte* table; |
149 int length; | 148 int length; |
150 inline TableSwitchOperand(Decoder* decoder, const byte* pc) { | 149 inline BranchTableOperand(Decoder* decoder, const byte* pc) { |
151 case_count = decoder->checked_read_u16(pc, 1, "expected #cases"); | 150 table_count = decoder->checked_read_u16(pc, 1, "expected #entries"); |
152 table_count = decoder->checked_read_u16(pc, 3, "expected #entries"); | 151 length = 2 + table_count * 2 + 2; |
153 length = 4 + table_count * 2; | |
154 | 152 |
155 if (decoder->check(pc, 5, table_count * 2, "expected <table entries>")) { | 153 if (decoder->check(pc, 3, table_count * 2 + 2, |
156 table = pc + 5; | 154 "expected <table entries>")) { |
| 155 table = pc + 3; |
157 } else { | 156 } else { |
158 table = nullptr; | 157 table = nullptr; |
159 } | 158 } |
160 } | 159 } |
161 inline uint16_t read_entry(Decoder* decoder, int i) { | 160 inline uint16_t read_entry(Decoder* decoder, int i) { |
162 DCHECK(i >= 0 && static_cast<uint32_t>(i) < table_count); | 161 DCHECK(i >= 0 && static_cast<uint32_t>(i) <= table_count); |
163 return table ? decoder->read_u16(table + i * sizeof(uint16_t)) : 0; | 162 return table ? decoder->read_u16(table + i * sizeof(uint16_t)) : 0; |
164 } | 163 } |
165 }; | 164 }; |
166 | 165 |
167 struct MemoryAccessOperand { | 166 struct MemoryAccessOperand { |
168 bool aligned; | 167 bool aligned; |
169 uint32_t offset; | 168 uint32_t offset; |
170 int length; | 169 int length; |
171 inline MemoryAccessOperand(Decoder* decoder, const byte* pc) { | 170 inline MemoryAccessOperand(Decoder* decoder, const byte* pc) { |
172 byte bitfield = decoder->checked_read_u8(pc, 1, "memory access byte"); | 171 byte bitfield = decoder->checked_read_u8(pc, 1, "memory access byte"); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 // Computes the length of the opcode at the given address. | 273 // Computes the length of the opcode at the given address. |
275 int OpcodeLength(const byte* pc, const byte* end); | 274 int OpcodeLength(const byte* pc, const byte* end); |
276 | 275 |
277 // Computes the arity (number of sub-nodes) of the opcode at the given address. | 276 // Computes the arity (number of sub-nodes) of the opcode at the given address. |
278 int OpcodeArity(FunctionEnv* env, const byte* pc, const byte* end); | 277 int OpcodeArity(FunctionEnv* env, const byte* pc, const byte* end); |
279 } // namespace wasm | 278 } // namespace wasm |
280 } // namespace internal | 279 } // namespace internal |
281 } // namespace v8 | 280 } // namespace v8 |
282 | 281 |
283 #endif // V8_WASM_AST_DECODER_H_ | 282 #endif // V8_WASM_AST_DECODER_H_ |
OLD | NEW |