diff --git a/src/compiler.ts b/src/compiler.ts index 9d8bd7838d..8128400889 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -452,35 +452,6 @@ export class Compiler extends DiagnosticEmitter { } } - // compile the start function if not empty or if explicitly requested - var startIsEmpty = !startFunctionBody.length; - var explicitStart = program.isWasi || options.explicitStart; - if (!startIsEmpty || explicitStart) { - let signature = startFunctionInstance.signature; - if (!startIsEmpty && explicitStart) { - module.addGlobal(BuiltinNames.started, NativeType.I32, true, module.i32(0)); - startFunctionBody.unshift( - module.global_set(BuiltinNames.started, module.i32(1)) - ); - startFunctionBody.unshift( - module.if( - module.global_get(BuiltinNames.started, NativeType.I32), - module.return() - ) - ); - } - let funcRef = module.addFunction( - startFunctionInstance.internalName, - signature.nativeParams, - signature.nativeResults, - typesToNativeTypes(startFunctionInstance.additionalLocals), - module.flatten(startFunctionBody) - ); - startFunctionInstance.finalize(module, funcRef); - if (!explicitStart) module.setStart(funcRef); - else module.addFunctionExport(startFunctionInstance.internalName, ExportNames.start); - } - // check if the entire program is acyclic var cyclicClasses = program.findCyclicClasses(); if (cyclicClasses.size) { @@ -520,6 +491,37 @@ export class Compiler extends DiagnosticEmitter { compileClassInstanceOf(this, prototype); } + // NOTE: no more element compiles from here. may go to the start function! + + // compile the start function if not empty or if explicitly requested + var startIsEmpty = !startFunctionBody.length; + var explicitStart = program.isWasi || options.explicitStart; + if (!startIsEmpty || explicitStart) { + let signature = startFunctionInstance.signature; + if (!startIsEmpty && explicitStart) { + module.addGlobal(BuiltinNames.started, NativeType.I32, true, module.i32(0)); + startFunctionBody.unshift( + module.global_set(BuiltinNames.started, module.i32(1)) + ); + startFunctionBody.unshift( + module.if( + module.global_get(BuiltinNames.started, NativeType.I32), + module.return() + ) + ); + } + let funcRef = module.addFunction( + startFunctionInstance.internalName, + signature.nativeParams, + signature.nativeResults, + typesToNativeTypes(startFunctionInstance.additionalLocals), + module.flatten(startFunctionBody) + ); + startFunctionInstance.finalize(module, funcRef); + if (!explicitStart) module.setStart(funcRef); + else module.addFunctionExport(startFunctionInstance.internalName, ExportNames.start); + } + // set up virtual lookup tables var functionTable = this.functionTable; for (let i = 0, k = functionTable.length; i < k; ++i) { diff --git a/tests/compiler/do.optimized.wat b/tests/compiler/do.optimized.wat index 387d88c372..cb44224960 100644 --- a/tests/compiler/do.optimized.wat +++ b/tests/compiler/do.optimized.wat @@ -1347,9 +1347,6 @@ unreachable end ) - (func $~start - call $start:do - ) (func $~lib/rt/pure/decrement (param $0 i32) (local $1 i32) (local $2 i32) @@ -1444,4 +1441,7 @@ i32.store offset=4 end ) + (func $~start + call $start:do + ) ) diff --git a/tests/compiler/do.untouched.wat b/tests/compiler/do.untouched.wat index 31e25710dd..851aa458b1 100644 --- a/tests/compiler/do.untouched.wat +++ b/tests/compiler/do.untouched.wat @@ -2231,9 +2231,6 @@ unreachable end ) - (func $~start - call $start:do - ) (func $~lib/rt/tlsf/freeBlock (param $0 i32) (param $1 i32) local.get $1 local.get $1 @@ -2340,6 +2337,9 @@ i32.store offset=4 end ) + (func $~start + call $start:do + ) (func $~lib/rt/pure/__visit (param $0 i32) (param $1 i32) local.get $0 global.get $~lib/memory/__heap_base diff --git a/tests/compiler/exports-lazy.optimized.wat b/tests/compiler/exports-lazy.optimized.wat index 16e77374e9..c9407f72d8 100644 --- a/tests/compiler/exports-lazy.optimized.wat +++ b/tests/compiler/exports-lazy.optimized.wat @@ -7,8 +7,8 @@ (global $exports-lazy/lazyGlobalUsed i32 (i32.const 1088)) (export "memory" (memory $0)) (export "lazyGlobalUsed" (global $exports-lazy/lazyGlobalUsed)) - (export "lazyFuncUsed" (func $~start)) - (func $~start + (export "lazyFuncUsed" (func $exports-lazy/lazyFuncUsed)) + (func $exports-lazy/lazyFuncUsed nop ) ) diff --git a/tests/compiler/exports-lazy.untouched.wat b/tests/compiler/exports-lazy.untouched.wat index fb88eff988..b8dfc482d8 100644 --- a/tests/compiler/exports-lazy.untouched.wat +++ b/tests/compiler/exports-lazy.untouched.wat @@ -16,10 +16,10 @@ drop call $exports-lazy/lazyFuncUsed ) - (func $~start - call $start:exports-lazy - ) (func $exports-lazy/lazyFuncUsed nop ) + (func $~start + call $start:exports-lazy + ) ) diff --git a/tests/compiler/extends-baseaggregate.optimized.wat b/tests/compiler/extends-baseaggregate.optimized.wat index ad8a799093..0dc7218963 100644 --- a/tests/compiler/extends-baseaggregate.optimized.wat +++ b/tests/compiler/extends-baseaggregate.optimized.wat @@ -1718,9 +1718,6 @@ local.get $0 call $~lib/rt/pure/__release ) - (func $~start - call $start:extends-baseaggregate - ) (func $~lib/rt/pure/decrement (param $0 i32) (local $1 i32) (local $2 i32) @@ -1886,6 +1883,9 @@ end end ) + (func $~start + call $start:extends-baseaggregate + ) (func $~lib/rt/pure/scanBlack (param $0 i32) local.get $0 local.get $0 diff --git a/tests/compiler/extends-baseaggregate.untouched.wat b/tests/compiler/extends-baseaggregate.untouched.wat index 0fafc7e1a7..5b1d0d8d7c 100644 --- a/tests/compiler/extends-baseaggregate.untouched.wat +++ b/tests/compiler/extends-baseaggregate.untouched.wat @@ -3354,9 +3354,6 @@ local.get $0 call $~lib/rt/pure/__release ) - (func $~start - call $start:extends-baseaggregate - ) (func $~lib/rt/pure/finalize (param $0 i32) i32.const 0 drop @@ -3586,6 +3583,9 @@ end end ) + (func $~start + call $start:extends-baseaggregate + ) (func $~lib/rt/pure/markGray (param $0 i32) (local $1 i32) local.get $0 diff --git a/tests/compiler/for.optimized.wat b/tests/compiler/for.optimized.wat index cb6293be03..d3bcc2be57 100644 --- a/tests/compiler/for.optimized.wat +++ b/tests/compiler/for.optimized.wat @@ -1359,9 +1359,6 @@ unreachable end ) - (func $~start - call $start:for - ) (func $~lib/rt/pure/decrement (param $0 i32) (local $1 i32) (local $2 i32) @@ -1456,4 +1453,7 @@ i32.store offset=4 end ) + (func $~start + call $start:for + ) ) diff --git a/tests/compiler/for.untouched.wat b/tests/compiler/for.untouched.wat index 637d88b68c..c4a98f4545 100644 --- a/tests/compiler/for.untouched.wat +++ b/tests/compiler/for.untouched.wat @@ -2276,9 +2276,6 @@ unreachable end ) - (func $~start - call $start:for - ) (func $~lib/rt/tlsf/freeBlock (param $0 i32) (param $1 i32) local.get $1 local.get $1 @@ -2385,6 +2382,9 @@ i32.store offset=4 end ) + (func $~start + call $start:for + ) (func $~lib/rt/pure/__visit (param $0 i32) (param $1 i32) local.get $0 global.get $~lib/memory/__heap_base diff --git a/tests/compiler/instanceof-class.optimized.wat b/tests/compiler/instanceof-class.optimized.wat index 33da57f588..6e617bea00 100644 --- a/tests/compiler/instanceof-class.optimized.wat +++ b/tests/compiler/instanceof-class.optimized.wat @@ -87,6 +87,36 @@ i32.const 16 i32.add ) + (func $~lib/rt/__instanceof (param $0 i32) (param $1 i32) (result i32) + local.get $0 + i32.const 20 + i32.sub + i32.load offset=12 + local.tee $0 + i32.const 1104 + i32.load + i32.le_u + if + loop $do-continue|0 + local.get $0 + local.get $1 + i32.eq + if + i32.const 1 + return + end + local.get $0 + i32.const 3 + i32.shl + i32.const 1108 + i32.add + i32.load offset=4 + local.tee $0 + br_if $do-continue|0 + end + end + i32.const 0 + ) (func $~start (local $0 i32) i32.const 1164 @@ -140,34 +170,4 @@ unreachable end ) - (func $~lib/rt/__instanceof (param $0 i32) (param $1 i32) (result i32) - local.get $0 - i32.const 20 - i32.sub - i32.load offset=12 - local.tee $0 - i32.const 1104 - i32.load - i32.le_u - if - loop $do-continue|0 - local.get $0 - local.get $1 - i32.eq - if - i32.const 1 - return - end - local.get $0 - i32.const 3 - i32.shl - i32.const 1108 - i32.add - i32.load offset=4 - local.tee $0 - br_if $do-continue|0 - end - end - i32.const 0 - ) ) diff --git a/tests/compiler/instanceof-class.untouched.wat b/tests/compiler/instanceof-class.untouched.wat index db05f4af22..bac7e1bc53 100644 --- a/tests/compiler/instanceof-class.untouched.wat +++ b/tests/compiler/instanceof-class.untouched.wat @@ -254,9 +254,6 @@ i32.eqz drop ) - (func $~start - call $start:instanceof-class - ) (func $~lib/rt/__instanceof (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) @@ -321,4 +318,7 @@ i32.const 0 return ) + (func $~start + call $start:instanceof-class + ) ) diff --git a/tests/compiler/issues/1095.optimized.wat b/tests/compiler/issues/1095.optimized.wat index 7823c14279..03c3cf39b4 100644 --- a/tests/compiler/issues/1095.optimized.wat +++ b/tests/compiler/issues/1095.optimized.wat @@ -928,52 +928,6 @@ call $~lib/rt/pure/decrement end ) - (func $~start - (local $0 i32) - (local $1 i32) - (local $2 i32) - (local $3 i32) - call $~lib/rt/pure/__new - call $~lib/rt/pure/__retain - local.tee $2 - i32.const 1248 - i32.store - local.get $2 - call $~lib/rt/pure/__retain - local.tee $0 - local.set $3 - local.get $0 - i32.load - local.tee $1 - i32.eqz - if - i32.const 1280 - i32.const 1344 - i32.const 8 - i32.const 13 - call $~lib/builtins/abort - unreachable - end - local.get $1 - local.get $0 - i32.load - local.tee $0 - i32.ne - if - local.get $1 - call $~lib/rt/pure/__retain - local.set $1 - local.get $0 - call $~lib/rt/pure/__release - end - local.get $3 - local.get $1 - i32.store - local.get $3 - call $~lib/rt/pure/__release - local.get $2 - call $~lib/rt/pure/__release - ) (func $~lib/rt/pure/decrement (param $0 i32) (local $1 i32) (local $2 i32) @@ -1067,4 +1021,50 @@ i32.store offset=4 end ) + (func $~start + (local $0 i32) + (local $1 i32) + (local $2 i32) + (local $3 i32) + call $~lib/rt/pure/__new + call $~lib/rt/pure/__retain + local.tee $2 + i32.const 1248 + i32.store + local.get $2 + call $~lib/rt/pure/__retain + local.tee $0 + local.set $3 + local.get $0 + i32.load + local.tee $1 + i32.eqz + if + i32.const 1280 + i32.const 1344 + i32.const 8 + i32.const 13 + call $~lib/builtins/abort + unreachable + end + local.get $1 + local.get $0 + i32.load + local.tee $0 + i32.ne + if + local.get $1 + call $~lib/rt/pure/__retain + local.set $1 + local.get $0 + call $~lib/rt/pure/__release + end + local.get $3 + local.get $1 + i32.store + local.get $3 + call $~lib/rt/pure/__release + local.get $2 + call $~lib/rt/pure/__release + ) ) diff --git a/tests/compiler/issues/1095.untouched.wat b/tests/compiler/issues/1095.untouched.wat index 8cf033aa58..3929920a57 100644 --- a/tests/compiler/issues/1095.untouched.wat +++ b/tests/compiler/issues/1095.untouched.wat @@ -1563,9 +1563,6 @@ local.get $0 call $~lib/rt/pure/__release ) - (func $~start - call $start:issues/1095 - ) (func $~lib/rt/tlsf/freeBlock (param $0 i32) (param $1 i32) local.get $1 local.get $1 @@ -1672,6 +1669,9 @@ i32.store offset=4 end ) + (func $~start + call $start:issues/1095 + ) (func $~lib/rt/pure/__visit (param $0 i32) (param $1 i32) local.get $0 global.get $~lib/memory/__heap_base diff --git a/tests/compiler/issues/1225.optimized.wat b/tests/compiler/issues/1225.optimized.wat index 8cbe5d08da..1f80f2c93d 100644 --- a/tests/compiler/issues/1225.optimized.wat +++ b/tests/compiler/issues/1225.optimized.wat @@ -877,6 +877,100 @@ global.get $issues/1225/x i32.load offset=4 ) + (func $~lib/rt/pure/decrement (param $0 i32) + (local $1 i32) + (local $2 i32) + local.get $0 + i32.load offset=4 + local.tee $2 + i32.const 268435455 + i32.and + local.set $1 + local.get $0 + i32.load + i32.const 1 + i32.and + if + i32.const 0 + i32.const 1120 + i32.const 122 + i32.const 14 + call $~lib/builtins/abort + unreachable + end + local.get $1 + i32.const 1 + i32.eq + if + block $__inlined_func$~lib/rt/__visit_members + block $invalid + block $~lib/arraybuffer/ArrayBufferView + local.get $0 + i32.const 12 + i32.add + i32.load + br_table $__inlined_func$~lib/rt/__visit_members $__inlined_func$~lib/rt/__visit_members $~lib/arraybuffer/ArrayBufferView $__inlined_func$~lib/rt/__visit_members $invalid + end + local.get $0 + i32.load offset=20 + local.tee $1 + if + local.get $1 + i32.const 1276 + i32.ge_u + if + local.get $1 + i32.const 20 + i32.sub + call $~lib/rt/pure/decrement + end + end + br $__inlined_func$~lib/rt/__visit_members + end + unreachable + end + local.get $2 + i32.const -2147483648 + i32.and + if + i32.const 0 + i32.const 1120 + i32.const 126 + i32.const 18 + call $~lib/builtins/abort + unreachable + end + local.get $0 + local.get $0 + i32.load + i32.const 1 + i32.or + i32.store + global.get $~lib/rt/tlsf/ROOT + local.get $0 + call $~lib/rt/tlsf/insertBlock + else + local.get $1 + i32.eqz + if + i32.const 0 + i32.const 1120 + i32.const 136 + i32.const 16 + call $~lib/builtins/abort + unreachable + end + local.get $0 + local.get $1 + i32.const 1 + i32.sub + local.get $2 + i32.const -268435456 + i32.and + i32.or + i32.store offset=4 + end + ) (func $~start (local $0 i32) (local $1 i32) @@ -984,98 +1078,4 @@ i32.const 0 global.set $issues/1225/x ) - (func $~lib/rt/pure/decrement (param $0 i32) - (local $1 i32) - (local $2 i32) - local.get $0 - i32.load offset=4 - local.tee $2 - i32.const 268435455 - i32.and - local.set $1 - local.get $0 - i32.load - i32.const 1 - i32.and - if - i32.const 0 - i32.const 1120 - i32.const 122 - i32.const 14 - call $~lib/builtins/abort - unreachable - end - local.get $1 - i32.const 1 - i32.eq - if - block $__inlined_func$~lib/rt/__visit_members - block $invalid - block $~lib/arraybuffer/ArrayBufferView - local.get $0 - i32.const 12 - i32.add - i32.load - br_table $__inlined_func$~lib/rt/__visit_members $__inlined_func$~lib/rt/__visit_members $~lib/arraybuffer/ArrayBufferView $__inlined_func$~lib/rt/__visit_members $invalid - end - local.get $0 - i32.load offset=20 - local.tee $1 - if - local.get $1 - i32.const 1276 - i32.ge_u - if - local.get $1 - i32.const 20 - i32.sub - call $~lib/rt/pure/decrement - end - end - br $__inlined_func$~lib/rt/__visit_members - end - unreachable - end - local.get $2 - i32.const -2147483648 - i32.and - if - i32.const 0 - i32.const 1120 - i32.const 126 - i32.const 18 - call $~lib/builtins/abort - unreachable - end - local.get $0 - local.get $0 - i32.load - i32.const 1 - i32.or - i32.store - global.get $~lib/rt/tlsf/ROOT - local.get $0 - call $~lib/rt/tlsf/insertBlock - else - local.get $1 - i32.eqz - if - i32.const 0 - i32.const 1120 - i32.const 136 - i32.const 16 - call $~lib/builtins/abort - unreachable - end - local.get $0 - local.get $1 - i32.const 1 - i32.sub - local.get $2 - i32.const -268435456 - i32.and - i32.or - i32.store offset=4 - end - ) ) diff --git a/tests/compiler/issues/1225.untouched.wat b/tests/compiler/issues/1225.untouched.wat index 7e6014e3c7..6ce8cc3221 100644 --- a/tests/compiler/issues/1225.untouched.wat +++ b/tests/compiler/issues/1225.untouched.wat @@ -1584,9 +1584,6 @@ local.get $0 global.set $issues/1225/x ) - (func $~start - call $start:issues/1225 - ) (func $~lib/rt/tlsf/freeBlock (param $0 i32) (param $1 i32) local.get $1 local.get $1 @@ -1693,6 +1690,9 @@ i32.store offset=4 end ) + (func $~start + call $start:issues/1225 + ) (func $~lib/rt/pure/__visit (param $0 i32) (param $1 i32) local.get $0 global.get $~lib/memory/__heap_base diff --git a/tests/compiler/logical.optimized.wat b/tests/compiler/logical.optimized.wat index db92fb280d..a7507ec143 100644 --- a/tests/compiler/logical.optimized.wat +++ b/tests/compiler/logical.optimized.wat @@ -926,49 +926,6 @@ call $~lib/rt/pure/decrement end ) - (func $~start - (local $0 i32) - (local $1 i32) - (local $2 i32) - call $~lib/rt/pure/__new - call $~lib/rt/pure/__retain - local.tee $0 - local.get $0 - call $~lib/rt/pure/__retain - local.tee $0 - call $~lib/rt/pure/__release - local.get $0 - i32.eqz - if - i32.const 0 - i32.const 1056 - i32.const 87 - i32.const 1 - call $~lib/builtins/abort - unreachable - end - call $~lib/rt/pure/__new - call $~lib/rt/pure/__retain - local.tee $0 - local.set $2 - local.get $0 - call $~lib/rt/pure/__retain - local.tee $0 - call $~lib/rt/pure/__release - local.get $0 - i32.eqz - if - i32.const 0 - i32.const 1056 - i32.const 92 - i32.const 1 - call $~lib/builtins/abort - unreachable - end - call $~lib/rt/pure/__release - local.get $2 - call $~lib/rt/pure/__release - ) (func $~lib/rt/pure/decrement (param $0 i32) (local $1 i32) (local $2 i32) @@ -1063,4 +1020,47 @@ i32.store offset=4 end ) + (func $~start + (local $0 i32) + (local $1 i32) + (local $2 i32) + call $~lib/rt/pure/__new + call $~lib/rt/pure/__retain + local.tee $0 + local.get $0 + call $~lib/rt/pure/__retain + local.tee $0 + call $~lib/rt/pure/__release + local.get $0 + i32.eqz + if + i32.const 0 + i32.const 1056 + i32.const 87 + i32.const 1 + call $~lib/builtins/abort + unreachable + end + call $~lib/rt/pure/__new + call $~lib/rt/pure/__retain + local.tee $0 + local.set $2 + local.get $0 + call $~lib/rt/pure/__retain + local.tee $0 + call $~lib/rt/pure/__release + local.get $0 + i32.eqz + if + i32.const 0 + i32.const 1056 + i32.const 92 + i32.const 1 + call $~lib/builtins/abort + unreachable + end + call $~lib/rt/pure/__release + local.get $2 + call $~lib/rt/pure/__release + ) ) diff --git a/tests/compiler/logical.untouched.wat b/tests/compiler/logical.untouched.wat index edb3d10edc..d822dfdc42 100644 --- a/tests/compiler/logical.untouched.wat +++ b/tests/compiler/logical.untouched.wat @@ -2113,9 +2113,6 @@ local.get $3 call $~lib/rt/pure/__release ) - (func $~start - call $start:logical - ) (func $~lib/rt/tlsf/freeBlock (param $0 i32) (param $1 i32) local.get $1 local.get $1 @@ -2222,6 +2219,9 @@ i32.store offset=4 end ) + (func $~start + call $start:logical + ) (func $~lib/rt/pure/__visit (param $0 i32) (param $1 i32) local.get $0 global.get $~lib/memory/__heap_base diff --git a/tests/compiler/managed-cast.optimized.wat b/tests/compiler/managed-cast.optimized.wat index 8debf75052..8cca8ef2c3 100644 --- a/tests/compiler/managed-cast.optimized.wat +++ b/tests/compiler/managed-cast.optimized.wat @@ -1112,9 +1112,6 @@ local.get $9 call $~lib/rt/pure/__release ) - (func $~start - call $start:managed-cast - ) (func $~lib/rt/pure/decrement (param $0 i32) (local $1 i32) (local $2 i32) @@ -1209,4 +1206,7 @@ i32.store offset=4 end ) + (func $~start + call $start:managed-cast + ) ) diff --git a/tests/compiler/managed-cast.untouched.wat b/tests/compiler/managed-cast.untouched.wat index 0e9f1eec6a..c00b1298ed 100644 --- a/tests/compiler/managed-cast.untouched.wat +++ b/tests/compiler/managed-cast.untouched.wat @@ -1820,9 +1820,6 @@ local.get $7 call $~lib/rt/pure/__release ) - (func $~start - call $start:managed-cast - ) (func $~lib/rt/tlsf/freeBlock (param $0 i32) (param $1 i32) local.get $1 local.get $1 @@ -1929,6 +1926,9 @@ i32.store offset=4 end ) + (func $~start + call $start:managed-cast + ) (func $~lib/rt/pure/__visit (param $0 i32) (param $1 i32) local.get $0 global.get $~lib/memory/__heap_base diff --git a/tests/compiler/object-literal.optimized.wat b/tests/compiler/object-literal.optimized.wat index 1ff5e95ded..30f84af07b 100644 --- a/tests/compiler/object-literal.optimized.wat +++ b/tests/compiler/object-literal.optimized.wat @@ -2121,9 +2121,6 @@ local.get $1 call $~lib/rt/pure/__release ) - (func $~start - call $start:object-literal - ) (func $~lib/rt/pure/decrement (param $0 i32) (local $1 i32) (local $2 i32) @@ -2273,6 +2270,9 @@ i32.store offset=4 end ) + (func $~start + call $start:object-literal + ) (func $~lib/rt/pure/__visit (param $0 i32) local.get $0 i32.const 1500 diff --git a/tests/compiler/object-literal.untouched.wat b/tests/compiler/object-literal.untouched.wat index 64a6aed47c..69aa96ca91 100644 --- a/tests/compiler/object-literal.untouched.wat +++ b/tests/compiler/object-literal.untouched.wat @@ -3857,9 +3857,6 @@ local.get $3 call $~lib/rt/pure/__release ) - (func $~start - call $start:object-literal - ) (func $~lib/rt/pure/finalize (param $0 i32) i32.const 0 drop @@ -3953,6 +3950,9 @@ i32.store offset=4 end ) + (func $~start + call $start:object-literal + ) (func $~lib/rt/pure/__visit (param $0 i32) (param $1 i32) local.get $0 global.get $~lib/memory/__heap_base diff --git a/tests/compiler/rc/global-init.untouched.wat b/tests/compiler/rc/global-init.untouched.wat index b59df1dcb3..eeab740011 100644 --- a/tests/compiler/rc/global-init.untouched.wat +++ b/tests/compiler/rc/global-init.untouched.wat @@ -130,9 +130,6 @@ local.get $1 global.set $rc/global-init/b ) - (func $~start - call $start:rc/global-init - ) (func $~lib/rt/tlsf/removeBlock (param $0 i32) (param $1 i32) (local $2 i32) (local $3 i32) @@ -817,6 +814,9 @@ i32.store offset=4 end ) + (func $~start + call $start:rc/global-init + ) (func $~lib/rt/pure/__visit (param $0 i32) (param $1 i32) local.get $0 global.get $~lib/memory/__heap_base diff --git a/tests/compiler/rc/local-init.optimized.wat b/tests/compiler/rc/local-init.optimized.wat index 0a2755109b..8b7010d3f2 100644 --- a/tests/compiler/rc/local-init.optimized.wat +++ b/tests/compiler/rc/local-init.optimized.wat @@ -866,65 +866,6 @@ i32.const 16 i32.add ) - (func $~start - (local $0 i32) - (local $1 i32) - (local $2 i32) - call $~lib/rt/pure/__new - local.tee $0 - i32.const 1260 - i32.gt_u - if - local.get $0 - i32.const 20 - i32.sub - local.tee $1 - i32.load offset=4 - local.tee $2 - i32.const -268435456 - i32.and - local.get $2 - i32.const 1 - i32.add - i32.const -268435456 - i32.and - i32.ne - if - i32.const 0 - i32.const 1152 - i32.const 109 - i32.const 3 - call $~lib/builtins/abort - unreachable - end - local.get $1 - local.get $2 - i32.const 1 - i32.add - i32.store offset=4 - local.get $1 - i32.load - i32.const 1 - i32.and - if - i32.const 0 - i32.const 1152 - i32.const 112 - i32.const 14 - call $~lib/builtins/abort - unreachable - end - end - local.get $0 - i32.const 1260 - i32.gt_u - if - local.get $0 - i32.const 20 - i32.sub - call $~lib/rt/pure/decrement - end - ) (func $~lib/rt/pure/decrement (param $0 i32) (local $1 i32) (local $2 i32) @@ -1019,4 +960,63 @@ i32.store offset=4 end ) + (func $~start + (local $0 i32) + (local $1 i32) + (local $2 i32) + call $~lib/rt/pure/__new + local.tee $0 + i32.const 1260 + i32.gt_u + if + local.get $0 + i32.const 20 + i32.sub + local.tee $1 + i32.load offset=4 + local.tee $2 + i32.const -268435456 + i32.and + local.get $2 + i32.const 1 + i32.add + i32.const -268435456 + i32.and + i32.ne + if + i32.const 0 + i32.const 1152 + i32.const 109 + i32.const 3 + call $~lib/builtins/abort + unreachable + end + local.get $1 + local.get $2 + i32.const 1 + i32.add + i32.store offset=4 + local.get $1 + i32.load + i32.const 1 + i32.and + if + i32.const 0 + i32.const 1152 + i32.const 112 + i32.const 14 + call $~lib/builtins/abort + unreachable + end + end + local.get $0 + i32.const 1260 + i32.gt_u + if + local.get $0 + i32.const 20 + i32.sub + call $~lib/rt/pure/decrement + end + ) ) diff --git a/tests/compiler/rc/local-init.untouched.wat b/tests/compiler/rc/local-init.untouched.wat index fc565bceb6..5d93529efb 100644 --- a/tests/compiler/rc/local-init.untouched.wat +++ b/tests/compiler/rc/local-init.untouched.wat @@ -1530,9 +1530,6 @@ local.get $0 call $~lib/rt/pure/__release ) - (func $~start - call $start:rc/local-init - ) (func $~lib/rt/tlsf/freeBlock (param $0 i32) (param $1 i32) local.get $1 local.get $1 @@ -1639,6 +1636,9 @@ i32.store offset=4 end ) + (func $~start + call $start:rc/local-init + ) (func $~lib/rt/pure/__visit (param $0 i32) (param $1 i32) local.get $0 global.get $~lib/memory/__heap_base diff --git a/tests/compiler/rc/logical-and-mismatch.optimized.wat b/tests/compiler/rc/logical-and-mismatch.optimized.wat index 565f247197..e76fceb0c1 100644 --- a/tests/compiler/rc/logical-and-mismatch.optimized.wat +++ b/tests/compiler/rc/logical-and-mismatch.optimized.wat @@ -926,48 +926,6 @@ call $~lib/rt/pure/decrement end ) - (func $~start - (local $0 i32) - call $~lib/rt/pure/__new - call $~lib/rt/pure/__retain - global.set $rc/logical-and-mismatch/gloRef - call $~lib/rt/pure/__new - call $~lib/rt/pure/__retain - local.tee $0 - if (result i32) - local.get $0 - call $~lib/rt/pure/__release - global.get $rc/logical-and-mismatch/gloRef - call $~lib/rt/pure/__retain - else - local.get $0 - end - call $~lib/rt/pure/__release - global.get $rc/logical-and-mismatch/gloRef - local.tee $0 - if (result i32) - call $~lib/rt/pure/__new - call $~lib/rt/pure/__retain - else - local.get $0 - call $~lib/rt/pure/__retain - end - call $~lib/rt/pure/__release - call $~lib/rt/pure/__new - call $~lib/rt/pure/__retain - local.tee $0 - if (result i32) - local.get $0 - call $~lib/rt/pure/__release - call $~lib/rt/pure/__new - call $~lib/rt/pure/__retain - else - local.get $0 - end - call $~lib/rt/pure/__release - global.get $rc/logical-and-mismatch/gloRef - call $~lib/rt/pure/__release - ) (func $~lib/rt/pure/decrement (param $0 i32) (local $1 i32) (local $2 i32) @@ -1062,4 +1020,46 @@ i32.store offset=4 end ) + (func $~start + (local $0 i32) + call $~lib/rt/pure/__new + call $~lib/rt/pure/__retain + global.set $rc/logical-and-mismatch/gloRef + call $~lib/rt/pure/__new + call $~lib/rt/pure/__retain + local.tee $0 + if (result i32) + local.get $0 + call $~lib/rt/pure/__release + global.get $rc/logical-and-mismatch/gloRef + call $~lib/rt/pure/__retain + else + local.get $0 + end + call $~lib/rt/pure/__release + global.get $rc/logical-and-mismatch/gloRef + local.tee $0 + if (result i32) + call $~lib/rt/pure/__new + call $~lib/rt/pure/__retain + else + local.get $0 + call $~lib/rt/pure/__retain + end + call $~lib/rt/pure/__release + call $~lib/rt/pure/__new + call $~lib/rt/pure/__retain + local.tee $0 + if (result i32) + local.get $0 + call $~lib/rt/pure/__release + call $~lib/rt/pure/__new + call $~lib/rt/pure/__retain + else + local.get $0 + end + call $~lib/rt/pure/__release + global.get $rc/logical-and-mismatch/gloRef + call $~lib/rt/pure/__release + ) ) diff --git a/tests/compiler/rc/logical-and-mismatch.untouched.wat b/tests/compiler/rc/logical-and-mismatch.untouched.wat index 106f1a32b9..af09857aeb 100644 --- a/tests/compiler/rc/logical-and-mismatch.untouched.wat +++ b/tests/compiler/rc/logical-and-mismatch.untouched.wat @@ -1570,9 +1570,6 @@ global.get $rc/logical-and-mismatch/gloRef call $~lib/rt/pure/__release ) - (func $~start - call $start:rc/logical-and-mismatch - ) (func $~lib/rt/tlsf/freeBlock (param $0 i32) (param $1 i32) local.get $1 local.get $1 @@ -1679,6 +1676,9 @@ i32.store offset=4 end ) + (func $~start + call $start:rc/logical-and-mismatch + ) (func $~lib/rt/pure/__visit (param $0 i32) (param $1 i32) local.get $0 global.get $~lib/memory/__heap_base diff --git a/tests/compiler/rc/logical-or-mismatch.optimized.wat b/tests/compiler/rc/logical-or-mismatch.optimized.wat index 710456e7d5..63848023ea 100644 --- a/tests/compiler/rc/logical-or-mismatch.optimized.wat +++ b/tests/compiler/rc/logical-or-mismatch.optimized.wat @@ -926,48 +926,6 @@ call $~lib/rt/pure/decrement end ) - (func $~start - (local $0 i32) - call $~lib/rt/pure/__new - call $~lib/rt/pure/__retain - global.set $rc/logical-or-mismatch/gloRef - call $~lib/rt/pure/__new - call $~lib/rt/pure/__retain - local.tee $0 - if (result i32) - local.get $0 - else - local.get $0 - call $~lib/rt/pure/__release - global.get $rc/logical-or-mismatch/gloRef - call $~lib/rt/pure/__retain - end - call $~lib/rt/pure/__release - global.get $rc/logical-or-mismatch/gloRef - local.tee $0 - if (result i32) - local.get $0 - call $~lib/rt/pure/__retain - else - call $~lib/rt/pure/__new - call $~lib/rt/pure/__retain - end - call $~lib/rt/pure/__release - call $~lib/rt/pure/__new - call $~lib/rt/pure/__retain - local.tee $0 - if (result i32) - local.get $0 - else - local.get $0 - call $~lib/rt/pure/__release - call $~lib/rt/pure/__new - call $~lib/rt/pure/__retain - end - call $~lib/rt/pure/__release - global.get $rc/logical-or-mismatch/gloRef - call $~lib/rt/pure/__release - ) (func $~lib/rt/pure/decrement (param $0 i32) (local $1 i32) (local $2 i32) @@ -1062,4 +1020,46 @@ i32.store offset=4 end ) + (func $~start + (local $0 i32) + call $~lib/rt/pure/__new + call $~lib/rt/pure/__retain + global.set $rc/logical-or-mismatch/gloRef + call $~lib/rt/pure/__new + call $~lib/rt/pure/__retain + local.tee $0 + if (result i32) + local.get $0 + else + local.get $0 + call $~lib/rt/pure/__release + global.get $rc/logical-or-mismatch/gloRef + call $~lib/rt/pure/__retain + end + call $~lib/rt/pure/__release + global.get $rc/logical-or-mismatch/gloRef + local.tee $0 + if (result i32) + local.get $0 + call $~lib/rt/pure/__retain + else + call $~lib/rt/pure/__new + call $~lib/rt/pure/__retain + end + call $~lib/rt/pure/__release + call $~lib/rt/pure/__new + call $~lib/rt/pure/__retain + local.tee $0 + if (result i32) + local.get $0 + else + local.get $0 + call $~lib/rt/pure/__release + call $~lib/rt/pure/__new + call $~lib/rt/pure/__retain + end + call $~lib/rt/pure/__release + global.get $rc/logical-or-mismatch/gloRef + call $~lib/rt/pure/__release + ) ) diff --git a/tests/compiler/rc/logical-or-mismatch.untouched.wat b/tests/compiler/rc/logical-or-mismatch.untouched.wat index 88684c0103..0c47e96b11 100644 --- a/tests/compiler/rc/logical-or-mismatch.untouched.wat +++ b/tests/compiler/rc/logical-or-mismatch.untouched.wat @@ -1570,9 +1570,6 @@ global.get $rc/logical-or-mismatch/gloRef call $~lib/rt/pure/__release ) - (func $~start - call $start:rc/logical-or-mismatch - ) (func $~lib/rt/tlsf/freeBlock (param $0 i32) (param $1 i32) local.get $1 local.get $1 @@ -1679,6 +1676,9 @@ i32.store offset=4 end ) + (func $~start + call $start:rc/logical-or-mismatch + ) (func $~lib/rt/pure/__visit (param $0 i32) (param $1 i32) local.get $0 global.get $~lib/memory/__heap_base diff --git a/tests/compiler/rc/rereturn.optimized.wat b/tests/compiler/rc/rereturn.optimized.wat index 2705443803..ff02b7c603 100644 --- a/tests/compiler/rc/rereturn.optimized.wat +++ b/tests/compiler/rc/rereturn.optimized.wat @@ -1460,12 +1460,6 @@ call $~lib/rt/pure/decrement end ) - (func $~start - i32.const 0 - i32.const 3 - call $~lib/rt/pure/__new - drop - ) (func $~lib/rt/pure/decrement (param $0 i32) (local $1 i32) (local $2 i32) @@ -1554,4 +1548,10 @@ i32.store offset=4 end ) + (func $~start + i32.const 0 + i32.const 3 + call $~lib/rt/pure/__new + drop + ) ) diff --git a/tests/compiler/rc/rereturn.untouched.wat b/tests/compiler/rc/rereturn.untouched.wat index 295dd8c07a..dc5291e315 100644 --- a/tests/compiler/rc/rereturn.untouched.wat +++ b/tests/compiler/rc/rereturn.untouched.wat @@ -3009,9 +3009,6 @@ call $rc/rereturn/rereturnRef call $~lib/rt/pure/__release ) - (func $~start - call $start:rc/rereturn - ) (func $~lib/rt/pure/finalize (param $0 i32) i32.const 0 drop @@ -3105,6 +3102,9 @@ i32.store offset=4 end ) + (func $~start + call $start:rc/rereturn + ) (func $~lib/rt/pure/__visit (param $0 i32) (param $1 i32) local.get $0 global.get $~lib/memory/__heap_base diff --git a/tests/compiler/rc/ternary-mismatch.optimized.wat b/tests/compiler/rc/ternary-mismatch.optimized.wat index 1c08e570c2..6d18a55c52 100644 --- a/tests/compiler/rc/ternary-mismatch.optimized.wat +++ b/tests/compiler/rc/ternary-mismatch.optimized.wat @@ -937,26 +937,6 @@ call $~lib/rt/pure/__retain end ) - (func $~start - (local $0 i32) - call $~lib/rt/pure/__new - call $~lib/rt/pure/__retain - global.set $rc/ternary-mismatch/gloRef - call $~lib/rt/pure/__new - drop - call $~lib/rt/pure/__new - drop - global.get $rc/ternary-mismatch/gloRef - local.tee $0 - i32.const 1228 - i32.gt_u - if - local.get $0 - i32.const 20 - i32.sub - call $~lib/rt/pure/decrement - end - ) (func $~lib/rt/pure/decrement (param $0 i32) (local $1 i32) (local $2 i32) @@ -1051,4 +1031,24 @@ i32.store offset=4 end ) + (func $~start + (local $0 i32) + call $~lib/rt/pure/__new + call $~lib/rt/pure/__retain + global.set $rc/ternary-mismatch/gloRef + call $~lib/rt/pure/__new + drop + call $~lib/rt/pure/__new + drop + global.get $rc/ternary-mismatch/gloRef + local.tee $0 + i32.const 1228 + i32.gt_u + if + local.get $0 + i32.const 20 + i32.sub + call $~lib/rt/pure/decrement + end + ) ) diff --git a/tests/compiler/rc/ternary-mismatch.untouched.wat b/tests/compiler/rc/ternary-mismatch.untouched.wat index 1a7d01538f..34f974c273 100644 --- a/tests/compiler/rc/ternary-mismatch.untouched.wat +++ b/tests/compiler/rc/ternary-mismatch.untouched.wat @@ -1554,9 +1554,6 @@ global.get $rc/ternary-mismatch/gloRef call $~lib/rt/pure/__release ) - (func $~start - call $start:rc/ternary-mismatch - ) (func $~lib/rt/tlsf/freeBlock (param $0 i32) (param $1 i32) local.get $1 local.get $1 @@ -1663,6 +1660,9 @@ i32.store offset=4 end ) + (func $~start + call $start:rc/ternary-mismatch + ) (func $~lib/rt/pure/__visit (param $0 i32) (param $1 i32) local.get $0 global.get $~lib/memory/__heap_base diff --git a/tests/compiler/resolve-ternary.optimized.wat b/tests/compiler/resolve-ternary.optimized.wat index a5343363de..50ba2cde5a 100644 --- a/tests/compiler/resolve-ternary.optimized.wat +++ b/tests/compiler/resolve-ternary.optimized.wat @@ -2560,9 +2560,6 @@ i32.const 2864 call $~lib/rt/pure/__release ) - (func $~start - call $start:resolve-ternary - ) (func $~lib/rt/pure/decrement (param $0 i32) (local $1 i32) (local $2 i32) @@ -2650,6 +2647,9 @@ i32.store offset=4 end ) + (func $~start + call $start:resolve-ternary + ) (func $~lib/rt/pure/__visit (param $0 i32) local.get $0 i32.const 2980 diff --git a/tests/compiler/resolve-ternary.untouched.wat b/tests/compiler/resolve-ternary.untouched.wat index 66380ea6a6..244672fc64 100644 --- a/tests/compiler/resolve-ternary.untouched.wat +++ b/tests/compiler/resolve-ternary.untouched.wat @@ -5266,9 +5266,6 @@ local.get $7 call $~lib/rt/pure/__release ) - (func $~start - call $start:resolve-ternary - ) (func $~lib/rt/pure/finalize (param $0 i32) i32.const 0 drop @@ -5362,6 +5359,9 @@ i32.store offset=4 end ) + (func $~start + call $start:resolve-ternary + ) (func $~lib/rt/pure/__visit (param $0 i32) (param $1 i32) local.get $0 global.get $~lib/memory/__heap_base diff --git a/tests/compiler/retain-release-sanity.optimized.wat b/tests/compiler/retain-release-sanity.optimized.wat index d90acf925c..73039f3168 100644 --- a/tests/compiler/retain-release-sanity.optimized.wat +++ b/tests/compiler/retain-release-sanity.optimized.wat @@ -2155,9 +2155,6 @@ call $~lib/rt/pure/__release call $~lib/rt/pure/__collect ) - (func $~start - call $start:retain-release-sanity - ) (func $~lib/rt/pure/decrement (param $0 i32) (local $1 i32) (local $2 i32) @@ -2540,6 +2537,9 @@ local.get $1 global.set $~lib/rt/pure/CUR ) + (func $~start + call $start:retain-release-sanity + ) (func $~lib/rt/pure/__visit (param $0 i32) (param $1 i32) local.get $0 i32.const 1716 diff --git a/tests/compiler/retain-release-sanity.untouched.wat b/tests/compiler/retain-release-sanity.untouched.wat index d14822f7b8..6186699da8 100644 --- a/tests/compiler/retain-release-sanity.untouched.wat +++ b/tests/compiler/retain-release-sanity.untouched.wat @@ -3952,9 +3952,6 @@ call $~lib/rt/pure/__release call $~lib/rt/pure/__collect ) - (func $~start - call $start:retain-release-sanity - ) (func $~lib/rt/pure/finalize (param $0 i32) i32.const 0 drop @@ -4444,6 +4441,9 @@ local.get $0 global.set $~lib/rt/pure/CUR ) + (func $~start + call $start:retain-release-sanity + ) (func $~lib/rt/pure/__visit (param $0 i32) (param $1 i32) (local $2 i32) (local $3 i32) diff --git a/tests/compiler/retain-return.optimized.wat b/tests/compiler/retain-return.optimized.wat index 344d524fe2..3a8c55d3f7 100644 --- a/tests/compiler/retain-return.optimized.wat +++ b/tests/compiler/retain-return.optimized.wat @@ -947,84 +947,6 @@ local.get $0 call $~lib/rt/pure/__retain ) - (func $~start - (local $0 i32) - global.get $~started - if - return - end - i32.const 1 - global.set $~started - call $~lib/rt/pure/__new - drop - call $~lib/rt/pure/__new - drop - call $~lib/rt/pure/__new - drop - call $~lib/rt/pure/__new - drop - call $~lib/rt/pure/__new - call $~lib/rt/pure/__retain - global.set $retain-return/ref - i32.const 1248 - i32.load - call_indirect (type $none_=>_i32) - call $~lib/rt/pure/__release - i32.const 1248 - i32.load - call_indirect (type $none_=>_i32) - call $~lib/rt/pure/__release - global.get $retain-return/ref - i32.const 1280 - i32.load - call_indirect (type $i32_=>_i32) - call $~lib/rt/pure/__release - global.get $retain-return/ref - i32.const 1280 - i32.load - call_indirect (type $i32_=>_i32) - call $~lib/rt/pure/__release - i32.const 1312 - i32.load - call_indirect (type $none_=>_i32) - call $~lib/rt/pure/__release - i32.const 1312 - i32.load - call_indirect (type $none_=>_i32) - call $~lib/rt/pure/__release - i32.const 1344 - i32.load - call_indirect (type $none_=>_i32) - call $~lib/rt/pure/__release - i32.const 1344 - i32.load - call_indirect (type $none_=>_i32) - call $~lib/rt/pure/__release - i32.const 1376 - i32.load - call_indirect (type $none_=>_i32) - call $~lib/rt/pure/__release - i32.const 1376 - i32.load - call_indirect (type $none_=>_i32) - call $~lib/rt/pure/__release - i32.const 1408 - i32.load - call_indirect (type $none_=>_i32) - call $~lib/rt/pure/__release - i32.const 1408 - i32.load - call_indirect (type $none_=>_i32) - call $~lib/rt/pure/__release - global.get $retain-return/ref - local.tee $0 - if - local.get $0 - call $~lib/rt/pure/__release - end - i32.const 0 - global.set $retain-return/ref - ) (func $~lib/rt/pure/decrement (param $0 i32) (local $1 i32) (local $2 i32) @@ -1117,6 +1039,84 @@ i32.store offset=4 end ) + (func $~start + (local $0 i32) + global.get $~started + if + return + end + i32.const 1 + global.set $~started + call $~lib/rt/pure/__new + drop + call $~lib/rt/pure/__new + drop + call $~lib/rt/pure/__new + drop + call $~lib/rt/pure/__new + drop + call $~lib/rt/pure/__new + call $~lib/rt/pure/__retain + global.set $retain-return/ref + i32.const 1248 + i32.load + call_indirect (type $none_=>_i32) + call $~lib/rt/pure/__release + i32.const 1248 + i32.load + call_indirect (type $none_=>_i32) + call $~lib/rt/pure/__release + global.get $retain-return/ref + i32.const 1280 + i32.load + call_indirect (type $i32_=>_i32) + call $~lib/rt/pure/__release + global.get $retain-return/ref + i32.const 1280 + i32.load + call_indirect (type $i32_=>_i32) + call $~lib/rt/pure/__release + i32.const 1312 + i32.load + call_indirect (type $none_=>_i32) + call $~lib/rt/pure/__release + i32.const 1312 + i32.load + call_indirect (type $none_=>_i32) + call $~lib/rt/pure/__release + i32.const 1344 + i32.load + call_indirect (type $none_=>_i32) + call $~lib/rt/pure/__release + i32.const 1344 + i32.load + call_indirect (type $none_=>_i32) + call $~lib/rt/pure/__release + i32.const 1376 + i32.load + call_indirect (type $none_=>_i32) + call $~lib/rt/pure/__release + i32.const 1376 + i32.load + call_indirect (type $none_=>_i32) + call $~lib/rt/pure/__release + i32.const 1408 + i32.load + call_indirect (type $none_=>_i32) + call $~lib/rt/pure/__release + i32.const 1408 + i32.load + call_indirect (type $none_=>_i32) + call $~lib/rt/pure/__release + global.get $retain-return/ref + local.tee $0 + if + local.get $0 + call $~lib/rt/pure/__release + end + i32.const 0 + global.set $retain-return/ref + ) (func $~lib/rt/pure/__visit (param $0 i32) local.get $0 i32.const 1420 diff --git a/tests/compiler/retain-return.untouched.wat b/tests/compiler/retain-return.untouched.wat index be329e00c1..f0d05117a3 100644 --- a/tests/compiler/retain-return.untouched.wat +++ b/tests/compiler/retain-return.untouched.wat @@ -1677,15 +1677,6 @@ local.get $0 global.set $retain-return/ref ) - (func $~start - global.get $~started - if - return - end - i32.const 1 - global.set $~started - call $start:retain-return - ) (func $~lib/rt/tlsf/freeBlock (param $0 i32) (param $1 i32) local.get $1 local.get $1 @@ -1792,6 +1783,15 @@ i32.store offset=4 end ) + (func $~start + global.get $~started + if + return + end + i32.const 1 + global.set $~started + call $start:retain-return + ) (func $~lib/rt/pure/__visit (param $0 i32) (param $1 i32) local.get $0 global.get $~lib/memory/__heap_base diff --git a/tests/compiler/rt/finalize.optimized.wat b/tests/compiler/rt/finalize.optimized.wat index 561545b506..8cc01785b8 100644 --- a/tests/compiler/rt/finalize.optimized.wat +++ b/tests/compiler/rt/finalize.optimized.wat @@ -25,10 +25,10 @@ (global $rt/finalize/expected (mut i32) (i32.const 0)) (global $rt/finalize/expectedWriteIndex (mut i32) (i32.const 0)) (global $rt/finalize/expectedReadIndex (mut i32) (i32.const 0)) - (global $~started (mut i32) (i32.const 0)) (global $~lib/rt/pure/CUR (mut i32) (i32.const 0)) (global $~lib/rt/pure/END (mut i32) (i32.const 0)) (global $~lib/rt/pure/ROOTS (mut i32) (i32.const 0)) + (global $~started (mut i32) (i32.const 0)) (export "_start" (func $~start)) (export "memory" (memory $0)) (func $~lib/rt/pure/__release (param $0 i32) @@ -1503,15 +1503,6 @@ unreachable end ) - (func $~start - global.get $~started - if - return - end - i32.const 1 - global.set $~started - call $start:rt/finalize - ) (func $~lib/rt/tlsf/freeBlock (param $0 i32) (param $1 i32) local.get $1 local.get $1 @@ -2145,6 +2136,15 @@ local.get $1 global.set $~lib/rt/pure/CUR ) + (func $~start + global.get $~started + if + return + end + i32.const 1 + global.set $~started + call $start:rt/finalize + ) (func $~lib/rt/pure/__visit (param $0 i32) (param $1 i32) local.get $0 i32.const 1660 diff --git a/tests/compiler/rt/finalize.untouched.wat b/tests/compiler/rt/finalize.untouched.wat index 1c4f9d5b93..6a913b3e9d 100644 --- a/tests/compiler/rt/finalize.untouched.wat +++ b/tests/compiler/rt/finalize.untouched.wat @@ -29,10 +29,10 @@ (global $rt/finalize/expected (mut i32) (i32.const 0)) (global $rt/finalize/expectedWriteIndex (mut i32) (i32.const 0)) (global $rt/finalize/expectedReadIndex (mut i32) (i32.const 0)) - (global $~started (mut i32) (i32.const 0)) (global $~lib/rt/pure/CUR (mut i32) (i32.const 0)) (global $~lib/rt/pure/END (mut i32) (i32.const 0)) (global $~lib/rt/pure/ROOTS (mut i32) (i32.const 0)) + (global $~started (mut i32) (i32.const 0)) (global $~lib/rt/__rtti_base i32 (i32.const 576)) (global $~lib/memory/__heap_base i32 (i32.const 636)) (export "_start" (func $~start)) @@ -2105,15 +2105,6 @@ unreachable end ) - (func $~start - global.get $~started - if - return - end - i32.const 1 - global.set $~started - call $start:rt/finalize - ) (func $~lib/staticarray/StaticArray#__uget (param $0 i32) (param $1 i32) (result i32) local.get $0 local.get $1 @@ -3949,6 +3940,15 @@ local.get $0 global.set $~lib/rt/pure/CUR ) + (func $~start + global.get $~started + if + return + end + i32.const 1 + global.set $~started + call $start:rt/finalize + ) (func $~lib/rt/pure/__visit (param $0 i32) (param $1 i32) (local $2 i32) (local $3 i32) diff --git a/tests/compiler/std/array-literal.optimized.wat b/tests/compiler/std/array-literal.optimized.wat index ad31e29783..f694189231 100644 --- a/tests/compiler/std/array-literal.optimized.wat +++ b/tests/compiler/std/array-literal.optimized.wat @@ -1515,9 +1515,6 @@ local.get $0 call $~lib/rt/pure/__release ) - (func $~start - call $start:std/array-literal - ) (func $~lib/rt/pure/decrement (param $0 i32) (local $1 i32) (local $2 i32) @@ -1646,6 +1643,9 @@ i32.store offset=4 end ) + (func $~start + call $start:std/array-literal + ) (func $~lib/rt/pure/__visit (param $0 i32) local.get $0 i32.const 1644 diff --git a/tests/compiler/std/array-literal.untouched.wat b/tests/compiler/std/array-literal.untouched.wat index 9bd8efe771..f8da45c66c 100644 --- a/tests/compiler/std/array-literal.untouched.wat +++ b/tests/compiler/std/array-literal.untouched.wat @@ -3325,9 +3325,6 @@ local.get $0 call $~lib/rt/pure/__release ) - (func $~start - call $start:std/array-literal - ) (func $~lib/rt/tlsf/freeBlock (param $0 i32) (param $1 i32) local.get $1 local.get $1 @@ -3434,6 +3431,9 @@ i32.store offset=4 end ) + (func $~start + call $start:std/array-literal + ) (func $~lib/rt/pure/__visit (param $0 i32) (param $1 i32) local.get $0 global.get $~lib/memory/__heap_base diff --git a/tests/compiler/std/array.optimized.wat b/tests/compiler/std/array.optimized.wat index 35953095fd..b92c7f9deb 100644 --- a/tests/compiler/std/array.optimized.wat +++ b/tests/compiler/std/array.optimized.wat @@ -19643,9 +19643,6 @@ local.get $0 call $~lib/rt/pure/__retain ) - (func $~start - call $start:std/array - ) (func $~lib/rt/pure/decrement (param $0 i32) (local $1 i32) (local $2 i32) @@ -19779,6 +19776,9 @@ i32.sub call $~lib/rt/pure/decrement ) + (func $~start + call $start:std/array + ) (func $~lib/array/Array~visit (param $0 i32) (local $1 i32) (local $2 i32) diff --git a/tests/compiler/std/array.untouched.wat b/tests/compiler/std/array.untouched.wat index bbaad8eb2f..cfb5c972e4 100644 --- a/tests/compiler/std/array.untouched.wat +++ b/tests/compiler/std/array.untouched.wat @@ -30834,9 +30834,6 @@ local.get $1 call $~lib/rt/pure/__visit ) - (func $~start - call $start:std/array - ) (func $~lib/rt/pure/finalize (param $0 i32) i32.const 0 drop @@ -30958,6 +30955,9 @@ i32.sub call $~lib/rt/pure/decrement ) + (func $~start + call $start:std/array + ) (func $~lib/arraybuffer/ArrayBuffer~visit (param $0 i32) (param $1 i32) nop ) diff --git a/tests/compiler/std/arraybuffer.optimized.wat b/tests/compiler/std/arraybuffer.optimized.wat index 2243a60e20..fc273c6b09 100644 --- a/tests/compiler/std/arraybuffer.optimized.wat +++ b/tests/compiler/std/arraybuffer.optimized.wat @@ -1908,9 +1908,6 @@ local.get $3 call $~lib/rt/pure/__release ) - (func $~start - call $start:std/arraybuffer - ) (func $~lib/rt/pure/decrement (param $0 i32) (local $1 i32) (local $2 i32) @@ -2013,6 +2010,9 @@ i32.store offset=4 end ) + (func $~start + call $start:std/arraybuffer + ) (func $~lib/rt/pure/__visit (param $0 i32) local.get $0 i32.const 1500 diff --git a/tests/compiler/std/arraybuffer.untouched.wat b/tests/compiler/std/arraybuffer.untouched.wat index 89855e1a4f..d5ead50251 100644 --- a/tests/compiler/std/arraybuffer.untouched.wat +++ b/tests/compiler/std/arraybuffer.untouched.wat @@ -4024,9 +4024,6 @@ local.get $5 call $~lib/rt/pure/__release ) - (func $~start - call $start:std/arraybuffer - ) (func $~lib/rt/tlsf/freeBlock (param $0 i32) (param $1 i32) local.get $1 local.get $1 @@ -4133,6 +4130,9 @@ i32.store offset=4 end ) + (func $~start + call $start:std/arraybuffer + ) (func $~lib/rt/pure/__visit (param $0 i32) (param $1 i32) local.get $0 global.get $~lib/memory/__heap_base diff --git a/tests/compiler/std/dataview.optimized.wat b/tests/compiler/std/dataview.optimized.wat index ddb90ff65e..5d6e64f2f2 100644 --- a/tests/compiler/std/dataview.optimized.wat +++ b/tests/compiler/std/dataview.optimized.wat @@ -3381,9 +3381,6 @@ local.get $1 call $~lib/rt/pure/__release ) - (func $~start - call $start:std/dataview - ) (func $~lib/rt/pure/decrement (param $0 i32) (local $1 i32) (local $2 i32) @@ -3473,6 +3470,9 @@ i32.store offset=4 end ) + (func $~start + call $start:std/dataview + ) (func $~lib/arraybuffer/ArrayBufferView~visit (param $0 i32) local.get $0 i32.load diff --git a/tests/compiler/std/dataview.untouched.wat b/tests/compiler/std/dataview.untouched.wat index b348d64808..155a81e020 100644 --- a/tests/compiler/std/dataview.untouched.wat +++ b/tests/compiler/std/dataview.untouched.wat @@ -4510,9 +4510,6 @@ local.get $1 call $~lib/rt/pure/__release ) - (func $~start - call $start:std/dataview - ) (func $~lib/rt/tlsf/freeBlock (param $0 i32) (param $1 i32) local.get $1 local.get $1 @@ -4619,6 +4616,9 @@ i32.store offset=4 end ) + (func $~start + call $start:std/dataview + ) (func $~lib/rt/pure/__visit (param $0 i32) (param $1 i32) local.get $0 global.get $~lib/memory/__heap_base diff --git a/tests/compiler/std/map.optimized.wat b/tests/compiler/std/map.optimized.wat index ea9957787f..3c511d4239 100644 --- a/tests/compiler/std/map.optimized.wat +++ b/tests/compiler/std/map.optimized.wat @@ -13038,18 +13038,6 @@ local.get $1 call $~lib/rt/pure/__release ) - (func $~start - call $std/map/testNumeric - call $std/map/testNumeric - call $std/map/testNumeric - call $std/map/testNumeric - call $std/map/testNumeric - call $std/map/testNumeric - call $std/map/testNumeric - call $std/map/testNumeric - call $std/map/testNumeric - call $std/map/testNumeric - ) (func $~lib/rt/pure/decrement (param $0 i32) (local $1 i32) (local $2 i32) @@ -13145,6 +13133,18 @@ i32.store offset=4 end ) + (func $~start + call $std/map/testNumeric + call $std/map/testNumeric + call $std/map/testNumeric + call $std/map/testNumeric + call $std/map/testNumeric + call $std/map/testNumeric + call $std/map/testNumeric + call $std/map/testNumeric + call $std/map/testNumeric + call $std/map/testNumeric + ) (func $~lib/rt/pure/__visit (param $0 i32) local.get $0 i32.const 1612 diff --git a/tests/compiler/std/map.untouched.wat b/tests/compiler/std/map.untouched.wat index 313ffd8474..b2ad8479ee 100644 --- a/tests/compiler/std/map.untouched.wat +++ b/tests/compiler/std/map.untouched.wat @@ -20944,9 +20944,6 @@ call $std/map/testNumeric call $std/map/testNumeric ) - (func $~start - call $start:std/map - ) (func $~lib/rt/pure/finalize (param $0 i32) i32.const 0 drop @@ -21040,6 +21037,9 @@ i32.store offset=4 end ) + (func $~start + call $start:std/map + ) (func $~lib/rt/pure/__visit (param $0 i32) (param $1 i32) local.get $0 global.get $~lib/memory/__heap_base diff --git a/tests/compiler/std/set.optimized.wat b/tests/compiler/std/set.optimized.wat index ef1a5fd5de..52aa702397 100644 --- a/tests/compiler/std/set.optimized.wat +++ b/tests/compiler/std/set.optimized.wat @@ -9378,18 +9378,6 @@ local.get $1 call $~lib/rt/pure/__release ) - (func $~start - call $std/set/testNumeric - call $std/set/testNumeric - call $std/set/testNumeric - call $std/set/testNumeric - call $std/set/testNumeric - call $std/set/testNumeric - call $std/set/testNumeric - call $std/set/testNumeric - call $std/set/testNumeric - call $std/set/testNumeric - ) (func $~lib/rt/pure/decrement (param $0 i32) (local $1 i32) (local $2 i32) @@ -9485,6 +9473,18 @@ i32.store offset=4 end ) + (func $~start + call $std/set/testNumeric + call $std/set/testNumeric + call $std/set/testNumeric + call $std/set/testNumeric + call $std/set/testNumeric + call $std/set/testNumeric + call $std/set/testNumeric + call $std/set/testNumeric + call $std/set/testNumeric + call $std/set/testNumeric + ) (func $~lib/rt/pure/__visit (param $0 i32) local.get $0 i32.const 1500 diff --git a/tests/compiler/std/set.untouched.wat b/tests/compiler/std/set.untouched.wat index 55a4329576..14d3bdf10c 100644 --- a/tests/compiler/std/set.untouched.wat +++ b/tests/compiler/std/set.untouched.wat @@ -14735,9 +14735,6 @@ call $std/set/testNumeric call $std/set/testNumeric ) - (func $~start - call $start:std/set - ) (func $~lib/rt/pure/finalize (param $0 i32) i32.const 0 drop @@ -14831,6 +14828,9 @@ i32.store offset=4 end ) + (func $~start + call $start:std/set + ) (func $~lib/rt/pure/__visit (param $0 i32) (param $1 i32) local.get $0 global.get $~lib/memory/__heap_base diff --git a/tests/compiler/std/staticarray.optimized.wat b/tests/compiler/std/staticarray.optimized.wat index a4644a72a9..c437653170 100644 --- a/tests/compiler/std/staticarray.optimized.wat +++ b/tests/compiler/std/staticarray.optimized.wat @@ -1543,9 +1543,6 @@ i32.const 0 global.set $std/staticarray/arr4 ) - (func $~start - call $start:std/staticarray - ) (func $~lib/rt/pure/decrement (param $0 i32) (local $1 i32) (local $2 i32) @@ -1667,6 +1664,9 @@ i32.store offset=4 end ) + (func $~start + call $start:std/staticarray + ) (func $~lib/rt/pure/__visit (param $0 i32) local.get $0 i32.const 1516 diff --git a/tests/compiler/std/staticarray.untouched.wat b/tests/compiler/std/staticarray.untouched.wat index 977e25fe08..c6b80a8b6e 100644 --- a/tests/compiler/std/staticarray.untouched.wat +++ b/tests/compiler/std/staticarray.untouched.wat @@ -3112,9 +3112,6 @@ local.get $1 global.set $std/staticarray/arr4 ) - (func $~start - call $start:std/staticarray - ) (func $~lib/rt/tlsf/freeBlock (param $0 i32) (param $1 i32) local.get $1 local.get $1 @@ -3221,6 +3218,9 @@ i32.store offset=4 end ) + (func $~start + call $start:std/staticarray + ) (func $~lib/rt/pure/__visit (param $0 i32) (param $1 i32) local.get $0 global.get $~lib/memory/__heap_base diff --git a/tests/compiler/std/string-casemapping.optimized.wat b/tests/compiler/std/string-casemapping.optimized.wat index b2b75c184a..4a7b8ba53e 100644 --- a/tests/compiler/std/string-casemapping.optimized.wat +++ b/tests/compiler/std/string-casemapping.optimized.wat @@ -4889,9 +4889,6 @@ local.get $98 call $~lib/rt/pure/__release ) - (func $~start - call $start:std/string-casemapping - ) (func $~lib/rt/pure/decrement (param $0 i32) (local $1 i32) (local $2 i32) @@ -4980,4 +4977,7 @@ i32.store offset=4 end ) + (func $~start + call $start:std/string-casemapping + ) ) diff --git a/tests/compiler/std/string-casemapping.untouched.wat b/tests/compiler/std/string-casemapping.untouched.wat index 584f20241a..27f97f4e5c 100644 --- a/tests/compiler/std/string-casemapping.untouched.wat +++ b/tests/compiler/std/string-casemapping.untouched.wat @@ -7212,9 +7212,6 @@ local.get $85 call $~lib/rt/pure/__release ) - (func $~start - call $start:std/string-casemapping - ) (func $~lib/rt/pure/finalize (param $0 i32) i32.const 0 drop @@ -7308,6 +7305,9 @@ i32.store offset=4 end ) + (func $~start + call $start:std/string-casemapping + ) (func $~lib/rt/pure/__visit (param $0 i32) (param $1 i32) local.get $0 global.get $~lib/memory/__heap_base diff --git a/tests/compiler/std/string-encoding.optimized.wat b/tests/compiler/std/string-encoding.optimized.wat index 988375dfc4..cd60afe594 100644 --- a/tests/compiler/std/string-encoding.optimized.wat +++ b/tests/compiler/std/string-encoding.optimized.wat @@ -3239,9 +3239,6 @@ i32.const 14784 call $std/string-encoding/testLarge ) - (func $~start - call $start:std/string-encoding - ) (func $~lib/rt/pure/decrement (param $0 i32) (local $1 i32) (local $2 i32) @@ -3330,4 +3327,7 @@ i32.store offset=4 end ) + (func $~start + call $start:std/string-encoding + ) ) diff --git a/tests/compiler/std/string-encoding.untouched.wat b/tests/compiler/std/string-encoding.untouched.wat index 381638cafe..b1d91dd9d1 100644 --- a/tests/compiler/std/string-encoding.untouched.wat +++ b/tests/compiler/std/string-encoding.untouched.wat @@ -5021,9 +5021,6 @@ i32.const 13760 call $std/string-encoding/testLarge ) - (func $~start - call $start:std/string-encoding - ) (func $~lib/rt/pure/finalize (param $0 i32) i32.const 0 drop @@ -5117,6 +5114,9 @@ i32.store offset=4 end ) + (func $~start + call $start:std/string-encoding + ) (func $~lib/rt/pure/__visit (param $0 i32) (param $1 i32) local.get $0 global.get $~lib/memory/__heap_base diff --git a/tests/compiler/std/string.optimized.wat b/tests/compiler/std/string.optimized.wat index 821f4c6eed..d462213253 100644 --- a/tests/compiler/std/string.optimized.wat +++ b/tests/compiler/std/string.optimized.wat @@ -17601,9 +17601,6 @@ global.get $std/string/str call $~lib/rt/pure/__retain ) - (func $~start - call $start:std/string - ) (func $~lib/rt/pure/decrement (param $0 i32) (local $1 i32) (local $2 i32) @@ -17727,6 +17724,9 @@ i32.store offset=4 end ) + (func $~start + call $start:std/string + ) (func $~lib/rt/pure/__visit (param $0 i32) local.get $0 i32.const 23820 diff --git a/tests/compiler/std/string.untouched.wat b/tests/compiler/std/string.untouched.wat index 7b39dcfddc..f4b1fef49b 100644 --- a/tests/compiler/std/string.untouched.wat +++ b/tests/compiler/std/string.untouched.wat @@ -21618,9 +21618,6 @@ global.get $std/string/str call $~lib/rt/pure/__retain ) - (func $~start - call $start:std/string - ) (func $~lib/rt/pure/finalize (param $0 i32) i32.const 0 drop @@ -21714,6 +21711,9 @@ i32.store offset=4 end ) + (func $~start + call $start:std/string + ) (func $~lib/rt/pure/__visit (param $0 i32) (param $1 i32) local.get $0 global.get $~lib/memory/__heap_base diff --git a/tests/compiler/std/typedarray.optimized.wat b/tests/compiler/std/typedarray.optimized.wat index 54f3444fdd..765dda5c5d 100644 --- a/tests/compiler/std/typedarray.optimized.wat +++ b/tests/compiler/std/typedarray.optimized.wat @@ -35821,9 +35821,6 @@ call $~lib/builtins/abort unreachable ) - (func $~start - call $start:std/typedarray - ) (func $~lib/rt/pure/decrement (param $0 i32) (local $1 i32) (local $2 i32) @@ -35926,6 +35923,9 @@ i32.store offset=4 end ) + (func $~start + call $start:std/typedarray + ) (func $~lib/rt/pure/__visit (param $0 i32) local.get $0 i32.const 13020 diff --git a/tests/compiler/std/typedarray.untouched.wat b/tests/compiler/std/typedarray.untouched.wat index ae168e22cd..db991bbdf8 100644 --- a/tests/compiler/std/typedarray.untouched.wat +++ b/tests/compiler/std/typedarray.untouched.wat @@ -57446,9 +57446,6 @@ local.get $20 call $~lib/rt/pure/__release ) - (func $~start - call $start:std/typedarray - ) (func $~lib/rt/pure/finalize (param $0 i32) i32.const 0 drop @@ -57542,6 +57539,9 @@ i32.store offset=4 end ) + (func $~start + call $start:std/typedarray + ) (func $~lib/rt/pure/__visit (param $0 i32) (param $1 i32) local.get $0 global.get $~lib/memory/__heap_base diff --git a/tests/compiler/throw.untouched.wat b/tests/compiler/throw.untouched.wat index 9b565bfd7d..ce3f3770e6 100644 --- a/tests/compiler/throw.untouched.wat +++ b/tests/compiler/throw.untouched.wat @@ -126,9 +126,6 @@ call $~lib/builtins/abort unreachable ) - (func $~start - call $start:throw - ) (func $~lib/rt/tlsf/removeBlock (param $0 i32) (param $1 i32) (local $2 i32) (local $3 i32) @@ -813,6 +810,9 @@ i32.store offset=4 end ) + (func $~start + call $start:throw + ) (func $~lib/rt/pure/__visit (param $0 i32) (param $1 i32) local.get $0 global.get $~lib/memory/__heap_base diff --git a/tests/compiler/while.optimized.wat b/tests/compiler/while.optimized.wat index 8036bb7afb..605764acfd 100644 --- a/tests/compiler/while.optimized.wat +++ b/tests/compiler/while.optimized.wat @@ -1418,9 +1418,6 @@ i32.const 1 global.set $while/ran ) - (func $~start - call $start:while - ) (func $~lib/rt/pure/decrement (param $0 i32) (local $1 i32) (local $2 i32) @@ -1515,4 +1512,7 @@ i32.store offset=4 end ) + (func $~start + call $start:while + ) ) diff --git a/tests/compiler/while.untouched.wat b/tests/compiler/while.untouched.wat index e19c633b84..934d68529a 100644 --- a/tests/compiler/while.untouched.wat +++ b/tests/compiler/while.untouched.wat @@ -2365,9 +2365,6 @@ unreachable end ) - (func $~start - call $start:while - ) (func $~lib/rt/tlsf/freeBlock (param $0 i32) (param $1 i32) local.get $1 local.get $1 @@ -2474,6 +2471,9 @@ i32.store offset=4 end ) + (func $~start + call $start:while + ) (func $~lib/rt/pure/__visit (param $0 i32) (param $1 i32) local.get $0 global.get $~lib/memory/__heap_base