• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "src/program_id.h"
16 
17 #include <atomic>
18 
19 namespace tint {
20 
21 namespace {
22 
23 std::atomic<uint32_t> next_program_id{1};
24 
25 }  // namespace
26 
27 ProgramID::ProgramID() = default;
28 
ProgramID(uint32_t id)29 ProgramID::ProgramID(uint32_t id) : val(id) {}
30 
New()31 ProgramID ProgramID::New() {
32   return ProgramID(next_program_id++);
33 }
34 
35 namespace detail {
36 
37 /// AssertProgramIDsEqual is called by TINT_ASSERT_PROGRAM_IDS_EQUAL() and
38 /// TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID() to assert that the ProgramIDs
39 /// `a` and `b` are equal.
AssertProgramIDsEqual(ProgramID a,ProgramID b,bool if_valid,diag::System system,const char * msg,const char * file,size_t line)40 void AssertProgramIDsEqual(ProgramID a,
41                            ProgramID b,
42                            bool if_valid,
43                            diag::System system,
44                            const char* msg,
45                            const char* file,
46                            size_t line) {
47   if (a == b) {
48     return;  // matched
49   }
50   if (if_valid && (!a || !b)) {
51     return;  //  a or b were not valid
52   }
53   diag::List diagnostics;
54   tint::InternalCompilerError(file, line, system, diagnostics) << msg;
55 }
56 
57 }  // namespace detail
58 }  // namespace tint
59