// Various tools for parsing LLVM. Utilities of various sorts, that are
// specific to Emscripten (and hence not in utility.js).
// Does simple 'macro' substitution, using Django-like syntax,
// {{{ code }}} will be replaced with |eval(code)|.
function processMacros(text) {
return text.replace(/{{{[^}]+}}}/g, function(str) {
str = str.substr(3, str.length-6);
var ret = eval(str);
if (ret !== undefined) ret = ret.toString();
return ret;
});
}
// Simple #if/else/endif preprocessing for a file. Checks if the
// ident checked is true in our global. Also replaces some constants.
function preprocess(text, constants) {
for (var constant in constants) {
text = text.replace(eval('/' + constant + '/g'), constants[constant]);
}
var lines = text.split('\n');
var ret = '';
var showStack = [];
for (var i = 0; i < lines.length; i++) {
var line = lines[i];
if (!line[0] || line[0] != '#') {
if (showStack.indexOf(false) == -1) {
ret += line + '\n';
}
} else {
if (line[1] && line[1] == 'i') { // if
var parts = line.split(' ');
var ident = parts[1];
var op = parts[2];
var value = parts[3];
if (op) {
assert(op === '==')
showStack.push(ident in this && this[ident] == value