summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/debug/wasm-08.js
blob: ca2256627398834af6104492bf462f17497fa5d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// |jit-test| test-also=--wasm-compiler=optimizing; skip-if: !wasmDebuggingEnabled()
// Checking if we destroying work registers by breakpoint/step handler.

load(libdir + "wasm.js");

// Running the following code compiled from C snippet:
//
//     signed func0(signed n) {
//         double a = 1; float b = 0; signed c = 1; long long d = 1;
//         for (;n > 0; n--) {
//             a *= c; b += c; c++; d <<= 1;
//         }
//         return (signed)a + (signed)b + c + (signed)d;
//     }
//
var onStepCalled;
wasmRunWithDebugger(
  `(module
  (func $func0 (param $var0 i32) (result i32)
    (local $var1 i32) (local $var2 i64) (local $var3 f64) (local $var4 f32)
    (local $var5 f64) (local $var6 i32) (local $var7 i32) (local $var8 i32)
    i32.const 1
    local.set $var1
    i32.const 0
    local.set $var7
    i32.const 1
    local.set $var6
    i32.const 1
    local.set $var8
    block $label0
      local.get $var0
      i32.const 1
      i32.lt_s
      br_if $label0
      local.get $var0
      i32.const 1
      i32.add
      local.set $var1
      f32.const 0
      local.set $var4
      i64.const 1
      local.set $var2
      f64.const 1
      local.set $var3
      i32.const 1
      local.set $var0
      f64.const 1
      local.set $var5
      block
        loop $label1
          local.get $var2
          i64.const 1
          i64.shl
          local.set $var2
          local.get $var5
          local.get $var3
          f64.mul
          local.set $var5
          local.get $var4
          local.get $var0
          f32.convert_i32_s
          f32.add
          local.set $var4
          local.get $var3
          f64.const 1
          f64.add
          local.set $var3
          local.get $var0
          i32.const 1
          i32.add
          local.tee $var6
          local.set $var0
          local.get $var1
          i32.const -1
          i32.add
          local.tee $var1
          i32.const 1
          i32.gt_s
          br_if $label1
        end $label1
      end
      local.get $var2
      i32.wrap_i64
      local.set $var1
      local.get $var4
      i32.trunc_f32_s
      local.set $var7
      local.get $var5
      i32.trunc_f64_s
      local.set $var8
    end $label0
    local.get $var7
    local.get $var8
    i32.add
    local.get $var6
    i32.add
    local.get $var1
    i32.add
    return
  )
  (func (export "test") (result i32) (call $func0 (i32.const 4)))
)`.split('\n').join(' '),
    undefined,
    function ({dbg}) {
        onStepCalled = [];
        dbg.onEnterFrame = function (frame) {
            if (frame.type != 'wasmcall') return;
            frame.onStep = function () {
                onStepCalled.push(frame.offset);
            };
        };
  },
  function ({result, error}) {
      assertEq(result, /* func0(4) = */ 55);
      assertEq(error, undefined);
      // The number below reflects amount of wasm operators executed during
      // the run of the test function, which runs $func0(4). It can change
      // when the code above and/or meaning of wasm operators will change.
      assertEq(onStepCalled.length, 85);
  }
);