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 15 #ifndef SRC_WRITER_APPEND_VECTOR_H_ 16 #define SRC_WRITER_APPEND_VECTOR_H_ 17 18 #include "src/program_builder.h" 19 20 namespace tint { 21 22 namespace ast { 23 class CallExpression; 24 class Expression; 25 } // namespace ast 26 27 namespace writer { 28 29 /// A helper function used to append a vector with an additional scalar. 30 /// If the scalar's type does not match the target vector element type, 31 /// then it is value-converted (via TypeConstructor) before being added. 32 /// All types must have been assigned to the expressions and their child nodes 33 /// before calling. 34 /// @param builder the program builder. 35 /// @param vector the vector to be appended. May be a scalar, `vec2` or `vec3`. 36 /// @param scalar the scalar to append to the vector. Must be a scalar. 37 /// @returns a vector expression containing the elements of `vector` followed by 38 /// the single element of `scalar` cast to the `vector` element type. 39 const sem::Call* AppendVector(ProgramBuilder* builder, 40 const ast::Expression* vector, 41 const ast::Expression* scalar); 42 43 } // namespace writer 44 } // namespace tint 45 46 #endif // SRC_WRITER_APPEND_VECTOR_H_ 47