Rename StorageClass to AddressSpace.

This CL updates the internals to use AddressSpace instead of the old
StorageClass name.

Bug: tint:1404
Change-Id: Iecc208e839453437f4d630f65e0152206a52db7e
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/104420
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
Auto-Submit: Dan Sinclair <dsinclair@chromium.org>
This commit is contained in:
dan sinclair
2022-10-03 14:05:23 +00:00
committed by Dawn LUCI CQ
parent d5b64ecd78
commit ff7cf21021
300 changed files with 2696 additions and 2766 deletions

View File

@@ -15,63 +15,63 @@
////////////////////////////////////////////////////////////////////////////////
// File generated by tools/src/cmd/gen
// using the template:
// src/tint/ast/storage_class.cc.tmpl
// src/tint/ast/address_space.cc.tmpl
//
// Do not modify this file directly
////////////////////////////////////////////////////////////////////////////////
#include "src/tint/ast/storage_class.h"
#include "src/tint/ast/address_space.h"
namespace tint::ast {
/// ParseStorageClass parses a StorageClass from a string.
/// ParseAddressSpace parses a AddressSpace from a string.
/// @param str the string to parse
/// @returns the parsed enum, or StorageClass::kInvalid if the string could not be parsed.
StorageClass ParseStorageClass(std::string_view str) {
/// @returns the parsed enum, or AddressSpace::kInvalid if the string could not be parsed.
AddressSpace ParseAddressSpace(std::string_view str) {
if (str == "function") {
return StorageClass::kFunction;
return AddressSpace::kFunction;
}
if (str == "private") {
return StorageClass::kPrivate;
return AddressSpace::kPrivate;
}
if (str == "workgroup") {
return StorageClass::kWorkgroup;
return AddressSpace::kWorkgroup;
}
if (str == "uniform") {
return StorageClass::kUniform;
return AddressSpace::kUniform;
}
if (str == "storage") {
return StorageClass::kStorage;
return AddressSpace::kStorage;
}
if (str == "push_constant") {
return StorageClass::kPushConstant;
return AddressSpace::kPushConstant;
}
return StorageClass::kInvalid;
return AddressSpace::kInvalid;
}
std::ostream& operator<<(std::ostream& out, StorageClass value) {
std::ostream& operator<<(std::ostream& out, AddressSpace value) {
switch (value) {
case StorageClass::kInvalid:
case AddressSpace::kInvalid:
return out << "invalid";
case StorageClass::kNone:
case AddressSpace::kNone:
return out << "none";
case StorageClass::kFunction:
case AddressSpace::kFunction:
return out << "function";
case StorageClass::kPrivate:
case AddressSpace::kPrivate:
return out << "private";
case StorageClass::kWorkgroup:
case AddressSpace::kWorkgroup:
return out << "workgroup";
case StorageClass::kUniform:
case AddressSpace::kUniform:
return out << "uniform";
case StorageClass::kStorage:
case AddressSpace::kStorage:
return out << "storage";
case StorageClass::kPushConstant:
case AddressSpace::kPushConstant:
return out << "push_constant";
case StorageClass::kHandle:
case AddressSpace::kHandle:
return out << "handle";
case StorageClass::kIn:
case AddressSpace::kIn:
return out << "in";
case StorageClass::kOut:
case AddressSpace::kOut:
return out << "out";
}
return out << "<unknown>";

View File

@@ -1,6 +1,6 @@
{{- /*
--------------------------------------------------------------------------------
Template file for use with tools/src/cmd/gen to generate storage_class.cc
Template file for use with tools/src/cmd/gen to generate address_space.cc
To update the generated file, run:
./tools/run gen
@@ -12,9 +12,9 @@ See:
*/ -}}
{{- Import "src/tint/templates/enums.tmpl.inc" -}}
{{- $enum := (Sem.Enum "storage_class") -}}
{{- $enum := (Sem.Enum "address_space") -}}
#include "src/tint/ast/storage_class.h"
#include "src/tint/ast/address_space.h"
namespace tint::ast {

View File

@@ -15,20 +15,20 @@
////////////////////////////////////////////////////////////////////////////////
// File generated by tools/src/cmd/gen
// using the template:
// src/tint/ast/storage_class.h.tmpl
// src/tint/ast/address_space.h.tmpl
//
// Do not modify this file directly
////////////////////////////////////////////////////////////////////////////////
#ifndef SRC_TINT_AST_STORAGE_CLASS_H_
#define SRC_TINT_AST_STORAGE_CLASS_H_
#ifndef SRC_TINT_AST_ADDRESS_SPACE_H_
#define SRC_TINT_AST_ADDRESS_SPACE_H_
#include <ostream>
namespace tint::ast {
/// Storage class of a given pointer.
enum class StorageClass {
/// Address space of a given pointer.
enum class AddressSpace {
kInvalid,
kNone, // Tint-internal enum entry - not parsed
kFunction,
@@ -43,23 +43,24 @@ enum class StorageClass {
};
/// @param out the std::ostream to write to
/// @param value the StorageClass
/// @param value the AddressSpace
/// @returns `out` so calls can be chained
std::ostream& operator<<(std::ostream& out, StorageClass value);
std::ostream& operator<<(std::ostream& out, AddressSpace value);
/// ParseStorageClass parses a StorageClass from a string.
/// ParseAddressSpace parses a AddressSpace from a string.
/// @param str the string to parse
/// @returns the parsed enum, or StorageClass::kInvalid if the string could not be parsed.
StorageClass ParseStorageClass(std::string_view str);
/// @returns the parsed enum, or AddressSpace::kInvalid if the string could not be parsed.
AddressSpace ParseAddressSpace(std::string_view str);
/// @returns true if the StorageClass is host-shareable
/// @param sc the StorageClass
/// @returns true if the AddressSpace is host-shareable
/// @param address_space the AddressSpace
/// @see https://gpuweb.github.io/gpuweb/wgsl.html#host-shareable
inline bool IsHostShareable(StorageClass sc) {
return sc == ast::StorageClass::kUniform || sc == ast::StorageClass::kStorage ||
sc == ast::StorageClass::kPushConstant;
inline bool IsHostShareable(AddressSpace address_space) {
return address_space == ast::AddressSpace::kUniform ||
address_space == ast::AddressSpace::kStorage ||
address_space == ast::AddressSpace::kPushConstant;
}
} // namespace tint::ast
#endif // SRC_TINT_AST_STORAGE_CLASS_H_
#endif // SRC_TINT_AST_ADDRESS_SPACE_H_

View File

@@ -1,6 +1,6 @@
{{- /*
--------------------------------------------------------------------------------
Template file for use with tools/src/cmd/gen to generate storage_class.h
Template file for use with tools/src/cmd/gen to generate address_space.h
To update the generated file, run:
./tools/run gen
@@ -12,26 +12,26 @@ See:
*/ -}}
{{- Import "src/tint/templates/enums.tmpl.inc" -}}
{{- $enum := (Sem.Enum "storage_class") -}}
{{- $enum := (Sem.Enum "address_space") -}}
#ifndef SRC_TINT_AST_STORAGE_CLASS_H_
#define SRC_TINT_AST_STORAGE_CLASS_H_
#ifndef SRC_TINT_AST_ADDRESS_SPACE_H_
#define SRC_TINT_AST_ADDRESS_SPACE_H_
#include <ostream>
namespace tint::ast {
/// Storage class of a given pointer.
/// Address space of a given pointer.
{{ Eval "DeclareEnum" $enum}}
/// @returns true if the StorageClass is host-shareable
/// @param sc the StorageClass
/// @returns true if the AddressSpace is host-shareable
/// @param address_space the AddressSpace
/// @see https://gpuweb.github.io/gpuweb/wgsl.html#host-shareable
inline bool IsHostShareable(StorageClass sc) {
return sc == ast::StorageClass::kUniform || sc == ast::StorageClass::kStorage ||
sc == ast::StorageClass::kPushConstant;
inline bool IsHostShareable(AddressSpace address_space) {
return address_space == ast::AddressSpace::kUniform || address_space == ast::AddressSpace::kStorage ||
address_space == ast::AddressSpace::kPushConstant;
}
} // namespace tint::ast
#endif // SRC_TINT_AST_STORAGE_CLASS_H_
#endif // SRC_TINT_AST_ADDRESS_SPACE_H_

View File

@@ -15,12 +15,12 @@
////////////////////////////////////////////////////////////////////////////////
// File generated by tools/src/cmd/gen
// using the template:
// src/tint/ast/storage_class_bench.cc.tmpl
// src/tint/ast/address_space_bench.cc.tmpl
//
// Do not modify this file directly
////////////////////////////////////////////////////////////////////////////////
#include "src/tint/ast/storage_class.h"
#include "src/tint/ast/address_space.h"
#include <array>
@@ -29,7 +29,7 @@
namespace tint::ast {
namespace {
void StorageClassParser(::benchmark::State& state) {
void AddressSpaceParser(::benchmark::State& state) {
std::array kStrings{
"fccnctin",
"ucti3",
@@ -76,13 +76,13 @@ void StorageClassParser(::benchmark::State& state) {
};
for (auto _ : state) {
for (auto& str : kStrings) {
auto result = ParseStorageClass(str);
auto result = ParseAddressSpace(str);
benchmark::DoNotOptimize(result);
}
}
}
BENCHMARK(StorageClassParser);
BENCHMARK(AddressSpaceParser);
} // namespace
} // namespace tint::ast

View File

@@ -1,6 +1,6 @@
{{- /*
--------------------------------------------------------------------------------
Template file for use with tools/src/cmd/gen to generate storage_class_bench.cc
Template file for use with tools/src/cmd/gen to generate address_space_bench.cc
To update the generated file, run:
./tools/run gen
@@ -12,9 +12,9 @@ See:
*/ -}}
{{- Import "src/tint/templates/enums.tmpl.inc" -}}
{{- $enum := (Sem.Enum "storage_class") -}}
{{- $enum := (Sem.Enum "address_space") -}}
#include "src/tint/ast/storage_class.h"
#include "src/tint/ast/address_space.h"
#include <array>

View File

@@ -0,0 +1,86 @@
// 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.
////////////////////////////////////////////////////////////////////////////////
// File generated by tools/src/cmd/gen
// using the template:
// src/tint/ast/address_space_test.cc.tmpl
//
// Do not modify this file directly
////////////////////////////////////////////////////////////////////////////////
#include "src/tint/ast/address_space.h"
#include <string>
#include "src/tint/ast/test_helper.h"
#include "src/tint/utils/string.h"
namespace tint::ast {
namespace {
namespace parse_print_tests {
struct Case {
const char* string;
AddressSpace value;
};
inline std::ostream& operator<<(std::ostream& out, Case c) {
return out << "'" << std::string(c.string) << "'";
}
static constexpr Case kValidCases[] = {
{"function", AddressSpace::kFunction}, {"private", AddressSpace::kPrivate},
{"workgroup", AddressSpace::kWorkgroup}, {"uniform", AddressSpace::kUniform},
{"storage", AddressSpace::kStorage}, {"push_constant", AddressSpace::kPushConstant},
};
static constexpr Case kInvalidCases[] = {
{"fccnctin", AddressSpace::kInvalid}, {"ucti3", AddressSpace::kInvalid},
{"functVon", AddressSpace::kInvalid}, {"priv1te", AddressSpace::kInvalid},
{"pqiJate", AddressSpace::kInvalid}, {"privat7ll", AddressSpace::kInvalid},
{"workroppqHH", AddressSpace::kInvalid}, {"workru", AddressSpace::kInvalid},
{"wbkgGoup", AddressSpace::kInvalid}, {"unifiivm", AddressSpace::kInvalid},
{"8WWiform", AddressSpace::kInvalid}, {"uxxform", AddressSpace::kInvalid},
{"sXraggg", AddressSpace::kInvalid}, {"traXe", AddressSpace::kInvalid},
{"stor3ge", AddressSpace::kInvalid}, {"push_constanE", AddressSpace::kInvalid},
{"push_TTPnstant", AddressSpace::kInvalid}, {"puxxdh_constan", AddressSpace::kInvalid},
};
using AddressSpaceParseTest = testing::TestWithParam<Case>;
TEST_P(AddressSpaceParseTest, Parse) {
const char* string = GetParam().string;
AddressSpace expect = GetParam().value;
EXPECT_EQ(expect, ParseAddressSpace(string));
}
INSTANTIATE_TEST_SUITE_P(ValidCases, AddressSpaceParseTest, testing::ValuesIn(kValidCases));
INSTANTIATE_TEST_SUITE_P(InvalidCases, AddressSpaceParseTest, testing::ValuesIn(kInvalidCases));
using AddressSpacePrintTest = testing::TestWithParam<Case>;
TEST_P(AddressSpacePrintTest, Print) {
AddressSpace value = GetParam().value;
const char* expect = GetParam().string;
EXPECT_EQ(expect, utils::ToString(value));
}
INSTANTIATE_TEST_SUITE_P(ValidCases, AddressSpacePrintTest, testing::ValuesIn(kValidCases));
} // namespace parse_print_tests
} // namespace
} // namespace tint::ast

View File

@@ -1,6 +1,6 @@
{{- /*
--------------------------------------------------------------------------------
Template file for use with tools/src/cmd/gen to generate storage_class_test.cc
Template file for use with tools/src/cmd/gen to generate address_space_test.cc
To update the generated file, run:
./tools/run gen
@@ -12,9 +12,9 @@ See:
*/ -}}
{{- Import "src/tint/templates/enums.tmpl.inc" -}}
{{- $enum := (Sem.Enum "storage_class") -}}
{{- $enum := (Sem.Enum "address_space") -}}
#include "src/tint/ast/storage_class.h"
#include "src/tint/ast/address_space.h"
#include <string>

View File

@@ -33,8 +33,8 @@ std::string DisableValidationAttribute::InternalName() const {
return "disable_validation__function_has_no_body";
case DisabledValidation::kBindingPointCollision:
return "disable_validation__binding_point_collision";
case DisabledValidation::kIgnoreStorageClass:
return "disable_validation__ignore_storage_class";
case DisabledValidation::kIgnoreAddressSpace:
return "disable_validation__ignore_address_space";
case DisabledValidation::kEntryPointParameter:
return "disable_validation__entry_point_parameter";
case DisabledValidation::kFunctionParameter:

View File

@@ -29,9 +29,9 @@ enum class DisabledValidation {
/// When applied to a module-scoped variable, the validator will not complain if two resource
/// variables have the same binding points.
kBindingPointCollision,
/// When applied to a variable, the validator will not complain about the declared storage
/// class.
kIgnoreStorageClass,
/// When applied to a variable, the validator will not complain about the declared address
/// space.
kIgnoreAddressSpace,
/// When applied to an entry-point function parameter, the validator will not check for entry IO
/// attributes.
kEntryPointParameter,

View File

@@ -72,7 +72,7 @@ TEST_F(ModuleTest, Assert_DifferentProgramID_GlobalVariable) {
{
ProgramBuilder b1;
ProgramBuilder b2;
b1.AST().AddGlobalVariable(b2.Var("var", b2.ty.i32(), ast::StorageClass::kPrivate));
b1.AST().AddGlobalVariable(b2.Var("var", b2.ty.i32(), ast::AddressSpace::kPrivate));
},
"internal compiler error");
}
@@ -92,7 +92,7 @@ TEST_F(ModuleTest, CloneOrder) {
ProgramBuilder b;
b.Func("F", {}, b.ty.void_(), {});
b.Alias("A", b.ty.u32());
b.GlobalVar("V", b.ty.i32(), ast::StorageClass::kPrivate);
b.GlobalVar("V", b.ty.i32(), ast::AddressSpace::kPrivate);
return Program(std::move(b));
}();

View File

@@ -24,15 +24,15 @@ Pointer::Pointer(ProgramID pid,
NodeID nid,
const Source& src,
const Type* const subtype,
ast::StorageClass sc,
ast::AddressSpace addr_space,
ast::Access ac)
: Base(pid, nid, src), type(subtype), storage_class(sc), access(ac) {}
: Base(pid, nid, src), type(subtype), address_space(addr_space), access(ac) {}
std::string Pointer::FriendlyName(const SymbolTable& symbols) const {
std::ostringstream out;
out << "ptr<";
if (storage_class != ast::StorageClass::kNone) {
out << storage_class << ", ";
if (address_space != ast::AddressSpace::kNone) {
out << address_space << ", ";
}
out << type->FriendlyName(symbols);
if (access != ast::Access::kUndefined) {
@@ -50,7 +50,7 @@ const Pointer* Pointer::Clone(CloneContext* ctx) const {
// Clone arguments outside of create() call to have deterministic ordering
auto src = ctx->Clone(source);
auto* ty = ctx->Clone(type);
return ctx->dst->create<Pointer>(src, ty, storage_class, access);
return ctx->dst->create<Pointer>(src, ty, address_space, access);
}
} // namespace tint::ast

View File

@@ -18,7 +18,7 @@
#include <string>
#include "src/tint/ast/access.h"
#include "src/tint/ast/storage_class.h"
#include "src/tint/ast/address_space.h"
#include "src/tint/ast/type.h"
namespace tint::ast {
@@ -31,13 +31,13 @@ class Pointer final : public Castable<Pointer, Type> {
/// @param nid the unique node identifier
/// @param src the source of this node
/// @param subtype the pointee type
/// @param storage_class the storage class of the pointer
/// @param address_space the address space of the pointer
/// @param access the access control of the pointer
Pointer(ProgramID pid,
NodeID nid,
const Source& src,
const Type* const subtype,
ast::StorageClass storage_class,
ast::AddressSpace address_space,
ast::Access access);
/// Move constructor
Pointer(Pointer&&);
@@ -56,8 +56,8 @@ class Pointer final : public Castable<Pointer, Type> {
/// The pointee type
const Type* const type;
/// The storage class of the pointer
ast::StorageClass const storage_class;
/// The address space of the pointer
ast::AddressSpace const address_space;
/// The access control of the pointer
ast::Access const access;

View File

@@ -24,21 +24,21 @@ using AstPointerTest = TestHelper;
TEST_F(AstPointerTest, Creation) {
auto* i32 = create<I32>();
auto* p = create<Pointer>(i32, ast::StorageClass::kStorage, Access::kRead);
auto* p = create<Pointer>(i32, ast::AddressSpace::kStorage, Access::kRead);
EXPECT_EQ(p->type, i32);
EXPECT_EQ(p->storage_class, ast::StorageClass::kStorage);
EXPECT_EQ(p->address_space, ast::AddressSpace::kStorage);
EXPECT_EQ(p->access, Access::kRead);
}
TEST_F(AstPointerTest, FriendlyName) {
auto* i32 = create<I32>();
auto* p = create<Pointer>(i32, ast::StorageClass::kWorkgroup, Access::kUndefined);
auto* p = create<Pointer>(i32, ast::AddressSpace::kWorkgroup, Access::kUndefined);
EXPECT_EQ(p->FriendlyName(Symbols()), "ptr<workgroup, i32>");
}
TEST_F(AstPointerTest, FriendlyNameWithAccess) {
auto* i32 = create<I32>();
auto* p = create<Pointer>(i32, ast::StorageClass::kStorage, Access::kReadWrite);
auto* p = create<Pointer>(i32, ast::AddressSpace::kStorage, Access::kReadWrite);
EXPECT_EQ(p->FriendlyName(Symbols()), "ptr<storage, i32, read_write>");
}

View File

@@ -1,86 +0,0 @@
// 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.
////////////////////////////////////////////////////////////////////////////////
// File generated by tools/src/cmd/gen
// using the template:
// src/tint/ast/storage_class_test.cc.tmpl
//
// Do not modify this file directly
////////////////////////////////////////////////////////////////////////////////
#include "src/tint/ast/storage_class.h"
#include <string>
#include "src/tint/ast/test_helper.h"
#include "src/tint/utils/string.h"
namespace tint::ast {
namespace {
namespace parse_print_tests {
struct Case {
const char* string;
StorageClass value;
};
inline std::ostream& operator<<(std::ostream& out, Case c) {
return out << "'" << std::string(c.string) << "'";
}
static constexpr Case kValidCases[] = {
{"function", StorageClass::kFunction}, {"private", StorageClass::kPrivate},
{"workgroup", StorageClass::kWorkgroup}, {"uniform", StorageClass::kUniform},
{"storage", StorageClass::kStorage}, {"push_constant", StorageClass::kPushConstant},
};
static constexpr Case kInvalidCases[] = {
{"fccnctin", StorageClass::kInvalid}, {"ucti3", StorageClass::kInvalid},
{"functVon", StorageClass::kInvalid}, {"priv1te", StorageClass::kInvalid},
{"pqiJate", StorageClass::kInvalid}, {"privat7ll", StorageClass::kInvalid},
{"workroppqHH", StorageClass::kInvalid}, {"workru", StorageClass::kInvalid},
{"wbkgGoup", StorageClass::kInvalid}, {"unifiivm", StorageClass::kInvalid},
{"8WWiform", StorageClass::kInvalid}, {"uxxform", StorageClass::kInvalid},
{"sXraggg", StorageClass::kInvalid}, {"traXe", StorageClass::kInvalid},
{"stor3ge", StorageClass::kInvalid}, {"push_constanE", StorageClass::kInvalid},
{"push_TTPnstant", StorageClass::kInvalid}, {"puxxdh_constan", StorageClass::kInvalid},
};
using StorageClassParseTest = testing::TestWithParam<Case>;
TEST_P(StorageClassParseTest, Parse) {
const char* string = GetParam().string;
StorageClass expect = GetParam().value;
EXPECT_EQ(expect, ParseStorageClass(string));
}
INSTANTIATE_TEST_SUITE_P(ValidCases, StorageClassParseTest, testing::ValuesIn(kValidCases));
INSTANTIATE_TEST_SUITE_P(InvalidCases, StorageClassParseTest, testing::ValuesIn(kInvalidCases));
using StorageClassPrintTest = testing::TestWithParam<Case>;
TEST_P(StorageClassPrintTest, Print) {
StorageClass value = GetParam().value;
const char* expect = GetParam().string;
EXPECT_EQ(expect, utils::ToString(value));
}
INSTANTIATE_TEST_SUITE_P(ValidCases, StorageClassPrintTest, testing::ValuesIn(kValidCases));
} // namespace parse_print_tests
} // namespace
} // namespace tint::ast

View File

@@ -25,12 +25,12 @@ Var::Var(ProgramID pid,
const Source& src,
const Symbol& sym,
const ast::Type* ty,
StorageClass storage_class,
AddressSpace address_space,
Access access,
const Expression* ctor,
utils::VectorRef<const Attribute*> attrs)
: Base(pid, nid, src, sym, ty, ctor, std::move(attrs)),
declared_storage_class(storage_class),
declared_address_space(address_space),
declared_access(access) {}
Var::Var(Var&&) = default;
@@ -47,7 +47,7 @@ const Var* Var::Clone(CloneContext* ctx) const {
auto* ty = ctx->Clone(type);
auto* ctor = ctx->Clone(constructor);
auto attrs = ctx->Clone(attributes);
return ctx->dst->create<Var>(src, sym, ty, declared_storage_class, declared_access, ctor,
return ctx->dst->create<Var>(src, sym, ty, declared_address_space, declared_access, ctor,
std::move(attrs));
}

View File

@@ -28,11 +28,11 @@ namespace tint::ast {
///
/// ```
/// // Declared outside a function, i.e. at module scope, requires
/// // a storage class.
/// // a address space.
/// var<workgroup> width : i32; // no initializer
/// var<private> height : i32 = 3; // with initializer
///
/// // A variable declared inside a function doesn't take a storage class,
/// // A variable declared inside a function doesn't take a address space,
/// // and maps to SPIR-V Function storage.
/// var computed_depth : i32;
/// var area : i32 = compute_area(width, height);
@@ -47,7 +47,7 @@ class Var final : public Castable<Var, Variable> {
/// @param source the variable source
/// @param sym the variable symbol
/// @param type the declared variable type
/// @param declared_storage_class the declared storage class
/// @param declared_address_space the declared address space
/// @param declared_access the declared access control
/// @param constructor the constructor expression
/// @param attributes the variable attributes
@@ -56,7 +56,7 @@ class Var final : public Castable<Var, Variable> {
const Source& source,
const Symbol& sym,
const ast::Type* type,
StorageClass declared_storage_class,
AddressSpace declared_address_space,
Access declared_access,
const Expression* constructor,
utils::VectorRef<const Attribute*> attributes);
@@ -76,8 +76,8 @@ class Var final : public Castable<Var, Variable> {
/// @return the newly cloned node
const Var* Clone(CloneContext* ctx) const override;
/// The declared storage class
const StorageClass declared_storage_class;
/// The declared address space
const AddressSpace declared_address_space;
/// The declared access control
const Access declared_access;

View File

@@ -19,11 +19,11 @@
#include <vector>
#include "src/tint/ast/access.h"
#include "src/tint/ast/address_space.h"
#include "src/tint/ast/attribute.h"
#include "src/tint/ast/binding_attribute.h"
#include "src/tint/ast/expression.h"
#include "src/tint/ast/group_attribute.h"
#include "src/tint/ast/storage_class.h"
// Forward declarations
namespace tint::ast {

View File

@@ -25,10 +25,10 @@ namespace {
using VariableTest = TestHelper;
TEST_F(VariableTest, Creation) {
auto* v = Var("my_var", ty.i32(), StorageClass::kFunction);
auto* v = Var("my_var", ty.i32(), AddressSpace::kFunction);
EXPECT_EQ(v->symbol, Symbol(1, ID()));
EXPECT_EQ(v->declared_storage_class, StorageClass::kFunction);
EXPECT_EQ(v->declared_address_space, AddressSpace::kFunction);
EXPECT_TRUE(v->type->Is<ast::I32>());
EXPECT_EQ(v->source.range.begin.line, 0u);
EXPECT_EQ(v->source.range.begin.column, 0u);
@@ -38,10 +38,10 @@ TEST_F(VariableTest, Creation) {
TEST_F(VariableTest, CreationWithSource) {
auto* v = Var(Source{Source::Range{Source::Location{27, 4}, Source::Location{27, 5}}}, "i",
ty.f32(), StorageClass::kPrivate, utils::Empty);
ty.f32(), AddressSpace::kPrivate, utils::Empty);
EXPECT_EQ(v->symbol, Symbol(1, ID()));
EXPECT_EQ(v->declared_storage_class, StorageClass::kPrivate);
EXPECT_EQ(v->declared_address_space, AddressSpace::kPrivate);
EXPECT_TRUE(v->type->Is<ast::F32>());
EXPECT_EQ(v->source.range.begin.line, 27u);
EXPECT_EQ(v->source.range.begin.column, 4u);
@@ -51,10 +51,10 @@ TEST_F(VariableTest, CreationWithSource) {
TEST_F(VariableTest, CreationEmpty) {
auto* v = Var(Source{Source::Range{Source::Location{27, 4}, Source::Location{27, 7}}}, "a_var",
ty.i32(), StorageClass::kWorkgroup, utils::Empty);
ty.i32(), AddressSpace::kWorkgroup, utils::Empty);
EXPECT_EQ(v->symbol, Symbol(1, ID()));
EXPECT_EQ(v->declared_storage_class, StorageClass::kWorkgroup);
EXPECT_EQ(v->declared_address_space, AddressSpace::kWorkgroup);
EXPECT_TRUE(v->type->Is<ast::I32>());
EXPECT_EQ(v->source.range.begin.line, 27u);
EXPECT_EQ(v->source.range.begin.column, 4u);
@@ -92,7 +92,7 @@ TEST_F(VariableTest, Assert_DifferentProgramID_Constructor) {
}
TEST_F(VariableTest, WithAttributes) {
auto* var = Var("my_var", ty.i32(), StorageClass::kFunction, Location(1_u),
auto* var = Var("my_var", ty.i32(), AddressSpace::kFunction, Location(1_u),
Builtin(BuiltinValue::kPosition), Id(1200_u));
auto& attributes = var->attributes;
@@ -107,22 +107,22 @@ TEST_F(VariableTest, WithAttributes) {
}
TEST_F(VariableTest, HasBindingPoint_BothProvided) {
auto* var = Var("my_var", ty.i32(), StorageClass::kFunction, Binding(2_a), Group(1_a));
auto* var = Var("my_var", ty.i32(), AddressSpace::kFunction, Binding(2_a), Group(1_a));
EXPECT_TRUE(var->HasBindingPoint());
}
TEST_F(VariableTest, HasBindingPoint_NeitherProvided) {
auto* var = Var("my_var", ty.i32(), StorageClass::kFunction, utils::Empty);
auto* var = Var("my_var", ty.i32(), AddressSpace::kFunction, utils::Empty);
EXPECT_FALSE(var->HasBindingPoint());
}
TEST_F(VariableTest, HasBindingPoint_MissingGroupAttribute) {
auto* var = Var("my_var", ty.i32(), StorageClass::kFunction, Binding(2_a));
auto* var = Var("my_var", ty.i32(), AddressSpace::kFunction, Binding(2_a));
EXPECT_FALSE(var->HasBindingPoint());
}
TEST_F(VariableTest, HasBindingPoint_MissingBindingAttribute) {
auto* var = Var("my_var", ty.i32(), StorageClass::kFunction, Group(1_a));
auto* var = Var("my_var", ty.i32(), AddressSpace::kFunction, Group(1_a));
EXPECT_FALSE(var->HasBindingPoint());
}