tint: Refactor Extensions / Enables.
* Extract ast::Enable::ExtensionKind to ast::Extension.
* Move the parsing out of ast::Enable and next to ast/extension.h
* Change the ast::Enable constructor to take the Extension, instead of
a std::string. It's the WGSL parser's responsibility to parse, not the
AST nodes.
* Add ProgramBuilder::Enable() helper.
* Keep ast::Module simple - keep track of the declared AST Enable nodes,
don't do any deduplicating of the enabled extensions.
* Add the de-duplicated ast::Extensions to the sem::Module.
* Remove the kInternalExtensionForTesting enum value - we have kF16
now, which can be used instead for testing.
* Rename kNoExtension to kNone.
Bug: tint:1472
Change-Id: I9af635e95d36991ea468e6e0bf6798bb50937edc
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/90523
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
diff --git a/src/tint/program_builder.h b/src/tint/program_builder.h
index a91d87c..32c0e93 100644
--- a/src/tint/program_builder.h
+++ b/src/tint/program_builder.h
@@ -39,6 +39,7 @@
#include "src/tint/ast/disable_validation_attribute.h"
#include "src/tint/ast/discard_statement.h"
#include "src/tint/ast/enable.h"
+#include "src/tint/ast/extension.h"
#include "src/tint/ast/external_texture.h"
#include "src/tint/ast/f16.h"
#include "src/tint/ast/f32.h"
@@ -1307,6 +1308,15 @@
return Construct(ty.array(subtype, std::forward<EXPR>(n)), std::forward<ARGS>(args)...);
}
+ /// Adds the extension to the list of enable directives at the top of the module.
+ /// @param ext the extension to enable
+ /// @return an `ast::Enable` enabling the given extension.
+ const ast::Enable* Enable(ast::Extension ext) {
+ auto* enable = create<ast::Enable>(ext);
+ AST().AddEnable(enable);
+ return enable;
+ }
+
/// @param name the variable name
/// @param type the variable type
/// @param optional the optional variable settings.