Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: add support for BinaryenArrayNewData #6236

Merged
merged 7 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 11 additions & 0 deletions src/binaryen-c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1819,6 +1819,17 @@ BinaryenExpressionRef BinaryenArrayNew(BinaryenModuleRef module,
Builder(*(Module*)module)
.makeArrayNew(HeapType(type), (Expression*)size, (Expression*)init));
}
BinaryenExpressionRef BinaryenArrayNewData(BinaryenModuleRef module,
BinaryenHeapType type,
const char* name,
BinaryenExpressionRef offset,
BinaryenExpressionRef size) {
return static_cast<Expression*>(
Builder(*(Module*)module)
.makeArrayNewData(
HeapType(type), name, (Expression*)offset, (Expression*)size));
}

BinaryenExpressionRef BinaryenArrayNewFixed(BinaryenModuleRef module,
BinaryenHeapType type,
BinaryenExpressionRef* values,
Expand Down
8 changes: 6 additions & 2 deletions src/binaryen-c.h
Original file line number Diff line number Diff line change
Expand Up @@ -1073,8 +1073,12 @@ BINARYEN_API BinaryenExpressionRef BinaryenArrayNew(BinaryenModuleRef module,
BinaryenExpressionRef size,
BinaryenExpressionRef init);

// TODO: BinaryenArrayNewSeg

BINARYEN_API BinaryenExpressionRef
BinaryenArrayNewData(BinaryenModuleRef module,
BinaryenHeapType type,
const char* name,
BinaryenExpressionRef offset,
BinaryenExpressionRef size);
BINARYEN_API BinaryenExpressionRef
BinaryenArrayNewFixed(BinaryenModuleRef module,
BinaryenHeapType type,
Expand Down
5 changes: 5 additions & 0 deletions test/example/c-api-kitchen-sink.c
Original file line number Diff line number Diff line change
Expand Up @@ -1128,6 +1128,11 @@ void test_core() {
BinaryenTypeGetHeapType(i8Array),
makeInt32(module, 3),
makeInt32(module, 42)),
BinaryenArrayNewData(module,
BinaryenTypeGetHeapType(i8Array),
"0",
makeInt32(module, 0),
makeInt32(module, 2)),
BinaryenArrayNewFixed(module,
BinaryenTypeGetHeapType(i8Array),
(BinaryenExpressionRef[]){makeInt32(module, 1),
Expand Down
6 changes: 6 additions & 0 deletions test/example/c-api-kitchen-sink.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2297,6 +2297,12 @@ BinaryenFeatureAll: 131071
(i32.const 3)
)
)
(drop
(array.new_data $0 $0
(i32.const 0)
(i32.const 2)
)
)
(drop
(array.new_fixed $0 3
(i32.const 1)
Expand Down
Loading