3 Star 0 Fork 0

DST/testsuite

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
func.wast 19.32 KB
一键复制 编辑 原始数据 按行查看 历史
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
;; Test `func` declarations, i.e. functions
(module
;; Auxiliary definition
(type $sig (func))
(func $dummy)
;; Syntax
(func)
(func (export "f"))
(func $f)
(func $h (export "g"))
(func (local))
(func (local) (local))
(func (local i32))
(func (local $x i32))
(func (local i32 f64 i64))
(func (local i32) (local f64))
(func (local i32 f32) (local $x i64) (local) (local i32 f64))
(func (param))
(func (param) (param))
(func (param i32))
(func (param $x i32))
(func (param i32 f64 i64))
(func (param i32) (param f64))
(func (param i32 f32) (param $x i64) (param) (param i32 f64))
(func (result i32) (unreachable))
(type $sig-1 (func))
(type $sig-2 (func (result i32)))
(type $sig-3 (func (param $x i32)))
(type $sig-4 (func (param i32 f64 i32) (result i32)))
(func (export "type-use-1") (type $sig-1))
(func (export "type-use-2") (type $sig-2) (i32.const 0))
(func (export "type-use-3") (type $sig-3))
(func (export "type-use-4") (type $sig-4) (i32.const 0))
(func (export "type-use-5") (type $sig-2) (result i32) (i32.const 0))
(func (export "type-use-6") (type $sig-3) (param i32))
(func (export "type-use-7")
(type $sig-4) (param i32) (param f64 i32) (result i32) (i32.const 0)
)
(func (type $sig))
(func (type $forward)) ;; forward reference
(func $complex
(param i32 f32) (param $x i64) (param) (param i32)
(result) (result i32) (result)
(local f32) (local $y i32) (local i64 i32) (local) (local f64 i32)
(unreachable) (unreachable)
)
(func $complex-sig
(type $sig)
(local f32) (local $y i32) (local i64 i32) (local) (local f64 i32)
(unreachable) (unreachable)
)
(type $forward (func))
;; Typing of locals
(func (export "local-first-i32") (result i32) (local i32 i32) (get_local 0))
(func (export "local-first-i64") (result i64) (local i64 i64) (get_local 0))
(func (export "local-first-f32") (result f32) (local f32 f32) (get_local 0))
(func (export "local-first-f64") (result f64) (local f64 f64) (get_local 0))
(func (export "local-second-i32") (result i32) (local i32 i32) (get_local 1))
(func (export "local-second-i64") (result i64) (local i64 i64) (get_local 1))
(func (export "local-second-f32") (result f32) (local f32 f32) (get_local 1))
(func (export "local-second-f64") (result f64) (local f64 f64) (get_local 1))
(func (export "local-mixed") (result f64)
(local f32) (local $x i32) (local i64 i32) (local) (local f64 i32)
(drop (f32.neg (get_local 0)))
(drop (i32.eqz (get_local 1)))
(drop (i64.eqz (get_local 2)))
(drop (i32.eqz (get_local 3)))
(drop (f64.neg (get_local 4)))
(drop (i32.eqz (get_local 5)))
(get_local 4)
)
;; Typing of parameters
(func (export "param-first-i32") (param i32 i32) (result i32) (get_local 0))
(func (export "param-first-i64") (param i64 i64) (result i64) (get_local 0))
(func (export "param-first-f32") (param f32 f32) (result f32) (get_local 0))
(func (export "param-first-f64") (param f64 f64) (result f64) (get_local 0))
(func (export "param-second-i32") (param i32 i32) (result i32) (get_local 1))
(func (export "param-second-i64") (param i64 i64) (result i64) (get_local 1))
(func (export "param-second-f32") (param f32 f32) (result f32) (get_local 1))
(func (export "param-second-f64") (param f64 f64) (result f64) (get_local 1))
(func (export "param-mixed") (param f32 i32) (param) (param $x i64) (param i32 f64 i32)
(result f64)
(drop (f32.neg (get_local 0)))
(drop (i32.eqz (get_local 1)))
(drop (i64.eqz (get_local 2)))
(drop (i32.eqz (get_local 3)))
(drop (f64.neg (get_local 4)))
(drop (i32.eqz (get_local 5)))
(get_local 4)
)
;; Typing of result
(func (export "empty"))
(func (export "value-void") (call $dummy))
(func (export "value-i32") (result i32) (i32.const 77))
(func (export "value-i64") (result i64) (i64.const 7777))
(func (export "value-f32") (result f32) (f32.const 77.7))
(func (export "value-f64") (result f64) (f64.const 77.77))
(func (export "value-block-void") (block (call $dummy) (call $dummy)))
(func (export "value-block-i32") (result i32)
(block (result i32) (call $dummy) (i32.const 77))
)
(func (export "return-empty") (return))
(func (export "return-i32") (result i32) (return (i32.const 78)))
(func (export "return-i64") (result i64) (return (i64.const 7878)))
(func (export "return-f32") (result f32) (return (f32.const 78.7)))
(func (export "return-f64") (result f64) (return (f64.const 78.78)))
(func (export "return-block-i32") (result i32)
(return (block (result i32) (call $dummy) (i32.const 77)))
)
(func (export "break-empty") (br 0))
(func (export "break-i32") (result i32) (br 0 (i32.const 79)))
(func (export "break-i64") (result i64) (br 0 (i64.const 7979)))
(func (export "break-f32") (result f32) (br 0 (f32.const 79.9)))
(func (export "break-f64") (result f64) (br 0 (f64.const 79.79)))
(func (export "break-block-i32") (result i32)
(br 0 (block (result i32) (call $dummy) (i32.const 77)))
)
(func (export "break-br_if-empty") (param i32)
(br_if 0 (get_local 0))
)
(func (export "break-br_if-num") (param i32) (result i32)
(drop (br_if 0 (i32.const 50) (get_local 0))) (i32.const 51)
)
(func (export "break-br_table-empty") (param i32)
(br_table 0 0 0 (get_local 0))
)
(func (export "break-br_table-num") (param i32) (result i32)
(br_table 0 0 (i32.const 50) (get_local 0)) (i32.const 51)
)
(func (export "break-br_table-nested-empty") (param i32)
(block (br_table 0 1 0 (get_local 0)))
)
(func (export "break-br_table-nested-num") (param i32) (result i32)
(i32.add
(block (result i32)
(br_table 0 1 0 (i32.const 50) (get_local 0)) (i32.const 51)
)
(i32.const 2)
)
)
;; Default initialization of locals
(func (export "init-local-i32") (result i32) (local i32) (get_local 0))
(func (export "init-local-i64") (result i64) (local i64) (get_local 0))
(func (export "init-local-f32") (result f32) (local f32) (get_local 0))
(func (export "init-local-f64") (result f64) (local f64) (get_local 0))
)
(assert_return (invoke "type-use-1"))
(assert_return (invoke "type-use-2") (i32.const 0))
(assert_return (invoke "type-use-3" (i32.const 1)))
(assert_return
(invoke "type-use-4" (i32.const 1) (f64.const 1) (i32.const 1))
(i32.const 0)
)
(assert_return (invoke "type-use-5") (i32.const 0))
(assert_return (invoke "type-use-6" (i32.const 1)))
(assert_return
(invoke "type-use-7" (i32.const 1) (f64.const 1) (i32.const 1))
(i32.const 0)
)
(assert_return (invoke "local-first-i32") (i32.const 0))
(assert_return (invoke "local-first-i64") (i64.const 0))
(assert_return (invoke "local-first-f32") (f32.const 0))
(assert_return (invoke "local-first-f64") (f64.const 0))
(assert_return (invoke "local-second-i32") (i32.const 0))
(assert_return (invoke "local-second-i64") (i64.const 0))
(assert_return (invoke "local-second-f32") (f32.const 0))
(assert_return (invoke "local-second-f64") (f64.const 0))
(assert_return (invoke "local-mixed") (f64.const 0))
(assert_return
(invoke "param-first-i32" (i32.const 2) (i32.const 3)) (i32.const 2)
)
(assert_return
(invoke "param-first-i64" (i64.const 2) (i64.const 3)) (i64.const 2)
)
(assert_return
(invoke "param-first-f32" (f32.const 2) (f32.const 3)) (f32.const 2)
)
(assert_return
(invoke "param-first-f64" (f64.const 2) (f64.const 3)) (f64.const 2)
)
(assert_return
(invoke "param-second-i32" (i32.const 2) (i32.const 3)) (i32.const 3)
)
(assert_return
(invoke "param-second-i64" (i64.const 2) (i64.const 3)) (i64.const 3)
)
(assert_return
(invoke "param-second-f32" (f32.const 2) (f32.const 3)) (f32.const 3)
)
(assert_return
(invoke "param-second-f64" (f64.const 2) (f64.const 3)) (f64.const 3)
)
(assert_return
(invoke "param-mixed"
(f32.const 1) (i32.const 2) (i64.const 3)
(i32.const 4) (f64.const 5.5) (i32.const 6)
)
(f64.const 5.5)
)
(assert_return (invoke "empty"))
(assert_return (invoke "value-void"))
(assert_return (invoke "value-i32") (i32.const 77))
(assert_return (invoke "value-i64") (i64.const 7777))
(assert_return (invoke "value-f32") (f32.const 77.7))
(assert_return (invoke "value-f64") (f64.const 77.77))
(assert_return (invoke "value-block-void"))
(assert_return (invoke "value-block-i32") (i32.const 77))
(assert_return (invoke "return-empty"))
(assert_return (invoke "return-i32") (i32.const 78))
(assert_return (invoke "return-i64") (i64.const 7878))
(assert_return (invoke "return-f32") (f32.const 78.7))
(assert_return (invoke "return-f64") (f64.const 78.78))
(assert_return (invoke "return-block-i32") (i32.const 77))
(assert_return (invoke "break-empty"))
(assert_return (invoke "break-i32") (i32.const 79))
(assert_return (invoke "break-i64") (i64.const 7979))
(assert_return (invoke "break-f32") (f32.const 79.9))
(assert_return (invoke "break-f64") (f64.const 79.79))
(assert_return (invoke "break-block-i32") (i32.const 77))
(assert_return (invoke "break-br_if-empty" (i32.const 0)))
(assert_return (invoke "break-br_if-empty" (i32.const 2)))
(assert_return (invoke "break-br_if-num" (i32.const 0)) (i32.const 51))
(assert_return (invoke "break-br_if-num" (i32.const 1)) (i32.const 50))
(assert_return (invoke "break-br_table-empty" (i32.const 0)))
(assert_return (invoke "break-br_table-empty" (i32.const 1)))
(assert_return (invoke "break-br_table-empty" (i32.const 5)))
(assert_return (invoke "break-br_table-empty" (i32.const -1)))
(assert_return (invoke "break-br_table-num" (i32.const 0)) (i32.const 50))
(assert_return (invoke "break-br_table-num" (i32.const 1)) (i32.const 50))
(assert_return (invoke "break-br_table-num" (i32.const 10)) (i32.const 50))
(assert_return (invoke "break-br_table-num" (i32.const -100)) (i32.const 50))
(assert_return (invoke "break-br_table-nested-empty" (i32.const 0)))
(assert_return (invoke "break-br_table-nested-empty" (i32.const 1)))
(assert_return (invoke "break-br_table-nested-empty" (i32.const 3)))
(assert_return (invoke "break-br_table-nested-empty" (i32.const -2)))
(assert_return
(invoke "break-br_table-nested-num" (i32.const 0)) (i32.const 52)
)
(assert_return
(invoke "break-br_table-nested-num" (i32.const 1)) (i32.const 50)
)
(assert_return
(invoke "break-br_table-nested-num" (i32.const 2)) (i32.const 52)
)
(assert_return
(invoke "break-br_table-nested-num" (i32.const -3)) (i32.const 52)
)
(assert_return (invoke "init-local-i32") (i32.const 0))
(assert_return (invoke "init-local-i64") (i64.const 0))
(assert_return (invoke "init-local-f32") (f32.const 0))
(assert_return (invoke "init-local-f64") (f64.const 0))
;; Expansion of inline function types
(module
(func $f (result f64) (f64.const 0)) ;; adds implicit type definition
(func $g (param i32)) ;; reuses explicit type definition
(type $t (func (param i32)))
(func $i32->void (type 0)) ;; (param i32)
(func $void->f64 (type 1) (f64.const 0)) ;; (result f64)
(func $check
(call $i32->void (i32.const 0))
(drop (call $void->f64))
)
)
(assert_invalid
(module
(func $f (result f64) (f64.const 0)) ;; adds implicit type definition
(func $g (param i32)) ;; reuses explicit type definition
(func $h (result f64) (f64.const 1)) ;; reuses implicit type definition
(type $t (func (param i32)))
(func (type 2)) ;; does not exist
)
"unknown type"
)
(module
(type $sig (func))
(func $empty-sig-1) ;; should be assigned type $sig
(func $complex-sig-1 (param f64 i64 f64 i64 f64 i64 f32 i32))
(func $empty-sig-2) ;; should be assigned type $sig
(func $complex-sig-2 (param f64 i64 f64 i64 f64 i64 f32 i32))
(func $complex-sig-3 (param f64 i64 f64 i64 f64 i64 f32 i32))
(func $complex-sig-4 (param i64 i64 f64 i64 f64 i64 f32 i32))
(func $complex-sig-5 (param i64 i64 f64 i64 f64 i64 f32 i32))
(type $empty-sig-duplicate (func))
(type $complex-sig-duplicate (func (param i64 i64 f64 i64 f64 i64 f32 i32)))
(table anyfunc
(elem
$complex-sig-3 $empty-sig-2 $complex-sig-1 $complex-sig-3 $empty-sig-1
$complex-sig-4 $complex-sig-5
)
)
(func (export "signature-explicit-reused")
(call_indirect (type $sig) (i32.const 1))
(call_indirect (type $sig) (i32.const 4))
)
(func (export "signature-implicit-reused")
;; The implicit index 3 in this test depends on the function and
;; type definitions, and may need adapting if they change.
(call_indirect (type 3)
(f64.const 0) (i64.const 0) (f64.const 0) (i64.const 0)
(f64.const 0) (i64.const 0) (f32.const 0) (i32.const 0)
(i32.const 0)
)
(call_indirect (type 3)
(f64.const 0) (i64.const 0) (f64.const 0) (i64.const 0)
(f64.const 0) (i64.const 0) (f32.const 0) (i32.const 0)
(i32.const 2)
)
(call_indirect (type 3)
(f64.const 0) (i64.const 0) (f64.const 0) (i64.const 0)
(f64.const 0) (i64.const 0) (f32.const 0) (i32.const 0)
(i32.const 3)
)
)
(func (export "signature-explicit-duplicate")
(call_indirect (type $empty-sig-duplicate) (i32.const 1))
)
(func (export "signature-implicit-duplicate")
(call_indirect (type $complex-sig-duplicate)
(i64.const 0) (i64.const 0) (f64.const 0) (i64.const 0)
(f64.const 0) (i64.const 0) (f32.const 0) (i32.const 0)
(i32.const 5)
)
(call_indirect (type $complex-sig-duplicate)
(i64.const 0) (i64.const 0) (f64.const 0) (i64.const 0)
(f64.const 0) (i64.const 0) (f32.const 0) (i32.const 0)
(i32.const 6)
)
)
)
(assert_return (invoke "signature-explicit-reused"))
(assert_return (invoke "signature-implicit-reused"))
(assert_return (invoke "signature-explicit-duplicate"))
(assert_return (invoke "signature-implicit-duplicate"))
;; Malformed type use
(assert_malformed
(module quote
"(type $sig (func (param i32) (result i32)))"
"(func (type $sig) (result i32) (param i32) (i32.const 0))"
)
"unexpected token"
)
(assert_malformed
(module quote
"(type $sig (func (param i32) (result i32)))"
"(func (param i32) (type $sig) (result i32) (i32.const 0))"
)
"unexpected token"
)
(assert_malformed
(module quote
"(type $sig (func (param i32) (result i32)))"
"(func (param i32) (result i32) (type $sig) (i32.const 0))"
)
"unexpected token"
)
(assert_malformed
(module quote
"(type $sig (func (param i32) (result i32)))"
"(func (result i32) (type $sig) (param i32) (i32.const 0))"
)
"unexpected token"
)
(assert_malformed
(module quote
"(type $sig (func (param i32) (result i32)))"
"(func (result i32) (param i32) (type $sig) (i32.const 0))"
)
"unexpected token"
)
(assert_malformed
(module quote
"(func (result i32) (param i32) (i32.const 0))"
)
"unexpected token"
)
(assert_malformed
(module quote
"(type $sig (func))"
"(func (type $sig) (result i32) (i32.const 0))"
)
"inline function type"
)
(assert_malformed
(module quote
"(type $sig (func (param i32) (result i32)))"
"(func (type $sig) (result i32) (i32.const 0))"
)
"inline function type"
)
(assert_malformed
(module quote
"(type $sig (func (param i32) (result i32)))"
"(func (type $sig) (param i32) (i32.const 0))"
)
"inline function type"
)
(assert_malformed
(module quote
"(type $sig (func (param i32 i32) (result i32)))"
"(func (type $sig) (param i32) (result i32) (unreachable))"
)
"inline function type"
)
;; Invalid typing of locals
(assert_invalid
(module (func $type-local-num-vs-num (result i64) (local i32) (get_local 0)))
"type mismatch"
)
(assert_invalid
(module (func $type-local-num-vs-num (local f32) (i32.eqz (get_local 0))))
"type mismatch"
)
(assert_invalid
(module (func $type-local-num-vs-num (local f64 i64) (f64.neg (get_local 1))))
"type mismatch"
)
;; Invalid typing of parameters
(assert_invalid
(module (func $type-param-num-vs-num (param i32) (result i64) (get_local 0)))
"type mismatch"
)
(assert_invalid
(module (func $type-param-num-vs-num (param f32) (i32.eqz (get_local 0))))
"type mismatch"
)
(assert_invalid
(module (func $type-param-num-vs-num (param f64 i64) (f64.neg (get_local 1))))
"type mismatch"
)
;; Invalid typing of result
(assert_invalid
(module (func $type-multiple-result (result i32 i32) (unreachable)))
"invalid result arity"
)
(assert_invalid
(module
(type (func (result i32 i32)))
(func $type-multiple-result (type 0) (unreachable))
)
"invalid result arity"
)
(assert_invalid
(module (func $type-empty-i32 (result i32)))
"type mismatch"
)
(assert_invalid
(module (func $type-empty-i64 (result i64)))
"type mismatch"
)
(assert_invalid
(module (func $type-empty-f32 (result f32)))
"type mismatch"
)
(assert_invalid
(module (func $type-empty-f64 (result f64)))
"type mismatch"
)
(assert_invalid
(module (func $type-value-void-vs-num (result i32)
(nop)
))
"type mismatch"
)
(assert_invalid
(module (func $type-value-num-vs-void
(i32.const 0)
))
"type mismatch"
)
(assert_invalid
(module (func $type-value-num-vs-num (result i32)
(f32.const 0)
))
"type mismatch"
)
(assert_invalid
(module (func $type-return-last-empty-vs-num (result i32)
(return)
))
"type mismatch"
)
(assert_invalid
(module (func $type-return-last-void-vs-num (result i32)
(return (nop))
))
"type mismatch"
)
(assert_invalid
(module (func $type-return-last-num-vs-num (result i32)
(return (i64.const 0))
))
"type mismatch"
)
(assert_invalid
(module (func $type-return-empty-vs-num (result i32)
(return) (i32.const 1)
))
"type mismatch"
)
(assert_invalid
(module (func $type-return-void-vs-num (result i32)
(return (nop)) (i32.const 1)
))
"type mismatch"
)
(assert_invalid
(module (func $type-return-num-vs-num (result i32)
(return (i64.const 1)) (i32.const 1)
))
"type mismatch"
)
(assert_invalid
(module (func $type-return-first-num-vs-num (result i32)
(return (i64.const 1)) (return (i32.const 1))
))
"type mismatch"
)
(assert_invalid
(module (func $type-break-last-void-vs-num (result i32)
(br 0)
))
"type mismatch"
)
(assert_invalid
(module (func $type-break-last-num-vs-num (result i32)
(br 0 (f32.const 0))
))
"type mismatch"
)
(assert_invalid
(module (func $type-break-void-vs-num (result i32)
(br 0) (i32.const 1)
))
"type mismatch"
)
(assert_invalid
(module (func $type-break-num-vs-num (result i32)
(br 0 (i64.const 1)) (i32.const 1)
))
"type mismatch"
)
(assert_invalid
(module (func $type-break-first-num-vs-num (result i32)
(br 0 (i64.const 1)) (br 0 (i32.const 1))
))
"type mismatch"
)
(assert_invalid
(module (func $type-break-nested-empty-vs-num (result i32)
(block (br 1)) (br 0 (i32.const 1))
))
"type mismatch"
)
(assert_invalid
(module (func $type-break-nested-void-vs-num (result i32)
(block (br 1 (nop))) (br 0 (i32.const 1))
))
"type mismatch"
)
(assert_invalid
(module (func $type-break-nested-num-vs-num (result i32)
(block (br 1 (i64.const 1))) (br 0 (i32.const 1))
))
"type mismatch"
)
;; Syntax errors
(assert_malformed
(module quote "(func (nop) (local i32))")
"unexpected token"
)
(assert_malformed
(module quote "(func (nop) (param i32))")
"unexpected token"
)
(assert_malformed
(module quote "(func (nop) (result i32))")
"unexpected token"
)
(assert_malformed
(module quote "(func (local i32) (param i32))")
"unexpected token"
)
(assert_malformed
(module quote "(func (local i32) (result i32) (get_local 0))")
"unexpected token"
)
(assert_malformed
(module quote "(func (result i32) (param i32) (get_local 0))")
"unexpected token"
)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/aosone/testsuite.git
git@gitee.com:aosone/testsuite.git
aosone
testsuite
testsuite
master

搜索帮助