RabsRincon | 6ef87b5 | 2018-02-27 14:58:21 +0100 | [diff] [blame] | 1 | // Copyright (c) 2017, Jared Wyles |
jaredwy | 13cd0fd | 2017-07-03 17:42:27 +1000 | [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 | |
Austin Morton | 044dcfb | 2020-09-26 16:59:26 -0400 | [diff] [blame] | 25 | import _ from 'underscore'; |
jaredwy | 13cd0fd | 2017-07-03 17:42:27 +1000 | [diff] [blame] | 26 | |
Austin Morton | 044dcfb | 2020-09-26 16:59:26 -0400 | [diff] [blame] | 27 | import { logger } from '../logger'; |
| 28 | import * as utils from '../utils'; |
| 29 | |
| 30 | export class BaseParser { |
Partouf | 96e8d72 | 2018-11-10 01:05:11 +0100 | [diff] [blame] | 31 | static hasSupport(options, forOption) { |
| 32 | return _.keys(options).find(option => option.includes(forOption)); |
| 33 | } |
| 34 | |
| 35 | static parseLines(stdout, optionRegex) { |
| 36 | let previousOption = false; |
| 37 | let options = {}; |
| 38 | |
| 39 | utils.eachLine(stdout, line => { |
| 40 | const match = line.match(optionRegex); |
| 41 | if (!match) { |
Matt Godbolt | a465962 | 2021-05-27 23:17:13 -0500 | [diff] [blame] | 42 | if (previousOption && (line.trim().length > 0)) { |
Rubén Rincón Blanco | ccff4b9 | 2020-08-04 22:39:02 +0200 | [diff] [blame] | 43 | if (options[previousOption].description.endsWith('-')) |
Partouf | 96e8d72 | 2018-11-10 01:05:11 +0100 | [diff] [blame] | 44 | options[previousOption].description += line.trim(); |
| 45 | else { |
Matt Godbolt | a465962 | 2021-05-27 23:17:13 -0500 | [diff] [blame] | 46 | if (options[previousOption].description.length > 0) |
Rubén Rincón Blanco | ccff4b9 | 2020-08-04 22:39:02 +0200 | [diff] [blame] | 47 | options[previousOption].description += ' ' + line.trim(); |
Partouf | 96e8d72 | 2018-11-10 01:05:11 +0100 | [diff] [blame] | 48 | else |
| 49 | options[previousOption].description = line.trim(); |
| 50 | } |
| 51 | } else { |
| 52 | previousOption = false; |
| 53 | } |
| 54 | return; |
| 55 | } |
| 56 | |
| 57 | if (match) previousOption = match[1]; |
| 58 | if (previousOption) { |
| 59 | options[previousOption] = { |
| 60 | description: match[2].trim(), |
Rubén Rincón Blanco | ccff4b9 | 2020-08-04 22:39:02 +0200 | [diff] [blame] | 61 | timesused: 0, |
Partouf | 96e8d72 | 2018-11-10 01:05:11 +0100 | [diff] [blame] | 62 | }; |
| 63 | } |
| 64 | }); |
| 65 | |
| 66 | return options; |
| 67 | } |
| 68 | |
Matt Godbolt | 03a3fb3 | 2020-01-14 22:37:58 -0600 | [diff] [blame] | 69 | static async getOptions(compiler, helpArg) { |
Rubén Rincón Blanco | ccff4b9 | 2020-08-04 22:39:02 +0200 | [diff] [blame] | 70 | const optionFinder = /^\s*(--?[\d+,<=>[\]a-z|-]*)\s*(.*)/i; |
Matt Godbolt | 03a3fb3 | 2020-01-14 22:37:58 -0600 | [diff] [blame] | 71 | const result = await compiler.execCompilerCached(compiler.compiler.exe, [helpArg]); |
| 72 | const options = result.code === 0 |
| 73 | ? BaseParser.parseLines(result.stdout + result.stderr, optionFinder) : {}; |
| 74 | compiler.possibleArguments.populateOptions(options); |
| 75 | return options; |
RabsRincon | a54faef | 2018-01-18 19:43:10 +0100 | [diff] [blame] | 76 | } |
RabsRincon | d493dfb | 2018-01-18 19:46:02 +0100 | [diff] [blame] | 77 | |
RabsRincon | a54faef | 2018-01-18 19:43:10 +0100 | [diff] [blame] | 78 | static parse(compiler) { |
| 79 | return compiler; |
| 80 | } |
| 81 | } |
Matt Godbolt | 6e7e30b | 2017-12-19 10:15:17 -0600 | [diff] [blame] | 82 | |
Austin Morton | 044dcfb | 2020-09-26 16:59:26 -0400 | [diff] [blame] | 83 | export class GCCParser extends BaseParser { |
Matt Godbolt | 03a3fb3 | 2020-01-14 22:37:58 -0600 | [diff] [blame] | 84 | static async parse(compiler) { |
| 85 | const results = await Promise.all([ |
Rubén Rincón Blanco | ccff4b9 | 2020-08-04 22:39:02 +0200 | [diff] [blame] | 86 | GCCParser.getOptions(compiler, '-fsyntax-only --target-help'), |
| 87 | GCCParser.getOptions(compiler, '-fsyntax-only --help=common'), |
| 88 | GCCParser.getOptions(compiler, '-fsyntax-only --help=optimizers'), |
Matt Godbolt | 03a3fb3 | 2020-01-14 22:37:58 -0600 | [diff] [blame] | 89 | ]); |
| 90 | const options = Object.assign({}, ...results); |
| 91 | const keys = _.keys(options); |
Rubén Rincón Blanco | ccff4b9 | 2020-08-04 22:39:02 +0200 | [diff] [blame] | 92 | logger.debug(`gcc-like compiler options: ${keys.join(' ')}`); |
| 93 | if (BaseParser.hasSupport(options, '-masm=')) { |
Iain Buclaw | 9129704 | 2020-06-08 12:47:44 +0200 | [diff] [blame] | 94 | // -masm= may be available but unsupported by the compiler. |
Austin Morton | a16013a | 2020-10-16 13:24:40 -0400 | [diff] [blame] | 95 | const res = await compiler.execCompilerCached(compiler.compiler.exe, |
| 96 | ['-fsyntax-only', '--target-help', '-masm=intel']); |
Austin Morton | 044dcfb | 2020-09-26 16:59:26 -0400 | [diff] [blame] | 97 | if (res.code === 0) { |
| 98 | compiler.compiler.intelAsm = '-masm=intel'; |
| 99 | compiler.compiler.supportsIntel = true; |
| 100 | } |
Matt Godbolt | 03a3fb3 | 2020-01-14 22:37:58 -0600 | [diff] [blame] | 101 | } |
Rubén Rincón Blanco | ccff4b9 | 2020-08-04 22:39:02 +0200 | [diff] [blame] | 102 | if (BaseParser.hasSupport(options, '-fdiagnostics-color')) { |
| 103 | if (compiler.compiler.options) compiler.compiler.options += ' '; |
| 104 | compiler.compiler.options += '-fdiagnostics-color=always'; |
Matt Godbolt | 03a3fb3 | 2020-01-14 22:37:58 -0600 | [diff] [blame] | 105 | } |
| 106 | // This check is not infallible, but takes care of Rust and Swift being picked up :) |
| 107 | if (_.find(keys, key => key.startsWith('-fdump-'))) { |
| 108 | compiler.compiler.supportsGccDump = true; |
| 109 | } |
| 110 | return compiler; |
RabsRincon | a54faef | 2018-01-18 19:43:10 +0100 | [diff] [blame] | 111 | } |
Iain Buclaw | 9129704 | 2020-06-08 12:47:44 +0200 | [diff] [blame] | 112 | |
| 113 | static async getOptions(compiler, helpArg) { |
Rubén Rincón Blanco | ccff4b9 | 2020-08-04 22:39:02 +0200 | [diff] [blame] | 114 | const optionFinder = /^\s*(--?[\d+,<=>[\]a-z|-]*)\s*(.*)/i; |
Iain Buclaw | 9129704 | 2020-06-08 12:47:44 +0200 | [diff] [blame] | 115 | const result = await compiler.execCompilerCached(compiler.compiler.exe, helpArg.split(' ')); |
| 116 | const options = result.code === 0 |
| 117 | ? BaseParser.parseLines(result.stdout + result.stderr, optionFinder) : {}; |
| 118 | compiler.possibleArguments.populateOptions(options); |
| 119 | return options; |
| 120 | } |
RabsRincon | a54faef | 2018-01-18 19:43:10 +0100 | [diff] [blame] | 121 | } |
jaredwy | 13cd0fd | 2017-07-03 17:42:27 +1000 | [diff] [blame] | 122 | |
Austin Morton | 044dcfb | 2020-09-26 16:59:26 -0400 | [diff] [blame] | 123 | export class ClangParser extends BaseParser { |
Matt Godbolt | 03a3fb3 | 2020-01-14 22:37:58 -0600 | [diff] [blame] | 124 | static async parse(compiler) { |
Rubén Rincón Blanco | ccff4b9 | 2020-08-04 22:39:02 +0200 | [diff] [blame] | 125 | const options = await ClangParser.getOptions(compiler, '--help'); |
| 126 | logger.debug(`clang-like compiler options: ${_.keys(options).join(' ')}`); |
Matt Godbolt | 03a3fb3 | 2020-01-14 22:37:58 -0600 | [diff] [blame] | 127 | if (BaseParser.hasSupport(options, '-fsave-optimization-record')) { |
Rubén Rincón Blanco | ccff4b9 | 2020-08-04 22:39:02 +0200 | [diff] [blame] | 128 | compiler.compiler.optArg = '-fsave-optimization-record'; |
Matt Godbolt | 03a3fb3 | 2020-01-14 22:37:58 -0600 | [diff] [blame] | 129 | compiler.compiler.supportsOptOutput = true; |
| 130 | } |
Rubén Rincón Blanco | ccff4b9 | 2020-08-04 22:39:02 +0200 | [diff] [blame] | 131 | if (BaseParser.hasSupport(options, '-fcolor-diagnostics')) { |
| 132 | if (compiler.compiler.options) compiler.compiler.options += ' '; |
| 133 | compiler.compiler.options += '-fcolor-diagnostics'; |
Matt Godbolt | 03a3fb3 | 2020-01-14 22:37:58 -0600 | [diff] [blame] | 134 | } |
Rubén Rincón Blanco | ccff4b9 | 2020-08-04 22:39:02 +0200 | [diff] [blame] | 135 | if (BaseParser.hasSupport(options, '-emit-llvm')) { |
Matt Godbolt | 03a3fb3 | 2020-01-14 22:37:58 -0600 | [diff] [blame] | 136 | compiler.compiler.supportsIrView = true; |
| 137 | compiler.compiler.irArg = ['-Xclang', '-emit-llvm', '-fsyntax-only']; |
| 138 | } |
Rubén Rincón Blanco | ccff4b9 | 2020-08-04 22:39:02 +0200 | [diff] [blame] | 139 | if (BaseParser.hasSupport(options, '-fno-crash-diagnostics')) { |
| 140 | if (compiler.compiler.options) compiler.compiler.options += ' '; |
| 141 | compiler.compiler.options += '-fno-crash-diagnostics'; |
Matt Godbolt | 03a3fb3 | 2020-01-14 22:37:58 -0600 | [diff] [blame] | 142 | } |
| 143 | return compiler; |
RabsRincon | a54faef | 2018-01-18 19:43:10 +0100 | [diff] [blame] | 144 | } |
| 145 | } |
jaredwy | 13cd0fd | 2017-07-03 17:42:27 +1000 | [diff] [blame] | 146 | |
Austin Morton | 044dcfb | 2020-09-26 16:59:26 -0400 | [diff] [blame] | 147 | export class PascalParser extends BaseParser { |
Matt Godbolt | 03a3fb3 | 2020-01-14 22:37:58 -0600 | [diff] [blame] | 148 | static async parse(compiler) { |
Rubén Rincón Blanco | ccff4b9 | 2020-08-04 22:39:02 +0200 | [diff] [blame] | 149 | await PascalParser.getOptions(compiler, '-help'); |
Matt Godbolt | 03a3fb3 | 2020-01-14 22:37:58 -0600 | [diff] [blame] | 150 | return compiler; |
Partouf | e892d35 | 2019-01-08 03:20:30 +0100 | [diff] [blame] | 151 | } |
| 152 | } |
| 153 | |
Austin Morton | 044dcfb | 2020-09-26 16:59:26 -0400 | [diff] [blame] | 154 | export class ISPCParser extends BaseParser { |
Matt Godbolt | 03a3fb3 | 2020-01-14 22:37:58 -0600 | [diff] [blame] | 155 | static async parse(compiler) { |
Rubén Rincón Blanco | ccff4b9 | 2020-08-04 22:39:02 +0200 | [diff] [blame] | 156 | const options = await ISPCParser.getOptions(compiler, '--help'); |
| 157 | if (BaseParser.hasSupport(options, '--x86-asm-syntax')) { |
| 158 | compiler.compiler.intelAsm = '--x86-asm-syntax=intel'; |
Matt Godbolt | 03a3fb3 | 2020-01-14 22:37:58 -0600 | [diff] [blame] | 159 | compiler.compiler.supportsIntel = true; |
| 160 | } |
| 161 | return compiler; |
Partouf | e892d35 | 2019-01-08 03:20:30 +0100 | [diff] [blame] | 162 | } |
| 163 | |
Matt Godbolt | 03a3fb3 | 2020-01-14 22:37:58 -0600 | [diff] [blame] | 164 | static async getOptions(compiler, helpArg) { |
| 165 | const result = await compiler.execCompilerCached(compiler.compiler.exe, [helpArg]); |
Rubén Rincón Blanco | ccff4b9 | 2020-08-04 22:39:02 +0200 | [diff] [blame] | 166 | const optionFinder = /^\s*\[(--?[\d\s()+,/<=>a-z{|}-]*)]\s*(.*)/i; |
Matt Godbolt | 03a3fb3 | 2020-01-14 22:37:58 -0600 | [diff] [blame] | 167 | const options = result.code === 0 |
| 168 | ? BaseParser.parseLines(result.stdout + result.stderr, optionFinder) : {}; |
| 169 | compiler.possibleArguments.populateOptions(options); |
| 170 | return options; |
Partouf | e892d35 | 2019-01-08 03:20:30 +0100 | [diff] [blame] | 171 | } |
| 172 | } |
| 173 | |
Austin Morton | 044dcfb | 2020-09-26 16:59:26 -0400 | [diff] [blame] | 174 | export class JavaParser extends BaseParser { |
Matt Godbolt | 03a3fb3 | 2020-01-14 22:37:58 -0600 | [diff] [blame] | 175 | static async parse(compiler) { |
Rubén Rincón Blanco | ccff4b9 | 2020-08-04 22:39:02 +0200 | [diff] [blame] | 176 | await JavaParser.getOptions(compiler, '-help'); |
Matt Godbolt | 03a3fb3 | 2020-01-14 22:37:58 -0600 | [diff] [blame] | 177 | return compiler; |
Christian Vonrüti | 92914a7 | 2019-05-26 19:16:14 +0200 | [diff] [blame] | 178 | } |
| 179 | } |
| 180 | |
Daniel Below | b4ebb47 | 2021-06-02 22:58:41 +0200 | [diff] [blame] | 181 | export class KotlinParser extends BaseParser { |
| 182 | static async parse(compiler) { |
| 183 | await KotlinParser.getOptions(compiler, '-help'); |
| 184 | return compiler; |
| 185 | } |
| 186 | } |
| 187 | |
Oleksandr | d1da148 | 2021-06-29 10:39:06 +0300 | [diff] [blame] | 188 | export class ScalaParser extends BaseParser { |
| 189 | static async parse(compiler) { |
| 190 | await ScalaParser.getOptions(compiler, '-help'); |
| 191 | return compiler; |
| 192 | } |
| 193 | } |
| 194 | |
Austin Morton | 044dcfb | 2020-09-26 16:59:26 -0400 | [diff] [blame] | 195 | export class VCParser extends BaseParser { |
Matt Godbolt | 03a3fb3 | 2020-01-14 22:37:58 -0600 | [diff] [blame] | 196 | static async parse(compiler) { |
Rubén Rincón Blanco | ccff4b9 | 2020-08-04 22:39:02 +0200 | [diff] [blame] | 197 | await VCParser.getOptions(compiler, '/help'); |
Matt Godbolt | 03a3fb3 | 2020-01-14 22:37:58 -0600 | [diff] [blame] | 198 | return compiler; |
Partouf | 96e8d72 | 2018-11-10 01:05:11 +0100 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | static parseLines(stdout, optionRegex) { |
| 202 | let previousOption = false; |
| 203 | let options = {}; |
| 204 | |
| 205 | const matchLine = (line) => { |
Rubén Rincón Blanco | ccff4b9 | 2020-08-04 22:39:02 +0200 | [diff] [blame] | 206 | if (line.startsWith('/?')) return; |
Partouf | 96e8d72 | 2018-11-10 01:05:11 +0100 | [diff] [blame] | 207 | |
| 208 | const match = line.match(optionRegex); |
| 209 | if (!match) { |
Matt Godbolt | a465962 | 2021-05-27 23:17:13 -0500 | [diff] [blame] | 210 | if (previousOption && (line.trim().length > 0)) { |
Rubén Rincón Blanco | ccff4b9 | 2020-08-04 22:39:02 +0200 | [diff] [blame] | 211 | if (options[previousOption].description.endsWith(':')) |
| 212 | options[previousOption].description += ' ' + line.trim(); |
Partouf | 96e8d72 | 2018-11-10 01:05:11 +0100 | [diff] [blame] | 213 | else { |
Matt Godbolt | a465962 | 2021-05-27 23:17:13 -0500 | [diff] [blame] | 214 | if (options[previousOption].description.length > 0) |
Rubén Rincón Blanco | ccff4b9 | 2020-08-04 22:39:02 +0200 | [diff] [blame] | 215 | options[previousOption].description += ', ' + line.trim(); |
Partouf | 96e8d72 | 2018-11-10 01:05:11 +0100 | [diff] [blame] | 216 | else |
| 217 | options[previousOption].description = line.trim(); |
| 218 | } |
| 219 | } else { |
| 220 | previousOption = false; |
| 221 | } |
| 222 | return; |
| 223 | } |
| 224 | |
| 225 | if (match) previousOption = match[1]; |
| 226 | if (previousOption) { |
| 227 | options[previousOption] = { |
| 228 | description: match[2].trim(), |
Rubén Rincón Blanco | ccff4b9 | 2020-08-04 22:39:02 +0200 | [diff] [blame] | 229 | timesused: 0, |
Partouf | 96e8d72 | 2018-11-10 01:05:11 +0100 | [diff] [blame] | 230 | }; |
| 231 | } |
| 232 | }; |
Matt Godbolt | 03a3fb3 | 2020-01-14 22:37:58 -0600 | [diff] [blame] | 233 | |
Partouf | 96e8d72 | 2018-11-10 01:05:11 +0100 | [diff] [blame] | 234 | utils.eachLine(stdout, line => { |
| 235 | if (line.length === 0) return; |
Rubén Rincón Blanco | ccff4b9 | 2020-08-04 22:39:02 +0200 | [diff] [blame] | 236 | if (line.includes('C/C++ COMPILER OPTIONS')) return; |
Matt Godbolt | 4e36d20 | 2021-05-27 23:19:32 -0500 | [diff] [blame] | 237 | if (/^\s+-.*-$/.test(line)) return; |
Partouf | 96e8d72 | 2018-11-10 01:05:11 +0100 | [diff] [blame] | 238 | |
| 239 | let col1; |
| 240 | let col2; |
| 241 | if ((line.length > 39) && (line[40] === '/')) { |
| 242 | col1 = line.substr(0, 39); |
| 243 | col2 = line.substr(40); |
| 244 | } else { |
| 245 | col1 = line; |
Rubén Rincón Blanco | ccff4b9 | 2020-08-04 22:39:02 +0200 | [diff] [blame] | 246 | col2 = ''; |
Partouf | 96e8d72 | 2018-11-10 01:05:11 +0100 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | if (col1) matchLine(col1); |
| 250 | if (col2) matchLine(col2); |
| 251 | }); |
| 252 | |
| 253 | return options; |
| 254 | } |
| 255 | |
Matt Godbolt | 03a3fb3 | 2020-01-14 22:37:58 -0600 | [diff] [blame] | 256 | static async getOptions(compiler, helpArg) { |
| 257 | const result = await compiler.execCompilerCached(compiler.compiler.exe, [helpArg]); |
Rubén Rincón Blanco | ccff4b9 | 2020-08-04 22:39:02 +0200 | [diff] [blame] | 258 | const optionFinder = /^\s*(\/[\w#+,.:<=>[\]{|}-]*)\s*(.*)/i; |
Matt Godbolt | 03a3fb3 | 2020-01-14 22:37:58 -0600 | [diff] [blame] | 259 | const options = result.code === 0 |
| 260 | ? this.parseLines(result.stdout, optionFinder) : {}; |
| 261 | compiler.possibleArguments.populateOptions(options); |
| 262 | return options; |
jaredwy | 13cd0fd | 2017-07-03 17:42:27 +1000 | [diff] [blame] | 263 | } |
| 264 | } |
| 265 | |
Austin Morton | 044dcfb | 2020-09-26 16:59:26 -0400 | [diff] [blame] | 266 | export class RustParser extends BaseParser { |
Matt Godbolt | 03a3fb3 | 2020-01-14 22:37:58 -0600 | [diff] [blame] | 267 | static async parse(compiler) { |
| 268 | const results = await Promise.all([ |
Rubén Rincón Blanco | ccff4b9 | 2020-08-04 22:39:02 +0200 | [diff] [blame] | 269 | RustParser.getOptions(compiler, '--help'), |
| 270 | RustParser.getOptions(compiler, '-C help'), |
| 271 | RustParser.getOptions(compiler, '--help -v'), |
Matt Godbolt | 03a3fb3 | 2020-01-14 22:37:58 -0600 | [diff] [blame] | 272 | ]); |
| 273 | const options = Object.assign({}, ...results); |
Rubén Rincón Blanco | ccff4b9 | 2020-08-04 22:39:02 +0200 | [diff] [blame] | 274 | if (BaseParser.hasSupport(options, '--color')) { |
| 275 | if (compiler.compiler.options) compiler.compiler.options += ' '; |
| 276 | compiler.compiler.options += '--color=always'; |
Matt Godbolt | 03a3fb3 | 2020-01-14 22:37:58 -0600 | [diff] [blame] | 277 | } |
| 278 | return compiler; |
Partouf | fb286bd | 2019-08-08 17:19:20 +0200 | [diff] [blame] | 279 | } |
| 280 | |
Matt Godbolt | 03a3fb3 | 2020-01-14 22:37:58 -0600 | [diff] [blame] | 281 | static async getOptions(compiler, helpArg) { |
| 282 | const result = await compiler.execCompilerCached(compiler.compiler.exe, helpArg.split(' ')); |
| 283 | let options = {}; |
| 284 | if (result.code === 0) { |
Rubén Rincón Blanco | ccff4b9 | 2020-08-04 22:39:02 +0200 | [diff] [blame] | 285 | if (helpArg === '-C help') { |
| 286 | const optionFinder = /^\s*(-c\s*[\d=a-z-]*)\s--\s(.*)/i; |
Partouf | fb286bd | 2019-08-08 17:19:20 +0200 | [diff] [blame] | 287 | |
Matt Godbolt | 03a3fb3 | 2020-01-14 22:37:58 -0600 | [diff] [blame] | 288 | options = BaseParser.parseLines(result.stdout + result.stderr, optionFinder); |
| 289 | } else { |
Rubén Rincón Blanco | ccff4b9 | 2020-08-04 22:39:02 +0200 | [diff] [blame] | 290 | const optionFinder = /^\s*(--?[\d+,<=>[\]a-z|-]*)\s*(.*)/i; |
Partouf | fb286bd | 2019-08-08 17:19:20 +0200 | [diff] [blame] | 291 | |
Matt Godbolt | 03a3fb3 | 2020-01-14 22:37:58 -0600 | [diff] [blame] | 292 | options = BaseParser.parseLines(result.stdout + result.stderr, optionFinder); |
Partouf | fb286bd | 2019-08-08 17:19:20 +0200 | [diff] [blame] | 293 | } |
Matt Godbolt | 03a3fb3 | 2020-01-14 22:37:58 -0600 | [diff] [blame] | 294 | } |
| 295 | compiler.possibleArguments.populateOptions(options); |
| 296 | return options; |
Partouf | fb286bd | 2019-08-08 17:19:20 +0200 | [diff] [blame] | 297 | } |
| 298 | } |
| 299 | |
Marc Poulhiès | b283b7e | 2021-05-27 21:51:33 +0200 | [diff] [blame] | 300 | export class MrustcParser extends BaseParser { |
| 301 | static async parse(compiler) { |
| 302 | await MrustcParser.getOptions(compiler, '--help'); |
| 303 | return compiler; |
| 304 | } |
| 305 | } |
| 306 | |
Austin Morton | 044dcfb | 2020-09-26 16:59:26 -0400 | [diff] [blame] | 307 | export class NimParser extends BaseParser { |
Matt Godbolt | 03a3fb3 | 2020-01-14 22:37:58 -0600 | [diff] [blame] | 308 | static async parse(compiler) { |
Rubén Rincón Blanco | ccff4b9 | 2020-08-04 22:39:02 +0200 | [diff] [blame] | 309 | await NimParser.getOptions(compiler, '-help'); |
Matt Godbolt | 03a3fb3 | 2020-01-14 22:37:58 -0600 | [diff] [blame] | 310 | return compiler; |
bastien penavayre | 3492287 | 2019-12-24 13:33:11 +0100 | [diff] [blame] | 311 | } |
| 312 | } |
Quinton Miller | 94ecb09 | 2021-07-08 06:23:48 +0800 | [diff] [blame] | 313 | |
| 314 | export class CrystalParser extends BaseParser { |
| 315 | static async parse(compiler) { |
| 316 | await CrystalParser.getOptions(compiler, 'build'); |
| 317 | return compiler; |
| 318 | } |
| 319 | } |