From 535d436ea9fa00d269bef74da4e46ad124cc4544 Mon Sep 17 00:00:00 2001 From: RabsRincon Date: Sat, 30 May 2020 13:22:40 +0200 Subject: [PATCH] Make gccDump output process filename agnostic --- lib/base-compiler.js | 49 ++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/lib/base-compiler.js b/lib/base-compiler.js index 0c435ede8..d104a3a53 100644 --- a/lib/base-compiler.js +++ b/lib/base-compiler.js @@ -934,7 +934,6 @@ class BaseCompiler { async processGccDumpOutput(opts, result) { const rootDir = path.dirname(result.inputFilename); const allFiles = await fs.readdir(rootDir); - const base = path.basename(result.inputFilename); if (opts.treeDump === false && opts.rtlDump === false) { return { @@ -945,38 +944,38 @@ class BaseCompiler { }; } - const allPasses = []; - - for (let file of allFiles) { - if (file.includes(`${base}.`)) { - allPasses.push(file.substring(base.length + 1)); - } - } - const output = { - all: allPasses, + all: [], selectedPass: opts.pass, currentPassOutput: '', syntaxHighlight: false }; - - if (opts.pass) { - const passDump = `${result.inputFilename}.${opts.pass}`; - - if (await fs.pathExists(passDump) && (await fs.stat(passDump)).isFile()) { - output.currentPassOutput = await fs.readFile(passDump, 'utf-8'); - if (output.currentPassOutput.match(/^\s*$/)) { - output.currentPassOutput = 'File for selected pass is empty.'; - } else { - output.syntaxHighlight = true; + let passFound = false; + // Phase letter is one of {i, l, r, t} + // {outpufilename}.{extension}.{passNumber}{phaseLetter}.{phaseName} + const dumpFilenameRegex = /^.+?\..+?\.(\d+?[ilrt]\..+)$/; + for (let filename of allFiles) { + const match = dumpFilenameRegex.exec(filename); + if (match) { + const pass = match[1]; + output.all.push(pass); + const filePath = path.join(rootDir, filename); + if (opts.pass === pass && (await fs.stat(filePath)).isFile()) { + passFound = true; + output.currentPassOutput = await fs.readFile(filePath, 'utf-8'); + if (output.currentPassOutput.match(/^\s*$/)) { + output.currentPassOutput = 'File for selected pass is empty.'; + } else { + output.syntaxHighlight = true; + } } - } else { - // most probably filter has changed and the request is outdated. - output.currentPassOutput = `Pass '${output.selectedPass}' was requested + } + } + + if (opts.pass && !passFound) { + output.currentPassOutput = `Pass '${opts.pass}' was requested but is not valid anymore with current filters. Please select another pass or change filters.`; - output.selectedPass = ""; - } } return output;