mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-20 18:29:23 +00:00
Move atomic to type/
This CL moves atomic to type/ and updates the namespaces. Bug: tint:1718 Change-Id: I3331bc0dfae2ccede52b5589b7d3cc443366096a Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/113424 Commit-Queue: Dan Sinclair <dsinclair@chromium.org> Reviewed-by: Ben Clayton <bclayton@google.com> Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
committed by
Dan Sinclair
parent
0e780da882
commit
d8a084585f
63
src/tint/type/atomic.cc
Normal file
63
src/tint/type/atomic.cc
Normal file
@@ -0,0 +1,63 @@
|
||||
// Copyright 2022 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/type/atomic.h"
|
||||
|
||||
#include "src/tint/program_builder.h"
|
||||
#include "src/tint/type/reference.h"
|
||||
#include "src/tint/utils/hash.h"
|
||||
|
||||
TINT_INSTANTIATE_TYPEINFO(tint::type::Atomic);
|
||||
|
||||
namespace tint::type {
|
||||
|
||||
Atomic::Atomic(const type::Type* subtype)
|
||||
: Base(type::TypeFlags{
|
||||
Flag::kCreationFixedFootprint,
|
||||
Flag::kFixedFootprint,
|
||||
}),
|
||||
subtype_(subtype) {
|
||||
TINT_ASSERT(AST, !subtype->Is<type::Reference>());
|
||||
}
|
||||
|
||||
size_t Atomic::Hash() const {
|
||||
return utils::Hash(TypeInfo::Of<Atomic>().full_hashcode, subtype_);
|
||||
}
|
||||
|
||||
bool Atomic::Equals(const type::Type& other) const {
|
||||
if (auto* o = other.As<Atomic>()) {
|
||||
return o->subtype_ == subtype_;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string Atomic::FriendlyName(const SymbolTable& symbols) const {
|
||||
std::ostringstream out;
|
||||
out << "atomic<" << subtype_->FriendlyName(symbols) << ">";
|
||||
return out.str();
|
||||
}
|
||||
|
||||
uint32_t Atomic::Size() const {
|
||||
return subtype_->Size();
|
||||
}
|
||||
|
||||
uint32_t Atomic::Align() const {
|
||||
return subtype_->Align();
|
||||
}
|
||||
|
||||
Atomic::Atomic(Atomic&&) = default;
|
||||
|
||||
Atomic::~Atomic() = default;
|
||||
|
||||
} // namespace tint::type
|
||||
62
src/tint/type/atomic.h
Normal file
62
src/tint/type/atomic.h
Normal file
@@ -0,0 +1,62 @@
|
||||
// Copyright 2022 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.
|
||||
|
||||
#ifndef SRC_TINT_TYPE_ATOMIC_H_
|
||||
#define SRC_TINT_TYPE_ATOMIC_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "src/tint/type/type.h"
|
||||
|
||||
namespace tint::type {
|
||||
|
||||
/// A atomic type.
|
||||
class Atomic final : public Castable<Atomic, type::Type> {
|
||||
public:
|
||||
/// Constructor
|
||||
/// @param subtype the atomic type
|
||||
explicit Atomic(const type::Type* subtype);
|
||||
|
||||
/// Move constructor
|
||||
Atomic(Atomic&&);
|
||||
~Atomic() override;
|
||||
|
||||
/// @returns a hash of the type.
|
||||
size_t Hash() const override;
|
||||
|
||||
/// @param other the other type to compare against
|
||||
/// @returns true if the this type is equal to the given type
|
||||
bool Equals(const Type& other) const override;
|
||||
|
||||
/// @returns the atomic type
|
||||
const type::Type* Type() const { return subtype_; }
|
||||
|
||||
/// @param symbols the program's symbol table
|
||||
/// @returns the name for this type that closely resembles how it would be
|
||||
/// declared in WGSL.
|
||||
std::string FriendlyName(const SymbolTable& symbols) const override;
|
||||
|
||||
/// @returns the size in bytes of the type.
|
||||
uint32_t Size() const override;
|
||||
|
||||
/// @returns the alignment in bytes of the type.
|
||||
uint32_t Align() const override;
|
||||
|
||||
private:
|
||||
type::Type const* const subtype_;
|
||||
};
|
||||
|
||||
} // namespace tint::type
|
||||
|
||||
#endif // SRC_TINT_TYPE_ATOMIC_H_
|
||||
56
src/tint/type/atomic_test.cc
Normal file
56
src/tint/type/atomic_test.cc
Normal file
@@ -0,0 +1,56 @@
|
||||
// Copyright 2022 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/type/atomic.h"
|
||||
|
||||
#include "src/tint/type/test_helper.h"
|
||||
|
||||
namespace tint::type {
|
||||
namespace {
|
||||
|
||||
using AtomicTest = TestHelper;
|
||||
|
||||
TEST_F(AtomicTest, Creation) {
|
||||
auto* a = create<Atomic>(create<type::I32>());
|
||||
auto* b = create<Atomic>(create<type::I32>());
|
||||
auto* c = create<Atomic>(create<type::U32>());
|
||||
EXPECT_TRUE(a->Type()->Is<type::I32>());
|
||||
EXPECT_EQ(a, b);
|
||||
EXPECT_NE(a, c);
|
||||
}
|
||||
|
||||
TEST_F(AtomicTest, Hash) {
|
||||
auto* a = create<Atomic>(create<type::I32>());
|
||||
auto* b = create<Atomic>(create<type::I32>());
|
||||
auto* c = create<Atomic>(create<type::U32>());
|
||||
EXPECT_EQ(a->Hash(), b->Hash());
|
||||
EXPECT_NE(a->Hash(), c->Hash());
|
||||
}
|
||||
|
||||
TEST_F(AtomicTest, Equals) {
|
||||
auto* a = create<Atomic>(create<type::I32>());
|
||||
auto* b = create<Atomic>(create<type::I32>());
|
||||
auto* c = create<Atomic>(create<type::U32>());
|
||||
EXPECT_TRUE(a->Equals(*b));
|
||||
EXPECT_FALSE(a->Equals(*c));
|
||||
EXPECT_FALSE(a->Equals(type::Void{}));
|
||||
}
|
||||
|
||||
TEST_F(AtomicTest, FriendlyName) {
|
||||
auto* a = create<Atomic>(create<type::I32>());
|
||||
EXPECT_EQ(a->FriendlyName(Symbols()), "atomic<i32>");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace tint::type
|
||||
Reference in New Issue
Block a user