(bytecode: Script, sourceMap: string, sourceCode: string, sourceTags?: string)
| 32 | } |
| 33 | |
| 34 | export function formatBitAuthScript(bytecode: Script, sourceMap: string, sourceCode: string, sourceTags?: string): string { |
| 35 | const locationData = sourceMapToLocationData(sourceMap); |
| 36 | const sourceLines = sourceCode.split('\n'); |
| 37 | |
| 38 | // Splice synthetic annotation lines (e.g. for-loop updates) into source and remap opcode lines |
| 39 | const insertions = buildInsertions(locationData, sourceLines, sourceTags); |
| 40 | const splicedSourceLines = spliceSyntheticSourceLines(sourceLines, insertions); |
| 41 | const splicedLocationData = updateLocationData(locationData, insertions); |
| 42 | |
| 43 | // Group opcodes by display line and convert to ASM |
| 44 | const lineToAsm = buildLineToAsmMap(bytecode, splicedLocationData); |
| 45 | |
| 46 | // Format output |
| 47 | const escapedLines = splicedSourceLines.map(escapeCommentChars); |
| 48 | const maxAsmLen = Math.max(...escapedLines.map((_, i) => (lineToAsm[i + 1] || '').length)); |
| 49 | const maxSrcLen = Math.max(...escapedLines.map((l) => l.length)); |
| 50 | |
| 51 | return escapedLines.map((src, i) => { |
| 52 | const asm = lineToAsm[i + 1] || ''; |
| 53 | return `${asm.padEnd(maxAsmLen)} /* ${src.padEnd(maxSrcLen)} */`; |
| 54 | }).join('\n'); |
| 55 | } |
| 56 | |
| 57 | // --- Helpers --- |
| 58 |
no test coverage detected