Move new WGSL AST fuzzer.
This CL moves the WGSL AST fuzzer up a level and uses the
`tint::wgsl::writer::Generate` method instead of calling the
`ASTPrinter::Generate` directly.
Change-Id: I43248ae467176cee3d1bfcc1b3e6b2089cafb193
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/167740
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
diff --git a/src/tint/cmd/fuzz/wgsl/BUILD.cmake b/src/tint/cmd/fuzz/wgsl/BUILD.cmake
index 4da9274..b0546c5 100644
--- a/src/tint/cmd/fuzz/wgsl/BUILD.cmake
+++ b/src/tint/cmd/fuzz/wgsl/BUILD.cmake
@@ -88,7 +88,7 @@
if(TINT_BUILD_WGSL_WRITER)
tint_target_add_dependencies(tint_cmd_fuzz_wgsl_fuzz_cmd fuzz_cmd
- tint_lang_wgsl_writer_ast_printer_fuzz
+ tint_lang_wgsl_writer_fuzz
)
endif(TINT_BUILD_WGSL_WRITER)
diff --git a/src/tint/cmd/fuzz/wgsl/BUILD.gn b/src/tint/cmd/fuzz/wgsl/BUILD.gn
index f4bec4d..5dc14cb 100644
--- a/src/tint/cmd/fuzz/wgsl/BUILD.gn
+++ b/src/tint/cmd/fuzz/wgsl/BUILD.gn
@@ -122,7 +122,7 @@
}
if (tint_build_wgsl_writer) {
- deps += [ "${tint_src_dir}/lang/wgsl/writer/ast_printer:fuzz" ]
+ deps += [ "${tint_src_dir}/lang/wgsl/writer:fuzz" ]
}
}
}
diff --git a/src/tint/lang/wgsl/writer/BUILD.bazel b/src/tint/lang/wgsl/writer/BUILD.bazel
index ff06810..44c5f29 100644
--- a/src/tint/lang/wgsl/writer/BUILD.bazel
+++ b/src/tint/lang/wgsl/writer/BUILD.bazel
@@ -129,6 +129,11 @@
)
alias(
+ name = "tint_build_wgsl_reader",
+ actual = "//src/tint:tint_build_wgsl_reader_true",
+)
+
+alias(
name = "tint_build_wgsl_writer",
actual = "//src/tint:tint_build_wgsl_writer_true",
)
diff --git a/src/tint/lang/wgsl/writer/BUILD.cmake b/src/tint/lang/wgsl/writer/BUILD.cmake
index 4e172c8..5305a89 100644
--- a/src/tint/lang/wgsl/writer/BUILD.cmake
+++ b/src/tint/lang/wgsl/writer/BUILD.cmake
@@ -139,4 +139,56 @@
)
endif(TINT_BUILD_WGSL_WRITER)
+endif(TINT_BUILD_WGSL_WRITER)
+if(TINT_BUILD_WGSL_WRITER)
+################################################################################
+# Target: tint_lang_wgsl_writer_fuzz
+# Kind: fuzz
+# Condition: TINT_BUILD_WGSL_WRITER
+################################################################################
+tint_add_target(tint_lang_wgsl_writer_fuzz fuzz
+)
+
+tint_target_add_dependencies(tint_lang_wgsl_writer_fuzz fuzz
+ tint_lang_core
+ tint_lang_core_constant
+ tint_lang_core_type
+ tint_lang_wgsl
+ tint_lang_wgsl_ast
+ tint_lang_wgsl_common
+ tint_lang_wgsl_features
+ tint_lang_wgsl_program
+ tint_lang_wgsl_sem
+ tint_lang_wgsl_writer_ir_to_program
+ tint_utils_bytes
+ tint_utils_containers
+ tint_utils_diagnostic
+ tint_utils_ice
+ tint_utils_id
+ tint_utils_macros
+ tint_utils_math
+ tint_utils_memory
+ tint_utils_reflection
+ tint_utils_result
+ tint_utils_rtti
+ tint_utils_symbol
+ tint_utils_text
+ tint_utils_traits
+)
+
+if(TINT_BUILD_WGSL_READER)
+ tint_target_add_sources(tint_lang_wgsl_writer_fuzz fuzz
+ "lang/wgsl/writer/writer_fuzz.cc"
+ )
+ tint_target_add_dependencies(tint_lang_wgsl_writer_fuzz fuzz
+ tint_cmd_fuzz_wgsl_fuzz
+ )
+endif(TINT_BUILD_WGSL_READER)
+
+if(TINT_BUILD_WGSL_WRITER)
+ tint_target_add_dependencies(tint_lang_wgsl_writer_fuzz fuzz
+ tint_lang_wgsl_writer
+ )
+endif(TINT_BUILD_WGSL_WRITER)
+
endif(TINT_BUILD_WGSL_WRITER)
\ No newline at end of file
diff --git a/src/tint/lang/wgsl/writer/BUILD.gn b/src/tint/lang/wgsl/writer/BUILD.gn
index 107e29b..f7afabd 100644
--- a/src/tint/lang/wgsl/writer/BUILD.gn
+++ b/src/tint/lang/wgsl/writer/BUILD.gn
@@ -125,3 +125,43 @@
}
}
}
+if (tint_build_wgsl_writer) {
+ tint_fuzz_source_set("fuzz") {
+ sources = []
+ deps = [
+ "${tint_src_dir}/lang/core",
+ "${tint_src_dir}/lang/core/constant",
+ "${tint_src_dir}/lang/core/type",
+ "${tint_src_dir}/lang/wgsl",
+ "${tint_src_dir}/lang/wgsl/ast",
+ "${tint_src_dir}/lang/wgsl/common",
+ "${tint_src_dir}/lang/wgsl/features",
+ "${tint_src_dir}/lang/wgsl/program",
+ "${tint_src_dir}/lang/wgsl/sem",
+ "${tint_src_dir}/lang/wgsl/writer/ir_to_program",
+ "${tint_src_dir}/utils/bytes",
+ "${tint_src_dir}/utils/containers",
+ "${tint_src_dir}/utils/diagnostic",
+ "${tint_src_dir}/utils/ice",
+ "${tint_src_dir}/utils/id",
+ "${tint_src_dir}/utils/macros",
+ "${tint_src_dir}/utils/math",
+ "${tint_src_dir}/utils/memory",
+ "${tint_src_dir}/utils/reflection",
+ "${tint_src_dir}/utils/result",
+ "${tint_src_dir}/utils/rtti",
+ "${tint_src_dir}/utils/symbol",
+ "${tint_src_dir}/utils/text",
+ "${tint_src_dir}/utils/traits",
+ ]
+
+ if (tint_build_wgsl_reader) {
+ sources += [ "writer_fuzz.cc" ]
+ deps += [ "${tint_src_dir}/cmd/fuzz/wgsl:fuzz" ]
+ }
+
+ if (tint_build_wgsl_writer) {
+ deps += [ "${tint_src_dir}/lang/wgsl/writer" ]
+ }
+ }
+}
diff --git a/src/tint/lang/wgsl/writer/ast_printer/BUILD.bazel b/src/tint/lang/wgsl/writer/ast_printer/BUILD.bazel
index fa899681..f4308d6 100644
--- a/src/tint/lang/wgsl/writer/ast_printer/BUILD.bazel
+++ b/src/tint/lang/wgsl/writer/ast_printer/BUILD.bazel
@@ -146,11 +146,6 @@
)
alias(
- name = "tint_build_wgsl_reader",
- actual = "//src/tint:tint_build_wgsl_reader_true",
-)
-
-alias(
name = "tint_build_wgsl_writer",
actual = "//src/tint:tint_build_wgsl_writer_true",
)
diff --git a/src/tint/lang/wgsl/writer/ast_printer/BUILD.cmake b/src/tint/lang/wgsl/writer/ast_printer/BUILD.cmake
index 11af11b..1f2d210 100644
--- a/src/tint/lang/wgsl/writer/ast_printer/BUILD.cmake
+++ b/src/tint/lang/wgsl/writer/ast_printer/BUILD.cmake
@@ -150,54 +150,4 @@
)
endif(TINT_BUILD_WGSL_WRITER)
-endif(TINT_BUILD_WGSL_WRITER)
-if(TINT_BUILD_WGSL_WRITER)
-################################################################################
-# Target: tint_lang_wgsl_writer_ast_printer_fuzz
-# Kind: fuzz
-# Condition: TINT_BUILD_WGSL_WRITER
-################################################################################
-tint_add_target(tint_lang_wgsl_writer_ast_printer_fuzz fuzz
-)
-
-tint_target_add_dependencies(tint_lang_wgsl_writer_ast_printer_fuzz fuzz
- tint_lang_core
- tint_lang_core_constant
- tint_lang_core_type
- tint_lang_wgsl
- tint_lang_wgsl_ast
- tint_lang_wgsl_program
- tint_lang_wgsl_sem
- tint_utils_bytes
- tint_utils_containers
- tint_utils_diagnostic
- tint_utils_generator
- tint_utils_ice
- tint_utils_id
- tint_utils_macros
- tint_utils_math
- tint_utils_memory
- tint_utils_reflection
- tint_utils_result
- tint_utils_rtti
- tint_utils_symbol
- tint_utils_text
- tint_utils_traits
-)
-
-if(TINT_BUILD_WGSL_READER)
- tint_target_add_sources(tint_lang_wgsl_writer_ast_printer_fuzz fuzz
- "lang/wgsl/writer/ast_printer/ast_printer_fuzz.cc"
- )
- tint_target_add_dependencies(tint_lang_wgsl_writer_ast_printer_fuzz fuzz
- tint_cmd_fuzz_wgsl_fuzz
- )
-endif(TINT_BUILD_WGSL_READER)
-
-if(TINT_BUILD_WGSL_WRITER)
- tint_target_add_dependencies(tint_lang_wgsl_writer_ast_printer_fuzz fuzz
- tint_lang_wgsl_writer_ast_printer
- )
-endif(TINT_BUILD_WGSL_WRITER)
-
endif(TINT_BUILD_WGSL_WRITER)
\ No newline at end of file
diff --git a/src/tint/lang/wgsl/writer/ast_printer/BUILD.gn b/src/tint/lang/wgsl/writer/ast_printer/BUILD.gn
index dd5524f..796fc83 100644
--- a/src/tint/lang/wgsl/writer/ast_printer/BUILD.gn
+++ b/src/tint/lang/wgsl/writer/ast_printer/BUILD.gn
@@ -145,41 +145,3 @@
}
}
}
-if (tint_build_wgsl_writer) {
- tint_fuzz_source_set("fuzz") {
- sources = []
- deps = [
- "${tint_src_dir}/lang/core",
- "${tint_src_dir}/lang/core/constant",
- "${tint_src_dir}/lang/core/type",
- "${tint_src_dir}/lang/wgsl",
- "${tint_src_dir}/lang/wgsl/ast",
- "${tint_src_dir}/lang/wgsl/program",
- "${tint_src_dir}/lang/wgsl/sem",
- "${tint_src_dir}/utils/bytes",
- "${tint_src_dir}/utils/containers",
- "${tint_src_dir}/utils/diagnostic",
- "${tint_src_dir}/utils/generator",
- "${tint_src_dir}/utils/ice",
- "${tint_src_dir}/utils/id",
- "${tint_src_dir}/utils/macros",
- "${tint_src_dir}/utils/math",
- "${tint_src_dir}/utils/memory",
- "${tint_src_dir}/utils/reflection",
- "${tint_src_dir}/utils/result",
- "${tint_src_dir}/utils/rtti",
- "${tint_src_dir}/utils/symbol",
- "${tint_src_dir}/utils/text",
- "${tint_src_dir}/utils/traits",
- ]
-
- if (tint_build_wgsl_reader) {
- sources += [ "ast_printer_fuzz.cc" ]
- deps += [ "${tint_src_dir}/cmd/fuzz/wgsl:fuzz" ]
- }
-
- if (tint_build_wgsl_writer) {
- deps += [ "${tint_src_dir}/lang/wgsl/writer/ast_printer" ]
- }
- }
-}
diff --git a/src/tint/lang/wgsl/writer/writer.h b/src/tint/lang/wgsl/writer/writer.h
index 64a1525..604ace2 100644
--- a/src/tint/lang/wgsl/writer/writer.h
+++ b/src/tint/lang/wgsl/writer/writer.h
@@ -28,12 +28,9 @@
#ifndef SRC_TINT_LANG_WGSL_WRITER_WRITER_H_
#define SRC_TINT_LANG_WGSL_WRITER_WRITER_H_
-#include <string>
-
#include "src/tint/lang/wgsl/writer/ir_to_program/program_options.h"
#include "src/tint/lang/wgsl/writer/options.h"
#include "src/tint/lang/wgsl/writer/output.h"
-#include "src/tint/utils/diagnostic/diagnostic.h"
#include "src/tint/utils/result/result.h"
// Forward declarations
diff --git a/src/tint/lang/wgsl/writer/ast_printer/ast_printer_fuzz.cc b/src/tint/lang/wgsl/writer/writer_fuzz.cc
similarity index 85%
rename from src/tint/lang/wgsl/writer/ast_printer/ast_printer_fuzz.cc
rename to src/tint/lang/wgsl/writer/writer_fuzz.cc
index 230ab20..4314774 100644
--- a/src/tint/lang/wgsl/writer/ast_printer/ast_printer_fuzz.cc
+++ b/src/tint/lang/wgsl/writer/writer_fuzz.cc
@@ -1,4 +1,4 @@
-// Copyright 2021 The Dawn & Tint Authors
+// Copyright 2024 The Dawn & Tint Authors
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
@@ -27,18 +27,18 @@
// GEN_BUILD:CONDITION(tint_build_wgsl_reader)
-#include "src/tint/lang/wgsl/writer/ast_printer/ast_printer.h"
+#include "src/tint/lang/wgsl/writer/writer.h"
#include "src/tint/cmd/fuzz/wgsl/fuzz.h"
namespace tint::wgsl::writer {
namespace {
-void ASTPrinterFuzzer(const tint::Program& program) {
- ASTPrinter{program}.Generate();
+void WriterFuzzer(const tint::Program& program) {
+ [[maybe_unused]] auto res = tint::wgsl::writer::Generate(program, {});
}
} // namespace
} // namespace tint::wgsl::writer
-TINT_WGSL_PROGRAM_FUZZER(tint::wgsl::writer::ASTPrinterFuzzer);
+TINT_WGSL_PROGRAM_FUZZER(tint::wgsl::writer::WriterFuzzer);