Skip to content

[C-API] Add packed type constants for use with GC types #4791

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

Merged
merged 2 commits into from
Jul 12, 2022
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
12 changes: 12 additions & 0 deletions src/binaryen-c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,18 @@ WASM_DEPRECATED BinaryenType BinaryenFloat32(void) { return Type::f32; }
WASM_DEPRECATED BinaryenType BinaryenFloat64(void) { return Type::f64; }
WASM_DEPRECATED BinaryenType BinaryenUndefined(void) { return uint32_t(-1); }

// Packed types

BinaryenPackedType BinaryenPackedTypeNotPacked(void) {
return Field::PackedType::not_packed;
}
BinaryenPackedType BinaryenPackedTypeInt8(void) {
return Field::PackedType::i8;
}
BinaryenPackedType BinaryenPackedTypeInt16(void) {
return Field::PackedType::i16;
}

// Expression ids

BinaryenExpressionId BinaryenInvalidId(void) {
Expand Down
8 changes: 8 additions & 0 deletions src/binaryen-c.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,14 @@ WASM_DEPRECATED BinaryenType BinaryenFloat32(void);
WASM_DEPRECATED BinaryenType BinaryenFloat64(void);
WASM_DEPRECATED BinaryenType BinaryenUndefined(void);

// Packed types (call to get the value of each; you can cache them)

typedef uint32_t BinaryenPackedType;

BINARYEN_API BinaryenPackedType BinaryenPackedTypeNotPacked(void);
BINARYEN_API BinaryenPackedType BinaryenPackedTypeInt8(void);
BINARYEN_API BinaryenPackedType BinaryenPackedTypeInt16(void);

// Expression ids (call to get the value of each; you can cache them)

typedef uint32_t BinaryenExpressionId;
Expand Down
7 changes: 7 additions & 0 deletions test/example/c-api-kitchen-sink.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,13 @@ void test_types() {
pair[0] = pair[1] = f32;
BinaryenType float_pair = BinaryenTypeCreate(pair, 2);
assert(float_pair != i32_pair);

BinaryenPackedType notPacked = BinaryenPackedTypeNotPacked();
printf(" // BinaryenPackedTypeNotPacked: %d\n", notPacked);
BinaryenPackedType i8 = BinaryenPackedTypeInt8();
printf(" // BinaryenPackedTypeInt8: %d\n", i8);
BinaryenPackedType i16 = BinaryenPackedTypeInt16();
printf(" // BinaryenPackedTypeInt16: %d\n", i16);
}

void test_features() {
Expand Down
3 changes: 3 additions & 0 deletions test/example/c-api-kitchen-sink.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
// BinaryenTypeI31ref: 10
// BinaryenTypeDataref: 11
// BinaryenTypeAuto: -1
// BinaryenPackedTypeNotPacked: 0
// BinaryenPackedTypeInt8: 1
// BinaryenPackedTypeInt16: 2
BinaryenFeatureMVP: 0
BinaryenFeatureAtomics: 1
BinaryenFeatureBulkMemory: 16
Expand Down