aboutsummaryrefslogtreecommitdiff
path: root/lib/compilers/pascal.js
diff options
context:
space:
mode:
authorRabsRincon <rubrinbla@gmail.com>2018-01-18 19:43:10 +0100
committerRabsRincon <rubrinbla@gmail.com>2018-01-18 19:43:10 +0100
commita54faefb4c8668d9c9f93c78bd6bc639d1f0c219 (patch)
tree6465bf3e1d8e270cc53e67c04277c5773b16f7d6 /lib/compilers/pascal.js
parent7bd30b4c4b10f93f26db81fbbe492149b8d487eb (diff)
downloadcompiler-explorer-a54faefb4c8668d9c9f93c78bd6bc639d1f0c219.tar.gz
compiler-explorer-a54faefb4c8668d9c9f93c78bd6bc639d1f0c219.zip
ES6fy compilers inheritance
Diffstat (limited to 'lib/compilers/pascal.js')
-rw-r--r--lib/compilers/pascal.js222
1 files changed, 112 insertions, 110 deletions
diff --git a/lib/compilers/pascal.js b/lib/compilers/pascal.js
index 3fa0d3821..cfe4065cf 100644
--- a/lib/compilers/pascal.js
+++ b/lib/compilers/pascal.js
@@ -23,66 +23,62 @@
// POSSIBILITY OF SUCH DAMAGE.
"use strict";
-var Compile = require('../base-compiler'),
+const BaseCompiler = require('../base-compiler'),
PascalDemangler = require('../pascal-support').demangler,
utils = require('../utils'),
fs = require("fs"),
- path = require("path");
-
-function compileFPC(info, env) {
- var demangler = new PascalDemangler();
- var compiler = new Compile(info, env);
- compiler.compileFilename = "output.pas";
- compiler.supportsOptOutput = false;
-
- var originalExecBinary = compiler.execBinary;
- var currentlyActiveFilters = {};
+ path = require("path"),
+ argumentParsers = require("./argument-parsers");
+
+class FPCCompiler extends BaseCompiler {
+ constructor(info, env) {
+ super(info, env);
+ this.demangler = new PascalDemangler();
+ this.compileFilename = 'output.pas';
+ this.supportsOptOutput = false;
+
+ if (info.unitTestMode) {
+ this.initialise();
+ return this;
+ } else {
+ return this.initialise();
+ }
+ }
- compiler.postProcessAsm = function (result) {
+ postProcessAsm(result, filters) {
if (!result.okToCache) return result;
- if (currentlyActiveFilters.binary) {
- preProcessAsm(result.asm);
+ if (filters.binary) {
+ for (let j = 0; j < result.asm.length; ++j) {
+ this.demangler.addDemangleToCache(result.asm[j].text);
+ }
}
- for (var j = 0; j < result.asm.length; ++j)
- result.asm[j].text = demangler.demangleIfNeeded(result.asm[j].text);
+ for (let j = 0; j < result.asm.length; ++j)
+ result.asm[j].text = this.demangler.demangleIfNeeded(result.asm[j].text);
return result;
- };
+ }
- compiler.optionsForFilter = function (filters, outputFilename, userOptions) {
- var options = ['-g'];
+ optionsForFilter(filters, outputFilename, userOptions) {
+ let options = ['-g'];
if (this.compiler.intelAsm && filters.intel && !filters.binary) {
options = options.concat(this.compiler.intelAsm.split(" "));
}
- currentlyActiveFilters = filters;
- filters.preProcessLines = preProcessLines;
-
return options;
- };
-
- compiler.getOutputFilename = function (dirPath, outputFilebase) {
- return path.join(dirPath, path.basename(this.compileFilename, this.lang.extensions[0]) + ".s");
- };
+ }
- var saveDummyProjectFile = function (filename) {
- const unitName = path.basename(compiler.compileFilename, compiler.lang.extensions[0]);
+ getOutputFilename(dirPath, outputFilebase) {
+ return path.join(dirPath, `${path.basename(this.compileFilename, this.lang.extensions[0])}.s`);
+ }
- fs.writeFileSync(filename,
- "program prog; " +
- "uses " + unitName + " in '" + compiler.compileFilename + "'; " +
- "begin " +
- "end.", function() {});
- };
-
- var preProcessBinaryAsm = function (input) {
- var relevantAsmStartsAt = input.indexOf("<OUTPUT");
- if (relevantAsmStartsAt != -1) {
- var lastLinefeedBeforeStart = input.lastIndexOf("\n", relevantAsmStartsAt);
- if (lastLinefeedBeforeStart != -1) {
+ static preProcessBinaryAsm(input) {
+ const relevantAsmStartsAt = input.indexOf("<OUTPUT");
+ if (relevantAsmStartsAt !== -1) {
+ const lastLinefeedBeforeStart = input.lastIndexOf("\n", relevantAsmStartsAt);
+ if (lastLinefeedBeforeStart !== -1) {
input =
input.substr(0, input.indexOf("00000000004")) + "\n" +
input.substr(lastLinefeedBeforeStart + 1);
@@ -92,15 +88,79 @@ function compileFPC(info, env) {
input.substr(relevantAsmStartsAt);
}
}
-
return input;
- };
+ }
+
+ objdump(outputFilename, result, maxSize, intelAsm, demangle) {
+ outputFilename = path.join(path.dirname(outputFilename), "prog");
+ let args = ["-d", outputFilename, "-l", "--insn-width=16"];
+ if (demangle) args = args.concat(["-C"]);
+ if (intelAsm) args = args.concat(["-M", "intel"]);
+ return this.exec(this.compiler.objdumper, args, {maxOutput: maxSize}).then(objResult => {
+ if (objResult.code !== 0) {
+ result.asm = "<No output: objdump returned " + objResult.code + ">";
+ } else {
+ result.asm = FPCCompiler.preProcessBinaryAsm(objResult.stdout);
+ }
+ return result;
+ });
+ }
+
+ saveDummyProjectFile(filename) {
+ const unitName = path.basename(this.compileFilename, this.lang.extensions[0]);
+
+ fs.writeFileSync(filename,
+ "program prog; " +
+ "uses " + unitName + " in '" + this.compileFilename + "'; " +
+ "begin " +
+ "end.", () => {});
+ }
+
+ runCompiler(compiler, options, inputFilename, execOptions) {
+ if (!execOptions) {
+ execOptions = this.getDefaultExecOptions();
+ }
+
+ const tempPath = path.dirname(inputFilename);
+ const projectFile = path.join(tempPath, "prog.dpr");
+
+ this.saveDummyProjectFile(projectFile);
+
+ options.pop();
+ options.push('-FE' + tempPath);
+ options.push('-B');
+ options.push(projectFile);
+
+ return this.exec(compiler, options, execOptions).then(result => {
+ result.inputFilename = inputFilename;
+ result.stdout = utils.parseOutput(result.stdout, inputFilename);
+ result.stderr = utils.parseOutput(result.stderr, inputFilename);
+ return result;
+ });
+ }
+
+ execBinary(executable, result, maxSize) {
+ executable = path.join(path.dirname(executable), "prog");
+
+ super.execBinary(executable, result, maxSize);
+ }
+
+ getArgumentParser() {
+ return argumentParsers.Base;
+ }
+}
+/*function compileFPC(info, env) {
+ const demangler = new PascalDemangler();
+ const compiler = new Compile(info, env);
+
+ const
- var getExtraAsmHint = function (asm) {
+
+ const getExtraAsmHint = asm => {
if (asm.startsWith("# [")) {
- var bracketEndPos = asm.indexOf("]", 3);
- var valueInBrackets = asm.substr(3, bracketEndPos - 3);
- var colonPos = valueInBrackets.indexOf(":");
+ const bracketEndPos = asm.indexOf("]", 3);
+ let valueInBrackets = asm.substr(3, bracketEndPos - 3);
+ const colonPos = valueInBrackets.indexOf(":");
if (colonPos != -1) {
valueInBrackets = valueInBrackets.substr(0, colonPos - 1);
}
@@ -119,11 +179,11 @@ function compileFPC(info, env) {
}
};
- var preProcessLines = function(asmLines) {
- var i = 0;
+ var preProcessLines = asmLines => {
+ let i = 0;
while (i < asmLines.length) {
- var extraHint = getExtraAsmHint(asmLines[i]);
+ const extraHint = getExtraAsmHint(asmLines[i]);
if (extraHint) {
i++;
asmLines.splice(i, 0, extraHint);
@@ -137,64 +197,6 @@ function compileFPC(info, env) {
return asmLines;
};
- var preProcessAsm = function(asm) {
- for (var j = 0; j < asm.length; ++j) demangler.addDemangleToCache(asm[j].text);
- };
-
- compiler.objdump = function (outputFilename, result, maxSize, intelAsm, demangle) {
- outputFilename = path.join(path.dirname(outputFilename), "prog");
-
- var args = ["-d", outputFilename, "-l", "--insn-width=16"];
- if (demangle) args = args.concat(["-C"]);
- if (intelAsm) args = args.concat(["-M", "intel"]);
- return this.exec(this.compiler.objdumper, args, {maxOutput: maxSize})
- .then(function (objResult) {
- if (objResult.code !== 0) {
- result.asm = "<No output: objdump returned " + objResult.code + ">";
- } else {
- result.asm = preProcessBinaryAsm(objResult.stdout);
- }
-
- return result;
- });
- };
-
- compiler.runCompiler = function (compiler, options, inputFilename, execOptions) {
- if (!execOptions) {
- execOptions = this.getDefaultExecOptions();
- }
-
- var tempPath = path.dirname(inputFilename);
- var projectFile = path.join(tempPath, "prog.dpr");
-
- saveDummyProjectFile(projectFile);
-
- options.pop();
- options.push('-FE' + tempPath);
- options.push('-B');
- options.push(projectFile);
-
- return this.exec(compiler, options, execOptions).then(function (result) {
- result.inputFilename = inputFilename;
- result.stdout = utils.parseOutput(result.stdout, inputFilename);
- result.stderr = utils.parseOutput(result.stderr, inputFilename);
- return result;
- });
- };
-
- compiler.execBinary = function (executable, result, maxSize) {
- executable = path.join(path.dirname(executable), "prog");
-
- originalExecBinary(executable, result, maxSize);
- };
-
- compiler.getArgumentParser = () => (compiler) => compiler;
-
- if (info.unitTestMode) {
- compiler.initialise();
- return compiler;
- } else
- return compiler.initialise();
-}
+}*/
-module.exports = compileFPC;
+module.exports = FPCCompiler;