UNPKG

uae-dap

Version:

Debug Adapter Protocol for Amiga development with FS-UAE or WinUAE

91 lines 3.48 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.disassemble = void 0; const cp = __importStar(require("child_process")); const path = __importStar(require("path")); const strings_1 = require("../utils/strings"); const files_1 = require("../utils/files"); /** * Disassemble a buffer into CPU instructions */ async function disassemble(buffer, startAddress = 0) { const args = ["m68k", buffer]; const wasmPath = path.join((0, files_1.findWasmDir)(), "cstool"); const proc = cp.fork(wasmPath, args, { stdio: "pipe", // Prevent the child process from also being started in inspect mode // See https://github.com/nodejs/node/issues/14325 execArgv: [], }); let code = ""; proc.stdout?.on("data", (data) => (code += data)); proc.stderr?.on("data", (data) => (code += data)); return new Promise((resolve, reject) => { proc.on("exit", () => code.includes("ERROR") ? reject(code) : resolve(processOutput(code, startAddress))); proc.on("error", () => reject(code)); }); } exports.disassemble = disassemble; function processOutput(code, startAddress) { const instructions = []; const lines = (0, strings_1.splitLines)(code); let i = 0; for (let l of lines) { l = l.trim(); if (l.length > 0) { const elms = l.split(" "); if (elms.length > 2) { const instructionElms = elms[2].split("\t"); let instruction = elms[2]; if (instructionElms.length > 1) { instruction = instructionElms[0].padEnd(10) + instructionElms[1]; } const offset = parseInt(elms[0], 16); instructions.push({ address: (0, strings_1.formatHexadecimal)(startAddress + offset), instruction, line: i, instructionBytes: elms[1], column: 0, }); } else { instructions.push({ address: (0, strings_1.formatHexadecimal)(i), instruction: l, line: i, instructionBytes: l, column: 0, }); } i++; } } return { instructions, code }; } //# sourceMappingURL=cpuDisassembler.js.map