diff --git a/include/wabt/stream.h b/include/wabt/stream.h index 3b68ac8a0..67f50975e 100644 --- a/include/wabt/stream.h +++ b/include/wabt/stream.h @@ -195,36 +195,6 @@ class MemoryStream : public Stream { std::unique_ptr buf_; }; -class MemoryAllocStream : public wabt::Stream { - public: - typedef void* (*wabt_realloc)(void* __ptr, size_t __size); - - MemoryAllocStream(uint8_t* _output_data = nullptr, - size_t _total_size = 0, - wabt_realloc _realloc_fn = nullptr) - : output_data(_output_data), total_size(_total_size), used_size(0) { - if (_realloc_fn) { - realloc_fn = _realloc_fn; - } else { - realloc_fn = std::realloc; - } - } - - wabt::Result WriteDataImpl(size_t dst_offset, const void* src, size_t size); - - wabt::Result MoveDataImpl(size_t dst_offset, size_t src_offset, size_t size); - - wabt::Result TruncateImpl(size_t size); - inline size_t GetSize() const { return used_size; } - inline uint8_t* GetData() { return output_data; } - - private: - uint8_t* output_data; - size_t total_size; - size_t used_size; - wabt_realloc realloc_fn; -}; - class FileStream : public Stream { public: WABT_DISALLOW_COPY_AND_ASSIGN(FileStream); diff --git a/src/binary-reader.cc b/src/binary-reader.cc index 4faa8522e..9ff79ec7c 100644 --- a/src/binary-reader.cc +++ b/src/binary-reader.cc @@ -1941,12 +1941,18 @@ Result BinaryReader::ReadInstructions(Offset end_offset, const char* context) { } Result BinaryReader::ReadSkippedFunctionBody(Offset end_offset) { +#ifdef WABT_KEEP_OPCODE_WHEN_SKIP_FUNC_BODY std::vector opcode_buffer; opcode_buffer.resize(end_offset - state_.offset); memcpy(opcode_buffer.data(), state_.data + state_.offset, opcode_buffer.size()); CALLBACK(OnSkipFunctionBodyExpr, opcode_buffer); state_.offset = end_offset; +#else + // old version with OnEndExpr + state_.offset = end_offset; + CALLBACK0(OnEndExpr); +#endif return Result::Ok; } @@ -2899,12 +2905,7 @@ Result BinaryReader::ReadCodeSection(Offset section_size) { CALLBACK(EndLocalDecls); if (options_.skip_function_bodies) { -#ifdef WABT_KEEP_OPCODE_WHEN_SKIP_FUNC_BODY CHECK_RESULT(ReadSkippedFunctionBody(end_offset)); -#else - state_.offset = end_offset; - CALLBACK0(OnEndExpr); -#endif } else { CHECK_RESULT(ReadFunctionBody(end_offset)); } diff --git a/src/stream.cc b/src/stream.cc index 122c0d7e3..5f27e01b2 100644 --- a/src/stream.cc +++ b/src/stream.cc @@ -229,71 +229,6 @@ Result MemoryStream::TruncateImpl(size_t size) { return Result::Ok; } -Result MemoryAllocStream::WriteDataImpl(size_t dst_offset, - const void* src, - size_t size) { - if (size == 0) { - return wabt::Result::Ok; - } - size_t end = dst_offset + size; - bool needRealloc = false; - while (end > total_size) { - total_size = total_size << 1; - needRealloc = true; - } - if (needRealloc) { - output_data = static_cast(realloc_fn(output_data, total_size)); - } - - if (end > used_size) { - used_size = end; - } - - memcpy(output_data + dst_offset, src, size); - return wabt::Result::Ok; -} - -Result MemoryAllocStream::MoveDataImpl(size_t dst_offset, - size_t src_offset, - size_t size) { - if (size == 0) { - return wabt::Result::Ok; - } - size_t src_end = src_offset + size; - size_t dst_end = dst_offset + size; - size_t end = src_end > dst_end ? src_end : dst_end; - - bool needRealloc = false; - while (end > total_size) { - total_size = total_size << 1; - needRealloc = true; - } - if (needRealloc) { - output_data = static_cast(realloc_fn(output_data, total_size)); - } - - if (end > used_size) { - used_size = end; - } - - uint8_t* dst = output_data + dst_offset; - uint8_t* src = output_data + src_offset; - memmove(dst, src, size); - return wabt::Result::Ok; -} - -Result MemoryAllocStream::TruncateImpl(size_t size) { - if (size > used_size) { - return wabt::Result::Error; - } - used_size = size; - - // will not truncate size, we can truncate it at end - // output_data = (uint8_t*)realloc_fn(output_data, size); - // total_size = size; - return wabt::Result::Ok; -} - FileStream::FileStream(std::string_view filename, Stream* log_stream) : Stream(log_stream), file_(nullptr), offset_(0), should_close_(false) { std::string filename_str(filename);