5 #ifndef V8_WASM_FUNCTION_BODY_DECODER_H_ 6 #define V8_WASM_FUNCTION_BODY_DECODER_H_ 8 #include "src/base/compiler-specific.h" 9 #include "src/base/iterator.h" 10 #include "src/globals.h" 11 #include "src/wasm/decoder.h" 12 #include "src/wasm/wasm-opcodes.h" 13 #include "src/wasm/wasm-result.h" 34 : sig(sig), offset(offset), start(start), end(end) {}
43 enum PrintLocals { kPrintLocals, kOmitLocals };
46 const WasmModule* module, PrintLocals print_locals);
50 const WasmModule* module, PrintLocals print_locals,
52 std::vector<int>* line_numbers =
nullptr);
55 void PrintRawWasmCode(
const byte* start,
const byte* end);
66 V8_EXPORT_PRIVATE
bool DecodeLocalDecls(
const WasmFeatures& enabled,
68 const byte* start,
const byte* end);
70 V8_EXPORT_PRIVATE
BitVector* AnalyzeLoopAssignmentForTesting(
Zone* zone,
76 V8_EXPORT_PRIVATE
unsigned OpcodeLength(
const byte* pc,
const byte* end);
83 std::pair<uint32_t, uint32_t> StackEffect(
const WasmModule* module,
92 inline iterator_base& operator++() {
93 DCHECK_LT(ptr_, end_);
94 ptr_ += OpcodeLength(ptr_, end_);
97 inline bool operator==(
const iterator_base& that) {
98 return this->ptr_ == that.ptr_;
100 inline bool operator!=(
const iterator_base& that) {
101 return this->ptr_ != that.ptr_;
107 iterator_base(
const byte* ptr,
const byte* end) : ptr_(ptr), end_(end) {}
113 :
public iterator_base,
116 inline WasmOpcode operator*() {
117 DCHECK_LT(ptr_, end_);
118 return static_cast<WasmOpcode
>(*ptr_);
124 : iterator_base(ptr, end) {}
129 :
public iterator_base,
133 DCHECK_LT(ptr_, end_);
134 return static_cast<uint32_t>(ptr_ - start_);
141 : iterator_base(ptr, end), start_(start) {}
157 offset_iterator(start_, pc_, end_),
158 offset_iterator(start_, end_, end_));
161 WasmOpcode current() {
162 return static_cast<WasmOpcode
>(
163 read_u8<Decoder::kNoValidate>(pc_,
"expected bytecode"));
168 pc_ += OpcodeLength(pc_, end_);
169 if (pc_ >= end_) pc_ = end_;
173 bool has_next() {
return pc_ < end_; }
175 WasmOpcode prefixed_opcode() {
176 byte prefix = read_u8<Decoder::kNoValidate>(pc_,
"expected prefix");
177 byte index = read_u8<Decoder::kNoValidate>(pc_ + 1,
"expected index");
178 return static_cast<WasmOpcode
>(prefix << 8 | index);
186 #endif // V8_WASM_FUNCTION_BODY_DECODER_H_