Patrick Quist | a2eed58 | 2020-09-27 00:26:02 +0200 | [diff] [blame] | 1 | // Copyright (c) 2017, Windel Bouwman & Compiler Explorer Authors |
RabsRincon | 02122d8 | 2018-01-28 21:25:25 +0100 | [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 | |
Matt Godbolt | f2c1e0b | 2022-05-09 23:13:50 -0500 | [diff] [blame] | 25 | import {BaseCompiler} from '../base-compiler'; |
Austin Morton | 044dcfb | 2020-09-26 16:59:26 -0400 | [diff] [blame] | 26 | import * as exec from '../exec'; |
Matt Godbolt | f2c1e0b | 2022-05-09 23:13:50 -0500 | [diff] [blame] | 27 | import {logger} from '../logger'; |
RabsRincon | 02122d8 | 2018-01-28 21:25:25 +0100 | [diff] [blame] | 28 | |
Matt Godbolt | f2c1e0b | 2022-05-09 23:13:50 -0500 | [diff] [blame] | 29 | const forbiddenOptions = new Set(['--report', '--text-report', '--html-report']); |
Austin Morton | e2595f3 | 2019-10-09 17:02:31 -0400 | [diff] [blame] | 30 | |
Austin Morton | 044dcfb | 2020-09-26 16:59:26 -0400 | [diff] [blame] | 31 | export class PPCICompiler extends BaseCompiler { |
Matt Godbolt | f2c1e0b | 2022-05-09 23:13:50 -0500 | [diff] [blame] | 32 | static get key() { |
| 33 | return 'ppci'; |
| 34 | } |
Austin Morton | bac07fe | 2020-09-25 11:21:30 -0400 | [diff] [blame] | 35 | |
Partouf | c8be475 | 2018-03-07 20:39:13 +0100 | [diff] [blame] | 36 | filterUserOptions(args) { |
Matt Godbolt | f2c1e0b | 2022-05-09 23:13:50 -0500 | [diff] [blame] | 37 | return args.filter(item => { |
Rubén Rincón Blanco | ccff4b9 | 2020-08-04 22:39:02 +0200 | [diff] [blame] | 38 | if (typeof item !== 'string') return true; |
Partouf | 28c2901 | 2018-03-07 21:03:18 +0100 | [diff] [blame] | 39 | |
Rubén Rincón Blanco | ccff4b9 | 2020-08-04 22:39:02 +0200 | [diff] [blame] | 40 | return !forbiddenOptions.has(item.toLowerCase()); |
Partouf | a412d5a | 2018-03-07 19:40:41 +0100 | [diff] [blame] | 41 | }); |
| 42 | } |
| 43 | |
RabsRincon | 02122d8 | 2018-01-28 21:25:25 +0100 | [diff] [blame] | 44 | exec(compiler, args, options) { |
| 45 | if (compiler.endsWith('.py')) { |
| 46 | const python = this.env.ceProps('python3'); |
| 47 | options = options || {}; |
| 48 | |
| 49 | const matches = compiler.match(/^(.*)(\/ppci\/)(.*).py/); |
| 50 | if (matches) { |
| 51 | const pythonPath = matches[1]; |
| 52 | const ppciName = `ppci.${matches[3].replace('/', '.')}`; |
| 53 | options.env = {PYTHONPATH: pythonPath}; |
| 54 | let python_args = ['-m', ppciName].concat(args); |
| 55 | return exec.execute(python, python_args, options); |
| 56 | } |
| 57 | logger.error(`Invalid ppci path ${compiler}`); |
| 58 | } else { |
| 59 | return super.exec(compiler, args, options); |
| 60 | } |
| 61 | } |
| 62 | } |