mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-21 02:39:11 +00:00
Move abstract types to type folder.
This CL moves the abstract files from sem to type and updates namespaces as needed. Bug: tint:1718 Change-Id: I5f0be7e820fc66ea72c1ebe612a6d28034e88be6 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/113341 Kokoro: Kokoro <noreply+kokoro@google.com> Commit-Queue: Dan Sinclair <dsinclair@chromium.org> Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
committed by
Dawn LUCI CQ
parent
5ee58b60a8
commit
094ace6f63
40
src/tint/type/abstract_float.cc
Normal file
40
src/tint/type/abstract_float.cc
Normal file
@@ -0,0 +1,40 @@
|
||||
// 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/abstract_float.h"
|
||||
|
||||
#include "src/tint/program_builder.h"
|
||||
#include "src/tint/utils/hash.h"
|
||||
|
||||
TINT_INSTANTIATE_TYPEINFO(tint::type::AbstractFloat);
|
||||
|
||||
namespace tint::type {
|
||||
|
||||
AbstractFloat::AbstractFloat() = default;
|
||||
AbstractFloat::AbstractFloat(AbstractFloat&&) = default;
|
||||
AbstractFloat::~AbstractFloat() = default;
|
||||
|
||||
size_t AbstractFloat::Hash() const {
|
||||
return utils::Hash(TypeInfo::Of<AbstractFloat>().full_hashcode);
|
||||
}
|
||||
|
||||
bool AbstractFloat::Equals(const type::Type& other) const {
|
||||
return other.Is<AbstractFloat>();
|
||||
}
|
||||
|
||||
std::string AbstractFloat::FriendlyName(const SymbolTable&) const {
|
||||
return "abstract-float";
|
||||
}
|
||||
|
||||
} // namespace tint::type
|
||||
49
src/tint/type/abstract_float.h
Normal file
49
src/tint/type/abstract_float.h
Normal file
@@ -0,0 +1,49 @@
|
||||
// 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_ABSTRACT_FLOAT_H_
|
||||
#define SRC_TINT_TYPE_ABSTRACT_FLOAT_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "src/tint/type/abstract_numeric.h"
|
||||
|
||||
namespace tint::type {
|
||||
|
||||
/// An abstract-float type.
|
||||
/// @see https://www.w3.org/TR/WGSL/#abstractFloat
|
||||
class AbstractFloat final : public Castable<AbstractFloat, AbstractNumeric> {
|
||||
public:
|
||||
/// Constructor
|
||||
AbstractFloat();
|
||||
|
||||
/// Move constructor
|
||||
AbstractFloat(AbstractFloat&&);
|
||||
~AbstractFloat() override;
|
||||
|
||||
/// @returns a hash of the type.
|
||||
size_t Hash() const override;
|
||||
|
||||
/// @param other the other type to compare against
|
||||
/// @returns true if this type is equal to the given type
|
||||
bool Equals(const Type& other) const override;
|
||||
|
||||
/// @param symbols the program's symbol table
|
||||
/// @returns the name for this type when printed in diagnostics.
|
||||
std::string FriendlyName(const SymbolTable& symbols) const override;
|
||||
};
|
||||
|
||||
} // namespace tint::type
|
||||
|
||||
#endif // SRC_TINT_TYPE_ABSTRACT_FLOAT_H_
|
||||
40
src/tint/type/abstract_int.cc
Normal file
40
src/tint/type/abstract_int.cc
Normal file
@@ -0,0 +1,40 @@
|
||||
// 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/abstract_int.h"
|
||||
|
||||
#include "src/tint/program_builder.h"
|
||||
#include "src/tint/utils/hash.h"
|
||||
|
||||
TINT_INSTANTIATE_TYPEINFO(tint::type::AbstractInt);
|
||||
|
||||
namespace tint::type {
|
||||
|
||||
AbstractInt::AbstractInt() = default;
|
||||
AbstractInt::AbstractInt(AbstractInt&&) = default;
|
||||
AbstractInt::~AbstractInt() = default;
|
||||
|
||||
size_t AbstractInt::Hash() const {
|
||||
return utils::Hash(TypeInfo::Of<AbstractInt>().full_hashcode);
|
||||
}
|
||||
|
||||
bool AbstractInt::Equals(const type::Type& other) const {
|
||||
return other.Is<AbstractInt>();
|
||||
}
|
||||
|
||||
std::string AbstractInt::FriendlyName(const SymbolTable&) const {
|
||||
return "abstract-int";
|
||||
}
|
||||
|
||||
} // namespace tint::type
|
||||
49
src/tint/type/abstract_int.h
Normal file
49
src/tint/type/abstract_int.h
Normal file
@@ -0,0 +1,49 @@
|
||||
// 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_ABSTRACT_INT_H_
|
||||
#define SRC_TINT_TYPE_ABSTRACT_INT_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "src/tint/type/abstract_numeric.h"
|
||||
|
||||
namespace tint::type {
|
||||
|
||||
/// An abstract-int type.
|
||||
/// @see https://www.w3.org/TR/WGSL/#abstractint
|
||||
class AbstractInt final : public Castable<AbstractInt, AbstractNumeric> {
|
||||
public:
|
||||
/// Constructor
|
||||
AbstractInt();
|
||||
|
||||
/// Move constructor
|
||||
AbstractInt(AbstractInt&&);
|
||||
~AbstractInt() 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;
|
||||
|
||||
/// @param symbols the program's symbol table
|
||||
/// @returns the name for this type when printed in diagnostics.
|
||||
std::string FriendlyName(const SymbolTable& symbols) const override;
|
||||
};
|
||||
|
||||
} // namespace tint::type
|
||||
|
||||
#endif // SRC_TINT_TYPE_ABSTRACT_INT_H_
|
||||
38
src/tint/type/abstract_numeric.cc
Normal file
38
src/tint/type/abstract_numeric.cc
Normal file
@@ -0,0 +1,38 @@
|
||||
// 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/abstract_numeric.h"
|
||||
|
||||
TINT_INSTANTIATE_TYPEINFO(tint::type::AbstractNumeric);
|
||||
|
||||
namespace tint::type {
|
||||
|
||||
AbstractNumeric::AbstractNumeric()
|
||||
: Base(type::TypeFlags{
|
||||
Flag::kConstructable,
|
||||
Flag::kCreationFixedFootprint,
|
||||
Flag::kFixedFootprint,
|
||||
}) {}
|
||||
AbstractNumeric::AbstractNumeric(AbstractNumeric&&) = default;
|
||||
AbstractNumeric::~AbstractNumeric() = default;
|
||||
|
||||
uint32_t AbstractNumeric::Size() const {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t AbstractNumeric::Align() const {
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace tint::type
|
||||
44
src/tint/type/abstract_numeric.h
Normal file
44
src/tint/type/abstract_numeric.h
Normal file
@@ -0,0 +1,44 @@
|
||||
// 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_ABSTRACT_NUMERIC_H_
|
||||
#define SRC_TINT_TYPE_ABSTRACT_NUMERIC_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "src/tint/type/type.h"
|
||||
|
||||
namespace tint::type {
|
||||
|
||||
/// The base class for abstract-int and abstract-float types.
|
||||
/// @see https://www.w3.org/TR/WGSL/#types-for-creation-time-constants
|
||||
class AbstractNumeric : public Castable<AbstractNumeric, type::Type> {
|
||||
public:
|
||||
/// Constructor
|
||||
AbstractNumeric();
|
||||
|
||||
/// Move constructor
|
||||
AbstractNumeric(AbstractNumeric&&);
|
||||
~AbstractNumeric() override;
|
||||
|
||||
/// @returns 0, as the type is abstract.
|
||||
uint32_t Size() const override;
|
||||
|
||||
/// @returns 0, as the type is abstract.
|
||||
uint32_t Align() const override;
|
||||
};
|
||||
|
||||
} // namespace tint::type
|
||||
|
||||
#endif // SRC_TINT_TYPE_ABSTRACT_NUMERIC_H_
|
||||
@@ -14,8 +14,6 @@
|
||||
|
||||
#include "src/tint/type/type.h"
|
||||
|
||||
#include "src/tint/sem/abstract_float.h"
|
||||
#include "src/tint/sem/abstract_int.h"
|
||||
#include "src/tint/sem/array.h"
|
||||
#include "src/tint/sem/bool.h"
|
||||
#include "src/tint/sem/f16.h"
|
||||
@@ -27,6 +25,8 @@
|
||||
#include "src/tint/sem/struct.h"
|
||||
#include "src/tint/sem/u32.h"
|
||||
#include "src/tint/sem/vector.h"
|
||||
#include "src/tint/type/abstract_float.h"
|
||||
#include "src/tint/type/abstract_int.h"
|
||||
#include "src/tint/type/sampler.h"
|
||||
#include "src/tint/type/texture.h"
|
||||
|
||||
@@ -69,15 +69,15 @@ uint32_t Type::Align() const {
|
||||
}
|
||||
|
||||
bool Type::is_scalar() const {
|
||||
return IsAnyOf<sem::F16, sem::F32, sem::U32, sem::I32, sem::AbstractNumeric, sem::Bool>();
|
||||
return IsAnyOf<sem::F16, sem::F32, sem::U32, sem::I32, type::AbstractNumeric, sem::Bool>();
|
||||
}
|
||||
|
||||
bool Type::is_numeric_scalar() const {
|
||||
return IsAnyOf<sem::F16, sem::F32, sem::U32, sem::I32, sem::AbstractNumeric>();
|
||||
return IsAnyOf<sem::F16, sem::F32, sem::U32, sem::I32, type::AbstractNumeric>();
|
||||
}
|
||||
|
||||
bool Type::is_float_scalar() const {
|
||||
return IsAnyOf<sem::F16, sem::F32, sem::AbstractNumeric>();
|
||||
return IsAnyOf<sem::F16, sem::F32, type::AbstractNumeric>();
|
||||
}
|
||||
|
||||
bool Type::is_float_matrix() const {
|
||||
@@ -107,7 +107,7 @@ bool Type::is_integer_scalar() const {
|
||||
}
|
||||
|
||||
bool Type::is_signed_integer_scalar() const {
|
||||
return IsAnyOf<sem::I32, sem::AbstractInt>();
|
||||
return IsAnyOf<sem::I32, type::AbstractInt>();
|
||||
}
|
||||
|
||||
bool Type::is_unsigned_integer_scalar() const {
|
||||
@@ -116,7 +116,7 @@ bool Type::is_unsigned_integer_scalar() const {
|
||||
|
||||
bool Type::is_signed_integer_vector() const {
|
||||
return Is(
|
||||
[](const sem::Vector* v) { return v->type()->IsAnyOf<sem::I32, sem::AbstractInt>(); });
|
||||
[](const sem::Vector* v) { return v->type()->IsAnyOf<sem::I32, type::AbstractInt>(); });
|
||||
}
|
||||
|
||||
bool Type::is_unsigned_integer_vector() const {
|
||||
@@ -128,7 +128,7 @@ bool Type::is_unsigned_integer_scalar_or_vector() const {
|
||||
}
|
||||
|
||||
bool Type::is_signed_integer_scalar_or_vector() const {
|
||||
return IsAnyOf<sem::I32, sem::AbstractInt>() || is_signed_integer_vector();
|
||||
return IsAnyOf<sem::I32, type::AbstractInt>() || is_signed_integer_vector();
|
||||
}
|
||||
|
||||
bool Type::is_integer_scalar_or_vector() const {
|
||||
@@ -136,19 +136,19 @@ bool Type::is_integer_scalar_or_vector() const {
|
||||
}
|
||||
|
||||
bool Type::is_abstract_integer_vector() const {
|
||||
return Is([](const sem::Vector* v) { return v->type()->Is<sem::AbstractInt>(); });
|
||||
return Is([](const sem::Vector* v) { return v->type()->Is<type::AbstractInt>(); });
|
||||
}
|
||||
|
||||
bool Type::is_abstract_float_vector() const {
|
||||
return Is([](const sem::Vector* v) { return v->type()->Is<sem::AbstractFloat>(); });
|
||||
return Is([](const sem::Vector* v) { return v->type()->Is<type::AbstractFloat>(); });
|
||||
}
|
||||
|
||||
bool Type::is_abstract_integer_scalar_or_vector() const {
|
||||
return Is<sem::AbstractInt>() || is_abstract_integer_vector();
|
||||
return Is<type::AbstractInt>() || is_abstract_integer_vector();
|
||||
}
|
||||
|
||||
bool Type::is_abstract_float_scalar_or_vector() const {
|
||||
return Is<sem::AbstractFloat>() || is_abstract_float_vector();
|
||||
return Is<type::AbstractFloat>() || is_abstract_float_vector();
|
||||
}
|
||||
|
||||
bool Type::is_bool_vector() const {
|
||||
@@ -178,7 +178,7 @@ bool Type::is_handle() const {
|
||||
bool Type::HoldsAbstract() const {
|
||||
return Switch(
|
||||
this, //
|
||||
[&](const sem::AbstractNumeric*) { return true; },
|
||||
[&](const type::AbstractNumeric*) { return true; },
|
||||
[&](const sem::Vector* v) { return v->type()->HoldsAbstract(); },
|
||||
[&](const sem::Matrix* m) { return m->type()->HoldsAbstract(); },
|
||||
[&](const sem::Array* a) { return a->ElemType()->HoldsAbstract(); },
|
||||
@@ -198,21 +198,21 @@ uint32_t Type::ConversionRank(const Type* from, const Type* to) {
|
||||
}
|
||||
return Switch(
|
||||
from,
|
||||
[&](const sem::AbstractFloat*) {
|
||||
[&](const type::AbstractFloat*) {
|
||||
return Switch(
|
||||
to, //
|
||||
[&](const sem::F32*) { return 1; }, //
|
||||
[&](const sem::F16*) { return 2; }, //
|
||||
[&](Default) { return kNoConversion; });
|
||||
},
|
||||
[&](const sem::AbstractInt*) {
|
||||
[&](const type::AbstractInt*) {
|
||||
return Switch(
|
||||
to, //
|
||||
[&](const sem::I32*) { return 3; }, //
|
||||
[&](const sem::U32*) { return 4; }, //
|
||||
[&](const sem::AbstractFloat*) { return 5; }, //
|
||||
[&](const sem::F32*) { return 6; }, //
|
||||
[&](const sem::F16*) { return 7; }, //
|
||||
to, //
|
||||
[&](const sem::I32*) { return 3; }, //
|
||||
[&](const sem::U32*) { return 4; }, //
|
||||
[&](const type::AbstractFloat*) { return 5; }, //
|
||||
[&](const sem::F32*) { return 6; }, //
|
||||
[&](const sem::F16*) { return 7; }, //
|
||||
[&](Default) { return kNoConversion; });
|
||||
},
|
||||
[&](const sem::Vector* from_vec) {
|
||||
|
||||
@@ -12,10 +12,10 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/tint/sem/abstract_float.h"
|
||||
#include "src/tint/sem/abstract_int.h"
|
||||
#include "src/tint/sem/f16.h"
|
||||
#include "src/tint/sem/reference.h"
|
||||
#include "src/tint/type/abstract_float.h"
|
||||
#include "src/tint/type/abstract_int.h"
|
||||
#include "src/tint/type/array_count.h"
|
||||
#include "src/tint/type/test_helper.h"
|
||||
|
||||
@@ -23,8 +23,8 @@ namespace tint::type {
|
||||
namespace {
|
||||
|
||||
struct TypeTest : public TestHelper {
|
||||
const sem::AbstractFloat* af = create<sem::AbstractFloat>();
|
||||
const sem::AbstractInt* ai = create<sem::AbstractInt>();
|
||||
const type::AbstractFloat* af = create<type::AbstractFloat>();
|
||||
const type::AbstractInt* ai = create<type::AbstractInt>();
|
||||
const sem::F32* f32 = create<sem::F32>();
|
||||
const sem::F16* f16 = create<sem::F16>();
|
||||
const sem::I32* i32 = create<sem::I32>();
|
||||
|
||||
Reference in New Issue
Block a user