/**
* @license
* Copyright 2010 The Emscripten Authors
* SPDX-License-Identifier: MIT
*/
// Various tools for parsing LLVM. Utilities of various sorts, that are
// specific to Emscripten (and hence not in utility.js).
let currentlyParsedFilename = '';
// Does simple 'macro' substitution, using Django-like syntax,
// {{{ code }}} will be replaced with |eval(code)|.
// NOTE: Be careful with that ret check. If ret is |0|, |ret ? ret.toString() : ''| would result in ''!
function processMacros(text) {
return text.replace(/{{{([^}]|}(?!}))+}}}/g, (str) => {
str = str.substr(3, str.length - 6);
try {
const ret = eval(str);
return ret !== null ? ret.toString() : '';
} catch (ex) {
ex.stack = 'In the following macro:\n\n' + str + '\n\n' + ex.stack;
throw ex;
}
});
}
// Simple #if/else/endif preprocessing for a file. Checks if the
// ident checked is true in our global.
// Also handles #include x.js (similar to C #include