blob: ad5511746bd5457168fdf403e4e37155d43b510f (
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
|
// Set to true to emit ' +' instead of the unreadable '\s+'.
var SPACEDEBUG = false;
// Any hex string
var HEX = '[0-9a-fA-F]'
var HEXES = `${HEX}+`;
function wrap(options, funcs) {
if ('memory' in options)
return `(module (memory ${options.memory}) ${funcs})`;
return `(module ${funcs})`;
}
function fixlines(s) {
return s.split(/\n+/)
.map(strip)
.filter(x => x.length > 0)
.map(x => '(?:0x)?' + HEXES + ' ' + x)
.map(spaces)
.join('\n');
}
function strip(s) {
while (s.length > 0 && isspace(s.charAt(0)))
s = s.substring(1);
while (s.length > 0 && isspace(s.charAt(s.length-1)))
s = s.substring(0, s.length-1);
return s;
}
function striplines(s) {
return s.split('\n').map(strip).join('\n');
}
function spaces(s) {
let t = '';
let i = 0;
while (i < s.length) {
if (isspace(s.charAt(i))) {
t += SPACEDEBUG ? ' +' : '\\s+';
i++;
while (i < s.length && isspace(s.charAt(i)))
i++;
} else {
t += s.charAt(i++);
}
}
return t;
}
function isspace(c) {
return c == ' ' || c == '\t';
}
|