Matt Godbolt | 895bfd5 | 2019-05-30 16:33:07 -0500 | [diff] [blame] | 1 | // Copyright (c) 2018, Compiler Explorer Authors |
Partouf | 7d1a83f | 2018-10-26 16:16:27 +0200 | [diff] [blame] | 2 | // All rights reserved. |
| 3 | // |
| 4 | // Redistribution and use in source and binary forms, with or without |
| 5 | // modification, are permitted provided that the following conditions are met: |
| 6 | // |
| 7 | // * Redistributions of source code must retain the above copyright notice, |
| 8 | // this list of conditions and the following disclaimer. |
| 9 | // * Redistributions in binary form must reproduce the above copyright |
| 10 | // notice, this list of conditions and the following disclaimer in the |
| 11 | // documentation and/or other materials provided with the distribution. |
| 12 | // |
| 13 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 14 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 16 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 17 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 18 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 19 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 20 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 21 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 22 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 23 | // POSSIBILITY OF SUCH DAMAGE. |
| 24 | "use strict"; |
| 25 | |
| 26 | const |
| 27 | BaseTool = require('./base-tool'), |
| 28 | fs = require('fs-extra'); |
| 29 | |
| 30 | class LLVMMcaTool extends BaseTool { |
| 31 | constructor(toolInfo, env) { |
| 32 | super(toolInfo, env); |
| 33 | } |
| 34 | |
| 35 | rewriteAsm(asm) { |
| 36 | return asm. |
| 37 | replace(/.hword\s/gim, '.short '). |
| 38 | replace(/OFFSET FLAT:/gim, ''). |
| 39 | replace(/PTR\s%fs/gim, 'PTR fs'); |
| 40 | } |
| 41 | |
| 42 | writeAsmFile(data, destination) { |
| 43 | return fs.writeFile(destination, this.rewriteAsm(data)); |
| 44 | } |
| 45 | |
Partouf | cea30e5 | 2019-07-18 23:46:33 +0200 | [diff] [blame] | 46 | runTool(compilationInfo, inputFilepath, args) { |
Partouf | 7d1a83f | 2018-10-26 16:16:27 +0200 | [diff] [blame] | 47 | let extraargs = []; |
Partouf | cea30e5 | 2019-07-18 23:46:33 +0200 | [diff] [blame] | 48 | if (compilationInfo.filters.intel) { |
Partouf | 7d1a83f | 2018-10-26 16:16:27 +0200 | [diff] [blame] | 49 | extraargs.push("--x86-asm-syntax=intel"); |
| 50 | extraargs.push("-output-asm-variant=1"); |
| 51 | } |
| 52 | |
Partouf | cea30e5 | 2019-07-18 23:46:33 +0200 | [diff] [blame] | 53 | if (compilationInfo.filters.binary) { |
Partouf | 7d1a83f | 2018-10-26 16:16:27 +0200 | [diff] [blame] | 54 | return new Promise((resolve) => { |
| 55 | resolve(this.createErrorResponse("<cannot run analysis on binary>")); |
| 56 | }); |
| 57 | } |
| 58 | |
Partouf | cea30e5 | 2019-07-18 23:46:33 +0200 | [diff] [blame] | 59 | const rewrittenOutputFilename = compilationInfo.outputFilename + ".mca"; |
| 60 | return this.writeAsmFile(compilationInfo.asm, rewrittenOutputFilename).then(() => { |
Partouf | ca7539b | 2019-07-19 13:43:07 +0200 | [diff] [blame] | 61 | return super.runTool(compilationInfo, rewrittenOutputFilename, args); |
Partouf | 7d1a83f | 2018-10-26 16:16:27 +0200 | [diff] [blame] | 62 | }); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | module.exports = LLVMMcaTool; |