Ben Clayton | 00b77a8 | 2020-12-04 09:06:09 +0000 | [diff] [blame] | 1 | // 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 Clayton | 0273f1a | 2021-06-30 13:23:36 +0000 | [diff] [blame] | 15 | #ifndef SRC_TRANSFORM_ROBUSTNESS_H_ |
| 16 | #define SRC_TRANSFORM_ROBUSTNESS_H_ |
Ben Clayton | 00b77a8 | 2020-12-04 09:06:09 +0000 | [diff] [blame] | 17 | |
Ben Clayton | 00b77a8 | 2020-12-04 09:06:09 +0000 | [diff] [blame] | 18 | #include "src/transform/transform.h" |
| 19 | |
Ben Clayton | e58ecaa | 2021-06-30 15:04:00 +0000 | [diff] [blame] | 20 | // Forward declarations |
| 21 | namespace tint { |
| 22 | namespace ast { |
| 23 | class ArrayAccessorExpression; |
| 24 | class CallExpression; |
| 25 | } // namespace ast |
| 26 | } // namespace tint |
| 27 | |
Ben Clayton | 00b77a8 | 2020-12-04 09:06:09 +0000 | [diff] [blame] | 28 | namespace tint { |
| 29 | namespace 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 Clayton | 0273f1a | 2021-06-30 13:23:36 +0000 | [diff] [blame] | 35 | class Robustness : public Castable<Robustness, Transform> { |
Ben Clayton | 00b77a8 | 2020-12-04 09:06:09 +0000 | [diff] [blame] | 36 | public: |
| 37 | /// Constructor |
Ben Clayton | 0273f1a | 2021-06-30 13:23:36 +0000 | [diff] [blame] | 38 | Robustness(); |
Ben Clayton | 00b77a8 | 2020-12-04 09:06:09 +0000 | [diff] [blame] | 39 | /// Destructor |
Ben Clayton | 0273f1a | 2021-06-30 13:23:36 +0000 | [diff] [blame] | 40 | ~Robustness() override; |
Ben Clayton | 00b77a8 | 2020-12-04 09:06:09 +0000 | [diff] [blame] | 41 | |
Ben Clayton | b5cd10c | 2021-06-25 10:26:26 +0000 | [diff] [blame] | 42 | 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 Clayton | 00b77a8 | 2020-12-04 09:06:09 +0000 | [diff] [blame] | 50 | |
| 51 | private: |
Ben Clayton | 1d10086 | 2021-07-15 16:41:05 +0000 | [diff] [blame] | 52 | struct State; |
Ben Clayton | 00b77a8 | 2020-12-04 09:06:09 +0000 | [diff] [blame] | 53 | }; |
| 54 | |
Ben Clayton | 0273f1a | 2021-06-30 13:23:36 +0000 | [diff] [blame] | 55 | using BoundArrayAccessors = Robustness; |
| 56 | |
Ben Clayton | 00b77a8 | 2020-12-04 09:06:09 +0000 | [diff] [blame] | 57 | } // namespace transform |
| 58 | } // namespace tint |
| 59 | |
Ben Clayton | 0273f1a | 2021-06-30 13:23:36 +0000 | [diff] [blame] | 60 | #endif // SRC_TRANSFORM_ROBUSTNESS_H_ |