Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(128)

Side by Side Diff: src/wasm/ast-decoder.h

Issue 1775873002: [Wasm] Convert many of the fixed-size values to LEB128. (Closed) Base URL: http://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 17 matching lines...) Expand all
139 inline ImportIndexOperand(Decoder* decoder, const byte* pc) { 137 inline ImportIndexOperand(Decoder* decoder, const byte* pc) {
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;
147 // Cache entry offsets, assuming we are iterating through them in order.
148 int next_entry_index;
149 const byte* next_entry;
149 inline BranchTableOperand(Decoder* decoder, const byte* pc) { 150 inline BranchTableOperand(Decoder* decoder, const byte* pc) {
titzer 2016/03/08 10:06:53 Maybe we can leave the branch table target as uint
binji 2016/03/08 16:30:15 :)
150 table_count = decoder->checked_read_u16(pc, 1, "expected #entries"); 151 int varint_length;
151 length = 2 + table_count * 2 + 2; 152 table_count =
153 decoder->checked_read_u32v(pc, 1, &varint_length, "expected #entries");
154 length = varint_length;
155 uint32_t table_start = 1 + length;
156 for (uint32_t i = 0; i < table_count; ++i) {
157 decoder->checked_read_u32v(pc, 1 + length, &varint_length);
158 length += varint_length;
159 }
160 // Default entry.
161 decoder->checked_read_u32v(pc, 1 + length, &varint_length);
162 length += varint_length;
152 163
153 if (decoder->check(pc, 3, table_count * 2 + 2, 164 if (decoder->check(pc, 1, length, "expected <table entries>")) {
154 "expected <table entries>")) { 165 table = pc + table_start;
155 table = pc + 3;
156 } else { 166 } else {
157 table = nullptr; 167 table = nullptr;
158 } 168 }
169 next_entry_index = 0;
170 next_entry = table;
159 } 171 }
160 inline uint16_t read_entry(Decoder* decoder, int i) { 172 inline uint32_t read_entry(Decoder* decoder, int i) {
161 DCHECK(i >= 0 && static_cast<uint32_t>(i) <= table_count); 173 DCHECK(i >= 0 && static_cast<uint32_t>(i) <= table_count);
162 return table ? decoder->read_u16(table + i * sizeof(uint16_t)) : 0; 174 if (!table) return 0;
175 if (next_entry_index > i) {
176 // Reset to zero and iterate.
177 next_entry_index = 0;
178 next_entry = table;
179 }
180 uint32_t result;
181 while (next_entry_index <= i) {
titzer 2016/03/08 10:06:53 Linear search; that's no good. Definitely gotta go
binji 2016/03/08 16:30:15 It shouldn't actually end up being linear here. In
182 int varint_length;
183 result = decoder->checked_read_u32v(next_entry, 0, &varint_length);
184 next_entry_index++;
185 next_entry += varint_length;
186 }
187 return result;
163 } 188 }
164 }; 189 };
165 190
166 struct MemoryAccessOperand { 191 struct MemoryAccessOperand {
167 bool aligned; 192 bool aligned;
168 uint32_t offset; 193 uint32_t offset;
169 int length; 194 int length;
170 inline MemoryAccessOperand(Decoder* decoder, const byte* pc) { 195 inline MemoryAccessOperand(Decoder* decoder, const byte* pc) {
171 byte bitfield = decoder->checked_read_u8(pc, 1, "memory access byte"); 196 byte bitfield = decoder->checked_read_u8(pc, 1, "memory access byte");
172 aligned = MemoryAccess::AlignmentField::decode(bitfield); 197 aligned = MemoryAccess::AlignmentField::decode(bitfield);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 int OpcodeLength(const byte* pc, const byte* end); 253 int OpcodeLength(const byte* pc, const byte* end);
229 254
230 // Computes the arity (number of sub-nodes) of the opcode at the given address. 255 // Computes the arity (number of sub-nodes) of the opcode at the given address.
231 int OpcodeArity(ModuleEnv* module, FunctionSig* sig, const byte* pc, 256 int OpcodeArity(ModuleEnv* module, FunctionSig* sig, const byte* pc,
232 const byte* end); 257 const byte* end);
233 } // namespace wasm 258 } // namespace wasm
234 } // namespace internal 259 } // namespace internal
235 } // namespace v8 260 } // namespace v8
236 261
237 #endif // V8_WASM_AST_DECODER_H_ 262 #endif // V8_WASM_AST_DECODER_H_
OLDNEW
« no previous file with comments | « src/wasm/asm-wasm-builder.cc ('k') | src/wasm/encoder.h » ('j') | src/wasm/encoder.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698