mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-07-09 06:35:54 +00:00
tint/sem: Add abstract int and float types
Bug: tint:1504 Bug: tint:1516 Change-Id: I7dafaade903c85a6bd6ed095d0d7545de2f238a7 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/88309 Reviewed-by: Dan Sinclair <dsinclair@chromium.org> Kokoro: Kokoro <noreply+kokoro@google.com> Commit-Queue: Ben Clayton <bclayton@google.com>
This commit is contained in:
parent
2c1154c36f
commit
9432887ce8
@ -553,6 +553,12 @@ libtint_source_set("libtint_core_all_src") {
|
|||||||
|
|
||||||
libtint_source_set("libtint_sem_src") {
|
libtint_source_set("libtint_sem_src") {
|
||||||
sources = [
|
sources = [
|
||||||
|
"sem/abstract_float.cc",
|
||||||
|
"sem/abstract_float.h",
|
||||||
|
"sem/abstract_int.cc",
|
||||||
|
"sem/abstract_int.h",
|
||||||
|
"sem/abstract_numeric.cc",
|
||||||
|
"sem/abstract_numeric.h",
|
||||||
"sem/array.cc",
|
"sem/array.cc",
|
||||||
"sem/array.h",
|
"sem/array.h",
|
||||||
"sem/atomic.cc",
|
"sem/atomic.cc",
|
||||||
|
@ -262,6 +262,12 @@ set(TINT_LIB_SRCS
|
|||||||
resolver/validator.cc
|
resolver/validator.cc
|
||||||
resolver/validator.h
|
resolver/validator.h
|
||||||
scope_stack.h
|
scope_stack.h
|
||||||
|
sem/abstract_float.cc
|
||||||
|
sem/abstract_float.h
|
||||||
|
sem/abstract_int.cc
|
||||||
|
sem/abstract_int.h
|
||||||
|
sem/abstract_numeric.cc
|
||||||
|
sem/abstract_numeric.h
|
||||||
sem/array.cc
|
sem/array.cc
|
||||||
sem/array.h
|
sem/array.h
|
||||||
sem/atomic.cc
|
sem/atomic.cc
|
||||||
|
40
src/tint/sem/abstract_float.cc
Normal file
40
src/tint/sem/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/sem/abstract_float.h"
|
||||||
|
|
||||||
|
#include "src/tint/program_builder.h"
|
||||||
|
#include "src/tint/utils/hash.h"
|
||||||
|
|
||||||
|
TINT_INSTANTIATE_TYPEINFO(tint::sem::AbstractFloat);
|
||||||
|
|
||||||
|
namespace tint::sem {
|
||||||
|
|
||||||
|
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 sem::Type& other) const {
|
||||||
|
return other.Is<AbstractFloat>();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string AbstractFloat::FriendlyName(const SymbolTable&) const {
|
||||||
|
return "AbstractFloat";
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace tint::sem
|
49
src/tint/sem/abstract_float.h
Normal file
49
src/tint/sem/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_SEM_ABSTRACT_FLOAT_H_
|
||||||
|
#define SRC_TINT_SEM_ABSTRACT_FLOAT_H_
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "src/tint/sem/abstract_numeric.h"
|
||||||
|
|
||||||
|
namespace tint::sem {
|
||||||
|
|
||||||
|
/// 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::sem
|
||||||
|
|
||||||
|
#endif // SRC_TINT_SEM_ABSTRACT_FLOAT_H_
|
40
src/tint/sem/abstract_int.cc
Normal file
40
src/tint/sem/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/sem/abstract_int.h"
|
||||||
|
|
||||||
|
#include "src/tint/program_builder.h"
|
||||||
|
#include "src/tint/utils/hash.h"
|
||||||
|
|
||||||
|
TINT_INSTANTIATE_TYPEINFO(tint::sem::AbstractInt);
|
||||||
|
|
||||||
|
namespace tint::sem {
|
||||||
|
|
||||||
|
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 sem::Type& other) const {
|
||||||
|
return other.Is<AbstractInt>();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string AbstractInt::FriendlyName(const SymbolTable&) const {
|
||||||
|
return "AbstractInt";
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace tint::sem
|
49
src/tint/sem/abstract_int.h
Normal file
49
src/tint/sem/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_SEM_ABSTRACT_INT_H_
|
||||||
|
#define SRC_TINT_SEM_ABSTRACT_INT_H_
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "src/tint/sem/abstract_numeric.h"
|
||||||
|
|
||||||
|
namespace tint::sem {
|
||||||
|
|
||||||
|
/// 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::sem
|
||||||
|
|
||||||
|
#endif // SRC_TINT_SEM_ABSTRACT_INT_H_
|
37
src/tint/sem/abstract_numeric.cc
Normal file
37
src/tint/sem/abstract_numeric.cc
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
// 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/sem/abstract_numeric.h"
|
||||||
|
|
||||||
|
TINT_INSTANTIATE_TYPEINFO(tint::sem::AbstractNumeric);
|
||||||
|
|
||||||
|
namespace tint::sem {
|
||||||
|
|
||||||
|
AbstractNumeric::AbstractNumeric() = default;
|
||||||
|
AbstractNumeric::AbstractNumeric(AbstractNumeric&&) = default;
|
||||||
|
AbstractNumeric::~AbstractNumeric() = default;
|
||||||
|
|
||||||
|
uint32_t AbstractNumeric::Size() const {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t AbstractNumeric::Align() const {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AbstractNumeric::IsConstructible() const {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace tint::sem
|
47
src/tint/sem/abstract_numeric.h
Normal file
47
src/tint/sem/abstract_numeric.h
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
// 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_SEM_ABSTRACT_NUMERIC_H_
|
||||||
|
#define SRC_TINT_SEM_ABSTRACT_NUMERIC_H_
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "src/tint/sem/type.h"
|
||||||
|
|
||||||
|
namespace tint::sem {
|
||||||
|
|
||||||
|
/// 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> {
|
||||||
|
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;
|
||||||
|
|
||||||
|
/// @returns 0, as the type is abstract.
|
||||||
|
bool IsConstructible() const override;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace tint::sem
|
||||||
|
|
||||||
|
#endif // SRC_TINT_SEM_ABSTRACT_NUMERIC_H_
|
@ -54,7 +54,7 @@ class Atomic final : public Castable<Atomic, Type> {
|
|||||||
uint32_t Align() const override;
|
uint32_t Align() const override;
|
||||||
|
|
||||||
/// @returns true if constructible as per
|
/// @returns true if constructible as per
|
||||||
/// https://gpuweb.github.io/gpuweb/wgsl/#constructible-typesd
|
/// https://gpuweb.github.io/gpuweb/wgsl/#constructible-types
|
||||||
bool IsConstructible() const override;
|
bool IsConstructible() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user