• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2021 The Tint Authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "fuzzers/fuzzer_init.h"
16 #include "fuzzers/random_generator.h"
17 #include "fuzzers/tint_common_fuzzer.h"
18 #include "fuzzers/transform_builder.h"
19 
20 namespace tint {
21 namespace fuzzers {
22 
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)23 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
24   {
25     TransformBuilder tb(data, size);
26     tb.AddPlatformIndependentPasses();
27 
28     fuzzers::CommonFuzzer fuzzer(InputFormat::kWGSL, OutputFormat::kSpv);
29     fuzzer.SetTransformManager(tb.manager(), tb.data_map());
30     fuzzer.SetDumpInput(GetCliParams().dump_input);
31 
32     fuzzer.Run(data, size);
33   }
34 
35 #if TINT_BUILD_HLSL_WRITER
36   {
37     TransformBuilder tb(data, size);
38     tb.AddPlatformIndependentPasses();
39 
40     fuzzers::CommonFuzzer fuzzer(InputFormat::kWGSL, OutputFormat::kHLSL);
41     fuzzer.SetTransformManager(tb.manager(), tb.data_map());
42     fuzzer.SetDumpInput(GetCliParams().dump_input);
43 
44     fuzzer.Run(data, size);
45   }
46 #endif  // TINT_BUILD_HLSL_WRITER
47 
48 #if TINT_BUILD_MSL_WRITER
49   {
50     TransformBuilder tb(data, size);
51     tb.AddPlatformIndependentPasses();
52 
53     fuzzers::CommonFuzzer fuzzer(InputFormat::kWGSL, OutputFormat::kMSL);
54     fuzzer.SetTransformManager(tb.manager(), tb.data_map());
55     fuzzer.SetDumpInput(GetCliParams().dump_input);
56 
57     fuzzer.Run(data, size);
58   }
59 #endif  // TINT_BUILD_MSL_WRITER
60 #if TINT_BUILD_SPV_WRITER
61   {
62     TransformBuilder tb(data, size);
63     tb.AddPlatformIndependentPasses();
64 
65     fuzzers::CommonFuzzer fuzzer(InputFormat::kWGSL, OutputFormat::kSpv);
66     fuzzer.SetTransformManager(tb.manager(), tb.data_map());
67     fuzzer.SetDumpInput(GetCliParams().dump_input);
68 
69     fuzzer.Run(data, size);
70   }
71 #endif  // TINT_BUILD_SPV_WRITER
72 
73   return 0;
74 }
75 
76 }  // namespace fuzzers
77 }  // namespace tint
78