summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/lib/gen/wasm-gc-limits-gen.js
blob: 01fd527cc3ba95b637585a7bebc4b53609b1c8cb (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
// Generates large .wasm files for use in ../limits.js.
// Make sure you are running this script from a release build or you will be sad.

loadRelativeToScript("../wasm-binary.js");

function moduleNRecGroupNTypes(numRecs, numTypes) {
  let types = [];
  for (let i = 0; i < numTypes; i++) {
    types.push({ kind: FuncCode, args: [], ret: [] });
  }
  let recs = [];
  for (let i = 0; i < numRecs; i++) {
    recs.push(recGroup(types));
  }
  return new Uint8Array(compressLZ4(new Uint8Array(moduleWithSections([typeSection(recs)])).buffer));
}

os.file.writeTypedArrayToFile("wasm-gc-limits-r1M-t1.wasm", moduleNRecGroupNTypes(1_000_000, 1));
os.file.writeTypedArrayToFile("wasm-gc-limits-r1M1-t1.wasm", moduleNRecGroupNTypes(1_000_001, 1));
os.file.writeTypedArrayToFile("wasm-gc-limits-r1-t1M.wasm", moduleNRecGroupNTypes(1, 1_000_000));
os.file.writeTypedArrayToFile("wasm-gc-limits-r1-t1M1.wasm", moduleNRecGroupNTypes(1, 1_000_001));
os.file.writeTypedArrayToFile("wasm-gc-limits-r2-t500K.wasm", moduleNRecGroupNTypes(2, 500_000));
os.file.writeTypedArrayToFile("wasm-gc-limits-r2-t500K1.wasm", moduleNRecGroupNTypes(2, 500_001));

function moduleLargeStruct(size) {
  let structInitializer = [];
  for (let i = 0; i < size; i++) {
    structInitializer.push(I64ConstCode);
    structInitializer.push(...varU32(0));
  }
  return new Uint8Array(compressLZ4(new Uint8Array(moduleWithSections([
    typeSection([
      {
        kind: StructCode,
        fields: Array(size).fill(I64Code)
      },
      {
        kind: FuncCode,
        args: [],
        ret: [AnyRefCode]
      }
    ]),
    declSection([1, 1]),
    exportSection([
      {name: "makeLargeStructDefault", funcIndex: 0},
      {name: "makeLargeStruct", funcIndex: 1}
    ]),
    bodySection([
      funcBody({
        locals: [],
        body: [
          GcPrefix,
          StructNewDefault,
          ...varU32(0)
        ],
      }),
      funcBody({
        locals: [],
        body: [
          ...structInitializer,
          GcPrefix,
          StructNew,
          ...varU32(0)
        ],
      }),
    ]),
  ])).buffer));
}

os.file.writeTypedArrayToFile("wasm-gc-limits-s10K.wasm", moduleLargeStruct(10_000));
os.file.writeTypedArrayToFile("wasm-gc-limits-s10K1.wasm", moduleLargeStruct(10_001));