blob: a4478f15f71694c88c05d9fa1e4864e60f3f83a0 [file] [log] [blame]
Ben Clayton00b77a82020-12-04 09:06:09 +00001// Copyright 2020 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
Ben Clayton0273f1a2021-06-30 13:23:36 +000015#ifndef SRC_TRANSFORM_ROBUSTNESS_H_
16#define SRC_TRANSFORM_ROBUSTNESS_H_
Ben Clayton00b77a82020-12-04 09:06:09 +000017
Ben Clayton00b77a82020-12-04 09:06:09 +000018#include "src/transform/transform.h"
19
Ben Claytone58ecaa2021-06-30 15:04:00 +000020// Forward declarations
21namespace tint {
22namespace ast {
23class ArrayAccessorExpression;
24class CallExpression;
25} // namespace ast
26} // namespace tint
27
Ben Clayton00b77a82020-12-04 09:06:09 +000028namespace tint {
29namespace transform {
30
31/// This transform is responsible for clamping all array accesses to be within
32/// the bounds of the array. Any access before the start of the array will clamp
33/// to zero and any access past the end of the array will clamp to
34/// (array length - 1).
Ben Clayton0273f1a2021-06-30 13:23:36 +000035class Robustness : public Castable<Robustness, Transform> {
Ben Clayton00b77a82020-12-04 09:06:09 +000036 public:
37 /// Constructor
Ben Clayton0273f1a2021-06-30 13:23:36 +000038 Robustness();
Ben Clayton00b77a82020-12-04 09:06:09 +000039 /// Destructor
Ben Clayton0273f1a2021-06-30 13:23:36 +000040 ~Robustness() override;
Ben Clayton00b77a82020-12-04 09:06:09 +000041
Ben Claytonb5cd10c2021-06-25 10:26:26 +000042 protected:
43 /// Runs the transform using the CloneContext built for transforming a
44 /// program. Run() is responsible for calling Clone() on the CloneContext.
45 /// @param ctx the CloneContext primed with the input program and
46 /// ProgramBuilder
47 /// @param inputs optional extra transform-specific input data
48 /// @param outputs optional extra transform-specific output data
49 void Run(CloneContext& ctx, const DataMap& inputs, DataMap& outputs) override;
Ben Clayton00b77a82020-12-04 09:06:09 +000050
51 private:
Ben Clayton1d100862021-07-15 16:41:05 +000052 struct State;
Ben Clayton00b77a82020-12-04 09:06:09 +000053};
54
Ben Clayton0273f1a2021-06-30 13:23:36 +000055using BoundArrayAccessors = Robustness;
56
Ben Clayton00b77a82020-12-04 09:06:09 +000057} // namespace transform
58} // namespace tint
59
Ben Clayton0273f1a2021-06-30 13:23:36 +000060#endif // SRC_TRANSFORM_ROBUSTNESS_H_