Progress and a tiny WASM binary parser

This commit is contained in:
dcodeIO
2018-04-03 23:56:48 +02:00
parent 06198a3723
commit 5823e35f37
58 changed files with 12075 additions and 3964 deletions

View File

@ -2,161 +2,170 @@
(type $ii (func (param i32) (result i32)))
(type $iv (func (param i32)))
(type $v (func))
(global "$(lib)/allocator/arena/startOffset" (mut i32) (i32.const 0))
(global "$(lib)/allocator/arena/offset" (mut i32) (i32.const 0))
(global $~lib/allocator/arena/startOffset (mut i32) (i32.const 0))
(global $~lib/allocator/arena/offset (mut i32) (i32.const 0))
(global $HEAP_BASE i32 (i32.const 4))
(memory $0 1)
(export "allocate_memory" (func "$(lib)/allocator/arena/allocate_memory"))
(export "free_memory" (func "$(lib)/allocator/arena/free_memory"))
(export "reset_memory" (func "$(lib)/allocator/arena/reset_memory"))
(export "allocate_memory" (func $~lib/allocator/arena/allocate_memory))
(export "free_memory" (func $~lib/allocator/arena/free_memory))
(export "reset_memory" (func $~lib/allocator/arena/reset_memory))
(export "memory" (memory $0))
(start $start)
(func "$(lib)/allocator/arena/allocate_memory" (; 0 ;) (type $ii) (param $0 i32) (result i32)
(func $~lib/allocator/arena/allocate_memory (; 0 ;) (type $ii) (param $0 i32) (result i32)
(local $1 i32)
(local $2 i32)
(local $3 i32)
(local $4 i32)
;;@ (lib)/allocator/arena.ts:17:2
;;@ ~lib/allocator/arena.ts:18:2
(if
;;@ (lib)/allocator/arena.ts:17:6
(i32.eqz
;;@ (lib)/allocator/arena.ts:17:7
(select
;;@ ~lib/allocator/arena.ts:18:14
(i32.lt_u
(get_local $0)
;;@ ~lib/allocator/arena.ts:18:21
(i32.const 1073741824)
)
(get_local $0)
;;@ ~lib/allocator/arena.ts:18:6
(get_local $0)
)
;;@ (lib)/allocator/arena.ts:17:20
(return
(i32.const 0)
)
)
;;@ (lib)/allocator/arena.ts:21:2
(if
;;@ (lib)/allocator/arena.ts:21:6
(i32.gt_u
;;@ (lib)/allocator/arena.ts:19:2
(tee_local $2
;;@ (lib)/allocator/arena.ts:19:15
(i32.and
(i32.add
;;@ (lib)/allocator/arena.ts:19:16
(i32.add
;;@ (lib)/allocator/arena.ts:18:2
(tee_local $1
;;@ (lib)/allocator/arena.ts:18:12
(get_global "$(lib)/allocator/arena/offset")
)
;;@ (lib)/allocator/arena.ts:19:22
(get_local $0)
)
;;@ (lib)/allocator/arena.ts:19:29
(i32.const 7)
)
(i32.const -8)
)
)
;;@ (lib)/allocator/arena.ts:21:15
(i32.shl
;;@ (lib)/allocator/arena.ts:20:2
(tee_local $0
;;@ (lib)/allocator/arena.ts:20:20
(current_memory)
)
;;@ (lib)/allocator/arena.ts:21:37
(i32.const 16)
)
)
;;@ (lib)/allocator/arena.ts:24:4
(if
;;@ (lib)/allocator/arena.ts:24:8
(i32.lt_s
(grow_memory
;;@ (lib)/allocator/arena.ts:23:22
(select
;;@ (lib)/allocator/arena.ts:23:26
(get_local $0)
(tee_local $4
;;@ (lib)/allocator/arena.ts:22:4
(tee_local $3
;;@ (lib)/allocator/arena.ts:22:22
(i32.shr_u
(i32.and
;;@ (lib)/allocator/arena.ts:22:23
(i32.add
;;@ (lib)/allocator/arena.ts:22:24
(i32.sub
(get_local $2)
;;@ (lib)/allocator/arena.ts:22:33
(get_local $1)
)
;;@ (lib)/allocator/arena.ts:22:39
(i32.const 65535)
)
(i32.const -65536)
;;@ ~lib/allocator/arena.ts:18:31
(block
;;@ ~lib/allocator/arena.ts:22:4
(if
;;@ ~lib/allocator/arena.ts:22:8
(i32.gt_u
;;@ ~lib/allocator/arena.ts:20:4
(tee_local $2
;;@ ~lib/allocator/arena.ts:20:17
(i32.and
(i32.add
;;@ ~lib/allocator/arena.ts:20:18
(i32.add
;;@ ~lib/allocator/arena.ts:19:4
(tee_local $1
;;@ ~lib/allocator/arena.ts:19:14
(get_global $~lib/allocator/arena/offset)
)
;;@ (lib)/allocator/arena.ts:22:62
(i32.const 16)
;;@ ~lib/allocator/arena.ts:20:24
(get_local $0)
)
;;@ ~lib/allocator/arena.ts:20:31
(i32.const 7)
)
(i32.const -8)
)
)
;;@ ~lib/allocator/arena.ts:22:17
(i32.shl
;;@ ~lib/allocator/arena.ts:21:4
(tee_local $0
;;@ ~lib/allocator/arena.ts:21:22
(current_memory)
)
;;@ ~lib/allocator/arena.ts:22:39
(i32.const 16)
)
)
;;@ ~lib/allocator/arena.ts:25:6
(if
;;@ ~lib/allocator/arena.ts:25:10
(i32.lt_s
(grow_memory
;;@ ~lib/allocator/arena.ts:24:24
(select
;;@ ~lib/allocator/arena.ts:24:28
(get_local $0)
(tee_local $4
;;@ ~lib/allocator/arena.ts:23:6
(tee_local $3
;;@ ~lib/allocator/arena.ts:23:24
(i32.shr_u
(i32.and
;;@ ~lib/allocator/arena.ts:23:25
(i32.add
;;@ ~lib/allocator/arena.ts:23:26
(i32.sub
(get_local $2)
;;@ ~lib/allocator/arena.ts:23:35
(get_local $1)
)
;;@ ~lib/allocator/arena.ts:23:41
(i32.const 65535)
)
(i32.const -65536)
)
;;@ ~lib/allocator/arena.ts:23:64
(i32.const 16)
)
)
)
(i32.gt_s
(get_local $0)
(get_local $4)
)
)
)
(i32.gt_s
(get_local $0)
(get_local $4)
;;@ ~lib/allocator/arena.ts:25:37
(i32.const 0)
)
;;@ ~lib/allocator/arena.ts:26:8
(if
;;@ ~lib/allocator/arena.ts:26:12
(i32.lt_s
(grow_memory
;;@ ~lib/allocator/arena.ts:26:24
(get_local $3)
)
;;@ ~lib/allocator/arena.ts:26:39
(i32.const 0)
)
;;@ ~lib/allocator/arena.ts:27:10
(unreachable)
)
)
;;@ (lib)/allocator/arena.ts:24:35
(i32.const 0)
)
;;@ (lib)/allocator/arena.ts:25:6
(if
;;@ (lib)/allocator/arena.ts:25:10
(i32.lt_s
(grow_memory
;;@ (lib)/allocator/arena.ts:25:22
(get_local $3)
)
;;@ (lib)/allocator/arena.ts:25:37
(i32.const 0)
)
;;@ (lib)/allocator/arena.ts:26:8
(unreachable)
;;@ ~lib/allocator/arena.ts:31:4
(set_global $~lib/allocator/arena/offset
;;@ ~lib/allocator/arena.ts:31:13
(get_local $2)
)
;;@ ~lib/allocator/arena.ts:32:11
(return
(get_local $1)
)
)
)
;;@ (lib)/allocator/arena.ts:30:2
(set_global "$(lib)/allocator/arena/offset"
;;@ (lib)/allocator/arena.ts:30:11
(get_local $2)
)
;;@ (lib)/allocator/arena.ts:31:9
(get_local $1)
;;@ ~lib/allocator/arena.ts:34:9
(i32.const 0)
)
(func "$(lib)/allocator/arena/free_memory" (; 1 ;) (type $iv) (param $0 i32)
;;@ (lib)/allocator/arena.ts:35:46
(func $~lib/allocator/arena/free_memory (; 1 ;) (type $iv) (param $0 i32)
;;@ ~lib/allocator/arena.ts:38:46
(nop)
)
(func "$(lib)/allocator/arena/reset_memory" (; 2 ;) (type $v)
;;@ (lib)/allocator/arena.ts:41:2
(set_global "$(lib)/allocator/arena/offset"
;;@ (lib)/allocator/arena.ts:41:11
(get_global "$(lib)/allocator/arena/startOffset")
(func $~lib/allocator/arena/reset_memory (; 2 ;) (type $v)
;;@ ~lib/allocator/arena.ts:44:2
(set_global $~lib/allocator/arena/offset
;;@ ~lib/allocator/arena.ts:44:11
(get_global $~lib/allocator/arena/startOffset)
)
)
(func $start (; 3 ;) (type $v)
(set_global "$(lib)/allocator/arena/startOffset"
;;@ (lib)/allocator/arena.ts:12:25
(set_global $~lib/allocator/arena/startOffset
;;@ ~lib/allocator/arena.ts:12:25
(i32.and
(i32.add
;;@ (lib)/allocator/arena.ts:12:26
;;@ ~lib/allocator/arena.ts:12:26
(get_global $HEAP_BASE)
;;@ (lib)/allocator/arena.ts:12:38
;;@ ~lib/allocator/arena.ts:12:38
(i32.const 7)
)
(i32.const -8)
)
)
(set_global "$(lib)/allocator/arena/offset"
;;@ (lib)/allocator/arena.ts:13:20
(get_global "$(lib)/allocator/arena/startOffset")
(set_global $~lib/allocator/arena/offset
;;@ ~lib/allocator/arena.ts:13:20
(get_global $~lib/allocator/arena/startOffset)
)
)
)

View File

@ -3,196 +3,208 @@
(type $ii (func (param i32) (result i32)))
(type $iv (func (param i32)))
(type $v (func))
(global "$(lib)/allocator/common/alignment/BITS" i32 (i32.const 3))
(global "$(lib)/allocator/common/alignment/SIZE" i32 (i32.const 8))
(global "$(lib)/allocator/common/alignment/MASK" i32 (i32.const 7))
(global "$(lib)/allocator/arena/startOffset" (mut i32) (i32.const 0))
(global "$(lib)/allocator/arena/offset" (mut i32) (i32.const 0))
(global $~lib/allocator/common/index/AL_BITS i32 (i32.const 3))
(global $~lib/allocator/common/index/AL_SIZE i32 (i32.const 8))
(global $~lib/allocator/common/index/AL_MASK i32 (i32.const 7))
(global $~lib/allocator/common/index/MAX_SIZE_32 i32 (i32.const 1073741824))
(global $~lib/allocator/arena/startOffset (mut i32) (i32.const 0))
(global $~lib/allocator/arena/offset (mut i32) (i32.const 0))
(global $HEAP_BASE i32 (i32.const 4))
(memory $0 1)
(export "allocate_memory" (func "$(lib)/allocator/arena/allocate_memory"))
(export "free_memory" (func "$(lib)/allocator/arena/free_memory"))
(export "reset_memory" (func "$(lib)/allocator/arena/reset_memory"))
(export "allocate_memory" (func $~lib/allocator/arena/allocate_memory))
(export "free_memory" (func $~lib/allocator/arena/free_memory))
(export "reset_memory" (func $~lib/allocator/arena/reset_memory))
(export "memory" (memory $0))
(start $start)
(func "$(lib)/allocator/arena/allocate_memory" (; 0 ;) (type $ii) (param $0 i32) (result i32)
(func $~lib/allocator/arena/allocate_memory (; 0 ;) (type $ii) (param $0 i32) (result i32)
(local $1 i32)
(local $2 i32)
(local $3 i32)
(local $4 i32)
(local $5 i32)
(local $6 i32)
;;@ (lib)/allocator/arena.ts:17:2
;;@ ~lib/allocator/arena.ts:17:2
(nop)
;;@ ~lib/allocator/arena.ts:18:2
(if
;;@ (lib)/allocator/arena.ts:17:6
(i32.eqz
;;@ (lib)/allocator/arena.ts:17:7
;;@ ~lib/allocator/arena.ts:18:6
(if (result i32)
(get_local $0)
;;@ ~lib/allocator/arena.ts:18:14
(i32.lt_u
(get_local $0)
;;@ ~lib/allocator/arena.ts:18:21
(i32.const 1073741824)
)
(get_local $0)
)
;;@ (lib)/allocator/arena.ts:17:20
(return
(i32.const 0)
)
)
;;@ (lib)/allocator/arena.ts:18:2
(set_local $1
;;@ (lib)/allocator/arena.ts:18:12
(get_global "$(lib)/allocator/arena/offset")
)
;;@ (lib)/allocator/arena.ts:19:2
(set_local $2
;;@ (lib)/allocator/arena.ts:19:15
(i32.and
(i32.add
;;@ (lib)/allocator/arena.ts:19:16
(i32.add
(get_local $1)
;;@ (lib)/allocator/arena.ts:19:22
(get_local $0)
)
;;@ (lib)/allocator/arena.ts:19:29
(i32.const 7)
)
;;@ (lib)/allocator/arena.ts:19:40
(i32.xor
;;@ (lib)/allocator/arena.ts:19:41
(i32.const 7)
(i32.const -1)
)
)
)
;;@ (lib)/allocator/arena.ts:20:2
(set_local $3
;;@ (lib)/allocator/arena.ts:20:20
(current_memory)
)
;;@ (lib)/allocator/arena.ts:21:2
(if
;;@ (lib)/allocator/arena.ts:21:6
(i32.gt_u
(get_local $2)
;;@ (lib)/allocator/arena.ts:21:15
(i32.shl
(get_local $3)
;;@ (lib)/allocator/arena.ts:21:37
(i32.const 16)
)
)
;;@ (lib)/allocator/arena.ts:21:41
;;@ ~lib/allocator/arena.ts:18:31
(block
;;@ (lib)/allocator/arena.ts:22:4
(set_local $4
;;@ (lib)/allocator/arena.ts:22:22
(i32.shr_u
(i32.and
;;@ (lib)/allocator/arena.ts:22:23
;;@ ~lib/allocator/arena.ts:19:4
(set_local $1
;;@ ~lib/allocator/arena.ts:19:14
(get_global $~lib/allocator/arena/offset)
)
;;@ ~lib/allocator/arena.ts:20:4
(set_local $2
;;@ ~lib/allocator/arena.ts:20:17
(i32.and
(i32.add
;;@ ~lib/allocator/arena.ts:20:18
(i32.add
;;@ (lib)/allocator/arena.ts:22:24
(i32.sub
(get_local $2)
;;@ (lib)/allocator/arena.ts:22:33
(get_local $1)
)
;;@ (lib)/allocator/arena.ts:22:39
(i32.const 65535)
)
;;@ (lib)/allocator/arena.ts:22:49
(i32.xor
;;@ (lib)/allocator/arena.ts:22:50
(i32.const 65535)
(i32.const -1)
(get_local $1)
;;@ ~lib/allocator/arena.ts:20:24
(get_local $0)
)
;;@ ~lib/allocator/arena.ts:20:31
(i32.const 7)
)
;;@ (lib)/allocator/arena.ts:22:62
(i32.const 16)
)
)
;;@ (lib)/allocator/arena.ts:23:4
(set_local $5
;;@ (lib)/allocator/arena.ts:23:22
(select
(tee_local $5
;;@ (lib)/allocator/arena.ts:23:26
(get_local $3)
)
(tee_local $6
;;@ (lib)/allocator/arena.ts:23:39
(get_local $4)
)
(i32.gt_s
(get_local $5)
(get_local $6)
;;@ ~lib/allocator/arena.ts:20:42
(i32.xor
;;@ ~lib/allocator/arena.ts:20:43
(i32.const 7)
(i32.const -1)
)
)
)
;;@ (lib)/allocator/arena.ts:24:4
;;@ ~lib/allocator/arena.ts:21:4
(set_local $3
;;@ ~lib/allocator/arena.ts:21:22
(current_memory)
)
;;@ ~lib/allocator/arena.ts:22:4
(if
;;@ (lib)/allocator/arena.ts:24:8
(i32.lt_s
(grow_memory
;;@ (lib)/allocator/arena.ts:24:20
(get_local $5)
;;@ ~lib/allocator/arena.ts:22:8
(i32.gt_u
(get_local $2)
;;@ ~lib/allocator/arena.ts:22:17
(i32.shl
(get_local $3)
;;@ ~lib/allocator/arena.ts:22:39
(i32.const 16)
)
;;@ (lib)/allocator/arena.ts:24:35
(i32.const 0)
)
;;@ (lib)/allocator/arena.ts:25:6
(if
;;@ (lib)/allocator/arena.ts:25:10
(i32.lt_s
(grow_memory
;;@ (lib)/allocator/arena.ts:25:22
(get_local $4)
;;@ ~lib/allocator/arena.ts:22:43
(block
;;@ ~lib/allocator/arena.ts:23:6
(set_local $4
;;@ ~lib/allocator/arena.ts:23:24
(i32.shr_u
(i32.and
;;@ ~lib/allocator/arena.ts:23:25
(i32.add
;;@ ~lib/allocator/arena.ts:23:26
(i32.sub
(get_local $2)
;;@ ~lib/allocator/arena.ts:23:35
(get_local $1)
)
;;@ ~lib/allocator/arena.ts:23:41
(i32.const 65535)
)
;;@ ~lib/allocator/arena.ts:23:51
(i32.xor
;;@ ~lib/allocator/arena.ts:23:52
(i32.const 65535)
(i32.const -1)
)
)
;;@ ~lib/allocator/arena.ts:23:64
(i32.const 16)
)
)
;;@ ~lib/allocator/arena.ts:24:6
(set_local $5
;;@ ~lib/allocator/arena.ts:24:24
(select
(tee_local $5
;;@ ~lib/allocator/arena.ts:24:28
(get_local $3)
)
(tee_local $6
;;@ ~lib/allocator/arena.ts:24:41
(get_local $4)
)
(i32.gt_s
(get_local $5)
(get_local $6)
)
)
)
;;@ ~lib/allocator/arena.ts:25:6
(if
;;@ ~lib/allocator/arena.ts:25:10
(i32.lt_s
(grow_memory
;;@ ~lib/allocator/arena.ts:25:22
(get_local $5)
)
;;@ ~lib/allocator/arena.ts:25:37
(i32.const 0)
)
;;@ ~lib/allocator/arena.ts:26:8
(if
;;@ ~lib/allocator/arena.ts:26:12
(i32.lt_s
(grow_memory
;;@ ~lib/allocator/arena.ts:26:24
(get_local $4)
)
;;@ ~lib/allocator/arena.ts:26:39
(i32.const 0)
)
;;@ ~lib/allocator/arena.ts:27:10
(unreachable)
)
;;@ (lib)/allocator/arena.ts:25:37
(i32.const 0)
)
;;@ (lib)/allocator/arena.ts:26:8
(unreachable)
)
)
;;@ ~lib/allocator/arena.ts:31:4
(set_global $~lib/allocator/arena/offset
;;@ ~lib/allocator/arena.ts:31:13
(get_local $2)
)
;;@ ~lib/allocator/arena.ts:32:11
(return
(get_local $1)
)
)
)
;;@ (lib)/allocator/arena.ts:30:2
(set_global "$(lib)/allocator/arena/offset"
;;@ (lib)/allocator/arena.ts:30:11
(get_local $2)
)
;;@ (lib)/allocator/arena.ts:31:9
;;@ ~lib/allocator/arena.ts:34:9
(return
(get_local $1)
(i32.const 0)
)
)
(func "$(lib)/allocator/arena/free_memory" (; 1 ;) (type $iv) (param $0 i32)
(func $~lib/allocator/arena/free_memory (; 1 ;) (type $iv) (param $0 i32)
)
(func "$(lib)/allocator/arena/reset_memory" (; 2 ;) (type $v)
;;@ (lib)/allocator/arena.ts:41:2
(set_global "$(lib)/allocator/arena/offset"
;;@ (lib)/allocator/arena.ts:41:11
(get_global "$(lib)/allocator/arena/startOffset")
(func $~lib/allocator/arena/reset_memory (; 2 ;) (type $v)
;;@ ~lib/allocator/arena.ts:44:2
(set_global $~lib/allocator/arena/offset
;;@ ~lib/allocator/arena.ts:44:11
(get_global $~lib/allocator/arena/startOffset)
)
)
(func $start (; 3 ;) (type $v)
(set_global "$(lib)/allocator/arena/startOffset"
;;@ (lib)/allocator/arena.ts:12:25
(set_global $~lib/allocator/arena/startOffset
;;@ ~lib/allocator/arena.ts:12:25
(i32.and
(i32.add
;;@ (lib)/allocator/arena.ts:12:26
;;@ ~lib/allocator/arena.ts:12:26
(get_global $HEAP_BASE)
;;@ (lib)/allocator/arena.ts:12:38
;;@ ~lib/allocator/arena.ts:12:38
(i32.const 7)
)
;;@ (lib)/allocator/arena.ts:12:49
;;@ ~lib/allocator/arena.ts:12:49
(i32.xor
;;@ (lib)/allocator/arena.ts:12:50
;;@ ~lib/allocator/arena.ts:12:50
(i32.const 7)
(i32.const -1)
)
)
)
(set_global "$(lib)/allocator/arena/offset"
;;@ (lib)/allocator/arena.ts:13:20
(get_global "$(lib)/allocator/arena/startOffset")
(set_global $~lib/allocator/arena/offset
;;@ ~lib/allocator/arena.ts:13:20
(get_global $~lib/allocator/arena/startOffset)
)
)
)

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,5 @@
const fs = require("fs");
const COMMON_MAX = 1 << 30;
function test(file) {
console.log("Testing '" + file + "' ...\n");
@ -23,6 +24,13 @@ function test(file) {
console.log("mem final: " + exports.memory.buffer.byteLength);
console.log();
if (exports.allocate_memory(COMMON_MAX + 1) != 0) {
throw Error("allocation is allowed to overflow MAX_SIZE");
}
if (exports.allocate_memory(0xffffffff) != 0) {
throw Error("allocation is allowed to overflow INT_MAX");
}
}
if (process.argv.length > 2) {

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff