neo-decompiler 0.11.0

Neo N3 NEF decompiler: parse, disassemble, lift bytecode to high-level pseudocode and C# skeletons, with a CLI, JSON reports, and optional WebAssembly bindings.
Documentation
export {
  convertTargetName,
  isPureRhs,
  literalIndex,
  resolvePackedValue,
  stripOuterParens,
  wrapExpression,
} from "./high-level-utils.js";

// `arg0`, `loc12`, `static3`, `t7` and bare integer literals are safe to
// duplicate by string copy. Anything else may carry side effects or precedence
// hazards, so DUP/OVER/PICK/TUCK materialise it before copying.
const SIMPLE_IDENT_OR_LITERAL_RE = /^(?:-?\d+|0x[0-9A-Fa-f]+|true|false|null|"(?:[^"\\]|\\.)*"|[A-Za-z_][A-Za-z0-9_]*)$/u;

export function materialiseStackTopForDup(state, value, slot = state.stack.length - 1) {
  if (SIMPLE_IDENT_OR_LITERAL_RE.test(value)) {
    return value;
  }
  const temp = `t${state.nextTempId}`;
  state.nextTempId += 1;
  state.statements.push(`let ${temp} = ${value};`);
  state.stack[slot] = temp;
  return temp;
}