UNPKG

uae-dap

Version:

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

131 lines 4.73 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.VasmSourceConstantResolver = void 0; const cp = __importStar(require("child_process")); const path = __importStar(require("path")); const path_1 = require("path"); const temp_1 = require("temp"); const fs = __importStar(require("fs/promises")); const files_1 = require("./utils/files"); const debugadapter_1 = require("@vscode/debugadapter"); /** * Wrapper for vasm assembler */ class Vasm { constructor(binPath) { this.binPath = binPath; } /** * RUn assembler * * @param args CLI arguments to pass to process * @param cwd Current directory to execute process in */ run(args, cwd) { const options = { cwd, stdio: "pipe", }; const wasmPath = path.join((0, files_1.findWasmDir)(), "vasmm68k_mot"); // Execute vasm via binary or wasm const proc = this.binPath ? cp.spawn(this.binPath, args, options) : cp.fork(wasmPath, args, { ...options, // Prevent the child process from also being started in inspect mode // See https://github.com/nodejs/node/issues/14325 execArgv: [], }); proc.stdout?.on("data", (data) => (out += data)); proc.stderr?.on("data", (data) => (out += data)); let out = ""; return new Promise((resolve, reject) => { proc.on("exit", (code) => { code === 0 ? resolve(out) : reject(new VasmError(out)); }); proc.on("error", reject); }); } } exports.default = Vasm; class VasmError extends Error { constructor(output) { super("Vasm error"); this.output = output; } } /** * Uses vasm to assemble the process in 'test' mode to list definitions */ class VasmSourceConstantResolver { constructor(vasmOptions = {}) { this.vasmOptions = vasmOptions; } /** * @inheritdoc */ async getSourceConstants(sourceFiles) { const constants = {}; if (this.vasmOptions?.parseSource === false) { return constants; } // Use vasm 'test' output module to list constants const vasm = new Vasm(this.vasmOptions?.binaryPath); await Promise.all(Array.from(sourceFiles).map(async (src) => { const outFile = (0, temp_1.openSync)((0, path_1.basename)(src)); const userArgs = this.vasmOptions?.args ?? []; try { const out = await vasm.run([ ...userArgs, "-Ftest", "-quiet", "-o", outFile.path, src, ]); const output = (await fs.readFile(outFile.path)).toString(); debugadapter_1.logger.log("[VASM] " + out); Array.from(output.matchAll(/^([^ ]+) EXPR\((-?[0-9]+)=0x[0-9a-f]+\) (UNUSED )?EQU/gm)).forEach((m) => (constants[m[1]] = parseInt(m[2], 10))); } catch (err) { let msg = ""; if (err instanceof VasmError) { msg = err.output; } else if (err instanceof Error) { msg = err.message; } debugadapter_1.logger.error(`[VASM] Error building ${src} to get constants:\n${msg}`); } finally { fs.unlink(outFile.path); } })); return constants; } } exports.VasmSourceConstantResolver = VasmSourceConstantResolver; //# sourceMappingURL=vasm.js.map