aboutsummaryrefslogtreecommitdiff
path: root/lib/compilers
diff options
context:
space:
mode:
authorDavid Spickett <david.spickett@linaro.org>2023-11-04 19:54:43 +0000
committerGitHub <noreply@github.com>2023-11-04 20:54:43 +0100
commit971889e5d77be91b854ab9376613b51d3ea6aec9 (patch)
tree8b4dcfbcc2d9a60576dd185c1b7f58839132a9f8 /lib/compilers
parentbb66fc6a9719f913b01fd6708b5e900329d65e0e (diff)
downloadcompiler-explorer-971889e5d77be91b854ab9376613b51d3ea6aec9.tar.gz
compiler-explorer-971889e5d77be91b854ab9376613b51d3ea6aec9.zip
LLVM TableGen: Add actions to Overrides menu (#5699)gh-9391
Diffstat (limited to 'lib/compilers')
-rw-r--r--lib/compilers/argument-parsers.ts35
-rw-r--r--lib/compilers/tablegen.ts24
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();
+ }
}