diff options
Diffstat (limited to 'test/example')
-rw-r--r-- | test/example/c-api-kitchen-sink.c | 303 | ||||
-rw-r--r-- | test/example/c-api-kitchen-sink.txt | 310 |
2 files changed, 610 insertions, 3 deletions
diff --git a/test/example/c-api-kitchen-sink.c b/test/example/c-api-kitchen-sink.c index 22f2d5f29..82651c7c3 100644 --- a/test/example/c-api-kitchen-sink.c +++ b/test/example/c-api-kitchen-sink.c @@ -365,6 +365,7 @@ void test_features() { BinaryenFeatureTypedFunctionReferences()); printf("BinaryenFeatureRelaxedSIMD: %d\n", BinaryenFeatureRelaxedSIMD()); printf("BinaryenFeatureExtendedConst: %d\n", BinaryenFeatureExtendedConst()); + printf("BinaryenFeatureStrings: %d\n", BinaryenFeatureStrings()); printf("BinaryenFeatureAll: %d\n", BinaryenFeatureAll()); } @@ -472,6 +473,28 @@ void test_core() { BinaryenType f32 = BinaryenTypeFloat32(); BinaryenType f64 = BinaryenTypeFloat64(); BinaryenType v128 = BinaryenTypeVec128(); + BinaryenType i8Array; + BinaryenType i16Array; + BinaryenType i32Struct; + { + TypeBuilderRef tb = TypeBuilderCreate(3); + TypeBuilderSetArrayType( + tb, 0, BinaryenTypeInt32(), BinaryenPackedTypeInt8(), true); + TypeBuilderSetArrayType( + tb, 1, BinaryenTypeInt32(), BinaryenPackedTypeInt16(), true); + TypeBuilderSetStructType( + tb, + 2, + (BinaryenType[]){BinaryenTypeInt32()}, + (BinaryenPackedType[]){BinaryenPackedTypeNotPacked()}, + (bool[]){true}, + 1); + BinaryenHeapType builtHeapTypes[3]; + TypeBuilderBuildAndDispose(tb, (BinaryenHeapType*)&builtHeapTypes, 0, 0); + i8Array = BinaryenTypeFromHeapType(builtHeapTypes[0], true); + i16Array = BinaryenTypeFromHeapType(builtHeapTypes[1], true); + i32Struct = BinaryenTypeFromHeapType(builtHeapTypes[2], true); + } // Memory. Add it before creating any memory-using instructions. @@ -979,6 +1002,12 @@ void test_core() { BinaryenRefAs(module, BinaryenRefAsI31(), BinaryenRefNull(module, BinaryenTypeAnyref())), + BinaryenRefAs(module, + BinaryenRefAsExternInternalize(), + BinaryenRefNull(module, BinaryenTypeExternref())), + BinaryenRefAs(module, + BinaryenRefAsExternExternalize(), + BinaryenRefNull(module, BinaryenTypeAnyref())), // Exception handling BinaryenTry(module, NULL, tryBody, catchTags, 1, catchBodies, 2, NULL), // (try $try_outer @@ -1040,6 +1069,249 @@ void test_core() { BinaryenI31New(module, makeInt32(module, 0)), BinaryenI31Get(module, i31refExpr, 1), BinaryenI31Get(module, BinaryenI31New(module, makeInt32(module, 2)), 0), + BinaryenRefTest(module, + BinaryenGlobalGet(module, "i8Array-global", i8Array), + BinaryenTypeGetHeapType(i8Array)), + BinaryenRefCast(module, + BinaryenGlobalGet(module, "i8Array-global", i8Array), + BinaryenTypeGetHeapType(i8Array)), + BinaryenStructNew(module, 0, 0, BinaryenTypeGetHeapType(i32Struct)), + BinaryenStructNew(module, + (BinaryenExpressionRef[]){makeInt32(module, 0)}, + 1, + BinaryenTypeGetHeapType(i32Struct)), + BinaryenStructGet(module, + 0, + BinaryenGlobalGet(module, "i32Struct-global", i32Struct), + BinaryenTypeInt32(), + false), + BinaryenStructSet(module, + 0, + BinaryenGlobalGet(module, "i32Struct-global", i32Struct), + makeInt32(module, 0)), + BinaryenArrayNew( + module, BinaryenTypeGetHeapType(i8Array), makeInt32(module, 3), 0), + BinaryenArrayNew(module, + BinaryenTypeGetHeapType(i8Array), + makeInt32(module, 3), + makeInt32(module, 42)), + BinaryenArrayInit(module, + BinaryenTypeGetHeapType(i8Array), + (BinaryenExpressionRef[]){makeInt32(module, 1), + makeInt32(module, 2), + makeInt32(module, 3)}, + 3), + BinaryenArrayGet(module, + BinaryenGlobalGet(module, "i8Array-global", i8Array), + makeInt32(module, 0), + true), + BinaryenArrayGet(module, + BinaryenGlobalGet(module, "i8Array-global", i8Array), + makeInt32(module, 0), + false), + BinaryenArraySet(module, + BinaryenGlobalGet(module, "i8Array-global", i8Array), + makeInt32(module, 0), + makeInt32(module, 42)), + BinaryenArrayLen(module, + BinaryenGlobalGet(module, "i8Array-global", i8Array)), + BinaryenArrayCopy(module, + BinaryenGlobalGet(module, "i8Array-global", i8Array), + makeInt32(module, 0), + BinaryenGlobalGet(module, "i8Array-global", i8Array), + makeInt32(module, 1), + makeInt32(module, 2)), + // Strings + BinaryenStringNew(module, + BinaryenStringNewUTF8(), + makeInt32(module, 0), + makeInt32(module, 0), + 0, + 0), + BinaryenStringNew(module, + BinaryenStringNewWTF8(), + makeInt32(module, 0), + makeInt32(module, 0), + 0, + 0), + BinaryenStringNew(module, + BinaryenStringNewReplace(), + makeInt32(module, 0), + makeInt32(module, 0), + 0, + 0), + BinaryenStringNew(module, + BinaryenStringNewWTF16(), + makeInt32(module, 0), + makeInt32(module, 0), + 0, + 0), + BinaryenStringNew(module, + BinaryenStringNewUTF8Array(), + BinaryenGlobalGet(module, "i8Array-global", i8Array), + 0, + makeInt32(module, 0), + makeInt32(module, 0)), + BinaryenStringNew(module, + BinaryenStringNewWTF8Array(), + BinaryenGlobalGet(module, "i8Array-global", i8Array), + 0, + makeInt32(module, 0), + makeInt32(module, 0)), + BinaryenStringNew(module, + BinaryenStringNewReplaceArray(), + BinaryenGlobalGet(module, "i8Array-global", i8Array), + 0, + makeInt32(module, 0), + makeInt32(module, 0)), + BinaryenStringNew(module, + BinaryenStringNewWTF16Array(), + BinaryenGlobalGet(module, "i16Array-global", i8Array), + 0, + makeInt32(module, 0), + makeInt32(module, 0)), + BinaryenStringConst(module, "hello world"), + BinaryenStringMeasure( + module, + BinaryenStringMeasureUTF8(), + BinaryenGlobalGet(module, "string-global", BinaryenTypeStringref())), + BinaryenStringMeasure( + module, + BinaryenStringMeasureWTF8(), + BinaryenGlobalGet(module, "string-global", BinaryenTypeStringref())), + BinaryenStringMeasure( + module, + BinaryenStringMeasureWTF16(), + BinaryenGlobalGet(module, "string-global", BinaryenTypeStringref())), + BinaryenStringMeasure( + module, + BinaryenStringMeasureIsUSV(), + BinaryenGlobalGet(module, "string-global", BinaryenTypeStringref())), + BinaryenStringMeasure( + module, + BinaryenStringMeasureWTF16View(), + BinaryenStringAs( + module, + BinaryenStringAsWTF16(), + BinaryenGlobalGet(module, "string-global", BinaryenTypeStringref()))), + BinaryenStringEncode( + module, + BinaryenStringEncodeUTF8(), + BinaryenGlobalGet(module, "string-global", BinaryenTypeStringref()), + makeInt32(module, 0), + 0), + BinaryenStringEncode( + module, + BinaryenStringEncodeWTF8(), + BinaryenGlobalGet(module, "string-global", BinaryenTypeStringref()), + makeInt32(module, 0), + 0), + BinaryenStringEncode( + module, + BinaryenStringEncodeWTF16(), + BinaryenGlobalGet(module, "string-global", BinaryenTypeStringref()), + makeInt32(module, 0), + 0), + BinaryenStringEncode( + module, + BinaryenStringEncodeUTF8Array(), + BinaryenGlobalGet(module, "string-global", BinaryenTypeStringref()), + BinaryenGlobalGet(module, "i8Array-global", i8Array), + makeInt32(module, 0)), + BinaryenStringEncode( + module, + BinaryenStringEncodeWTF8Array(), + BinaryenGlobalGet(module, "string-global", BinaryenTypeStringref()), + BinaryenGlobalGet(module, "i8Array-global", i8Array), + makeInt32(module, 0)), + BinaryenStringEncode( + module, + BinaryenStringEncodeWTF16Array(), + BinaryenGlobalGet(module, "string-global", BinaryenTypeStringref()), + BinaryenGlobalGet(module, "i16Array-global", i16Array), + makeInt32(module, 0)), + BinaryenStringConcat( + module, + BinaryenGlobalGet(module, "string-global", BinaryenTypeStringref()), + BinaryenGlobalGet(module, "string-global", BinaryenTypeStringref())), + BinaryenStringEq( + module, + BinaryenGlobalGet(module, "string-global", BinaryenTypeStringref()), + BinaryenGlobalGet(module, "string-global", BinaryenTypeStringref())), + BinaryenStringAs( + module, + BinaryenStringAsWTF8(), + BinaryenGlobalGet(module, "string-global", BinaryenTypeStringref())), + BinaryenStringAs( + module, + BinaryenStringAsWTF16(), + BinaryenGlobalGet(module, "string-global", BinaryenTypeStringref())), + BinaryenStringAs( + module, + BinaryenStringAsIter(), + BinaryenGlobalGet(module, "string-global", BinaryenTypeStringref())), + BinaryenStringWTF8Advance( + module, + BinaryenStringAs( + module, + BinaryenStringAsWTF8(), + BinaryenGlobalGet(module, "string-global", BinaryenTypeStringref())), + makeInt32(module, 0), + makeInt32(module, 0)), + BinaryenStringWTF16Get( + module, + BinaryenStringAs( + module, + BinaryenStringAsWTF16(), + BinaryenGlobalGet(module, "string-global", BinaryenTypeStringref())), + makeInt32(module, 0)), + BinaryenStringIterNext( + module, + BinaryenStringAs( + module, + BinaryenStringAsIter(), + BinaryenGlobalGet(module, "string-global", BinaryenTypeStringref()))), + BinaryenStringIterMove( + module, + BinaryenStringIterMoveAdvance(), + BinaryenStringAs( + module, + BinaryenStringAsIter(), + BinaryenGlobalGet(module, "string-global", BinaryenTypeStringref())), + makeInt32(module, 1)), + BinaryenStringIterMove( + module, + BinaryenStringIterMoveRewind(), + BinaryenStringAs( + module, + BinaryenStringAsIter(), + BinaryenGlobalGet(module, "string-global", BinaryenTypeStringref())), + makeInt32(module, 1)), + BinaryenStringSliceWTF( + module, + BinaryenStringSliceWTF8(), + BinaryenStringAs( + module, + BinaryenStringAsWTF8(), + BinaryenGlobalGet(module, "string-global", BinaryenTypeStringref())), + makeInt32(module, 0), + makeInt32(module, 0)), + BinaryenStringSliceWTF( + module, + BinaryenStringSliceWTF16(), + BinaryenStringAs( + module, + BinaryenStringAsWTF16(), + BinaryenGlobalGet(module, "string-global", BinaryenTypeStringref())), + makeInt32(module, 0), + makeInt32(module, 0)), + BinaryenStringSliceIter( + module, + BinaryenStringAs( + module, + BinaryenStringAsIter(), + BinaryenGlobalGet(module, "string-global", BinaryenTypeStringref())), + makeInt32(module, 0)), // Other BinaryenNop(module), BinaryenUnreachable(module), @@ -1077,6 +1349,31 @@ void test_core() { BinaryenTypeFloat32(), 1, makeFloat32(module, 7.5)); + BinaryenAddGlobal( + module, + "i8Array-global", + i8Array, + true, + BinaryenArrayNew( + module, BinaryenTypeGetHeapType(i8Array), makeInt32(module, 0), 0)); + BinaryenAddGlobal( + module, + "i16Array-global", + i16Array, + true, + BinaryenArrayNew( + module, BinaryenTypeGetHeapType(i16Array), makeInt32(module, 0), 0)); + BinaryenAddGlobal( + module, + "i32Struct-global", + i32Struct, + true, + BinaryenStructNew(module, 0, 0, BinaryenTypeGetHeapType(i32Struct))); + BinaryenAddGlobal(module, + "string-global", + BinaryenTypeStringref(), + true, + BinaryenStringConst(module, "")); // Imports @@ -1830,7 +2127,7 @@ void test_typebuilder() { TypeBuilderSetSignatureType( builder, tempSignatureIndex, - TypeBuilderGetTempTupleType(builder, ¶mTypes, 2), + TypeBuilderGetTempTupleType(builder, (BinaryenType*)¶mTypes, 2), tempSignatureType); } @@ -1908,8 +2205,8 @@ void test_typebuilder() { arrayType, structType, signatureType, basicType, subStructType}; BinaryenAddFunction(module, "test", - BinaryenNone(), - BinaryenNone(), + BinaryenTypeNone(), + BinaryenTypeNone(), varTypes, 5, BinaryenNop(module)); diff --git a/test/example/c-api-kitchen-sink.txt b/test/example/c-api-kitchen-sink.txt index 82c917067..5c96ea964 100644 --- a/test/example/c-api-kitchen-sink.txt +++ b/test/example/c-api-kitchen-sink.txt @@ -45,6 +45,7 @@ BinaryenFeatureMemory64: 2048 BinaryenFeatureTypedFunctionReferences: 4096 BinaryenFeatureRelaxedSIMD: 16384 BinaryenFeatureExtendedConst: 32768 +BinaryenFeatureStrings: 65536 BinaryenFeatureAll: 253951 (f32.neg (f32.const -33.61199951171875) @@ -62,13 +63,24 @@ BinaryenFeatureAll: 253951 (i32.const 0) ) (module + (type $[mut:i8] (array (mut i8))) + (type ${mut:i32} (struct (field (mut i32)))) (type $i32_i64_f32_f64_=>_i32 (func (param i32 i64 f32 f64) (result i32))) + (type $[mut:i16] (array (mut i16))) (type $i32_=>_none (func (param i32))) (type $i32_f64_=>_f32 (func (param i32 f64) (result f32))) (type $none_=>_none (func)) (import "module" "base" (func $an-imported (param i32 f64) (result f32))) (global $a-global i32 (i32.const 7)) (global $a-mutable-global (mut f32) (f32.const 7.5)) + (global $i8Array-global (mut (ref null $[mut:i8])) (array.new_default $[mut:i8] + (i32.const 0) + )) + (global $i16Array-global (mut (ref null $[mut:i16])) (array.new_default $[mut:i16] + (i32.const 0) + )) + (global $i32Struct-global (mut (ref null ${mut:i32})) (struct.new_default ${mut:i32})) + (global $string-global (mut stringref) (string.const "")) (memory $0 (shared 1 256)) (data (i32.const 10) "hello, world") (data "I am passive") @@ -2019,6 +2031,16 @@ BinaryenFeatureAll: 253951 (ref.null any) ) ) + (drop + (extern.internalize + (ref.null extern) + ) + ) + (drop + (extern.externalize + (ref.null any) + ) + ) (try (do (throw $a-tag @@ -2135,6 +2157,294 @@ BinaryenFeatureAll: 253951 ) ) ) + (drop + (ref.test_static $[mut:i8] + (global.get $i8Array-global) + ) + ) + (drop + (ref.cast_static $[mut:i8] + (global.get $i8Array-global) + ) + ) + (drop + (struct.new_default ${mut:i32}) + ) + (drop + (struct.new ${mut:i32} + (i32.const 0) + ) + ) + (drop + (struct.get ${mut:i32} 0 + (global.get $i32Struct-global) + ) + ) + (struct.set ${mut:i32} 0 + (global.get $i32Struct-global) + (i32.const 0) + ) + (drop + (array.new_default $[mut:i8] + (i32.const 3) + ) + ) + (drop + (array.new $[mut:i8] + (i32.const 42) + (i32.const 3) + ) + ) + (drop + (array.init_static $[mut:i8] + (i32.const 1) + (i32.const 2) + (i32.const 3) + ) + ) + (drop + (array.get_s $[mut:i8] + (global.get $i8Array-global) + (i32.const 0) + ) + ) + (drop + (array.get_u $[mut:i8] + (global.get $i8Array-global) + (i32.const 0) + ) + ) + (array.set $[mut:i8] + (global.get $i8Array-global) + (i32.const 0) + (i32.const 42) + ) + (drop + (array.len $[mut:i8] + (global.get $i8Array-global) + ) + ) + (array.copy $[mut:i8] $[mut:i8] + (global.get $i8Array-global) + (i32.const 0) + (global.get $i8Array-global) + (i32.const 1) + (i32.const 2) + ) + (drop + (string.new_wtf8 utf8 + (i32.const 0) + (i32.const 0) + ) + ) + (drop + (string.new_wtf8 wtf8 + (i32.const 0) + (i32.const 0) + ) + ) + (drop + (string.new_wtf8 replace + (i32.const 0) + (i32.const 0) + ) + ) + (drop + (string.new_wtf16 + (i32.const 0) + (i32.const 0) + ) + ) + (drop + (string.new_wtf8_array utf8 + (global.get $i8Array-global) + (i32.const 0) + (i32.const 0) + ) + ) + (drop + (string.new_wtf8_array wtf8 + (global.get $i8Array-global) + (i32.const 0) + (i32.const 0) + ) + ) + (drop + (string.new_wtf8_array replace + (global.get $i8Array-global) + (i32.const 0) + (i32.const 0) + ) + ) + (drop + (string.new_wtf16_array + (global.get $i16Array-global) + (i32.const 0) + (i32.const 0) + ) + ) + (drop + (string.const "hello world") + ) + (drop + (string.measure_wtf8 utf8 + (global.get $string-global) + ) + ) + (drop + (string.measure_wtf8 wtf8 + (global.get $string-global) + ) + ) + (drop + (string.measure_wtf16 + (global.get $string-global) + ) + ) + (drop + (string.is_usv_sequence + (global.get $string-global) + ) + ) + (drop + (stringview_wtf16.length + (string.as_wtf16 + (global.get $string-global) + ) + ) + ) + (drop + (string.encode_wtf8 utf8 + (global.get $string-global) + (i32.const 0) + ) + ) + (drop + (string.encode_wtf8 wtf8 + (global.get $string-global) + (i32.const 0) + ) + ) + (drop + (string.encode_wtf16 + (global.get $string-global) + (i32.const 0) + ) + ) + (drop + (string.encode_wtf8_array utf8 + (global.get $string-global) + (global.get $i8Array-global) + (i32.const 0) + ) + ) + (drop + (string.encode_wtf8_array wtf8 + (global.get $string-global) + (global.get $i8Array-global) + (i32.const 0) + ) + ) + (drop + (string.encode_wtf16_array + (global.get $string-global) + (global.get $i16Array-global) + (i32.const 0) + ) + ) + (drop + (string.concat + (global.get $string-global) + (global.get $string-global) + ) + ) + (drop + (string.eq + (global.get $string-global) + (global.get $string-global) + ) + ) + (drop + (string.as_wtf8 + (global.get $string-global) + ) + ) + (drop + (string.as_wtf16 + (global.get $string-global) + ) + ) + (drop + (string.as_iter + (global.get $string-global) + ) + ) + (drop + (stringview_wtf8.advance + (string.as_wtf8 + (global.get $string-global) + ) + (i32.const 0) + (i32.const 0) + ) + ) + (drop + (stringview_wtf16.get_codeunit + (string.as_wtf16 + (global.get $string-global) + ) + (i32.const 0) + ) + ) + (drop + (stringview_iter.next + (string.as_iter + (global.get $string-global) + ) + ) + ) + (drop + (stringview_iter.advance + (string.as_iter + (global.get $string-global) + ) + (i32.const 1) + ) + ) + (drop + (stringview_iter.rewind + (string.as_iter + (global.get $string-global) + ) + (i32.const 1) + ) + ) + (drop + (stringview_wtf8.slice + (string.as_wtf8 + (global.get $string-global) + ) + (i32.const 0) + (i32.const 0) + ) + ) + (drop + (stringview_wtf16.slice + (string.as_wtf16 + (global.get $string-global) + ) + (i32.const 0) + (i32.const 0) + ) + ) + (drop + (stringview_iter.slice + (string.as_iter + (global.get $string-global) + ) + (i32.const 0) + ) + ) (nop) (unreachable) ) |