diff options
Diffstat (limited to 'lib/compilers/assembly.js')
-rw-r--r-- | lib/compilers/assembly.js | 57 |
1 files changed, 25 insertions, 32 deletions
diff --git a/lib/compilers/assembly.js b/lib/compilers/assembly.js index e2f6d9d88..e6efb0603 100644 --- a/lib/compilers/assembly.js +++ b/lib/compilers/assembly.js @@ -23,62 +23,64 @@ // POSSIBILITY OF SUCH DAMAGE. "use strict"; -var Compile = require('../base-compiler'), - logger = require('../logger').logger, +const BaseCompiler = require('../base-compiler'), AsmRaw = require('../asm-raw').AsmParser, utils = require('../utils'), fs = require("fs"), - path = require("path"); + path = require("path"), + argumentParsers = require("./argument-parsers"); -function compileAssembly(info, env) { - var compiler = new Compile(info, env); - compiler.asm = new AsmRaw(); +class AssemblyCompiler extends BaseCompiler { + constructor(info, env) { + super(info, env); + this.asm = new AsmRaw(); + } - compiler.getArgumentParser = () => (compiler) => compiler; + getArgumentParser() { + return argumentParsers.Base; + } - compiler.optionsForFilter = function (filters, outputFilename, userOptions) { + optionsForFilter(filters, outputFilename, userOptions) { filters.binary = true; - return []; - }; + } - compiler.runCompiler = function (compiler, options, inputFilename, execOptions) { + runCompiler(compiler, options, inputFilename, execOptions) { if (!execOptions) { execOptions = this.getDefaultExecOptions(); } execOptions.customCwd = path.dirname(inputFilename); - - return this.exec(compiler, options, execOptions).then(function (result) { + + 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; }); - }; + } - function getGeneratedOutputfilename(inputFilename) { + getGeneratedOutputfilename(inputFilename) { const outputFolder = path.dirname(inputFilename); return new Promise((resolve, reject) => { fs.readdir(outputFolder, (err, files) => { files.forEach(file => { - if (file !== compiler.compileFilename) { + if (file !== this.compileFilename) { resolve(path.join(outputFolder, file)); } }); - reject("No output file was generated"); }); }); } - compiler.objdump = function (outputFilename, result, maxSize, intelAsm, demangle) { - return getGeneratedOutputfilename(outputFilename).then((realOutputFilename) => { + objdump(outputFilename, result, maxSize, intelAsm, demangle) { + return this.getGeneratedOutputfilename(outputFilename).then((realOutputFilename) => { let args = ["-d", realOutputFilename, "-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) { + .then(objResult => { result.asm = objResult.stdout; if (objResult.code !== 0) { result.asm = "<No output: objdump returned " + objResult.code + ">"; @@ -86,17 +88,8 @@ function compileAssembly(info, env) { return result; }); }); - }; - - compiler.getOutputFilename = function (dirPath, outputFilebase) { - return path.join(dirPath, this.compileFilename); - }; - - if (info.unitTestMode) { - compiler.initialise(); - return compiler; - } else - return compiler.initialise(); + } } -module.exports = compileAssembly; + +module.exports = AssemblyCompiler; |