aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCassandra Beckley <cbeckley@google.com>2023-10-22 03:17:24 -0700
committerGitHub <noreply@github.com>2023-10-22 12:17:24 +0200
commitd23bbc65967f99ab3a30b2735cb13638cb2e59b1 (patch)
treeee216c29c306ce80a4705b17188075252f6adfee
parentbd164adf149d3641145642ef29a17f099a691431 (diff)
downloadcompiler-explorer-gh-9164.tar.gz
compiler-explorer-gh-9164.zip
Add AST viewer support for HLSL/DXC (#5627)gh-9164
<!-- THIS COMMENT IS INVISIBLE IN THE FINAL PR, BUT FEEL FREE TO REMOVE IT Thanks for taking the time to improve CE. We really appreciate it. Before opening the PR, please make sure that the tests & linter pass their checks, by running `make check`. In the best case scenario, you are also adding tests to back up your changes, but don't sweat it if you don't. We can discuss them at a later date. Feel free to append your name to the CONTRIBUTORS.md file Thanks again, we really appreciate this! --> Since DXC is a fork of Clang from LLVM 3.7, the AST can be generated and parsed in a manner similar to the Clang AST.
-rw-r--r--lib/compilers/hlsl.ts20
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/compilers/hlsl.ts b/lib/compilers/hlsl.ts
index 7050355c1..26d5423b1 100644
--- a/lib/compilers/hlsl.ts
+++ b/lib/compilers/hlsl.ts
@@ -23,6 +23,7 @@
// POSSIBILITY OF SUCH DAMAGE.
import path from 'path';
+import _ from 'underscore';
import type {ParseFiltersAndOutputOptions} from '../../types/features/filters.interfaces.js';
import {BaseCompiler} from '../base-compiler.js';
@@ -41,6 +42,25 @@ export class HLSLCompiler extends BaseCompiler {
this.spirvAsm = new SPIRVAsmParser(this.compilerProps);
}
+ override async generateAST(inputFilename, options) {
+ // These options make DXC produce an AST dump
+ const newOptions = _.filter(options, option => option !== '-Zi' && option !== '-Qembed_debug').concat([
+ '-ast-dump',
+ ]);
+
+ const execOptions = this.getDefaultExecOptions();
+ // A higher max output is needed for when the user includes headers
+ execOptions.maxOutput = 1024 * 1024 * 1024;
+
+ return this.llvmAst.processAst(
+ await this.runCompiler(this.compiler.exe, newOptions, this.filename(inputFilename), execOptions),
+ );
+ }
+
+ override couldSupportASTDump(version: string) {
+ return version.includes('libdxcompiler');
+ }
+
/* eslint-disable no-unused-vars */
override optionsForFilter(
filters: ParseFiltersAndOutputOptions,