| // Copyright 2023 The Tint Authors. |
| // |
| // Licensed under the Apache License, Version 2.0 (the "License"); |
| // you may not use this file except in compliance with the License. |
| // You may obtain a copy of the License at |
| // |
| // http://www.apache.org/licenses/LICENSE-2.0 |
| // |
| // Unless required by applicable law or agreed to in writing, software |
| // distributed under the License is distributed on an "AS IS" BASIS, |
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| // See the License for the specific language governing permissions and |
| // limitations under the License. |
| |
| #include "src/tint/writer/spirv/test_helper_ir.h" |
| |
| namespace tint::writer::spirv { |
| namespace { |
| |
| TEST_F(SpvGeneratorImplTest, Function_Empty) { |
| auto* func = CreateFunction(); |
| func->name = ir.symbols.Register("foo"); |
| func->return_type = ir.types.Get<type::Void>(); |
| |
| generator_.EmitFunction(func); |
| EXPECT_EQ(DumpModule(generator_.Module()), R"(OpName %1 "foo" |
| %2 = OpTypeVoid |
| %3 = OpTypeFunction %2 |
| %1 = OpFunction %2 None %3 |
| %4 = OpLabel |
| OpReturn |
| OpFunctionEnd |
| )"); |
| } |
| |
| // Test that we do not emit the same function type more than once. |
| TEST_F(SpvGeneratorImplTest, Function_DeduplicateType) { |
| auto* func = CreateFunction(); |
| func->return_type = ir.types.Get<type::Void>(); |
| |
| generator_.EmitFunction(func); |
| generator_.EmitFunction(func); |
| generator_.EmitFunction(func); |
| EXPECT_EQ(DumpTypes(), R"(%2 = OpTypeVoid |
| %3 = OpTypeFunction %2 |
| )"); |
| } |
| |
| } // namespace |
| } // namespace tint::writer::spirv |