Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/wabt/binary-reader-logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ class BinaryReaderLogging : public BinaryReaderDelegate {
Result OnDropExpr() override;
Result OnElseExpr() override;
Result OnEndExpr() override;
Result OnSkipFunctionBodyExpr(std::vector<uint8_t>& opcode_buffer) override;
Result OnF32ConstExpr(uint32_t value_bits) override;
Result OnF64ConstExpr(uint64_t value_bits) override;
Result OnV128ConstExpr(v128 value_bits) override;
Expand Down
3 changes: 3 additions & 0 deletions include/wabt/binary-reader-nop.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,9 @@ class BinaryReaderNop : public BinaryReaderDelegate {
Result OnDropExpr() override { return Result::Ok; }
Result OnElseExpr() override { return Result::Ok; }
Result OnEndExpr() override { return Result::Ok; }
Result OnSkipFunctionBodyExpr(std::vector<uint8_t>& opcode_buffer) override {
return Result::Ok;
}
Result OnF32ConstExpr(uint32_t value_bits) override { return Result::Ok; }
Result OnF64ConstExpr(uint64_t value_bits) override { return Result::Ok; }
Result OnV128ConstExpr(v128 value_bits) override { return Result::Ok; }
Expand Down
2 changes: 2 additions & 0 deletions include/wabt/binary-reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@ class BinaryReaderDelegate {
virtual Result OnDropExpr() = 0;
virtual Result OnElseExpr() = 0;
virtual Result OnEndExpr() = 0;
virtual Result OnSkipFunctionBodyExpr(
std::vector<uint8_t>& opcode_buffer) = 0;
virtual Result OnF32ConstExpr(uint32_t value_bits) = 0;
virtual Result OnF64ConstExpr(uint64_t value_bits) = 0;
virtual Result OnV128ConstExpr(v128 value_bits) = 0;
Expand Down
3 changes: 3 additions & 0 deletions include/wabt/expr-visitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class ExprVisitor {
Try,
TryTable,
Catch,
OpcodeRaw
};

Result HandleDefaultState(Expr*);
Expand Down Expand Up @@ -141,6 +142,7 @@ class ExprVisitor::Delegate {
virtual Result OnSimdShuffleOpExpr(SimdShuffleOpExpr*) = 0;
virtual Result OnLoadSplatExpr(LoadSplatExpr*) = 0;
virtual Result OnLoadZeroExpr(LoadZeroExpr*) = 0;
virtual Result OnOpcodeRawExpr(OpcodeRawExpr*) = 0;
};

class ExprVisitor::DelegateNop : public ExprVisitor::Delegate {
Expand Down Expand Up @@ -222,6 +224,7 @@ class ExprVisitor::DelegateNop : public ExprVisitor::Delegate {
Result OnSimdShuffleOpExpr(SimdShuffleOpExpr*) override { return Result::Ok; }
Result OnLoadSplatExpr(LoadSplatExpr*) override { return Result::Ok; }
Result OnLoadZeroExpr(LoadZeroExpr*) override { return Result::Ok; }
Result OnOpcodeRawExpr(OpcodeRawExpr*) override { return Result::Ok; }
};

} // namespace wabt
Expand Down
19 changes: 18 additions & 1 deletion include/wabt/ir.h
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,8 @@ enum class ExprType {
Unreachable,

First = AtomicLoad,
Last = Unreachable
Last = Unreachable,
OpCodeRaw = Last + 1, // virual type
};

const char* GetExprTypeName(ExprType type);
Expand Down Expand Up @@ -839,6 +840,22 @@ class AtomicFenceExpr : public ExprMixin<ExprType::AtomicFence> {
uint32_t consistency_model;
};

class OpcodeRawExpr : public ExprMixin<ExprType::OpCodeRaw> {
public:
explicit OpcodeRawExpr(std::vector<uint8_t>&& in_opcode_buffer,
FuncSignature& in_func_sig,
const Location& loc = Location())
: ExprMixin<ExprType::OpCodeRaw>(loc),
opcode_buffer(std::move(in_opcode_buffer)),
is_extracted(false),
func_sig(&in_func_sig) {}

std::vector<uint8_t> opcode_buffer;
bool is_extracted;
ExprList extracted_exprs;
const FuncSignature* func_sig;
};

struct Tag {
explicit Tag(std::string_view name) : name(name) {}

Expand Down
30 changes: 30 additions & 0 deletions include/wabt/stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,36 @@ class MemoryStream : public Stream {
std::unique_ptr<OutputBuffer> buf_;
};

class MemoryAllocStream : public wabt::Stream {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any uses of this new class. Can you perhaps split this out into its own PR along with a description of why its needed?

Copy link
Author

@primstar-cool primstar-cool Jan 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sometimes we can't use std mem alloc (such as run in a pre-allocated mempool)
if we use MemoryStream and copy to managed buffer, it will cost double size.
in low-mem device, we need prevent it.
it can be removed from this feature, and impl by proj.

and macro wabt_expr_make_unique is the same reason. we need prevent huge mem allocate(size or times).
final export override for its size, expr override alloc for frequency

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'v remove it in new commit

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);
Expand Down
Loading
Loading