tint/ast: Generate access.[h|cc]

Emits all the enum info from the single-source-of-truth `intrinsics.def` file

Change-Id: Ib9170a2337597d4d81983c446d50582b518c6d71
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/105329
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@chromium.org>
This commit is contained in:
Ben Clayton 2022-10-12 09:42:00 +00:00 committed by Dawn LUCI CQ
parent 47b7fe5785
commit bccd87c37a
27 changed files with 235 additions and 157 deletions

View File

@ -12,30 +12,46 @@
// 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/access.cc.tmpl
//
// Do not modify this file directly
////////////////////////////////////////////////////////////////////////////////
#include "src/tint/ast/access.h"
namespace tint::ast {
std::ostream& operator<<(std::ostream& out, Access access) {
switch (access) {
case ast::Access::kUndefined: {
out << "undefined";
break;
}
case ast::Access::kRead: {
out << "read";
break;
}
case ast::Access::kReadWrite: {
out << "read_write";
break;
}
case ast::Access::kWrite: {
out << "write";
break;
}
/// ParseAccess parses a Access from a string.
/// @param str the string to parse
/// @returns the parsed enum, or Access::kInvalid if the string could not be parsed.
Access ParseAccess(std::string_view str) {
if (str == "read") {
return Access::kRead;
}
return out;
if (str == "read_write") {
return Access::kReadWrite;
}
if (str == "write") {
return Access::kWrite;
}
return Access::kInvalid;
}
std::ostream& operator<<(std::ostream& out, Access value) {
switch (value) {
case Access::kInvalid:
return out << "invalid";
case Access::kRead:
return out << "read";
case Access::kReadWrite:
return out << "read_write";
case Access::kWrite:
return out << "write";
}
return out << "<unknown>";
}
} // namespace tint::ast

View File

@ -0,0 +1,25 @@
{{- /*
--------------------------------------------------------------------------------
Template file for use with tools/src/cmd/gen to generate access.cc
To update the generated file, run:
./tools/run gen
See:
* tools/src/cmd/gen for structures used by this template
* https://golang.org/pkg/text/template/ for documentation on the template syntax
--------------------------------------------------------------------------------
*/ -}}
{{- Import "src/tint/templates/enums.tmpl.inc" -}}
{{- $enum := (Sem.Enum "access") -}}
#include "src/tint/ast/access.h"
namespace tint::ast {
{{ Eval "ParseEnum" $enum}}
{{ Eval "EnumOStream" $enum}}
} // namespace tint::ast

View File

@ -12,32 +12,44 @@
// 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/access.h.tmpl
//
// Do not modify this file directly
////////////////////////////////////////////////////////////////////////////////
#ifndef SRC_TINT_AST_ACCESS_H_
#define SRC_TINT_AST_ACCESS_H_
#include <ostream>
#include <string>
namespace tint::ast {
/// The access control settings
enum Access {
/// Not declared in the source
kUndefined = 0,
/// Read only
/// Address space of a given pointer.
enum class Access {
kInvalid,
kRead,
/// Write only
kWrite,
/// Read write
kReadWrite,
// Last valid access mode
kLastValid = kReadWrite,
kWrite,
};
/// @param out the std::ostream to write to
/// @param access the Access
/// @return the std::ostream so calls can be chained
std::ostream& operator<<(std::ostream& out, Access access);
/// @param value the Access
/// @returns `out` so calls can be chained
std::ostream& operator<<(std::ostream& out, Access value);
/// ParseAccess parses a Access from a string.
/// @param str the string to parse
/// @returns the parsed enum, or Access::kInvalid if the string could not be parsed.
Access ParseAccess(std::string_view str);
constexpr const char* kAccessStrings[] = {
"read",
"read_write",
"write",
};
} // namespace tint::ast

View File

@ -0,0 +1,29 @@
{{- /*
--------------------------------------------------------------------------------
Template file for use with tools/src/cmd/gen to generate access.h
To update the generated file, run:
./tools/run gen
See:
* tools/src/cmd/gen for structures used by this template
* https://golang.org/pkg/text/template/ for documentation on the template syntax
--------------------------------------------------------------------------------
*/ -}}
{{- Import "src/tint/templates/enums.tmpl.inc" -}}
{{- $enum := (Sem.Enum "access") -}}
#ifndef SRC_TINT_AST_ACCESS_H_
#define SRC_TINT_AST_ACCESS_H_
#include <ostream>
namespace tint::ast {
/// Address space of a given pointer.
{{ Eval "DeclareEnum" $enum}}
} // namespace tint::ast
#endif // SRC_TINT_AST_ACCESS_H_

View File

@ -35,7 +35,7 @@ std::string Pointer::FriendlyName(const SymbolTable& symbols) const {
out << address_space << ", ";
}
out << type->FriendlyName(symbols);
if (access != ast::Access::kUndefined) {
if (access != ast::Access::kInvalid) {
out << ", " << access;
}
out << ">";

View File

@ -32,7 +32,7 @@ TEST_F(AstPointerTest, Creation) {
TEST_F(AstPointerTest, FriendlyName) {
auto* i32 = create<I32>();
auto* p = create<Pointer>(i32, ast::AddressSpace::kWorkgroup, Access::kUndefined);
auto* p = create<Pointer>(i32, ast::AddressSpace::kWorkgroup, Access::kInvalid);
EXPECT_EQ(p->FriendlyName(Symbols()), "ptr<workgroup, i32>");
}

View File

@ -173,7 +173,7 @@ class ProgramBuilder {
const ast::Type* type = nullptr;
ast::AddressSpace address_space = ast::AddressSpace::kNone;
ast::Access access = ast::Access::kUndefined;
ast::Access access = ast::Access::kInvalid;
const ast::Expression* constructor = nullptr;
utils::Vector<const ast::Attribute*, 4> attributes;
@ -902,7 +902,7 @@ class ProgramBuilder {
/// @return the pointer to `type` with the given ast::AddressSpace
const ast::Pointer* pointer(const ast::Type* type,
ast::AddressSpace address_space,
ast::Access access = ast::Access::kUndefined) const {
ast::Access access = ast::Access::kInvalid) const {
return builder->create<ast::Pointer>(type, address_space, access);
}
@ -914,7 +914,7 @@ class ProgramBuilder {
const ast::Pointer* pointer(const Source& source,
const ast::Type* type,
ast::AddressSpace address_space,
ast::Access access = ast::Access::kUndefined) const {
ast::Access access = ast::Access::kInvalid) const {
return builder->create<ast::Pointer>(source, type, address_space, access);
}
@ -923,7 +923,7 @@ class ProgramBuilder {
/// @return the pointer to type `T` with the given ast::AddressSpace.
template <typename T>
const ast::Pointer* pointer(ast::AddressSpace address_space,
ast::Access access = ast::Access::kUndefined) const {
ast::Access access = ast::Access::kInvalid) const {
return pointer(Of<T>(), address_space, access);
}
@ -934,7 +934,7 @@ class ProgramBuilder {
template <typename T>
const ast::Pointer* pointer(const Source& source,
ast::AddressSpace address_space,
ast::Access access = ast::Access::kUndefined) const {
ast::Access access = ast::Access::kInvalid) const {
return pointer(source, Of<T>(), address_space, access);
}

View File

@ -4854,7 +4854,7 @@ DefInfo::Pointer FunctionEmitter::GetPointerInfo(uint32_t id) {
}
// Local variables are always Function storage class, with default
// access mode.
return DefInfo::Pointer{ast::AddressSpace::kFunction, ast::Access::kUndefined};
return DefInfo::Pointer{ast::AddressSpace::kFunction, ast::Access::kInvalid};
}
case SpvOpFunctionParameter: {
const auto* type = As<Pointer>(parser_impl_.ConvertType(inst.type_id()));
@ -4862,7 +4862,7 @@ DefInfo::Pointer FunctionEmitter::GetPointerInfo(uint32_t id) {
// Using kUndefined is ok for now, since the only non-default access mode
// on a pointer would be for a storage buffer, and baseline SPIR-V doesn't
// allow passing pointers to buffers as function parameters.
return DefInfo::Pointer{type->address_space, ast::Access::kUndefined};
return DefInfo::Pointer{type->address_space, ast::Access::kInvalid};
}
default:
break;

View File

@ -335,7 +335,7 @@ struct DefInfo {
ast::AddressSpace address_space = ast::AddressSpace::kInvalid;
/// The declared access mode.
ast::Access access = ast::kUndefined;
ast::Access access = ast::Access::kInvalid;
};
/// The expression to use when sinking pointers into their use.

View File

@ -1567,7 +1567,7 @@ ast::Var* ParserImpl::MakeVar(uint32_t id,
return nullptr;
}
ast::Access access = ast::Access::kUndefined;
ast::Access access = ast::Access::kInvalid;
if (address_space == ast::AddressSpace::kStorage) {
bool read_only = false;
if (auto* tn = storage_type->As<Named>()) {

View File

@ -1006,7 +1006,7 @@ Maybe<ParserImpl::VariableQualifier> ParserImpl::variable_qualifier() {
}
return VariableQualifier{sc.value, ac.value};
}
return Expect<VariableQualifier>{VariableQualifier{sc.value, ast::Access::kUndefined},
return Expect<VariableQualifier>{VariableQualifier{sc.value, ast::Access::kInvalid},
source};
});
@ -1262,7 +1262,7 @@ Expect<const ast::Type*> ParserImpl::expect_type_specifier_pointer(const Source&
const char* use = "ptr declaration";
auto address_space = ast::AddressSpace::kNone;
auto access = ast::Access::kUndefined;
auto access = ast::Access::kInvalid;
auto subtype = expect_lt_gt_block(use, [&]() -> Expect<const ast::Type*> {
auto sc = expect_address_space(use);

View File

@ -296,7 +296,7 @@ class ParserImpl {
/// Variable address space
ast::AddressSpace address_space = ast::AddressSpace::kNone;
/// Variable access control
ast::Access access = ast::Access::kUndefined;
ast::Access access = ast::Access::kInvalid;
/// Variable type
const ast::Type* type = nullptr;
};
@ -306,7 +306,7 @@ class ParserImpl {
/// The variable's address space
ast::AddressSpace address_space = ast::AddressSpace::kNone;
/// The variable's access control
ast::Access access = ast::Access::kUndefined;
ast::Access access = ast::Access::kInvalid;
};
/// MatrixDimensions contains the column and row information for a matrix

View File

@ -47,11 +47,11 @@ INSTANTIATE_TEST_SUITE_P(
ParserImplTest,
VariableQualifierTest,
testing::Values(
VariableStorageData{"uniform", ast::AddressSpace::kUniform, ast::Access::kUndefined},
VariableStorageData{"workgroup", ast::AddressSpace::kWorkgroup, ast::Access::kUndefined},
VariableStorageData{"storage", ast::AddressSpace::kStorage, ast::Access::kUndefined},
VariableStorageData{"private", ast::AddressSpace::kPrivate, ast::Access::kUndefined},
VariableStorageData{"function", ast::AddressSpace::kFunction, ast::Access::kUndefined},
VariableStorageData{"uniform", ast::AddressSpace::kUniform, ast::Access::kInvalid},
VariableStorageData{"workgroup", ast::AddressSpace::kWorkgroup, ast::Access::kInvalid},
VariableStorageData{"storage", ast::AddressSpace::kStorage, ast::Access::kInvalid},
VariableStorageData{"private", ast::AddressSpace::kPrivate, ast::Access::kInvalid},
VariableStorageData{"function", ast::AddressSpace::kFunction, ast::Access::kInvalid},
VariableStorageData{"storage, read", ast::AddressSpace::kStorage, ast::Access::kRead},
VariableStorageData{"storage, write", ast::AddressSpace::kStorage, ast::Access::kWrite},
VariableStorageData{"storage, read_write", ast::AddressSpace::kStorage,

View File

@ -721,7 +721,7 @@ TEST_F(StructMemberAttributeTest, Align_Attribute_ConstAFloat) {
}
TEST_F(StructMemberAttributeTest, Align_Attribute_Var) {
GlobalVar(Source{{1, 2}}, "val", ty.f32(), ast::AddressSpace::kPrivate, ast::Access::kUndefined,
GlobalVar(Source{{1, 2}}, "val", ty.f32(), ast::AddressSpace::kPrivate, ast::Access::kInvalid,
Expr(1.23_f));
Structure(Source{{6, 4}}, "mystruct",

View File

@ -1186,7 +1186,7 @@ Impl::Builtin Impl::Lookup(sem::BuiltinType builtin_type,
for (auto& p : match.parameters) {
params.Push(builder.create<sem::Parameter>(
nullptr, static_cast<uint32_t>(params.Length()), p.type, ast::AddressSpace::kNone,
ast::Access::kUndefined, p.usage));
ast::Access::kInvalid, p.usage));
}
sem::PipelineStageSet supported_stages;
if (match.overload->flags.Contains(OverloadFlag::kSupportsVertexPipeline)) {
@ -1384,7 +1384,7 @@ IntrinsicTable::CtorOrConv Impl::Lookup(CtorConvIntrinsic type,
for (auto& p : match.parameters) {
params.Push(builder.create<sem::Parameter>(
nullptr, static_cast<uint32_t>(params.Length()), p.type, ast::AddressSpace::kNone,
ast::Access::kUndefined, p.usage));
ast::Access::kInvalid, p.usage));
}
auto eval_stage = match.overload->const_eval_fn ? sem::EvaluationStage::kConstant
: sem::EvaluationStage::kRuntime;
@ -1397,9 +1397,9 @@ IntrinsicTable::CtorOrConv Impl::Lookup(CtorConvIntrinsic type,
// Conversion.
auto* target = utils::GetOrCreate(converters, match, [&]() {
auto param = builder.create<sem::Parameter>(
nullptr, 0u, match.parameters[0].type, ast::AddressSpace::kNone,
ast::Access::kUndefined, match.parameters[0].usage);
auto param = builder.create<sem::Parameter>(nullptr, 0u, match.parameters[0].type,
ast::AddressSpace::kNone, ast::Access::kInvalid,
match.parameters[0].usage);
auto eval_stage = match.overload->const_eval_fn ? sem::EvaluationStage::kConstant
: sem::EvaluationStage::kRuntime;
return builder.create<sem::TypeConversion>(match.return_type, param, eval_stage);

View File

@ -1,6 +1,6 @@
{{- /*
--------------------------------------------------------------------------------
Template file for use with tools/src/cmd/gen to generate builtin_table.inl
Template file for use with tools/src/cmd/gen to generate intrinsic_table.inl
Used by BuiltinTable.cc for builtin overload resolution.
To update the generated file, run:

View File

@ -251,7 +251,7 @@ sem::Type* Resolver::Type(const ast::Type* ty) {
[&](const ast::Pointer* t) -> sem::Pointer* {
if (auto* el = Type(t->type)) {
auto access = t->access;
if (access == ast::kUndefined) {
if (access == ast::Access::kInvalid) {
access = DefaultAccessForAddressSpace(t->address_space);
}
return builder_->create<sem::Pointer>(el, t->address_space, access);
@ -386,13 +386,12 @@ sem::Variable* Resolver::Let(const ast::Let* v, bool is_global) {
sem::Variable* sem = nullptr;
if (is_global) {
sem = builder_->create<sem::GlobalVariable>(
v, ty, sem::EvaluationStage::kRuntime, ast::AddressSpace::kNone,
ast::Access::kUndefined, /* constant_value */ nullptr, sem::BindingPoint{},
std::nullopt);
v, ty, sem::EvaluationStage::kRuntime, ast::AddressSpace::kNone, ast::Access::kInvalid,
/* constant_value */ nullptr, sem::BindingPoint{}, std::nullopt);
} else {
sem = builder_->create<sem::LocalVariable>(v, ty, sem::EvaluationStage::kRuntime,
ast::AddressSpace::kNone,
ast::Access::kUndefined, current_statement_,
ast::AddressSpace::kNone, ast::Access::kInvalid,
current_statement_,
/* constant_value */ nullptr);
}
@ -442,7 +441,7 @@ sem::Variable* Resolver::Override(const ast::Override* v) {
}
auto* sem = builder_->create<sem::GlobalVariable>(
v, ty, sem::EvaluationStage::kOverride, ast::AddressSpace::kNone, ast::Access::kUndefined,
v, ty, sem::EvaluationStage::kOverride, ast::AddressSpace::kNone, ast::Access::kInvalid,
/* constant_value */ nullptr, sem::BindingPoint{}, std::nullopt);
sem->SetConstructor(rhs);
@ -527,10 +526,10 @@ sem::Variable* Resolver::Const(const ast::Const* c, bool is_global) {
auto* sem = is_global ? static_cast<sem::Variable*>(builder_->create<sem::GlobalVariable>(
c, ty, sem::EvaluationStage::kConstant, ast::AddressSpace::kNone,
ast::Access::kUndefined, value, sem::BindingPoint{}, std::nullopt))
ast::Access::kInvalid, value, sem::BindingPoint{}, std::nullopt))
: static_cast<sem::Variable*>(builder_->create<sem::LocalVariable>(
c, ty, sem::EvaluationStage::kConstant, ast::AddressSpace::kNone,
ast::Access::kUndefined, current_statement_, value));
ast::Access::kInvalid, current_statement_, value));
sem->SetConstructor(rhs);
builder_->Sem().Add(c, sem);
@ -589,7 +588,7 @@ sem::Variable* Resolver::Var(const ast::Var* var, bool is_global) {
}
auto access = var->declared_access;
if (access == ast::Access::kUndefined) {
if (access == ast::Access::kInvalid) {
access = DefaultAccessForAddressSpace(address_space);
}
@ -753,9 +752,9 @@ sem::Parameter* Resolver::Parameter(const ast::Parameter* param, uint32_t index)
location = c->As<uint32_t>();
}
auto* sem = builder_->create<sem::Parameter>(
param, index, ty, ast::AddressSpace::kNone, ast::Access::kUndefined,
sem::ParameterUsage::kNone, binding_point, location);
auto* sem = builder_->create<sem::Parameter>(param, index, ty, ast::AddressSpace::kNone,
ast::Access::kInvalid, sem::ParameterUsage::kNone,
binding_point, location);
builder_->Sem().Add(param, sem);
return sem;
}
@ -1789,7 +1788,7 @@ sem::Call* Resolver::Call(const ast::CallExpression* expr) {
static_cast<uint32_t>(i), // index
arr->ElemType(), // type
ast::AddressSpace::kNone, // address_space
ast::Access::kUndefined);
ast::Access::kInvalid);
});
return builder_->create<sem::TypeConstructor>(arr, std::move(params),
args_stage);
@ -1818,7 +1817,7 @@ sem::Call* Resolver::Call(const ast::CallExpression* expr) {
static_cast<uint32_t>(i), // index
str->Members()[i]->Type(), // type
ast::AddressSpace::kNone, // address_space
ast::Access::kUndefined); // access
ast::Access::kInvalid); // access
}
return builder_->create<sem::TypeConstructor>(str, std::move(params),
args_stage);

View File

@ -1165,7 +1165,7 @@ TEST_F(StorageTextureAccessTest, MissingAccess_Fail) {
// var a : texture_storage_1d<ru32int>;
auto* st = ty.storage_texture(Source{{12, 34}}, ast::TextureDimension::k1d,
ast::TexelFormat::kR32Uint, ast::Access::kUndefined);
ast::TexelFormat::kR32Uint, ast::Access::kInvalid);
GlobalVar("a", st, Group(0_a), Binding(0_a));

View File

@ -263,7 +263,7 @@ bool Validator::StorageTexture(const ast::StorageTexture* t) const {
switch (t->access) {
case ast::Access::kWrite:
break;
case ast::Access::kUndefined:
case ast::Access::kInvalid:
AddError("storage texture missing access control", t->source);
return false;
default:
@ -621,7 +621,7 @@ bool Validator::GlobalVariable(
// https://gpuweb.github.io/gpuweb/wgsl/#variable-declaration
// The access mode always has a default, and except for variables in the storage address
// space, must not be written.
if (var->declared_access != ast::Access::kUndefined) {
if (var->declared_access != ast::Access::kInvalid) {
if (global->AddressSpace() == ast::AddressSpace::kStorage) {
// The access mode for the storage address space can only be 'read' or
// 'read_write'.

View File

@ -25,7 +25,7 @@ namespace tint::sem {
Pointer::Pointer(const Type* subtype, ast::AddressSpace address_space, ast::Access access)
: subtype_(subtype), address_space_(address_space), access_(access) {
TINT_ASSERT(Semantic, !subtype->Is<Reference>());
TINT_ASSERT(Semantic, access != ast::Access::kUndefined);
TINT_ASSERT(Semantic, access != ast::Access::kInvalid);
}
size_t Pointer::Hash() const {

View File

@ -24,7 +24,7 @@ namespace tint::sem {
Reference::Reference(const Type* subtype, ast::AddressSpace address_space, ast::Access access)
: subtype_(subtype), address_space_(address_space), access_(access) {
TINT_ASSERT(Semantic, !subtype->Is<Reference>());
TINT_ASSERT(Semantic, access != ast::Access::kUndefined);
TINT_ASSERT(Semantic, access != ast::Access::kInvalid);
}
size_t Reference::Hash() const {

View File

@ -121,7 +121,7 @@ void BindingRemapper::Run(CloneContext& ctx, const DataMap& inputs, DataMap&) co
auto ac_it = remappings->access_controls.find(from);
if (ac_it != remappings->access_controls.end()) {
ast::Access ac = ac_it->second;
if (ac > ast::Access::kLastValid) {
if (ac == ast::Access::kInvalid) {
ctx.dst->Diagnostics().add_error(
diag::System::Transform,
"invalid access mode (" + std::to_string(static_cast<uint32_t>(ac)) + ")");

View File

@ -137,7 +137,7 @@ const sem::Call* AppendVector(ProgramBuilder* b,
auto* scalar_cast_target = b->create<sem::TypeConversion>(
packed_el_sem_ty,
b->create<sem::Parameter>(nullptr, 0u, scalar_sem->Type()->UnwrapRef(),
ast::AddressSpace::kNone, ast::Access::kUndefined),
ast::AddressSpace::kNone, ast::Access::kInvalid),
sem::EvaluationStage::kRuntime);
auto* scalar_cast_sem = b->create<sem::Call>(
scalar_cast_ast, scalar_cast_target, sem::EvaluationStage::kRuntime,
@ -158,7 +158,7 @@ const sem::Call* AppendVector(ProgramBuilder* b,
[&](const tint::sem::Expression* arg, size_t i) -> const sem::Parameter* {
return b->create<sem::Parameter>(
nullptr, static_cast<uint32_t>(i), arg->Type()->UnwrapRef(),
ast::AddressSpace::kNone, ast::Access::kUndefined);
ast::AddressSpace::kNone, ast::Access::kInvalid);
}),
sem::EvaluationStage::kRuntime);
auto* constructor_sem =

View File

@ -509,20 +509,20 @@ bool GeneratorImpl::EmitFloatModulo(std::ostream& out, const ast::BinaryExpressi
{
auto decl = line(&b);
if (!EmitTypeAndName(decl, ret_ty, ast::AddressSpace::kNone,
ast::Access::kUndefined, fn_name)) {
ast::Access::kInvalid, fn_name)) {
return "";
}
{
ScopedParen sp(decl);
const auto* ty = TypeOf(expr->lhs)->UnwrapRef();
if (!EmitTypeAndName(decl, ty, ast::AddressSpace::kNone,
ast::Access::kUndefined, "lhs")) {
ast::Access::kInvalid, "lhs")) {
return "";
}
decl << ", ";
ty = TypeOf(expr->rhs)->UnwrapRef();
if (!EmitTypeAndName(decl, ty, ast::AddressSpace::kNone,
ast::Access::kUndefined, "rhs")) {
ast::Access::kInvalid, "rhs")) {
return "";
}
}
@ -935,7 +935,7 @@ bool GeneratorImpl::EmitWorkgroupAtomicCall(std::ostream& out,
{
auto pre = line();
if (!EmitTypeAndName(pre, builtin->ReturnType(), ast::AddressSpace::kNone,
ast::Access::kUndefined, result)) {
ast::Access::kInvalid, result)) {
return false;
}
pre << ";";
@ -1213,7 +1213,7 @@ bool GeneratorImpl::EmitModfCall(std::ostream& out,
{
auto l = line(b);
if (!EmitType(l, builtin->ReturnType(), ast::AddressSpace::kNone,
ast::Access::kUndefined, "")) {
ast::Access::kInvalid, "")) {
return false;
}
l << " result;";
@ -1239,7 +1239,7 @@ bool GeneratorImpl::EmitFrexpCall(std::ostream& out,
{
auto l = line(b);
if (!EmitType(l, builtin->ReturnType(), ast::AddressSpace::kNone,
ast::Access::kUndefined, "")) {
ast::Access::kInvalid, "")) {
return false;
}
l << " result;";
@ -2198,7 +2198,7 @@ bool GeneratorImpl::EmitConstant(std::ostream& out, const sem::Constant* constan
return true;
},
[&](const sem::Vector* v) {
if (!EmitType(out, v, ast::AddressSpace::kNone, ast::Access::kUndefined, "")) {
if (!EmitType(out, v, ast::AddressSpace::kNone, ast::Access::kInvalid, "")) {
return false;
}
@ -2219,7 +2219,7 @@ bool GeneratorImpl::EmitConstant(std::ostream& out, const sem::Constant* constan
return true;
},
[&](const sem::Matrix* m) {
if (!EmitType(out, m, ast::AddressSpace::kNone, ast::Access::kUndefined, "")) {
if (!EmitType(out, m, ast::AddressSpace::kNone, ast::Access::kInvalid, "")) {
return false;
}
@ -2236,7 +2236,7 @@ bool GeneratorImpl::EmitConstant(std::ostream& out, const sem::Constant* constan
return true;
},
[&](const sem::Array* a) {
if (!EmitType(out, a, ast::AddressSpace::kNone, ast::Access::kUndefined, "")) {
if (!EmitType(out, a, ast::AddressSpace::kNone, ast::Access::kInvalid, "")) {
return false;
}
@ -2260,7 +2260,7 @@ bool GeneratorImpl::EmitConstant(std::ostream& out, const sem::Constant* constan
return true;
},
[&](const sem::Struct* s) {
if (!EmitType(out, s, ast::AddressSpace::kNone, ast::Access::kUndefined, "")) {
if (!EmitType(out, s, ast::AddressSpace::kNone, ast::Access::kInvalid, "")) {
return false;
}
@ -2351,7 +2351,7 @@ bool GeneratorImpl::EmitZeroValue(std::ostream& out, const sem::Type* type) {
}
}
} else if (auto* str = type->As<sem::Struct>()) {
if (!EmitType(out, type, ast::AddressSpace::kNone, ast::Access::kUndefined, "")) {
if (!EmitType(out, type, ast::AddressSpace::kNone, ast::Access::kInvalid, "")) {
return false;
}
bool first = true;
@ -2365,7 +2365,7 @@ bool GeneratorImpl::EmitZeroValue(std::ostream& out, const sem::Type* type) {
EmitZeroValue(out, member->Type());
}
} else if (auto* arr = type->As<sem::Array>()) {
if (!EmitType(out, type, ast::AddressSpace::kNone, ast::Access::kUndefined, "")) {
if (!EmitType(out, type, ast::AddressSpace::kNone, ast::Access::kInvalid, "")) {
return false;
}
ScopedParen sp(out);
@ -2972,7 +2972,7 @@ bool GeneratorImpl::EmitLet(const ast::Let* let) {
auto out = line();
// TODO(senorblanco): handle const
if (!EmitTypeAndName(out, type, ast::AddressSpace::kNone, ast::Access::kUndefined,
if (!EmitTypeAndName(out, type, ast::AddressSpace::kNone, ast::Access::kInvalid,
builder_.Symbols().NameFor(let->symbol))) {
return false;
}
@ -2994,7 +2994,7 @@ bool GeneratorImpl::EmitProgramConstVariable(const ast::Variable* var) {
auto out = line();
out << "const ";
if (!EmitTypeAndName(out, type, ast::AddressSpace::kNone, ast::Access::kUndefined,
if (!EmitTypeAndName(out, type, ast::AddressSpace::kNone, ast::Access::kInvalid,
builder_.Symbols().NameFor(var->symbol))) {
return false;
}
@ -3022,7 +3022,7 @@ bool GeneratorImpl::CallBuiltinHelper(std::ostream& out,
{
auto decl = line(&b);
if (!EmitTypeAndName(decl, builtin->ReturnType(), ast::AddressSpace::kNone,
ast::Access::kUndefined, fn_name)) {
ast::Access::kInvalid, fn_name)) {
return "";
}
{
@ -3037,8 +3037,8 @@ bool GeneratorImpl::CallBuiltinHelper(std::ostream& out,
decl << "inout ";
ty = ptr->StoreType();
}
if (!EmitTypeAndName(decl, ty, ast::AddressSpace::kNone,
ast::Access::kUndefined, param_name)) {
if (!EmitTypeAndName(decl, ty, ast::AddressSpace::kNone, ast::Access::kInvalid,
param_name)) {
return "";
}
parameter_names.emplace_back(std::move(param_name));

View File

@ -325,8 +325,7 @@ bool GeneratorImpl::EmitDynamicVectorAssignment(const ast::AssignmentStatement*
std::string fn;
{
std::ostringstream ss;
if (!EmitType(ss, vec, tint::ast::AddressSpace::kInvalid, ast::Access::kUndefined,
"")) {
if (!EmitType(ss, vec, tint::ast::AddressSpace::kInvalid, ast::Access::kInvalid, "")) {
return "";
}
fn = UniqueIdentifier("set_" + ss.str());
@ -334,13 +333,13 @@ bool GeneratorImpl::EmitDynamicVectorAssignment(const ast::AssignmentStatement*
{
auto out = line(&helpers_);
out << "void " << fn << "(inout ";
if (!EmitTypeAndName(out, vec, ast::AddressSpace::kInvalid, ast::Access::kUndefined,
if (!EmitTypeAndName(out, vec, ast::AddressSpace::kInvalid, ast::Access::kInvalid,
"vec")) {
return "";
}
out << ", int idx, ";
if (!EmitTypeAndName(out, vec->type(), ast::AddressSpace::kInvalid,
ast::Access::kUndefined, "val")) {
ast::Access::kInvalid, "val")) {
return "";
}
out << ") {";
@ -399,8 +398,7 @@ bool GeneratorImpl::EmitDynamicMatrixVectorAssignment(const ast::AssignmentState
std::string fn;
{
std::ostringstream ss;
if (!EmitType(ss, mat, tint::ast::AddressSpace::kInvalid, ast::Access::kUndefined,
"")) {
if (!EmitType(ss, mat, tint::ast::AddressSpace::kInvalid, ast::Access::kInvalid, "")) {
return "";
}
fn = UniqueIdentifier("set_vector_" + ss.str());
@ -408,13 +406,13 @@ bool GeneratorImpl::EmitDynamicMatrixVectorAssignment(const ast::AssignmentState
{
auto out = line(&helpers_);
out << "void " << fn << "(inout ";
if (!EmitTypeAndName(out, mat, ast::AddressSpace::kInvalid, ast::Access::kUndefined,
if (!EmitTypeAndName(out, mat, ast::AddressSpace::kInvalid, ast::Access::kInvalid,
"mat")) {
return "";
}
out << ", int col, ";
if (!EmitTypeAndName(out, mat->ColumnType(), ast::AddressSpace::kInvalid,
ast::Access::kUndefined, "val")) {
ast::Access::kInvalid, "val")) {
return "";
}
out << ") {";
@ -468,8 +466,7 @@ bool GeneratorImpl::EmitDynamicMatrixScalarAssignment(const ast::AssignmentState
std::string fn;
{
std::ostringstream ss;
if (!EmitType(ss, mat, tint::ast::AddressSpace::kInvalid, ast::Access::kUndefined,
"")) {
if (!EmitType(ss, mat, tint::ast::AddressSpace::kInvalid, ast::Access::kInvalid, "")) {
return "";
}
fn = UniqueIdentifier("set_scalar_" + ss.str());
@ -477,13 +474,13 @@ bool GeneratorImpl::EmitDynamicMatrixScalarAssignment(const ast::AssignmentState
{
auto out = line(&helpers_);
out << "void " << fn << "(inout ";
if (!EmitTypeAndName(out, mat, ast::AddressSpace::kInvalid, ast::Access::kUndefined,
if (!EmitTypeAndName(out, mat, ast::AddressSpace::kInvalid, ast::Access::kInvalid,
"mat")) {
return "";
}
out << ", int col, int row, ";
if (!EmitTypeAndName(out, mat->type(), ast::AddressSpace::kInvalid,
ast::Access::kUndefined, "val")) {
ast::Access::kInvalid, "val")) {
return "";
}
out << ") {";
@ -658,7 +655,7 @@ bool GeneratorImpl::EmitExpressionOrOneIfZero(std::ostream& out, const ast::Expr
if (auto* vec = ty->As<sem::Vector>()) {
auto* elem_ty = vec->type();
if (!EmitType(out, ty, ast::AddressSpace::kNone, ast::Access::kUndefined, "")) {
if (!EmitType(out, ty, ast::AddressSpace::kNone, ast::Access::kInvalid, "")) {
return false;
}
@ -723,7 +720,7 @@ bool GeneratorImpl::EmitExpressionOrOneIfZero(std::ostream& out, const ast::Expr
std::string ty_name;
{
std::ostringstream ss;
if (!EmitType(ss, ty, tint::ast::AddressSpace::kInvalid, ast::Access::kUndefined, "")) {
if (!EmitType(ss, ty, tint::ast::AddressSpace::kInvalid, ast::Access::kInvalid, "")) {
return "";
}
ty_name = ss.str();
@ -1431,12 +1428,12 @@ bool GeneratorImpl::EmitStorageAtomicIntrinsic(
auto rmw = [&](const char* hlsl) -> bool {
{
auto fn = line(&buf);
if (!EmitTypeAndName(fn, result_ty, ast::AddressSpace::kNone, ast::Access::kUndefined,
if (!EmitTypeAndName(fn, result_ty, ast::AddressSpace::kNone, ast::Access::kInvalid,
name)) {
return false;
}
fn << "(RWByteAddressBuffer buffer, uint offset, ";
if (!EmitTypeAndName(fn, result_ty, ast::AddressSpace::kNone, ast::Access::kUndefined,
if (!EmitTypeAndName(fn, result_ty, ast::AddressSpace::kNone, ast::Access::kInvalid,
"value")) {
return false;
}
@ -1452,7 +1449,7 @@ bool GeneratorImpl::EmitStorageAtomicIntrinsic(
{
auto l = line(&buf);
if (!EmitTypeAndName(l, result_ty, ast::AddressSpace::kNone, ast::Access::kUndefined,
if (!EmitTypeAndName(l, result_ty, ast::AddressSpace::kNone, ast::Access::kInvalid,
"original_value")) {
return false;
}
@ -1501,8 +1498,8 @@ bool GeneratorImpl::EmitStorageAtomicIntrinsic(
// InterlockedOr using 0 as the OR value
{
auto fn = line(&buf);
if (!EmitTypeAndName(fn, result_ty, ast::AddressSpace::kNone,
ast::Access::kUndefined, name)) {
if (!EmitTypeAndName(fn, result_ty, ast::AddressSpace::kNone, ast::Access::kInvalid,
name)) {
return false;
}
fn << "(RWByteAddressBuffer buffer, uint offset) {";
@ -1517,8 +1514,8 @@ bool GeneratorImpl::EmitStorageAtomicIntrinsic(
{
auto l = line(&buf);
if (!EmitTypeAndName(l, result_ty, ast::AddressSpace::kNone,
ast::Access::kUndefined, "value")) {
if (!EmitTypeAndName(l, result_ty, ast::AddressSpace::kNone, ast::Access::kInvalid,
"value")) {
return false;
}
l << " = 0;";
@ -1535,8 +1532,8 @@ bool GeneratorImpl::EmitStorageAtomicIntrinsic(
{
auto fn = line(&buf);
fn << "void " << name << "(RWByteAddressBuffer buffer, uint offset, ";
if (!EmitTypeAndName(fn, value_ty, ast::AddressSpace::kNone,
ast::Access::kUndefined, "value")) {
if (!EmitTypeAndName(fn, value_ty, ast::AddressSpace::kNone, ast::Access::kInvalid,
"value")) {
return false;
}
fn << ") {";
@ -1551,7 +1548,7 @@ bool GeneratorImpl::EmitStorageAtomicIntrinsic(
{
auto l = line(&buf);
if (!EmitTypeAndName(l, value_ty, ast::AddressSpace::kNone, ast::Access::kUndefined,
if (!EmitTypeAndName(l, value_ty, ast::AddressSpace::kNone, ast::Access::kInvalid,
"ignored")) {
return false;
}
@ -1566,18 +1563,18 @@ bool GeneratorImpl::EmitStorageAtomicIntrinsic(
auto* value_ty = params[2]->Type()->UnwrapRef();
{
auto fn = line(&buf);
if (!EmitTypeAndName(fn, result_ty, ast::AddressSpace::kNone,
ast::Access::kUndefined, name)) {
if (!EmitTypeAndName(fn, result_ty, ast::AddressSpace::kNone, ast::Access::kInvalid,
name)) {
return false;
}
fn << "(RWByteAddressBuffer buffer, uint offset, ";
if (!EmitTypeAndName(fn, value_ty, ast::AddressSpace::kNone,
ast::Access::kUndefined, "compare")) {
if (!EmitTypeAndName(fn, value_ty, ast::AddressSpace::kNone, ast::Access::kInvalid,
"compare")) {
return false;
}
fn << ", ";
if (!EmitTypeAndName(fn, value_ty, ast::AddressSpace::kNone,
ast::Access::kUndefined, "value")) {
if (!EmitTypeAndName(fn, value_ty, ast::AddressSpace::kNone, ast::Access::kInvalid,
"value")) {
return false;
}
fn << ") {";
@ -1592,8 +1589,8 @@ bool GeneratorImpl::EmitStorageAtomicIntrinsic(
{ // T result = {0};
auto l = line(&buf);
if (!EmitTypeAndName(l, result_ty, ast::AddressSpace::kNone,
ast::Access::kUndefined, "result")) {
if (!EmitTypeAndName(l, result_ty, ast::AddressSpace::kNone, ast::Access::kInvalid,
"result")) {
return false;
}
l << "=";
@ -1628,7 +1625,7 @@ bool GeneratorImpl::EmitWorkgroupAtomicCall(std::ostream& out,
if (!builtin->ReturnType()->Is<sem::Void>()) {
auto pre = line();
if (!EmitTypeAndName(pre, builtin->ReturnType(), ast::AddressSpace::kNone,
ast::Access::kUndefined, result)) {
ast::Access::kInvalid, result)) {
return false;
}
pre << " = ";
@ -1691,8 +1688,8 @@ bool GeneratorImpl::EmitWorkgroupAtomicCall(std::ostream& out,
{ // T result = 0;
auto pre = line();
auto* value_ty = builtin->Parameters()[1]->Type()->UnwrapRef();
if (!EmitTypeAndName(pre, value_ty, ast::AddressSpace::kNone,
ast::Access::kUndefined, result)) {
if (!EmitTypeAndName(pre, value_ty, ast::AddressSpace::kNone, ast::Access::kInvalid,
result)) {
return false;
}
pre << " = ";
@ -1732,7 +1729,7 @@ bool GeneratorImpl::EmitWorkgroupAtomicCall(std::ostream& out,
{ // T compare_value = <compare_value>;
auto pre = line();
if (!EmitTypeAndName(pre, TypeOf(compare_value)->UnwrapRef(),
ast::AddressSpace::kNone, ast::Access::kUndefined, compare)) {
ast::AddressSpace::kNone, ast::Access::kInvalid, compare)) {
return false;
}
pre << " = ";
@ -1842,7 +1839,7 @@ bool GeneratorImpl::EmitModfCall(std::ostream& out,
{
auto l = line(b);
if (!EmitType(l, builtin->ReturnType(), ast::AddressSpace::kNone,
ast::Access::kUndefined, "")) {
ast::Access::kInvalid, "")) {
return false;
}
l << " result;";
@ -1884,7 +1881,7 @@ bool GeneratorImpl::EmitFrexpCall(std::ostream& out,
{
auto l = line(b);
if (!EmitType(l, builtin->ReturnType(), ast::AddressSpace::kNone,
ast::Access::kUndefined, "")) {
ast::Access::kInvalid, "")) {
return false;
}
l << " result = {sig, int" << width << "(exp)};";
@ -2721,7 +2718,7 @@ bool GeneratorImpl::EmitFunction(const ast::Function* func) {
auto const* type = v->Type();
auto address_space = ast::AddressSpace::kNone;
auto access = ast::Access::kUndefined;
auto access = ast::Access::kInvalid;
if (auto* ptr = type->As<sem::Pointer>()) {
type = ptr->StoreType();
@ -3143,7 +3140,7 @@ bool GeneratorImpl::EmitConstant(std::ostream& out, const sem::Constant* constan
return true;
}
if (!EmitType(out, v, ast::AddressSpace::kNone, ast::Access::kUndefined, "")) {
if (!EmitType(out, v, ast::AddressSpace::kNone, ast::Access::kInvalid, "")) {
return false;
}
@ -3160,7 +3157,7 @@ bool GeneratorImpl::EmitConstant(std::ostream& out, const sem::Constant* constan
return true;
},
[&](const sem::Matrix* m) {
if (!EmitType(out, m, ast::AddressSpace::kNone, ast::Access::kUndefined, "")) {
if (!EmitType(out, m, ast::AddressSpace::kNone, ast::Access::kInvalid, "")) {
return false;
}
@ -3179,7 +3176,7 @@ bool GeneratorImpl::EmitConstant(std::ostream& out, const sem::Constant* constan
[&](const sem::Array* a) {
if (constant->AllZero()) {
out << "(";
if (!EmitType(out, a, ast::AddressSpace::kNone, ast::Access::kUndefined, "")) {
if (!EmitType(out, a, ast::AddressSpace::kNone, ast::Access::kInvalid, "")) {
return false;
}
out << ")0";
@ -3209,7 +3206,7 @@ bool GeneratorImpl::EmitConstant(std::ostream& out, const sem::Constant* constan
[&](const sem::Struct* s) {
if (constant->AllZero()) {
out << "(";
if (!EmitType(out, s, ast::AddressSpace::kNone, ast::Access::kUndefined, "")) {
if (!EmitType(out, s, ast::AddressSpace::kNone, ast::Access::kInvalid, "")) {
return false;
}
out << ")0";
@ -3330,12 +3327,12 @@ bool GeneratorImpl::EmitValue(std::ostream& out, const sem::Type* type, int valu
[&](const sem::Struct*) {
out << "(";
TINT_DEFER(out << ")" << value);
return EmitType(out, type, ast::AddressSpace::kNone, ast::Access::kUndefined, "");
return EmitType(out, type, ast::AddressSpace::kNone, ast::Access::kInvalid, "");
},
[&](const sem::Array*) {
out << "(";
TINT_DEFER(out << ")" << value);
return EmitType(out, type, ast::AddressSpace::kNone, ast::Access::kUndefined, "");
return EmitType(out, type, ast::AddressSpace::kNone, ast::Access::kInvalid, "");
},
[&](Default) {
diagnostics_.add_error(
@ -4083,7 +4080,7 @@ bool GeneratorImpl::EmitLet(const ast::Let* let) {
auto out = line();
out << "const ";
if (!EmitTypeAndName(out, type, ast::AddressSpace::kNone, ast::Access::kUndefined,
if (!EmitTypeAndName(out, type, ast::AddressSpace::kNone, ast::Access::kInvalid,
builder_.Symbols().NameFor(let->symbol))) {
return false;
}
@ -4111,7 +4108,7 @@ bool GeneratorImpl::CallBuiltinHelper(std::ostream& out,
{
auto decl = line(&b);
if (!EmitTypeAndName(decl, builtin->ReturnType(), ast::AddressSpace::kNone,
ast::Access::kUndefined, fn_name)) {
ast::Access::kInvalid, fn_name)) {
return "";
}
{
@ -4126,8 +4123,8 @@ bool GeneratorImpl::CallBuiltinHelper(std::ostream& out,
decl << "inout ";
ty = ptr->StoreType();
}
if (!EmitTypeAndName(decl, ty, ast::AddressSpace::kNone,
ast::Access::kUndefined, param_name)) {
if (!EmitTypeAndName(decl, ty, ast::AddressSpace::kNone, ast::Access::kInvalid,
param_name)) {
return "";
}
parameter_names.emplace_back(std::move(param_name));

View File

@ -766,7 +766,7 @@ bool Builder::GenerateGlobalVariable(const ast::Variable* v) {
push_annot(spv::Op::OpDecorate,
{Operand(var_id), U32Operand(SpvDecorationNonWritable)});
break;
case ast::Access::kUndefined:
case ast::Access::kInvalid:
case ast::Access::kReadWrite:
break;
}
@ -3684,11 +3684,11 @@ uint32_t Builder::GenerateTypeIfNeeded(const sem::Type* type) {
// references are not legal in WGSL, so only considering the top-level type is
// fine.
if (auto* ptr = type->As<sem::Pointer>()) {
type =
builder_.create<sem::Pointer>(ptr->StoreType(), ptr->AddressSpace(), ast::kReadWrite);
type = builder_.create<sem::Pointer>(ptr->StoreType(), ptr->AddressSpace(),
ast::Access::kReadWrite);
} else if (auto* ref = type->As<sem::Reference>()) {
type =
builder_.create<sem::Pointer>(ref->StoreType(), ref->AddressSpace(), ast::kReadWrite);
type = builder_.create<sem::Pointer>(ref->StoreType(), ref->AddressSpace(),
ast::Access::kReadWrite);
}
return utils::GetOrCreate(type_to_id_, type, [&]() -> uint32_t {

View File

@ -433,7 +433,7 @@ bool GeneratorImpl::EmitType(std::ostream& out, const ast::Type* ty) {
if (!EmitType(out, ptr->type)) {
return false;
}
if (ptr->access != ast::Access::kUndefined) {
if (ptr->access != ast::Access::kInvalid) {
out << ", ";
if (!EmitAccess(out, ptr->access)) {
return false;
@ -656,9 +656,9 @@ bool GeneratorImpl::EmitVariable(std::ostream& out, const ast::Variable* v) {
out << "var";
auto address_space = var->declared_address_space;
auto ac = var->declared_access;
if (address_space != ast::AddressSpace::kNone || ac != ast::Access::kUndefined) {
if (address_space != ast::AddressSpace::kNone || ac != ast::Access::kInvalid) {
out << "<" << address_space;
if (ac != ast::Access::kUndefined) {
if (ac != ast::Access::kInvalid) {
out << ", ";
if (!EmitAccess(out, ac)) {
return false;