diff options
author | Patrick Quist <partouf@gmail.com> | 2021-09-13 20:22:27 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-13 20:22:27 +0200 |
commit | bc6757ae94dbc46fa1243f3277de2262794d5a75 (patch) | |
tree | d264a83fea30a6b189def084c0d422814b814de3 /lib/compilers/pascal-win.js | |
parent | 3d1a6a672066d5d2b93255ffb7e39a1293bb227c (diff) | |
download | compiler-explorer-bc6757ae94dbc46fa1243f3277de2262794d5a75.tar.gz compiler-explorer-bc6757ae94dbc46fa1243f3277de2262794d5a75.zip |
Pascalchanges (#2881)
* Changes to allow Program (vs Unit) in Object Pascal
* add possibility of dpr
* more flexibility with pascal filenames
* lintfixes
* i have no idea what im doing
* apply changes to pascal-win
* pascal fixes
* pascal projectfile changes
* work in progress
* bugfixes
* bla
* bugfixes
* mostly working
Co-authored-by: paul mcgee <paul.mcgee.8@bigpond.com>
Co-authored-by: Paul McGee <paulmcgee1969@gmail.com>
Diffstat (limited to 'lib/compilers/pascal-win.js')
-rw-r--r-- | lib/compilers/pascal-win.js | 67 |
1 files changed, 55 insertions, 12 deletions
diff --git a/lib/compilers/pascal-win.js b/lib/compilers/pascal-win.js index eef29685e..85bdac61b 100644 --- a/lib/compilers/pascal-win.js +++ b/lib/compilers/pascal-win.js @@ -31,6 +31,8 @@ import { MapFileReaderDelphi } from '../map-file-delphi'; import { PELabelReconstructor } from '../pe32-support'; import * as utils from '../utils'; +import { PascalUtils } from './pascal-utils'; + export class PascalWinCompiler extends BaseCompiler { static get key() { return 'pascal-win'; } @@ -40,6 +42,12 @@ export class PascalWinCompiler extends BaseCompiler { this.mapFilename = false; this.compileFilename = 'output.pas'; + this.dprFilename = 'prog.dpr'; + this.pasUtils = new PascalUtils(); + } + + getSharedLibraryPathsAsArguments() { + return []; } exec(command, args, options) { @@ -56,6 +64,10 @@ export class PascalWinCompiler extends BaseCompiler { return super.exec(command, args, options); } + getExecutableFilename(dirPath) { + return path.join(dirPath, 'prog.exe'); + } + getOutputFilename(dirPath) { return path.join(dirPath, 'prog.exe'); } @@ -85,30 +97,59 @@ export class PascalWinCompiler extends BaseCompiler { }); } - saveDummyProjectFile(dprfile, sourcefile) { - if (dprfile.startsWith('Z:')) { - dprfile = dprfile.substr(2); + async saveDummyProjectFile(filename, unitName, unitPath) { + await fs.writeFile(filename, + 'program prog;\n' + + 'uses ' + unitName + ' in \'' + unitPath + '\';\n' + + 'begin\n' + + 'end.\n'); + } + + async writeAllFiles(dirPath, source, files, filters) { + let inputFilename; + if (this.pasUtils.isProgram(source)) { + inputFilename = path.join(dirPath, this.dprFilename); + } else { + const unitName = this.pasUtils.getUnitname(source); + if (unitName) { + inputFilename = path.join(dirPath, unitName + '.pas'); + } else { + inputFilename = path.join(dirPath, this.compileFilename); + } + } + + await fs.writeFile(inputFilename, source); + + if (files) { + filters.dontMaskFilenames = true; + + await this.writeMultipleFiles(files, dirPath); } - fs.writeFileSync(dprfile, - 'program prog; ' + - "uses output in '" + sourcefile + "'; " + - 'begin ' + - 'end.'); + return { + inputFilename, + }; } - runCompiler(compiler, options, inputFilename, execOptions) { + async runCompiler(compiler, options, inputFilename, execOptions) { if (!execOptions) { execOptions = this.getDefaultExecOptions(); } + let alreadyHasDPR = path.basename(inputFilename) === this.dprFilename; + const tempPath = path.dirname(inputFilename); - const projectFile = path.join(tempPath, 'prog.dpr'); + const projectFile = path.join(tempPath, this.dprFilename); this.mapFilename = path.join(tempPath, 'prog.map'); inputFilename = inputFilename.replace(/\//g, '\\'); - this.saveDummyProjectFile(projectFile, inputFilename); + + if (!alreadyHasDPR) { + const unitFilepath = path.basename(inputFilename); + const unitName = unitFilepath.replace(/.pas$/i, ''); + await this.saveDummyProjectFile(projectFile, unitName, unitFilepath); + } options.pop(); @@ -121,7 +162,8 @@ export class PascalWinCompiler extends BaseCompiler { '-V', '-B'); - options.push(projectFile.replace(/\//g, '\\')); + options.push(projectFile); + execOptions.customCwd = tempPath; return this.exec(compiler, options, execOptions).then((result) => { result.inputFilename = inputFilename; @@ -133,6 +175,7 @@ export class PascalWinCompiler extends BaseCompiler { optionsForFilter(filters) { filters.binary = true; + filters.dontMaskFilenames = true; filters.preProcessBinaryAsmLines = (asmLines) => { const mapFileReader = new MapFileReaderDelphi(this.mapFilename); const reconstructor = new PELabelReconstructor(asmLines, false, mapFileReader, false); |