wa-lang.org/wazero@v1.0.2/internal/integration_test/spectest/v1/testdata/nop.wast (about)

     1  ;; Test `nop` operator.
     2  
     3  (module
     4    ;; Auxiliary definitions
     5    (func $dummy)
     6    (func $3-ary (param i32 i32 i32) (result i32)
     7      local.get 0 local.get 1 local.get 2 i32.sub i32.add
     8    )
     9    (memory 1)
    10  
    11    (func (export "as-func-first") (result i32)
    12      (nop) (i32.const 1)
    13    )
    14    (func (export "as-func-mid") (result i32)
    15      (call $dummy) (nop) (i32.const 2)
    16    )
    17    (func (export "as-func-last") (result i32)
    18      (call $dummy) (i32.const 3) (nop)
    19    )
    20    (func (export "as-func-everywhere") (result i32)
    21      (nop) (nop) (call $dummy) (nop) (i32.const 4) (nop) (nop)
    22    )
    23  
    24    (func (export "as-drop-first") (param i32)
    25      (nop) (local.get 0) (drop)
    26    )
    27    (func (export "as-drop-last") (param i32)
    28      (local.get 0) (nop) (drop)
    29    )
    30    (func (export "as-drop-everywhere") (param i32)
    31      (nop) (nop) (local.get 0) (nop) (nop) (drop)
    32    )
    33  
    34    (func (export "as-select-first") (param i32) (result i32)
    35      (nop) (local.get 0) (local.get 0) (local.get 0) (select)
    36    )
    37    (func (export "as-select-mid1") (param i32) (result i32)
    38      (local.get 0) (nop) (local.get 0) (local.get 0) (select)
    39    )
    40    (func (export "as-select-mid2") (param i32) (result i32)
    41      (local.get 0) (local.get 0) (nop) (local.get 0) (select)
    42    )
    43    (func (export "as-select-last") (param i32) (result i32)
    44      (local.get 0) (local.get 0) (local.get 0) (nop) (select)
    45    )
    46    (func (export "as-select-everywhere") (param i32) (result i32)
    47      (nop) (local.get 0) (nop) (nop) (local.get 0)
    48      (nop) (nop) (local.get 0) (nop) (nop) (select)
    49    )
    50  
    51    (func (export "as-block-first") (result i32)
    52      (block (result i32) (nop) (i32.const 2))
    53    )
    54    (func (export "as-block-mid") (result i32)
    55      (block (result i32) (call $dummy) (nop) (i32.const 2))
    56    )
    57    (func (export "as-block-last") (result i32)
    58      (block (result i32) (nop) (call $dummy) (i32.const 3) (nop))
    59    )
    60    (func (export "as-block-everywhere") (result i32)
    61      (block (result i32)
    62        (nop) (nop) (call $dummy) (nop) (i32.const 4) (nop) (nop)
    63      )
    64    )
    65  
    66    (func (export "as-loop-first") (result i32)
    67      (loop (result i32) (nop) (i32.const 2))
    68    )
    69    (func (export "as-loop-mid") (result i32)
    70      (loop (result i32) (call $dummy) (nop) (i32.const 2))
    71    )
    72    (func (export "as-loop-last") (result i32)
    73      (loop (result i32) (call $dummy) (i32.const 3) (nop))
    74    )
    75    (func (export "as-loop-everywhere") (result i32)
    76      (loop (result i32)
    77        (nop) (nop) (call $dummy) (nop) (i32.const 4) (nop) (nop)
    78      )
    79    )
    80  
    81    (func (export "as-if-condition") (param i32)
    82      (local.get 0) (nop) (if (then (call $dummy)))
    83    )
    84    (func (export "as-if-then") (param i32)
    85      (if (local.get 0) (then (nop)) (else (call $dummy)))
    86    )
    87    (func (export "as-if-else") (param i32)
    88      (if (local.get 0) (then (call $dummy)) (else (nop)))
    89    )
    90  
    91    (func (export "as-br-first") (param i32) (result i32)
    92      (block (result i32) (nop) (local.get 0) (br 0))
    93    )
    94    (func (export "as-br-last") (param i32) (result i32)
    95      (block (result i32) (local.get 0) (nop) (br 0))
    96    )
    97    (func (export "as-br-everywhere") (param i32) (result i32)
    98      (block (result i32) (nop) (nop) (local.get 0) (nop) (nop) (br 0))
    99    )
   100  
   101    (func (export "as-br_if-first") (param i32) (result i32)
   102      (block (result i32) (nop) (local.get 0) (local.get 0) (br_if 0))
   103    )
   104    (func (export "as-br_if-mid") (param i32) (result i32)
   105      (block (result i32) (local.get 0) (nop) (local.get 0) (br_if 0))
   106    )
   107    (func (export "as-br_if-last") (param i32) (result i32)
   108      (block (result i32) (local.get 0) (local.get 0) (nop) (br_if 0))
   109    )
   110    (func (export "as-br_if-everywhere") (param i32) (result i32)
   111      (block (result i32)
   112        (nop) (nop) (local.get 0) (nop) (nop) (local.get 0) (nop) (nop)
   113        (br_if 0)
   114      )
   115    )
   116  
   117    (func (export "as-br_table-first") (param i32) (result i32)
   118      (block (result i32) (nop) (local.get 0) (local.get 0) (br_table 0 0))
   119    )
   120    (func (export "as-br_table-mid") (param i32) (result i32)
   121      (block (result i32) (local.get 0) (nop) (local.get 0) (br_table 0 0))
   122    )
   123    (func (export "as-br_table-last") (param i32) (result i32)
   124      (block (result i32) (local.get 0) (local.get 0) (nop) (br_table 0 0))
   125    )
   126    (func (export "as-br_table-everywhere") (param i32) (result i32)
   127      (block (result i32)
   128        (nop) (nop) (local.get 0) (nop) (nop) (local.get 0) (nop) (nop)
   129        (br_table 0 0)
   130      )
   131    )
   132  
   133    (func (export "as-return-first") (param i32) (result i32)
   134      (nop) (local.get 0) (return)
   135    )
   136    (func (export "as-return-last") (param i32) (result i32)
   137      (local.get 0) (nop) (return)
   138    )
   139    (func (export "as-return-everywhere") (param i32) (result i32)
   140      (nop) (nop) (local.get 0) (nop) (nop) (return)
   141    )
   142  
   143    (func (export "as-call-first") (param i32 i32 i32) (result i32)
   144      (nop) (local.get 0) (local.get 1) (local.get 2) (call $3-ary)
   145    )
   146    (func (export "as-call-mid1") (param i32 i32 i32) (result i32)
   147      (local.get 0) (nop) (local.get 1) (local.get 2) (call $3-ary)
   148    )
   149    (func (export "as-call-mid2") (param i32 i32 i32) (result i32)
   150      (local.get 0) (local.get 1) (nop) (local.get 2) (call $3-ary)
   151    )
   152    (func (export "as-call-last") (param i32 i32 i32) (result i32)
   153      (local.get 0) (local.get 1) (local.get 2) (nop) (call $3-ary)
   154    )
   155    (func (export "as-call-everywhere") (param i32 i32 i32) (result i32)
   156      (nop) (nop) (local.get 0) (nop) (nop) (local.get 1)
   157      (nop) (nop) (local.get 2) (nop) (nop) (call $3-ary)
   158    )
   159  
   160    (func (export "as-unary-first") (param i32) (result i32)
   161      (nop) (local.get 0) (i32.ctz)
   162    )
   163    (func (export "as-unary-last") (param i32) (result i32)
   164      (local.get 0) (nop) (i32.ctz)
   165    )
   166    (func (export "as-unary-everywhere") (param i32) (result i32)
   167      (nop) (nop) (local.get 0) (nop) (nop) (i32.ctz)
   168    )
   169  
   170    (func (export "as-binary-first") (param i32) (result i32)
   171      (nop) (local.get 0) (local.get 0) (i32.add)
   172    )
   173    (func (export "as-binary-mid") (param i32) (result i32)
   174      (local.get 0) (nop) (local.get 0) (i32.add)
   175    )
   176    (func (export "as-binary-last") (param i32) (result i32)
   177      (local.get 0) (local.get 0) (nop) (i32.add)
   178    )
   179    (func (export "as-binary-everywhere") (param i32) (result i32)
   180      (nop) (local.get 0) (nop) (nop) (local.get 0) (nop) (nop) (i32.add)
   181    )
   182  
   183    (func (export "as-test-first") (param i32) (result i32)
   184      (nop) (local.get 0) (i32.eqz)
   185    )
   186    (func (export "as-test-last") (param i32) (result i32)
   187      (local.get 0) (nop) (i32.eqz)
   188    )
   189    (func (export "as-test-everywhere") (param i32) (result i32)
   190      (nop) (nop) (local.get 0) (nop) (nop) i32.eqz
   191    )
   192  
   193    (func (export "as-compare-first") (param i32) (result i32)
   194      (nop) (local.get 0) (local.get 0) (i32.ne)
   195    )
   196    (func (export "as-compare-mid") (param i32) (result i32)
   197      (local.get 0) (nop) (local.get 0) (i32.ne)
   198    )
   199    (func (export "as-compare-last") (param i32) (result i32)
   200      (local.get 0) (local.get 0) (nop) (i32.lt_u)
   201    )
   202    (func (export "as-compare-everywhere") (param i32) (result i32)
   203      (nop) (local.get 0) (nop) (nop) (local.get 0) (nop) (nop) (i32.le_s)
   204    )
   205  
   206    (func (export "as-memory.grow-first") (param i32) (result i32)
   207      (nop) (local.get 0) (memory.grow)
   208    )
   209    (func (export "as-memory.grow-last") (param i32) (result i32)
   210      (local.get 0) (nop) (memory.grow)
   211    )
   212    (func (export "as-memory.grow-everywhere") (param i32) (result i32)
   213      (nop) (nop) (local.get 0) (nop) (nop) (memory.grow)
   214    )
   215  
   216    (func $func (param i32 i32) (result i32) (local.get 0))
   217    (type $check (func (param i32 i32) (result i32)))
   218    (table funcref (elem $func))
   219    (func (export "as-call_indirect-first") (result i32)
   220      (block (result i32)
   221        (nop) (i32.const 1) (i32.const 2) (i32.const 0)
   222        (call_indirect (type $check))
   223      )
   224    )
   225    (func (export "as-call_indirect-mid1") (result i32)
   226      (block (result i32)
   227        (i32.const 1) (nop) (i32.const 2) (i32.const 0)
   228        (call_indirect (type $check))
   229      )
   230    )
   231    (func (export "as-call_indirect-mid2") (result i32)
   232      (block (result i32)
   233        (i32.const 1) (i32.const 2) (nop) (i32.const 0)
   234        (call_indirect (type $check))
   235      )
   236    )
   237    (func (export "as-call_indirect-last") (result i32)
   238      (block (result i32)
   239        (i32.const 1) (i32.const 2) (i32.const 0) (nop)
   240        (call_indirect (type $check))
   241      )
   242    )
   243    (func (export "as-call_indirect-everywhere") (result i32)
   244      (block (result i32)
   245        (nop) (nop) (i32.const 1) (nop) (nop) (i32.const 2) (nop) (nop) (i32.const 0) (nop) (nop)
   246        (call_indirect (type $check))
   247      )
   248    )
   249  
   250    (func (export "as-local.set-first") (param i32) (result i32)
   251      (nop) (i32.const 2) (local.set 0) (local.get 0)
   252    )
   253    (func (export "as-local.set-last") (param i32) (result i32)
   254      (i32.const 2) (nop) (local.set 0) (local.get 0)
   255    )
   256    (func (export "as-local.set-everywhere") (param i32) (result i32)
   257      (nop) (nop) (i32.const 2) (nop) (nop) (local.set 0) (local.get 0)
   258    )
   259  
   260    (func (export "as-local.tee-first") (param i32) (result i32)
   261      (nop) (i32.const 2) (local.tee 0)
   262    )
   263    (func (export "as-local.tee-last") (param i32) (result i32)
   264      (i32.const 2) (nop) (local.tee 0)
   265    )
   266    (func (export "as-local.tee-everywhere") (param i32) (result i32)
   267      (nop) (nop) (i32.const 2) (nop) (nop) (local.tee 0)
   268    )
   269  
   270    (global $a (mut i32) (i32.const 0))
   271    (func (export "as-global.set-first") (result i32)
   272      (nop) (i32.const 2) (global.set $a) (global.get $a)
   273    )
   274    (func (export "as-global.set-last") (result i32)
   275      (i32.const 2) (nop) (global.set $a) (global.get $a)
   276    )
   277    (func (export "as-global.set-everywhere") (result i32)
   278      (nop) (nop) (i32.const 2) (nop) (nop) (global.set 0)
   279      (global.get $a)
   280    )
   281  
   282    (func (export "as-load-first") (param i32) (result i32)
   283      (nop) (local.get 0) (i32.load)
   284    )
   285    (func (export "as-load-last") (param i32) (result i32)
   286      (local.get 0) (nop) (i32.load)
   287    )
   288    (func (export "as-load-everywhere") (param i32) (result i32)
   289      (nop) (nop) (local.get 0) (nop) (nop) (i32.load)
   290    )
   291  
   292    (func (export "as-store-first") (param i32 i32)
   293      (nop) (local.get 0) (local.get 1) (i32.store)
   294    )
   295    (func (export "as-store-mid") (param i32 i32)
   296      (local.get 0) (nop) (local.get 1) (i32.store)
   297    )
   298    (func (export "as-store-last") (param i32 i32)
   299      (local.get 0) (local.get 1) (nop) (i32.store)
   300    )
   301    (func (export "as-store-everywhere") (param i32 i32)
   302      (nop) (nop) (local.get 0) (nop) (nop) (local.get 1) (nop) (nop) (i32.store)
   303    )
   304  )
   305  
   306  (assert_return (invoke "as-func-first") (i32.const 1))
   307  (assert_return (invoke "as-func-mid") (i32.const 2))
   308  (assert_return (invoke "as-func-last") (i32.const 3))
   309  (assert_return (invoke "as-func-everywhere") (i32.const 4))
   310  
   311  (assert_return (invoke "as-drop-first" (i32.const 0)))
   312  (assert_return (invoke "as-drop-last" (i32.const 0)))
   313  (assert_return (invoke "as-drop-everywhere" (i32.const 0)))
   314  
   315  (assert_return (invoke "as-select-first" (i32.const 3)) (i32.const 3))
   316  (assert_return (invoke "as-select-mid1" (i32.const 3)) (i32.const 3))
   317  (assert_return (invoke "as-select-mid2" (i32.const 3)) (i32.const 3))
   318  (assert_return (invoke "as-select-last" (i32.const 3)) (i32.const 3))
   319  (assert_return (invoke "as-select-everywhere" (i32.const 3)) (i32.const 3))
   320  
   321  (assert_return (invoke "as-block-first") (i32.const 2))
   322  (assert_return (invoke "as-block-mid") (i32.const 2))
   323  (assert_return (invoke "as-block-last") (i32.const 3))
   324  (assert_return (invoke "as-block-everywhere") (i32.const 4))
   325  
   326  (assert_return (invoke "as-loop-first") (i32.const 2))
   327  (assert_return (invoke "as-loop-mid") (i32.const 2))
   328  (assert_return (invoke "as-loop-last") (i32.const 3))
   329  (assert_return (invoke "as-loop-everywhere") (i32.const 4))
   330  
   331  (assert_return (invoke "as-if-condition" (i32.const 0)))
   332  (assert_return (invoke "as-if-condition" (i32.const -1)))
   333  (assert_return (invoke "as-if-then" (i32.const 0)))
   334  (assert_return (invoke "as-if-then" (i32.const 4)))
   335  (assert_return (invoke "as-if-else" (i32.const 0)))
   336  (assert_return (invoke "as-if-else" (i32.const 3)))
   337  
   338  (assert_return (invoke "as-br-first" (i32.const 5)) (i32.const 5))
   339  (assert_return (invoke "as-br-last" (i32.const 6)) (i32.const 6))
   340  (assert_return (invoke "as-br-everywhere" (i32.const 7)) (i32.const 7))
   341  
   342  (assert_return (invoke "as-br_if-first" (i32.const 4)) (i32.const 4))
   343  (assert_return (invoke "as-br_if-mid" (i32.const 5)) (i32.const 5))
   344  (assert_return (invoke "as-br_if-last" (i32.const 6)) (i32.const 6))
   345  (assert_return (invoke "as-br_if-everywhere" (i32.const 7)) (i32.const 7))
   346  
   347  (assert_return (invoke "as-br_table-first" (i32.const 4)) (i32.const 4))
   348  (assert_return (invoke "as-br_table-mid" (i32.const 5)) (i32.const 5))
   349  (assert_return (invoke "as-br_table-last" (i32.const 6)) (i32.const 6))
   350  (assert_return (invoke "as-br_table-everywhere" (i32.const 7)) (i32.const 7))
   351  
   352  (assert_return (invoke "as-return-first" (i32.const 5)) (i32.const 5))
   353  (assert_return (invoke "as-return-last" (i32.const 6)) (i32.const 6))
   354  (assert_return (invoke "as-return-everywhere" (i32.const 7)) (i32.const 7))
   355  
   356  (assert_return (invoke "as-call-first" (i32.const 3) (i32.const 1) (i32.const 2)) (i32.const 2))
   357  (assert_return (invoke "as-call-mid1" (i32.const 3) (i32.const 1) (i32.const 2)) (i32.const 2))
   358  (assert_return (invoke "as-call-mid2" (i32.const 0) (i32.const 3) (i32.const 1)) (i32.const 2))
   359  (assert_return (invoke "as-call-last" (i32.const 10) (i32.const 9) (i32.const -1)) (i32.const 20))
   360  (assert_return (invoke "as-call-everywhere" (i32.const 2) (i32.const 1) (i32.const 5)) (i32.const -2))
   361  
   362  (assert_return (invoke "as-unary-first" (i32.const 30)) (i32.const 1))
   363  (assert_return (invoke "as-unary-last" (i32.const 30)) (i32.const 1))
   364  (assert_return (invoke "as-unary-everywhere" (i32.const 12)) (i32.const 2))
   365  
   366  (assert_return (invoke "as-binary-first" (i32.const 3)) (i32.const 6))
   367  (assert_return (invoke "as-binary-mid" (i32.const 3)) (i32.const 6))
   368  (assert_return (invoke "as-binary-last" (i32.const 3)) (i32.const 6))
   369  (assert_return (invoke "as-binary-everywhere" (i32.const 3)) (i32.const 6))
   370  
   371  (assert_return (invoke "as-test-first" (i32.const 0)) (i32.const 1))
   372  (assert_return (invoke "as-test-last" (i32.const 0)) (i32.const 1))
   373  (assert_return (invoke "as-test-everywhere" (i32.const 0)) (i32.const 1))
   374  
   375  (assert_return (invoke "as-compare-first" (i32.const 3)) (i32.const 0))
   376  (assert_return (invoke "as-compare-mid" (i32.const 3)) (i32.const 0))
   377  (assert_return (invoke "as-compare-last" (i32.const 3)) (i32.const 0))
   378  (assert_return (invoke "as-compare-everywhere" (i32.const 3)) (i32.const 1))
   379  
   380  (assert_return (invoke "as-memory.grow-first" (i32.const 0)) (i32.const 1))
   381  (assert_return (invoke "as-memory.grow-last" (i32.const 2)) (i32.const 1))
   382  (assert_return (invoke "as-memory.grow-everywhere" (i32.const 12)) (i32.const 3))
   383  
   384  (assert_return (invoke "as-call_indirect-first") (i32.const 1))
   385  (assert_return (invoke "as-call_indirect-mid1") (i32.const 1))
   386  (assert_return (invoke "as-call_indirect-mid2") (i32.const 1))
   387  (assert_return (invoke "as-call_indirect-last") (i32.const 1))
   388  (assert_return (invoke "as-call_indirect-everywhere") (i32.const 1))
   389  
   390  (assert_return (invoke "as-local.set-first" (i32.const 1)) (i32.const 2))
   391  (assert_return (invoke "as-local.set-last" (i32.const 1)) (i32.const 2))
   392  (assert_return (invoke "as-local.set-everywhere" (i32.const 1)) (i32.const 2))
   393  
   394  (assert_return (invoke "as-local.tee-first" (i32.const 1)) (i32.const 2))
   395  (assert_return (invoke "as-local.tee-last" (i32.const 1)) (i32.const 2))
   396  (assert_return (invoke "as-local.tee-everywhere" (i32.const 1)) (i32.const 2))
   397  
   398  (assert_return (invoke "as-global.set-first") (i32.const 2))
   399  (assert_return (invoke "as-global.set-last") (i32.const 2))
   400  (assert_return (invoke "as-global.set-everywhere") (i32.const 2))
   401  
   402  (assert_return (invoke "as-load-first" (i32.const 100)) (i32.const 0))
   403  (assert_return (invoke "as-load-last" (i32.const 100)) (i32.const 0))
   404  (assert_return (invoke "as-load-everywhere" (i32.const 100)) (i32.const 0))
   405  
   406  (assert_return (invoke "as-store-first" (i32.const 0) (i32.const 1)))
   407  (assert_return (invoke "as-store-mid" (i32.const 0) (i32.const 2)))
   408  (assert_return (invoke "as-store-last" (i32.const 0) (i32.const 3)))
   409  (assert_return (invoke "as-store-everywhere" (i32.const 0) (i32.const 4)))
   410  
   411  (assert_invalid
   412    (module (func $type-i32 (result i32) (nop)))
   413    "type mismatch"
   414  )
   415  (assert_invalid
   416    (module (func $type-i64 (result i64) (nop)))
   417    "type mismatch"
   418  )
   419  (assert_invalid
   420    (module (func $type-f32 (result f32) (nop)))
   421    "type mismatch"
   422  )
   423  (assert_invalid
   424    (module (func $type-f64 (result f64) (nop)))
   425    "type mismatch"
   426  )