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

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

Issue 1763433002: [wasm] Rework encoding of local declarations. (Closed) Base URL: https://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
« no previous file with comments | « src/compiler/wasm-compiler.cc ('k') | src/wasm/ast-decoder.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 } else { 176 } else {
177 offset = 0; 177 offset = 0;
178 length = 1; 178 length = 1;
179 } 179 }
180 } 180 }
181 }; 181 };
182 182
183 typedef compiler::WasmGraphBuilder TFBuilder; 183 typedef compiler::WasmGraphBuilder TFBuilder;
184 struct ModuleEnv; // forward declaration of module interface. 184 struct ModuleEnv; // forward declaration of module interface.
185 185
186 // Interface the function environment during decoding, include the signature 186 // All of the various data structures necessary to decode a function body.
187 // and number of locals. 187 struct FunctionBody {
188 struct FunctionEnv { 188 ModuleEnv* module; // module environment
189 ModuleEnv* module; // module environment 189 FunctionSig* sig; // function signature
190 FunctionSig* sig; // signature of this function 190 const byte* base; // base of the module bytes, for error reporting
191 uint32_t local_i32_count; // number of int32 locals 191 const byte* start; // start of the function body
192 uint32_t local_i64_count; // number of int64 locals 192 const byte* end; // end of the function body
193 uint32_t local_f32_count; // number of float32 locals
194 uint32_t local_f64_count; // number of float64 locals
195 uint32_t total_locals; // sum of parameters and all locals
196
197 uint32_t GetLocalCount() { return total_locals; }
198 LocalType GetLocalType(uint32_t index) {
199 if (index < static_cast<uint32_t>(sig->parameter_count())) {
200 return sig->GetParam(index);
201 }
202 index -= static_cast<uint32_t>(sig->parameter_count());
203 if (index < local_i32_count) return kAstI32;
204 index -= local_i32_count;
205 if (index < local_i64_count) return kAstI64;
206 index -= local_i64_count;
207 if (index < local_f32_count) return kAstF32;
208 index -= local_f32_count;
209 if (index < local_f64_count) return kAstF64;
210 return kAstStmt;
211 }
212
213 void AddLocals(LocalType type, uint32_t count) {
214 switch (type) {
215 case kAstI32:
216 local_i32_count += count;
217 break;
218 case kAstI64:
219 local_i64_count += count;
220 break;
221 case kAstF32:
222 local_f32_count += count;
223 break;
224 case kAstF64:
225 local_f64_count += count;
226 break;
227 default:
228 UNREACHABLE();
229 }
230 total_locals += count;
231 DCHECK_EQ(total_locals,
232 (sig->parameter_count() + local_i32_count + local_i64_count +
233 local_f32_count + local_f64_count));
234 }
235
236 void SumLocals() {
237 total_locals = static_cast<uint32_t>(sig->parameter_count()) +
238 local_i32_count + local_i64_count + local_f32_count +
239 local_f64_count;
240 }
241 }; 193 };
242 194
243 struct Tree; 195 struct Tree;
244 typedef Result<Tree*> TreeResult; 196 typedef Result<Tree*> TreeResult;
245 197
246 std::ostream& operator<<(std::ostream& os, const Tree& tree); 198 std::ostream& operator<<(std::ostream& os, const Tree& tree);
247 199
248 TreeResult VerifyWasmCode(FunctionEnv* env, const byte* base, const byte* start, 200 TreeResult VerifyWasmCode(FunctionBody& body);
249 const byte* end); 201 TreeResult BuildTFGraph(TFBuilder* builder, FunctionBody& body);
250 TreeResult BuildTFGraph(TFBuilder* builder, FunctionEnv* env, const byte* base, 202 void PrintAst(FunctionBody& body);
251 const byte* start, const byte* end);
252 203
253 void PrintAst(FunctionEnv* env, const byte* start, const byte* end); 204 inline TreeResult VerifyWasmCode(ModuleEnv* module, FunctionSig* sig,
254 205 const byte* start, const byte* end) {
255 inline TreeResult VerifyWasmCode(FunctionEnv* env, const byte* start, 206 FunctionBody body = {module, sig, nullptr, start, end};
256 const byte* end) { 207 return VerifyWasmCode(body);
257 return VerifyWasmCode(env, nullptr, start, end);
258 } 208 }
259 209
260 inline TreeResult BuildTFGraph(TFBuilder* builder, FunctionEnv* env, 210 inline TreeResult BuildTFGraph(TFBuilder* builder, ModuleEnv* module,
261 const byte* start, const byte* end) { 211 FunctionSig* sig, const byte* start,
262 return BuildTFGraph(builder, env, nullptr, start, end); 212 const byte* end) {
213 FunctionBody body = {module, sig, nullptr, start, end};
214 return BuildTFGraph(builder, body);
263 } 215 }
264 216
265 enum ReadUnsignedLEB128ErrorCode { kNoError, kInvalidLEB128, kMissingLEB128 }; 217 enum ReadUnsignedLEB128ErrorCode { kNoError, kInvalidLEB128, kMissingLEB128 };
266 218
267 ReadUnsignedLEB128ErrorCode ReadUnsignedLEB128Operand(const byte*, const byte*, 219 ReadUnsignedLEB128ErrorCode ReadUnsignedLEB128Operand(const byte*, const byte*,
268 int*, uint32_t*); 220 int*, uint32_t*);
269 221
270 BitVector* AnalyzeLoopAssignmentForTesting(Zone* zone, FunctionEnv* env, 222 std::vector<LocalType>* DecodeLocalDeclsForTesting(const byte* start,
223 const byte* end);
224 BitVector* AnalyzeLoopAssignmentForTesting(Zone* zone, size_t num_locals,
271 const byte* start, const byte* end); 225 const byte* start, const byte* end);
272 226
273 // Computes the length of the opcode at the given address. 227 // Computes the length of the opcode at the given address.
274 int OpcodeLength(const byte* pc, const byte* end); 228 int OpcodeLength(const byte* pc, const byte* end);
275 229
276 // Computes the arity (number of sub-nodes) of the opcode at the given address. 230 // Computes the arity (number of sub-nodes) of the opcode at the given address.
277 int OpcodeArity(FunctionEnv* env, const byte* pc, const byte* end); 231 int OpcodeArity(ModuleEnv* module, FunctionSig* sig, const byte* pc,
232 const byte* end);
278 } // namespace wasm 233 } // namespace wasm
279 } // namespace internal 234 } // namespace internal
280 } // namespace v8 235 } // namespace v8
281 236
282 #endif // V8_WASM_AST_DECODER_H_ 237 #endif // V8_WASM_AST_DECODER_H_
OLDNEW
« no previous file with comments | « src/compiler/wasm-compiler.cc ('k') | src/wasm/ast-decoder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698