OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef V8_WASM_AST_DECODER_H_ |
| 6 #define V8_WASM_AST_DECODER_H_ |
| 7 |
| 8 #include "src/signature.h" |
| 9 #include "src/wasm/wasm-opcodes.h" |
| 10 #include "src/wasm/wasm-result.h" |
| 11 |
| 12 namespace v8 { |
| 13 namespace internal { |
| 14 |
| 15 namespace compiler { // external declarations from compiler. |
| 16 class WasmGraphBuilder; |
| 17 } |
| 18 |
| 19 namespace wasm { |
| 20 |
| 21 typedef compiler::WasmGraphBuilder TFBuilder; |
| 22 struct ModuleEnv; // forward declaration of module interface. |
| 23 |
| 24 // Interface the function environment during decoding, include the signature |
| 25 // and number of locals. |
| 26 struct FunctionEnv { |
| 27 ModuleEnv* module; // module environment |
| 28 FunctionSig* sig; // signature of this function |
| 29 uint32_t local_int32_count; // number of int32 locals |
| 30 uint32_t local_int64_count; // number of int64 locals |
| 31 uint32_t local_float32_count; // number of float32 locals |
| 32 uint32_t local_float64_count; // number of float64 locals |
| 33 uint32_t total_locals; // sum of parameters and all locals |
| 34 |
| 35 bool IsValidLocal(uint32_t index) { return index < total_locals; } |
| 36 uint32_t GetLocalCount() { return total_locals; } |
| 37 LocalType GetLocalType(uint32_t index) { |
| 38 if (index < sig->parameter_count()) return sig->GetParam(index); |
| 39 index -= sig->parameter_count(); |
| 40 if (index < local_int32_count) return kAstI32; |
| 41 index -= local_int32_count; |
| 42 if (index < local_int64_count) return kAstI64; |
| 43 index -= local_int64_count; |
| 44 if (index < local_float32_count) return kAstF32; |
| 45 index -= local_float32_count; |
| 46 if (index < local_float64_count) return kAstF64; |
| 47 return kAstStmt; |
| 48 } |
| 49 |
| 50 void AddLocals(LocalType type, uint32_t count) { |
| 51 switch (type) { |
| 52 case kAstI32: |
| 53 local_int32_count += count; |
| 54 break; |
| 55 case kAstI64: |
| 56 local_int64_count += count; |
| 57 break; |
| 58 case kAstF32: |
| 59 local_float32_count += count; |
| 60 break; |
| 61 case kAstF64: |
| 62 local_float64_count += count; |
| 63 break; |
| 64 default: |
| 65 UNREACHABLE(); |
| 66 } |
| 67 total_locals += count; |
| 68 DCHECK(total_locals == |
| 69 (sig->parameter_count() + local_int32_count + local_int64_count + |
| 70 local_float32_count + local_float64_count)); |
| 71 } |
| 72 |
| 73 void SumLocals() { |
| 74 total_locals = static_cast<uint32_t>(sig->parameter_count()) + |
| 75 local_int32_count + local_int64_count + local_float32_count + |
| 76 local_float64_count; |
| 77 } |
| 78 }; |
| 79 |
| 80 struct Tree; |
| 81 typedef Result<Tree*> TreeResult; |
| 82 |
| 83 std::ostream& operator<<(std::ostream& os, const Tree& tree); |
| 84 |
| 85 TreeResult VerifyWasmCode(FunctionEnv* env, const byte* base, const byte* start, |
| 86 const byte* end); |
| 87 TreeResult BuildTFGraph(TFBuilder* builder, FunctionEnv* env, const byte* base, |
| 88 const byte* start, const byte* end); |
| 89 |
| 90 inline TreeResult VerifyWasmCode(FunctionEnv* env, const byte* start, |
| 91 const byte* end) { |
| 92 return VerifyWasmCode(env, nullptr, start, end); |
| 93 } |
| 94 |
| 95 inline TreeResult BuildTFGraph(TFBuilder* builder, FunctionEnv* env, |
| 96 const byte* start, const byte* end) { |
| 97 return BuildTFGraph(builder, env, nullptr, start, end); |
| 98 } |
| 99 |
| 100 enum ReadUnsignedLEB128ErrorCode { kNoError, kInvalidLEB128, kMissingLEB128 }; |
| 101 |
| 102 ReadUnsignedLEB128ErrorCode ReadUnsignedLEB128Operand(const byte*, const byte*, |
| 103 int*, uint32_t*); |
| 104 |
| 105 // Computes the length of the opcode at the given address. |
| 106 int OpcodeLength(const byte* pc); |
| 107 |
| 108 // Computes the arity (number of sub-nodes) of the opcode at the given address. |
| 109 int OpcodeArity(FunctionEnv* env, const byte* pc); |
| 110 } // namespace wasm |
| 111 } // namespace internal |
| 112 } // namespace v8 |
| 113 |
| 114 #endif // V8_WASM_AST_DECODER_H_ |
OLD | NEW |