mirror of
https://github.com/xmrig/xmrig.git
synced 2024-11-18 18:11:05 +00:00
50 lines
1.7 KiB
JavaScript
50 lines
1.7 KiB
JavaScript
|
'use strict';
|
||
|
|
||
|
function opencl_minify(input)
|
||
|
{
|
||
|
let out = input.replace(/\/\*[\s\S]*?\*\/|\/\/.*$/gm, ''); // comments
|
||
|
out = out.replace(/^#\s+/gm, '#'); // macros with spaces
|
||
|
out = out.replace(/\n{2,}/g, '\n'); // empty lines
|
||
|
out = out.replace(/^\s+/gm, ''); // leading whitespace
|
||
|
out = out.replace(/ {2,}/g, ' '); // extra whitespace
|
||
|
|
||
|
let array = out.split('\n').map(line => {
|
||
|
if (line[0] === '#') {
|
||
|
return line
|
||
|
}
|
||
|
|
||
|
line = line.replace(/, /g, ',');
|
||
|
line = line.replace(/ \? /g, '?');
|
||
|
line = line.replace(/ : /g, ':');
|
||
|
line = line.replace(/ = /g, '=');
|
||
|
line = line.replace(/ != /g, '!=');
|
||
|
line = line.replace(/ >= /g, '>=');
|
||
|
line = line.replace(/ <= /g, '<=');
|
||
|
line = line.replace(/ == /g, '==');
|
||
|
line = line.replace(/ \+= /g, '+=');
|
||
|
line = line.replace(/ -= /g, '-=');
|
||
|
line = line.replace(/ \|= /g, '|=');
|
||
|
line = line.replace(/ \| /g, '|');
|
||
|
line = line.replace(/ \|\| /g, '||');
|
||
|
line = line.replace(/ & /g, '&');
|
||
|
line = line.replace(/ && /g, '&&');
|
||
|
line = line.replace(/ > /g, '>');
|
||
|
line = line.replace(/ < /g, '<');
|
||
|
line = line.replace(/ \+ /g, '+');
|
||
|
line = line.replace(/ - /g, '-');
|
||
|
line = line.replace(/ \* /g, '*');
|
||
|
line = line.replace(/ \^ /g, '^');
|
||
|
line = line.replace(/ & /g, '&');
|
||
|
line = line.replace(/ \/ /g, '/');
|
||
|
line = line.replace(/ << /g, '<<');
|
||
|
line = line.replace(/ >> /g, '>>');
|
||
|
line = line.replace(/if \(/g, 'if(');
|
||
|
|
||
|
return line;
|
||
|
});
|
||
|
|
||
|
return array.join('\n');
|
||
|
}
|
||
|
|
||
|
|
||
|
module.exports.opencl_minify = opencl_minify;
|