Debian Codegraph @

js/src/jit-test/lib/codegen-test-common.js

raw
1 // Set to true to emit ' +' instead of the unreadable '\s+'.
2 var SPACEDEBUG = false;
3
4 // Any hex string
5 var HEX = '[0-9a-fA-F]'
6 var HEXES = `${HEX}+`;
7
8 function wrap(options, funcs) {
9 if ('memory' in options)
10 return `(module (memory ${options.memory}) ${funcs})`;
11 return `(module ${funcs})`;
12 }
13
14 function fixlines(s) {
15 return s.split(/\n+/)
16 .map(strip)
17 .filter(x => x.length > 0)
18 .map(x => '(?:0x)?' + HEXES + ' ' + x)
19 .map(spaces)
20 .join('\n');
21 }
22
23 function strip(s) {
24 while (s.length > 0 && isspace(s.charAt(0)))
25 s = s.substring(1);
26 while (s.length > 0 && isspace(s.charAt(s.length-1)))
27 s = s.substring(0, s.length-1);
28 return s;
29 }
30
31 function striplines(s) {
32 return s.split('\n').map(strip).join('\n');
33 }
34
35 function spaces(s) {
36 let t = '';
37 let i = 0;
38 while (i < s.length) {
39 if (isspace(s.charAt(i))) {
40 t += SPACEDEBUG ? ' +' : '\\s+';
41 i++;
42 while (i < s.length && isspace(s.charAt(i)))
43 i++;
44 } else {
45 t += s.charAt(i++);
46 }
47 }
48 return t;
49 }
50
51 function isspace(c) {
52 return c == ' ' || c == '\t';
53 }