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 #ifndef SRC_TRANSFORM_SINGLE_ENTRY_POINT_H_ 16 #define SRC_TRANSFORM_SINGLE_ENTRY_POINT_H_ 17 18 #include <string> 19 20 #include "src/transform/transform.h" 21 22 namespace tint { 23 namespace transform { 24 25 /// Strip all but one entry point a module. 26 /// 27 /// All module-scope variables, types, and functions that are not used by the 28 /// target entry point will also be removed. 29 class SingleEntryPoint : public Castable<SingleEntryPoint, Transform> { 30 public: 31 /// Configuration options for the transform 32 struct Config : public Castable<Config, Data> { 33 /// Constructor 34 /// @param entry_point the name of the entry point to keep 35 explicit Config(std::string entry_point = ""); 36 37 /// Copy constructor 38 Config(const Config&); 39 40 /// Destructor 41 ~Config() override; 42 43 /// Assignment operator 44 /// @returns this Config 45 Config& operator=(const Config&); 46 47 /// The name of the entry point to keep. 48 std::string entry_point_name; 49 }; 50 51 /// Constructor 52 SingleEntryPoint(); 53 54 /// Destructor 55 ~SingleEntryPoint() override; 56 57 protected: 58 /// Runs the transform using the CloneContext built for transforming a 59 /// program. Run() is responsible for calling Clone() on the CloneContext. 60 /// @param ctx the CloneContext primed with the input program and 61 /// ProgramBuilder 62 /// @param inputs optional extra transform-specific input data 63 /// @param outputs optional extra transform-specific output data 64 void Run(CloneContext& ctx, const DataMap& inputs, DataMap& outputs) override; 65 }; 66 67 } // namespace transform 68 } // namespace tint 69 70 #endif // SRC_TRANSFORM_SINGLE_ENTRY_POINT_H_ 71