blob: 45eff5d7edc5c9ffd402a3b1f31909d0f11d5346 [file] [log] [blame] [raw]
Matt Godbolt895bfd52019-05-30 16:33:07 -05001// Copyright (c) 2018, Compiler Explorer Authors
Partouf7d1a83f2018-10-26 16:16:27 +02002// 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
26const
27 BaseTool = require('./base-tool'),
28 fs = require('fs-extra');
29
30class 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
Partoufcea30e52019-07-18 23:46:33 +020046 runTool(compilationInfo, inputFilepath, args) {
Partouf7d1a83f2018-10-26 16:16:27 +020047 let extraargs = [];
Partoufcea30e52019-07-18 23:46:33 +020048 if (compilationInfo.filters.intel) {
Partouf7d1a83f2018-10-26 16:16:27 +020049 extraargs.push("--x86-asm-syntax=intel");
50 extraargs.push("-output-asm-variant=1");
51 }
52
Partoufcea30e52019-07-18 23:46:33 +020053 if (compilationInfo.filters.binary) {
Partouf7d1a83f2018-10-26 16:16:27 +020054 return new Promise((resolve) => {
55 resolve(this.createErrorResponse("<cannot run analysis on binary>"));
56 });
57 }
58
Partoufcea30e52019-07-18 23:46:33 +020059 const rewrittenOutputFilename = compilationInfo.outputFilename + ".mca";
60 return this.writeAsmFile(compilationInfo.asm, rewrittenOutputFilename).then(() => {
Partoufca7539b2019-07-19 13:43:07 +020061 return super.runTool(compilationInfo, rewrittenOutputFilename, args);
Partouf7d1a83f2018-10-26 16:16:27 +020062 });
63 }
64}
65
66module.exports = LLVMMcaTool;