2017-12-06 19:33:48 +01:00
|
|
|
(module
|
|
|
|
(type $ii (func (param i32) (result i32)))
|
2018-02-04 07:51:40 +01:00
|
|
|
(type $iiiiv (func (param i32 i32 i32 i32)))
|
2017-12-06 23:38:17 +01:00
|
|
|
(type $i (func (result i32)))
|
2017-12-06 19:33:48 +01:00
|
|
|
(type $iiv (func (param i32 i32)))
|
|
|
|
(type $iiiv (func (param i32 i32 i32)))
|
|
|
|
(type $iv (func (param i32)))
|
|
|
|
(type $v (func))
|
2018-02-04 07:51:40 +01:00
|
|
|
(import "env" "abort" (func $abort (param i32 i32 i32 i32)))
|
2017-12-06 19:33:48 +01:00
|
|
|
(global $tlsf/ALIGN_SIZE_LOG2 i32 (i32.const 3))
|
2017-12-06 23:38:17 +01:00
|
|
|
(global $tlsf/ALIGN_SIZE i32 (i32.const 8))
|
2018-01-04 06:00:42 +01:00
|
|
|
(global $tlsf/SL_INDEX_COUNT_LOG2 i32 (i32.const 5))
|
|
|
|
(global $tlsf/FL_INDEX_MAX i32 (i32.const 30))
|
|
|
|
(global $tlsf/SL_INDEX_COUNT i32 (i32.const 32))
|
|
|
|
(global $tlsf/FL_INDEX_SHIFT i32 (i32.const 8))
|
|
|
|
(global $tlsf/FL_INDEX_COUNT i32 (i32.const 23))
|
|
|
|
(global $tlsf/SMALL_BLOCK_SIZE i32 (i32.const 256))
|
2017-12-07 02:02:22 +01:00
|
|
|
(global $tlsf/BLOCK$PREV_PHYS_BLOCK_OFFSET i32 (i32.const 0))
|
|
|
|
(global $tlsf/BLOCK$TAGGED_SIZE_OFFSET i32 (i32.const 4))
|
|
|
|
(global $tlsf/BLOCK$NEXT_FREE_OFFSET i32 (i32.const 8))
|
|
|
|
(global $tlsf/BLOCK$PREV_FREE_OFFSET i32 (i32.const 12))
|
|
|
|
(global $tlsf/BLOCK$SIZE i32 (i32.const 16))
|
2018-01-04 06:00:42 +01:00
|
|
|
(global $tlsf/BLOCK_HEADER_FREE_BIT i32 (i32.const 1))
|
|
|
|
(global $tlsf/BLOCK_HEADER_PREV_FREE_BIT i32 (i32.const 2))
|
|
|
|
(global $tlsf/BLOCK_OVERHEAD i32 (i32.const 4))
|
|
|
|
(global $tlsf/BLOCK_START_OFFSET i32 (i32.const 8))
|
|
|
|
(global $tlsf/BLOCK_SIZE_MIN i32 (i32.const 12))
|
|
|
|
(global $tlsf/BLOCK_SIZE_MAX i32 (i32.const 1073741824))
|
2017-12-07 02:02:22 +01:00
|
|
|
(global $tlsf/CONTROL$FL_BITMAP_OFFSET i32 (i32.const 16))
|
|
|
|
(global $tlsf/CONTROL$SL_BITMAP_OFFSET i32 (i32.const 20))
|
|
|
|
(global $tlsf/CONTROL$BLOCKS_OFFSET i32 (i32.const 112))
|
2018-01-04 06:00:42 +01:00
|
|
|
(global $tlsf/CONTROL$SIZE i32 (i32.const 3056))
|
2018-02-14 09:18:43 +01:00
|
|
|
(global $HEAP_BASE i32 (i32.const 24))
|
2017-12-06 19:33:48 +01:00
|
|
|
(memory $0 1)
|
2018-02-14 09:18:43 +01:00
|
|
|
(data (i32.const 4) "\07\00\00\00t\00l\00s\00f\00.\00t\00s\00")
|
2017-12-07 02:02:22 +01:00
|
|
|
(export "control$construct" (func $tlsf/control$construct))
|
2017-12-06 19:33:48 +01:00
|
|
|
(export "memory" (memory $0))
|
|
|
|
(start $start)
|
2018-02-04 07:51:40 +01:00
|
|
|
(func $tlsf/fls (; 1 ;) (type $ii) (param $0 i32) (result i32)
|
2017-12-06 19:33:48 +01:00
|
|
|
(return
|
|
|
|
(if (result i32)
|
|
|
|
(i32.eqz
|
|
|
|
(get_local $0)
|
|
|
|
)
|
2018-02-14 09:18:43 +01:00
|
|
|
(i32.const -1)
|
2017-12-06 19:33:48 +01:00
|
|
|
(i32.sub
|
|
|
|
(i32.const 31)
|
|
|
|
(i32.clz
|
|
|
|
(get_local $0)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
2018-02-04 07:51:40 +01:00
|
|
|
(func $tlsf/ffs (; 2 ;) (type $ii) (param $0 i32) (result i32)
|
2017-12-06 19:33:48 +01:00
|
|
|
(return
|
|
|
|
(if (result i32)
|
|
|
|
(i32.eqz
|
|
|
|
(get_local $0)
|
|
|
|
)
|
2018-02-14 09:18:43 +01:00
|
|
|
(i32.const -1)
|
2017-12-06 19:33:48 +01:00
|
|
|
(i32.ctz
|
|
|
|
(get_local $0)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
2018-02-04 07:51:40 +01:00
|
|
|
(func $tlsf/block$set_next_free (; 3 ;) (type $iiv) (param $0 i32) (param $1 i32)
|
2017-12-06 19:33:48 +01:00
|
|
|
(i32.store
|
|
|
|
(i32.add
|
|
|
|
(get_local $0)
|
2017-12-06 23:38:17 +01:00
|
|
|
(i32.const 8)
|
2017-12-06 19:33:48 +01:00
|
|
|
)
|
|
|
|
(get_local $1)
|
|
|
|
)
|
|
|
|
)
|
2018-02-04 07:51:40 +01:00
|
|
|
(func $tlsf/block$set_prev_free (; 4 ;) (type $iiv) (param $0 i32) (param $1 i32)
|
2017-12-06 19:33:48 +01:00
|
|
|
(i32.store
|
|
|
|
(i32.add
|
|
|
|
(get_local $0)
|
2017-12-06 23:38:17 +01:00
|
|
|
(i32.const 12)
|
2017-12-06 19:33:48 +01:00
|
|
|
)
|
|
|
|
(get_local $1)
|
|
|
|
)
|
|
|
|
)
|
2018-02-04 07:51:40 +01:00
|
|
|
(func $tlsf/control$set_fl_bitmap (; 5 ;) (type $iiv) (param $0 i32) (param $1 i32)
|
2017-12-06 19:33:48 +01:00
|
|
|
(i32.store
|
|
|
|
(i32.add
|
|
|
|
(get_local $0)
|
2017-12-06 23:38:17 +01:00
|
|
|
(i32.const 16)
|
2017-12-06 19:33:48 +01:00
|
|
|
)
|
|
|
|
(get_local $1)
|
|
|
|
)
|
|
|
|
)
|
2018-02-04 07:51:40 +01:00
|
|
|
(func $tlsf/control$set_sl_bitmap (; 6 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32)
|
2017-12-06 19:33:48 +01:00
|
|
|
(if
|
|
|
|
(i32.eqz
|
2017-12-11 18:46:11 +01:00
|
|
|
(i32.lt_u
|
2017-12-06 19:33:48 +01:00
|
|
|
(get_local $1)
|
2017-12-06 23:38:17 +01:00
|
|
|
(i32.const 23)
|
2017-12-06 19:33:48 +01:00
|
|
|
)
|
|
|
|
)
|
2018-02-04 07:51:40 +01:00
|
|
|
(block
|
|
|
|
(call $abort
|
|
|
|
(i32.const 0)
|
2018-02-14 09:18:43 +01:00
|
|
|
(i32.const 4)
|
2018-02-04 07:51:40 +01:00
|
|
|
(i32.const 162)
|
|
|
|
(i32.const 2)
|
|
|
|
)
|
|
|
|
(unreachable)
|
|
|
|
)
|
2017-12-06 19:33:48 +01:00
|
|
|
)
|
|
|
|
(i32.store
|
|
|
|
(i32.add
|
2017-12-06 23:38:17 +01:00
|
|
|
(i32.add
|
|
|
|
(get_local $0)
|
|
|
|
(i32.const 20)
|
|
|
|
)
|
2017-12-06 19:33:48 +01:00
|
|
|
(i32.mul
|
|
|
|
(get_local $1)
|
|
|
|
(i32.const 4)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
(get_local $2)
|
|
|
|
)
|
|
|
|
)
|
2018-02-04 07:51:40 +01:00
|
|
|
(func $tlsf/control$set_block (; 7 ;) (type $iiiiv) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32)
|
2017-12-06 19:33:48 +01:00
|
|
|
(if
|
|
|
|
(i32.eqz
|
2017-12-11 18:46:11 +01:00
|
|
|
(i32.lt_u
|
2017-12-06 19:33:48 +01:00
|
|
|
(get_local $1)
|
2017-12-06 23:38:17 +01:00
|
|
|
(i32.const 23)
|
2017-12-06 19:33:48 +01:00
|
|
|
)
|
|
|
|
)
|
2018-02-04 07:51:40 +01:00
|
|
|
(block
|
|
|
|
(call $abort
|
|
|
|
(i32.const 0)
|
2018-02-14 09:18:43 +01:00
|
|
|
(i32.const 4)
|
2018-02-04 07:51:40 +01:00
|
|
|
(i32.const 173)
|
|
|
|
(i32.const 2)
|
|
|
|
)
|
|
|
|
(unreachable)
|
|
|
|
)
|
2017-12-06 19:33:48 +01:00
|
|
|
)
|
|
|
|
(if
|
|
|
|
(i32.eqz
|
2017-12-11 18:46:11 +01:00
|
|
|
(i32.lt_u
|
2017-12-06 19:33:48 +01:00
|
|
|
(get_local $2)
|
2017-12-06 23:38:17 +01:00
|
|
|
(i32.const 32)
|
2017-12-06 19:33:48 +01:00
|
|
|
)
|
|
|
|
)
|
2018-02-04 07:51:40 +01:00
|
|
|
(block
|
|
|
|
(call $abort
|
|
|
|
(i32.const 0)
|
2018-02-14 09:18:43 +01:00
|
|
|
(i32.const 4)
|
2018-02-04 07:51:40 +01:00
|
|
|
(i32.const 174)
|
|
|
|
(i32.const 2)
|
|
|
|
)
|
|
|
|
(unreachable)
|
|
|
|
)
|
2017-12-06 19:33:48 +01:00
|
|
|
)
|
|
|
|
(i32.store
|
|
|
|
(i32.add
|
2017-12-06 23:38:17 +01:00
|
|
|
(i32.add
|
|
|
|
(get_local $0)
|
|
|
|
(i32.const 112)
|
|
|
|
)
|
2017-12-06 19:33:48 +01:00
|
|
|
(i32.mul
|
|
|
|
(i32.add
|
|
|
|
(i32.mul
|
|
|
|
(get_local $1)
|
2017-12-06 23:38:17 +01:00
|
|
|
(i32.const 32)
|
2017-12-06 19:33:48 +01:00
|
|
|
)
|
|
|
|
(get_local $2)
|
|
|
|
)
|
|
|
|
(i32.const 4)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
(get_local $3)
|
|
|
|
)
|
|
|
|
)
|
2018-02-04 07:51:40 +01:00
|
|
|
(func $tlsf/control$construct (; 8 ;) (type $iv) (param $0 i32)
|
2017-12-06 19:33:48 +01:00
|
|
|
(local $1 i32)
|
|
|
|
(local $2 i32)
|
2017-12-07 02:02:22 +01:00
|
|
|
(call $tlsf/block$set_next_free
|
2017-12-06 19:33:48 +01:00
|
|
|
(get_local $0)
|
|
|
|
(get_local $0)
|
|
|
|
)
|
2017-12-07 02:02:22 +01:00
|
|
|
(call $tlsf/block$set_prev_free
|
2017-12-06 19:33:48 +01:00
|
|
|
(get_local $0)
|
|
|
|
(get_local $0)
|
|
|
|
)
|
2017-12-07 02:02:22 +01:00
|
|
|
(call $tlsf/control$set_fl_bitmap
|
2017-12-06 19:33:48 +01:00
|
|
|
(get_local $0)
|
|
|
|
(i32.const 0)
|
|
|
|
)
|
2017-12-08 16:11:58 +01:00
|
|
|
(block $break|0
|
2018-01-18 23:34:12 +01:00
|
|
|
(set_local $1
|
|
|
|
(i32.const 0)
|
2017-12-06 19:33:48 +01:00
|
|
|
)
|
2017-12-08 16:11:58 +01:00
|
|
|
(loop $continue|0
|
2017-12-06 19:33:48 +01:00
|
|
|
(if
|
2017-12-11 18:46:11 +01:00
|
|
|
(i32.lt_u
|
2017-12-06 19:33:48 +01:00
|
|
|
(get_local $1)
|
2017-12-06 23:38:17 +01:00
|
|
|
(i32.const 23)
|
2017-12-06 19:33:48 +01:00
|
|
|
)
|
|
|
|
(block
|
|
|
|
(block
|
2017-12-07 02:02:22 +01:00
|
|
|
(call $tlsf/control$set_sl_bitmap
|
2017-12-06 19:33:48 +01:00
|
|
|
(get_local $0)
|
|
|
|
(get_local $1)
|
|
|
|
(i32.const 0)
|
|
|
|
)
|
2017-12-08 16:11:58 +01:00
|
|
|
(block $break|1
|
2018-01-18 23:34:12 +01:00
|
|
|
(set_local $2
|
|
|
|
(i32.const 0)
|
2017-12-06 19:33:48 +01:00
|
|
|
)
|
2017-12-08 16:11:58 +01:00
|
|
|
(loop $continue|1
|
2017-12-06 19:33:48 +01:00
|
|
|
(if
|
2017-12-11 18:46:11 +01:00
|
|
|
(i32.lt_u
|
2017-12-06 19:33:48 +01:00
|
|
|
(get_local $2)
|
2017-12-06 23:38:17 +01:00
|
|
|
(i32.const 32)
|
2017-12-06 19:33:48 +01:00
|
|
|
)
|
|
|
|
(block
|
2017-12-07 02:02:22 +01:00
|
|
|
(call $tlsf/control$set_block
|
2017-12-06 19:33:48 +01:00
|
|
|
(get_local $0)
|
|
|
|
(get_local $1)
|
|
|
|
(get_local $2)
|
|
|
|
(get_local $0)
|
|
|
|
)
|
|
|
|
(set_local $2
|
|
|
|
(i32.add
|
|
|
|
(get_local $2)
|
|
|
|
(i32.const 1)
|
|
|
|
)
|
|
|
|
)
|
2017-12-08 16:11:58 +01:00
|
|
|
(br $continue|1)
|
2017-12-06 19:33:48 +01:00
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
(set_local $1
|
|
|
|
(i32.add
|
|
|
|
(get_local $1)
|
|
|
|
(i32.const 1)
|
|
|
|
)
|
|
|
|
)
|
2017-12-08 16:11:58 +01:00
|
|
|
(br $continue|0)
|
2017-12-06 19:33:48 +01:00
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
2018-02-04 07:51:40 +01:00
|
|
|
(func $start (; 9 ;) (type $v)
|
2017-12-06 19:33:48 +01:00
|
|
|
(if
|
|
|
|
(i32.eqz
|
|
|
|
(i32.eq
|
|
|
|
(call $tlsf/fls
|
|
|
|
(i32.const 0)
|
|
|
|
)
|
2018-02-14 09:18:43 +01:00
|
|
|
(i32.const -1)
|
2017-12-06 19:33:48 +01:00
|
|
|
)
|
|
|
|
)
|
2018-02-04 07:51:40 +01:00
|
|
|
(block
|
|
|
|
(call $abort
|
|
|
|
(i32.const 0)
|
2018-02-14 09:18:43 +01:00
|
|
|
(i32.const 4)
|
2018-02-04 07:51:40 +01:00
|
|
|
(i32.const 10)
|
|
|
|
(i32.const 0)
|
|
|
|
)
|
|
|
|
(unreachable)
|
|
|
|
)
|
2017-12-06 19:33:48 +01:00
|
|
|
)
|
|
|
|
(if
|
|
|
|
(i32.eqz
|
|
|
|
(i32.eq
|
|
|
|
(call $tlsf/fls
|
|
|
|
(i32.const 1)
|
|
|
|
)
|
|
|
|
(i32.const 0)
|
|
|
|
)
|
|
|
|
)
|
2018-02-04 07:51:40 +01:00
|
|
|
(block
|
|
|
|
(call $abort
|
|
|
|
(i32.const 0)
|
2018-02-14 09:18:43 +01:00
|
|
|
(i32.const 4)
|
2018-02-04 07:51:40 +01:00
|
|
|
(i32.const 11)
|
|
|
|
(i32.const 0)
|
|
|
|
)
|
|
|
|
(unreachable)
|
|
|
|
)
|
2017-12-06 19:33:48 +01:00
|
|
|
)
|
|
|
|
(if
|
|
|
|
(i32.eqz
|
|
|
|
(i32.eq
|
|
|
|
(call $tlsf/fls
|
|
|
|
(i32.const -2147483640)
|
|
|
|
)
|
|
|
|
(i32.const 31)
|
|
|
|
)
|
|
|
|
)
|
2018-02-04 07:51:40 +01:00
|
|
|
(block
|
|
|
|
(call $abort
|
|
|
|
(i32.const 0)
|
2018-02-14 09:18:43 +01:00
|
|
|
(i32.const 4)
|
2018-02-04 07:51:40 +01:00
|
|
|
(i32.const 12)
|
|
|
|
(i32.const 0)
|
|
|
|
)
|
|
|
|
(unreachable)
|
|
|
|
)
|
2017-12-06 19:33:48 +01:00
|
|
|
)
|
|
|
|
(if
|
|
|
|
(i32.eqz
|
|
|
|
(i32.eq
|
|
|
|
(call $tlsf/fls
|
|
|
|
(i32.const 2147483647)
|
|
|
|
)
|
|
|
|
(i32.const 30)
|
|
|
|
)
|
|
|
|
)
|
2018-02-04 07:51:40 +01:00
|
|
|
(block
|
|
|
|
(call $abort
|
|
|
|
(i32.const 0)
|
2018-02-14 09:18:43 +01:00
|
|
|
(i32.const 4)
|
2018-02-04 07:51:40 +01:00
|
|
|
(i32.const 13)
|
|
|
|
(i32.const 0)
|
|
|
|
)
|
|
|
|
(unreachable)
|
|
|
|
)
|
2017-12-06 19:33:48 +01:00
|
|
|
)
|
|
|
|
(if
|
|
|
|
(i32.eqz
|
|
|
|
(i32.eq
|
|
|
|
(call $tlsf/ffs
|
|
|
|
(i32.const 0)
|
|
|
|
)
|
2018-02-14 09:18:43 +01:00
|
|
|
(i32.const -1)
|
2017-12-06 19:33:48 +01:00
|
|
|
)
|
|
|
|
)
|
2018-02-04 07:51:40 +01:00
|
|
|
(block
|
|
|
|
(call $abort
|
|
|
|
(i32.const 0)
|
2018-02-14 09:18:43 +01:00
|
|
|
(i32.const 4)
|
2018-02-04 07:51:40 +01:00
|
|
|
(i32.const 20)
|
|
|
|
(i32.const 0)
|
|
|
|
)
|
|
|
|
(unreachable)
|
|
|
|
)
|
2017-12-06 19:33:48 +01:00
|
|
|
)
|
|
|
|
(if
|
|
|
|
(i32.eqz
|
|
|
|
(i32.eq
|
|
|
|
(call $tlsf/ffs
|
|
|
|
(i32.const 1)
|
|
|
|
)
|
|
|
|
(i32.const 0)
|
|
|
|
)
|
|
|
|
)
|
2018-02-04 07:51:40 +01:00
|
|
|
(block
|
|
|
|
(call $abort
|
|
|
|
(i32.const 0)
|
2018-02-14 09:18:43 +01:00
|
|
|
(i32.const 4)
|
2018-02-04 07:51:40 +01:00
|
|
|
(i32.const 21)
|
|
|
|
(i32.const 0)
|
|
|
|
)
|
|
|
|
(unreachable)
|
|
|
|
)
|
2017-12-06 19:33:48 +01:00
|
|
|
)
|
|
|
|
(if
|
|
|
|
(i32.eqz
|
|
|
|
(i32.eq
|
|
|
|
(call $tlsf/ffs
|
|
|
|
(i32.const -2147483648)
|
|
|
|
)
|
|
|
|
(i32.const 31)
|
|
|
|
)
|
|
|
|
)
|
2018-02-04 07:51:40 +01:00
|
|
|
(block
|
|
|
|
(call $abort
|
|
|
|
(i32.const 0)
|
2018-02-14 09:18:43 +01:00
|
|
|
(i32.const 4)
|
2018-02-04 07:51:40 +01:00
|
|
|
(i32.const 22)
|
|
|
|
(i32.const 0)
|
|
|
|
)
|
|
|
|
(unreachable)
|
|
|
|
)
|
2017-12-06 19:33:48 +01:00
|
|
|
)
|
|
|
|
(if
|
|
|
|
(i32.eqz
|
|
|
|
(i32.eq
|
2017-12-06 23:38:17 +01:00
|
|
|
(i32.const 8)
|
2017-12-06 19:33:48 +01:00
|
|
|
(i32.const 8)
|
|
|
|
)
|
|
|
|
)
|
2018-02-04 07:51:40 +01:00
|
|
|
(block
|
|
|
|
(call $abort
|
|
|
|
(i32.const 0)
|
2018-02-14 09:18:43 +01:00
|
|
|
(i32.const 4)
|
2018-02-04 07:51:40 +01:00
|
|
|
(i32.const 29)
|
|
|
|
(i32.const 0)
|
|
|
|
)
|
|
|
|
(unreachable)
|
|
|
|
)
|
2017-12-06 19:33:48 +01:00
|
|
|
)
|
2017-12-07 02:02:22 +01:00
|
|
|
(call $tlsf/control$construct
|
2017-12-06 19:33:48 +01:00
|
|
|
(i32.load
|
2017-12-06 23:38:17 +01:00
|
|
|
(i32.const 4)
|
2017-12-06 19:33:48 +01:00
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|