var moduleName, symsName; function parseDecls(text, arr, name, bin, bout) { var re = new RegExp(name + "(\\d*)[(](\\w+),(\\d+),(\\d+)[)]", 'gm'); var m; while ((m = re.exec(text))) { arr.push({ wordlen:parseInt(m[1]), name:m[2], len:parseInt(m[3]), ofs:parseInt(m[4]), }); } re = new RegExp(name + "(\\d*)[(](\\w+)\\[(\\d+)\\],(\\d+),(\\d+)[)]", 'gm'); var m; while ((m = re.exec(text))) { arr.push({ wordlen:parseInt(m[1]), name:m[2], arrdim:[parseInt(m[3])], len:parseInt(m[4]), ofs:parseInt(m[5]), }); } re = new RegExp(name + "(\\d*)[(](\\w+)\\[(\\d+)\\]\\[(\\d+)\\],(\\d+),(\\d+)[)]", 'gm'); var m; while ((m = re.exec(text))) { arr.push({ wordlen:parseInt(m[1]), name:m[2], arrdim:[parseInt(m[3]), parseInt(m[4])], len:parseInt(m[5]), ofs:parseInt(m[6]), }); } } function buildModule(o) { var m = '"use strict";\n'; m += '\tvar self = this;\n'; for (var i=0; i\b/g, "."); text = text.replace('VL_INLINE_OPT', ''); text = text.replace(/[(]IData[)]/g, ''); text = text.replace(/\b(0x[0-9a-f]+)U/gi, '$1'); text = text.replace(/\b([0-9]+)U/gi, '$1'); text = text.replace(/\bQData /g, 'var '); text = text.replace(/\bbool /g, ''); text = text.replace(/\bint /g, 'var '); text = text.replace(/(\w+ = VL_RAND_RESET_)/g, 'self.$1'); // TODO? //text = text.replace(/^\s*(\w+ = \d+;)/gm, 'self.$1'); // TODO? //text = text.replace(/(\w+\[\w+\] = VL_RAND_RESET_I)/g, 'self.$1'); text = text.replace(/^#/gm, '//#'); text = text.replace(/VL_LIKELY/g, '!!'); text = text.replace(/VL_UNLIKELY/g, '!!'); text = text.replace(/Verilated::(\w+)Error/g, 'console.log'); text = text.replace(/vlSymsp.name[(][)]/g, '"'+moduleName+'"'); return "function " + text + "\nself." + funcname + " = " + funcname + ";\n"; } function translateStaticVars(text) { var s = ""; var m; var re = /VL_ST_SIG(\d+)[(](\w+?)::(\w+).(\d+).,(\d+),(\d+)[)]/g; while (m = re.exec(text)) { s += "var " + m[3] + " = this." + m[3] + " = new Uint" + m[1] + "Array(" + m[4] + ");\n"; } return s; } function translateVerilatorOutputToJS(htext, cpptext) { // parse header file moduleName = /VL_MODULE.(\w+)./.exec(htext)[1]; symsName = moduleName + "__Syms"; var ports = []; parseDecls(htext, ports, 'VL_IN', true, false); parseDecls(htext, ports, 'VL_OUT', false, true); var signals = []; parseDecls(htext, signals, 'VL_SIG'); // parse cpp file // split functions var re_fnsplit = new RegExp("(?:void|QData) " + moduleName + "::"); var functexts = cpptext.split(re_fnsplit); var funcs = []; funcs.push(translateStaticVars(functexts[0])); for (var i=4; i