diff options
Diffstat (limited to 'lib/compilers')
-rw-r--r-- | lib/compilers/argument-parsers.ts | 35 | ||||
-rw-r--r-- | lib/compilers/tablegen.ts | 24 |
2 files changed, 59 insertions, 0 deletions
diff --git a/lib/compilers/argument-parsers.ts b/lib/compilers/argument-parsers.ts index 4586a7eb4..7ce4bef4f 100644 --- a/lib/compilers/argument-parsers.ts +++ b/lib/compilers/argument-parsers.ts @@ -889,6 +889,41 @@ export class CrystalParser extends BaseParser { } } +export class TableGenParser extends BaseParser { + static async getPossibleActions(compiler): Promise<CompilerOverrideOptions> { + const result = await compiler.execCompilerCached(compiler.compiler.exe, ['--help']); + return this.extractPossibleActions(utils.splitLines(result.stdout)); + } + + static extractPossibleActions(lines: string[]): CompilerOverrideOptions { + const actions: CompilerOverrideOptions = []; + let found_actions = false; + + for (const line of lines) { + // Action options are in a section with this header. + if (line.indexOf('Action to perform:') !== -1) { + found_actions = true; + } else if (found_actions) { + // Actions are indented 6 spaces. The description follows after + // a dash, for example: + // <6 spaces>--do-thing - Description of thing. + const action_match = line.match(/^ {6}(--[^\s]+)\s+-\s+(.+)$/); + // The end of the option section is an option indented only 2 spaces. + if (action_match == null) { + break; + } + + actions.push({ + name: action_match[1].substr(2) + ': ' + action_match[2], + value: action_match[1], + }); + } + } + + return actions; + } +} + export class TypeScriptNativeParser extends BaseParser { static override async parse(compiler) { await this.getOptions(compiler, '--help'); diff --git a/lib/compilers/tablegen.ts b/lib/compilers/tablegen.ts index ea2465000..1ce51f2cc 100644 --- a/lib/compilers/tablegen.ts +++ b/lib/compilers/tablegen.ts @@ -1,5 +1,7 @@ import {BaseCompiler} from '../base-compiler.js'; import type {ParseFiltersAndOutputOptions} from '../../types/features/filters.interfaces.js'; +import {TableGenParser} from './argument-parsers.js'; +import {CompilerOverrideType} from '../../types/compilation/compiler-overrides.interfaces.js'; export class TableGenCompiler extends BaseCompiler { static get key() { @@ -17,4 +19,26 @@ export class TableGenCompiler extends BaseCompiler { override isCfgCompiler() { return false; } + + override getArgumentParser() { + return TableGenParser; + } + + override async populatePossibleOverrides() { + const possibleActions = await TableGenParser.getPossibleActions(this); + if (possibleActions.length > 0) { + this.compiler.possibleOverrides?.push({ + name: CompilerOverrideType.action, + display_title: 'Action', + description: + 'The action to perform, which is the backend you wish to ' + + 'run. By default, the records are just printed as text.', + flags: ['<value>'], + values: possibleActions, + default: '--print-records', + }); + } + + await super.populatePossibleOverrides(); + } } |