2121#ifndef wasm_wasm_binary_h
2222#define wasm_wasm_binary_h
2323
24- // Default to using the standard encodings. Override the default with
25- // USE_STANDARD_GC_ENCODINGS or USE_LEGACY_GC_ENCODINGS.
26- #define STANDARD_GC_ENCODINGS 1
27-
28- #ifdef USE_STANDARD_GC_ENCODINGS
29- #ifdef USE_LEGACY_GC_ENCODINGS
30- #error \
31- " Cannot define both USE_STANDARD_GC_ENCODINGS and USE_LEGACY_GC_ENCODINGS"
32- #endif
33- #undef STANDARD_GC_ENCODINGS
34- #define STANDARD_GC_ENCODINGS 1
35- #else
36- #ifdef USE_LEGACY_GC_ENCODINGS
37- #undef STANDARD_GC_ENCODINGS
38- #define STANDARD_GC_ENCODINGS 0
39- #endif
40- #endif
41-
4224#include < cassert>
4325#include < ostream>
4426#include < type_traits>
@@ -374,62 +356,28 @@ enum EncodedType {
374356 f32 = -0x3 , // 0x7d
375357 f64 = -0x4 , // 0x7c
376358 v128 = -0x5 , // 0x7b
377- // packed types
378- #if STANDARD_GC_ENCODINGS
359+ // packed types
379360 i8 = -0x8 , // 0x78
380361 i16 = -0x9 , // 0x77
381- #else
382- i8 = -0x6 , // 0x7a
383- i16 = -0x7 , // 0x79
384- #endif
385- // reference types
386- #if STANDARD_GC_ENCODINGS
362+ // reference types
387363 nullfuncref = -0xd , // 0x73
388364 nullexternref = -0xe , // 0x72
389365 nullref = -0xf , // 0x71
390366 i31ref = -0x14 , // 0x6c
391367 structref = -0x15 , // 0x6b
392368 arrayref = -0x16 , // 0x6a
393- #else
394- nullexternref = -0x17 , // 0x69
395- nullfuncref = -0x18 , // 0x68
396- nullref = -0x1b , // 0x65
397- i31ref = -0x16 , // 0x6a
398- structref = -0x19 , // 0x67
399- arrayref = -0x1a , // 0x66
400- #endif
401- funcref = -0x10 , // 0x70
402- externref = -0x11 , // 0x6f
403- anyref = -0x12 , // 0x6e
404- eqref = -0x13 , // 0x6d
405- #if STANDARD_GC_ENCODINGS
406- #else
407- #endif
408- #if STANDARD_GC_ENCODINGS
409- nonnullable = -0x1c , // 0x64
410- nullable = -0x1d , // 0x63
411- #else
412- nullable = -0x14 , // 0x6c
413- nonnullable = -0x15 , // 0x6b
414- #endif
415- #if STANDARD_GC_ENCODINGS
369+ funcref = -0x10 , // 0x70
370+ externref = -0x11 , // 0x6f
371+ anyref = -0x12 , // 0x6e
372+ eqref = -0x13 , // 0x6d
373+ nonnullable = -0x1c , // 0x64
374+ nullable = -0x1d , // 0x63
416375 // exception handling
417376 exnref = -0x17 , // 0x69
418- #else
419- // Currently the legacy GC encoding's nullexternref encoding overlaps with
420- // exnref's. We assume the legacy GC encoding won't be used with the exnref
421- // for the moment and assign a random value to it to prevent the clash.
422- exnref = -0xfe ,
423- #endif
424377 nullexnref = -0xc , // 0x74
425- // string reference types
426- #if STANDARD_GC_ENCODINGS
378+ // string reference types
427379 stringref = -0x19 , // 0x67
428380 stringview_wtf8 = -0x1a , // 0x66
429- #else
430- stringref = -0x1c , // 0x64
431- stringview_wtf8 = -0x1d , // 0x63
432- #endif
433381 stringview_wtf16 = -0x1e , // 0x62
434382 stringview_iter = -0x1f , // 0x61
435383 // type forms
@@ -438,45 +386,23 @@ enum EncodedType {
438386 Struct = -0x21 , // 0x5f
439387 Array = -0x22 , // 0x5e
440388 Sub = -0x30 , // 0x50
441- #if STANDARD_GC_ENCODINGS
442389 SubFinal = -0x31 , // 0x4f
443- #else
444- SubFinal = -0x32 , // 0x4e
445- #endif
446- // isorecursive recursion groups
447- #if STANDARD_GC_ENCODINGS
448- Rec = -0x32 , // 0x4e
449- #else
450- Rec = -0x31 , // 0x4f
451- #endif
390+ // isorecursive recursion groups
391+ Rec = -0x32 , // 0x4e
452392 // block_type
453393 Empty = -0x40 , // 0x40
454394};
455395
456396enum EncodedHeapType {
457- #if STANDARD_GC_ENCODINGS
458397 nofunc = -0xd , // 0x73
459398 noext = -0xe , // 0x72
460399 none = -0xf , // 0x71
461- #else
462- noext = -0x17 , // 0x69
463- nofunc = -0x18 , // 0x68
464- none = -0x1b , // 0x65
465- #endif
466400 func = -0x10 , // 0x70
467401 ext = -0x11 , // 0x6f
468402 any = -0x12 , // 0x6e
469403 eq = -0x13 , // 0x6d
470- #if STANDARD_GC_ENCODINGS
471404 exn = -0x17 , // 0x69
472- #else
473- // Currently the legacy GC encoding's nullexternref encoding overlaps with
474- // exnref's. We assume the legacy GC encoding won't be used with the exnref
475- // for the moment and assign a random value to it to prevent the clash.
476- exn = -0xfe ,
477- #endif
478405 noexn = -0xc , // 0x74
479- #if STANDARD_GC_ENCODINGS
480406 i31 = -0x14 , // 0x6c
481407 struct_ = -0x15 , // 0x6b
482408 array = -0x16 , // 0x6a
@@ -485,13 +411,6 @@ enum EncodedHeapType {
485411 // here as that would be a compiler error, so add _heap suffixes. See
486412 // https://github.com/WebAssembly/stringref/issues/12
487413 stringview_wtf8_heap = -0x1a , // 0x66
488- #else
489- i31 = -0x16 , // 0x6a
490- struct_ = -0x19 , // 0x67
491- array = -0x1a , // 0x66
492- string = -0x1c , // 0x64
493- stringview_wtf8_heap = -0x1d , // 0x63
494- #endif
495414 stringview_wtf16_heap = -0x1e , // 0x62
496415 stringview_iter_heap = -0x1f , // 0x61
497416};
@@ -1155,17 +1074,10 @@ enum ASTNodes {
11551074 RefNull = 0xd0 ,
11561075 RefIsNull = 0xd1 ,
11571076 RefFunc = 0xd2 ,
1158- #if STANDARD_GC_ENCODINGS
11591077 RefEq = 0xd3 ,
11601078 RefAsNonNull = 0xd4 ,
11611079 BrOnNull = 0xd5 ,
11621080 BrOnNonNull = 0xd6 ,
1163- #else
1164- RefAsNonNull = 0xd3 ,
1165- BrOnNull = 0xd4 ,
1166- RefEq = 0xd5 ,
1167- BrOnNonNull = 0xd6 ,
1168- #endif
11691081
11701082 // exception handling opcodes
11711083
@@ -1187,8 +1099,8 @@ enum ASTNodes {
11871099 CallRef = 0x14 ,
11881100 RetCallRef = 0x15 ,
11891101
1190- // gc opcodes
1191- # if STANDARD_GC_ENCODINGS
1102+ // gc opcodes
1103+
11921104 StructNew = 0x00 ,
11931105 StructNewDefault = 0x01 ,
11941106 StructGet = 0x02 ,
@@ -1220,39 +1132,6 @@ enum ASTNodes {
12201132 RefI31 = 0x1c ,
12211133 I31GetS = 0x1d ,
12221134 I31GetU = 0x1e ,
1223- #else
1224- StructGet = 0x03 ,
1225- StructGetS = 0x04 ,
1226- StructGetU = 0x05 ,
1227- StructSet = 0x06 ,
1228- StructNew = 0x07 ,
1229- StructNewDefault = 0x08 ,
1230- ArrayNewElem = 0x10 ,
1231- ArrayGet = 0x13 ,
1232- ArrayGetS = 0x14 ,
1233- ArrayGetU = 0x15 ,
1234- ArraySet = 0x16 ,
1235- ArrayCopy = 0x18 ,
1236- ArrayLen = 0x19 ,
1237- ArrayNewFixed = 0x1a ,
1238- ArrayNew = 0x1b ,
1239- ArrayNewDefault = 0x1c ,
1240- ArrayNewData = 0x1d ,
1241- RefI31 = 0x20 ,
1242- I31GetS = 0x21 ,
1243- I31GetU = 0x22 ,
1244- RefTest = 0x40 ,
1245- RefCast = 0x41 ,
1246- BrOnCast = 0x4e ,
1247- BrOnCastFail = 0x4f ,
1248- RefTestNull = 0x48 ,
1249- RefCastNull = 0x49 ,
1250- ExternInternalize = 0x70 ,
1251- ExternExternalize = 0x71 ,
1252- ArrayFill = 0x0f ,
1253- ArrayInitData = 0x54 ,
1254- ArrayInitElem = 0x55 ,
1255- #endif
12561135
12571136 // stringref opcodes
12581137
0 commit comments