[ir] Convert BlockDecoratedStructs to a free function

Bug: tint:1718
Change-Id: I69930e39c5bf1ba1f763f5b0926cd426dff2dbd0
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/143827
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
diff --git a/src/tint/lang/core/ir/transform/block_decorated_structs.cc b/src/tint/lang/core/ir/transform/block_decorated_structs.cc
index 9861231..cb191c6 100644
--- a/src/tint/lang/core/ir/transform/block_decorated_structs.cc
+++ b/src/tint/lang/core/ir/transform/block_decorated_structs.cc
@@ -18,20 +18,17 @@
 
 #include "src/tint/lang/core/ir/builder.h"
 #include "src/tint/lang/core/ir/module.h"
+#include "src/tint/lang/core/ir/validator.h"
 #include "src/tint/lang/core/type/pointer.h"
 #include "src/tint/lang/core/type/struct.h"
 
-TINT_INSTANTIATE_TYPEINFO(tint::ir::transform::BlockDecoratedStructs);
-
 using namespace tint::number_suffixes;  // NOLINT
 
 namespace tint::ir::transform {
 
-BlockDecoratedStructs::BlockDecoratedStructs() = default;
+namespace {
 
-BlockDecoratedStructs::~BlockDecoratedStructs() = default;
-
-void BlockDecoratedStructs::Run(Module* ir) const {
+void Run(Module* ir) {
     Builder builder(*ir);
 
     if (!ir->root_block) {
@@ -112,4 +109,17 @@
     }
 }
 
+}  // namespace
+
+Result<SuccessType, std::string> BlockDecoratedStructs(Module* ir) {
+    auto result = ValidateAndDumpIfNeeded(*ir, "BlockDecoratedStructs transform");
+    if (!result) {
+        return result;
+    }
+
+    Run(ir);
+
+    return Success;
+}
+
 }  // namespace tint::ir::transform
diff --git a/src/tint/lang/core/ir/transform/block_decorated_structs.h b/src/tint/lang/core/ir/transform/block_decorated_structs.h
index 529db18..39f991b 100644
--- a/src/tint/lang/core/ir/transform/block_decorated_structs.h
+++ b/src/tint/lang/core/ir/transform/block_decorated_structs.h
@@ -15,25 +15,23 @@
 #ifndef SRC_TINT_LANG_CORE_IR_TRANSFORM_BLOCK_DECORATED_STRUCTS_H_
 #define SRC_TINT_LANG_CORE_IR_TRANSFORM_BLOCK_DECORATED_STRUCTS_H_
 
-#include "src/tint/lang/core/ir/transform/transform.h"
+#include <string>
 
-#include "src/tint/lang/core/type/struct.h"
+#include "src/tint/utils/result/result.h"
+
+// Forward declarations.
+namespace tint::ir {
+class Module;
+}
 
 namespace tint::ir::transform {
 
 /// BlockDecoratedStructs is a transform that changes the store type of a buffer to be a special
 /// structure that is recognized as needing a block decoration in SPIR-V, potentially wrapping the
 /// existing store type in a new structure if necessary.
-class BlockDecoratedStructs final : public Castable<BlockDecoratedStructs, Transform> {
-  public:
-    /// Constructor
-    BlockDecoratedStructs();
-    /// Destructor
-    ~BlockDecoratedStructs() override;
-
-    /// @copydoc Transform::Run
-    void Run(ir::Module* module) const override;
-};
+/// @param module the module to transform
+/// @returns an error string on failure
+Result<SuccessType, std::string> BlockDecoratedStructs(Module* module);
 
 }  // namespace tint::ir::transform
 
diff --git a/src/tint/lang/core/ir/transform/block_decorated_structs_test.cc b/src/tint/lang/core/ir/transform/block_decorated_structs_test.cc
index 2ee009f..fba58ca 100644
--- a/src/tint/lang/core/ir/transform/block_decorated_structs_test.cc
+++ b/src/tint/lang/core/ir/transform/block_decorated_structs_test.cc
@@ -41,7 +41,7 @@
 }
 )";
 
-    Run<BlockDecoratedStructs>();
+    Run(BlockDecoratedStructs);
 
     EXPECT_EQ(expect, str());
 }
@@ -75,7 +75,7 @@
 }
 )";
 
-    Run<BlockDecoratedStructs>();
+    Run(BlockDecoratedStructs);
 
     EXPECT_EQ(expect, str());
 }
@@ -107,7 +107,7 @@
 }
 )";
 
-    Run<BlockDecoratedStructs>();
+    Run(BlockDecoratedStructs);
 
     EXPECT_EQ(expect, str());
 }
@@ -139,7 +139,7 @@
 }
 )";
 
-    Run<BlockDecoratedStructs>();
+    Run(BlockDecoratedStructs);
 
     EXPECT_EQ(expect, str());
 }
@@ -176,7 +176,7 @@
 }
 )";
 
-    Run<BlockDecoratedStructs>();
+    Run(BlockDecoratedStructs);
 
     EXPECT_EQ(expect, str());
 }
@@ -230,7 +230,7 @@
 }
 )";
 
-    Run<BlockDecoratedStructs>();
+    Run(BlockDecoratedStructs);
 
     EXPECT_EQ(expect, str());
 }
@@ -276,7 +276,7 @@
 }
 )";
 
-    Run<BlockDecoratedStructs>();
+    Run(BlockDecoratedStructs);
 
     EXPECT_EQ(expect, str());
 }
@@ -332,7 +332,7 @@
 }
 )";
 
-    Run<BlockDecoratedStructs>();
+    Run(BlockDecoratedStructs);
 
     EXPECT_EQ(expect, str());
 }
diff --git a/src/tint/lang/spirv/writer/printer/printer.cc b/src/tint/lang/spirv/writer/printer/printer.cc
index e96f5e1..02fa5e5 100644
--- a/src/tint/lang/spirv/writer/printer/printer.cc
+++ b/src/tint/lang/spirv/writer/printer/printer.cc
@@ -106,8 +106,8 @@
     } while (false)
 
     ir::transform::AddEmptyEntryPoint{}.Run(module);
-    ir::transform::BlockDecoratedStructs{}.Run(module);
 
+    RUN_TRANSFORM(BlockDecoratedStructs);
     RUN_TRANSFORM(BuiltinPolyfillSpirv);
     RUN_TRANSFORM(DemoteToHelper);
     RUN_TRANSFORM(ExpandImplicitSplats);