Marc Poulhiès | f000d51 | 2021-07-12 22:35:01 +0200 | [diff] [blame] | 1 | // Copyright (c) 2021, Compiler Explorer Authors |
| 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 | |
| 25 | import path from 'path'; |
| 26 | |
Matt Godbolt | f2c1e0b | 2022-05-09 23:13:50 -0500 | [diff] [blame] | 27 | import {RustCompiler} from './rust'; |
Marc Poulhiès | f000d51 | 2021-07-12 22:35:01 +0200 | [diff] [blame] | 28 | |
| 29 | export class RustcCgGCCCompiler extends RustCompiler { |
Matt Godbolt | f2c1e0b | 2022-05-09 23:13:50 -0500 | [diff] [blame] | 30 | static get key() { |
| 31 | return 'rustc-cg-gcc'; |
| 32 | } |
Marc Poulhiès | f000d51 | 2021-07-12 22:35:01 +0200 | [diff] [blame] | 33 | |
| 34 | constructor(info, env) { |
| 35 | super(info, env); |
| 36 | this.compiler.supportsIrView = false; |
Marc Poulhiès | 177fee0 | 2021-11-21 14:18:25 +0100 | [diff] [blame] | 37 | |
| 38 | // Enable GCC dump code, |
| 39 | this.compiler.supportsGccDump = true; |
| 40 | |
| 41 | // but do not try to filter out empty dumps: |
| 42 | // This filtering needs to dump all files but currently libgccjit (used by |
| 43 | // this rustc backend) and compiler-explorer's use of jails makes this task a bit tricky. |
| 44 | // The user will be presented more dumps than effectively created. |
| 45 | // Turning this to 'true' will break the dumps. |
| 46 | |
| 47 | this.compiler.removeEmptyGccDump = false; |
| 48 | } |
| 49 | |
Matt Godbolt | f2c1e0b | 2022-05-09 23:13:50 -0500 | [diff] [blame] | 50 | getGccDumpOptions(gccDumpOptions, removeEmptyPasses) { |
| 51 | return ['-C', 'llvm-args=' + super.getGccDumpOptions(gccDumpOptions, removeEmptyPasses).join(' ')]; |
Marc Poulhiès | f000d51 | 2021-07-12 22:35:01 +0200 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | optionsForFilter(filters, outputFilename, userOptions) { |
| 55 | // these options are direcly taken from rustc_codegen_gcc doc. |
| 56 | // See https://github.com/antoyo/rustc_codegen_gcc |
| 57 | let toolroot = path.resolve(path.dirname(this.compiler.exe), '..'); |
| 58 | |
Matt Godbolt | f2c1e0b | 2022-05-09 23:13:50 -0500 | [diff] [blame] | 59 | let options = [ |
| 60 | '-C', |
| 61 | 'panic=abort', |
| 62 | '-Z', |
| 63 | 'codegen-backend=librustc_codegen_gcc.so', |
| 64 | '--sysroot', |
| 65 | toolroot + '/sysroot', |
| 66 | ]; |
Marc Poulhiès | f000d51 | 2021-07-12 22:35:01 +0200 | [diff] [blame] | 67 | |
| 68 | // rust.js makes the asumption that LLVM is used. This may go away when cranelift is available. |
| 69 | // Until this is the case and the super() class is refactored, simply ditch -Cllvm arg. |
Matt Godbolt | f2c1e0b | 2022-05-09 23:13:50 -0500 | [diff] [blame] | 70 | let super_options = super |
| 71 | .optionsForFilter(filters, outputFilename, userOptions) |
| 72 | .filter(arg => !/-Cllvm.*/.test(arg)); |
Marc Poulhiès | f000d51 | 2021-07-12 22:35:01 +0200 | [diff] [blame] | 73 | options = options.concat(super_options); |
| 74 | return options; |
| 75 | } |
| 76 | } |