diff options
Diffstat (limited to 'src/interp/interp.cc')
-rw-r--r-- | src/interp/interp.cc | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/src/interp/interp.cc b/src/interp/interp.cc index f23f687d..1cfa333f 100644 --- a/src/interp/interp.cc +++ b/src/interp/interp.cc @@ -1126,8 +1126,7 @@ Result Thread::TableGet(const uint8_t** pc) { TRAP_MSG(TableAccessOutOfBounds, "table.get at %u >= max value %" PRIzx, index, table->size()); } - Ref ref = static_cast<Ref>(table->entries[index]); - return Push(ref); + return Push(table->entries[index]); } Result Thread::ElemDrop(const uint8_t** pc) { @@ -1486,7 +1485,7 @@ ValueTypeRep<R> IntEqz(ValueTypeRep<T> v_rep) { } ValueTypeRep<uint32_t> RefIsNull(ValueTypeRep<Ref> v_rep) { - return ToRep(v_rep.index == kInvalidIndex); + return ToRep(v_rep.kind == RefType::Null); } template <typename T> @@ -3596,10 +3595,24 @@ Result Thread::Run(int num_instructions) { CHECK_TRAP(Push(Ref{RefType::Null, kInvalidIndex})); break; - case Opcode::TableGrow: - case Opcode::TableSize: - WABT_UNREACHABLE; + case Opcode::TableGrow: { + Table* table = ReadTable(&pc); + uint32_t increment = Pop<uint32_t>(); + Ref ref = Pop<Ref>(); + uint32_t old_size = table->size(); + uint32_t max = table->limits.has_max ? table->limits.max : UINT32_MAX; + PUSH_NEG_1_AND_BREAK_IF(int64_t(old_size) + increment > max); + uint32_t new_size = old_size + increment; + table->resize(new_size, ref); + CHECK_TRAP(Push<uint32_t>(old_size)); break; + } + + case Opcode::TableSize: { + Table* table = ReadTable(&pc); + CHECK_TRAP(Push<uint32_t>(table->entries.size())); + break; + } case Opcode::MemoryInit: CHECK_TRAP(MemoryInit(&pc)); @@ -3709,6 +3722,10 @@ Result Executor::InitializeSegments(DefinedModule* module) { enum Pass { Check = 0, Init = 1 }; int pass = env_->features_.bulk_memory_enabled() ? Init : Check; + if (trace_stream_) { + trace_stream_->Writef(">>> initializing segments\n"); + } + for (; pass <= Init; ++pass) { for (const ElemSegmentInfo& info : module->active_elem_segments_) { uint32_t table_size = info.table->size(); @@ -3823,8 +3840,9 @@ void Executor::CopyResults(const FuncSignature* sig, TypedValues* out_results) { assert(expected_results == thread_.NumValues()); out_results->clear(); - for (size_t i = 0; i < expected_results; ++i) + for (size_t i = 0; i < expected_results; ++i) { out_results->emplace_back(sig->result_types[i], thread_.ValueAt(i)); + } } } // namespace interp |