Remove name fields

This CL removes the name fields from the various AST nodes now that the
symbols are used everywhere.

Change-Id: I73e8fa8958aa6e6f0159b12b63176b12c418f525
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/36762
Reviewed-by: Ben Clayton <bclayton@google.com>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
This commit is contained in:
dan sinclair 2021-01-11 16:24:32 +00:00 committed by dan sinclair
parent e65e4bd2c5
commit c8c31560de
23 changed files with 117 additions and 171 deletions

View File

@ -40,8 +40,8 @@ Variable* Builder::Var(const std::string& name,
type::Type* type, type::Type* type,
Expression* constructor, Expression* constructor,
VariableDecorationList decorations) { VariableDecorationList decorations) {
auto* var = create<Variable>(mod->RegisterSymbol(name), name, storage, type, auto* var = create<Variable>(mod->RegisterSymbol(name), storage, type, false,
false, constructor, decorations); constructor, decorations);
OnVariableBuilt(var); OnVariableBuilt(var);
return var; return var;
} }
@ -52,8 +52,8 @@ Variable* Builder::Var(const Source& source,
type::Type* type, type::Type* type,
Expression* constructor, Expression* constructor,
VariableDecorationList decorations) { VariableDecorationList decorations) {
auto* var = create<Variable>(source, mod->RegisterSymbol(name), name, storage, auto* var = create<Variable>(source, mod->RegisterSymbol(name), storage, type,
type, false, constructor, decorations); false, constructor, decorations);
OnVariableBuilt(var); OnVariableBuilt(var);
return var; return var;
} }
@ -69,8 +69,8 @@ Variable* Builder::Const(const std::string& name,
type::Type* type, type::Type* type,
Expression* constructor, Expression* constructor,
VariableDecorationList decorations) { VariableDecorationList decorations) {
auto* var = create<Variable>(mod->RegisterSymbol(name), name, storage, type, auto* var = create<Variable>(mod->RegisterSymbol(name), storage, type, true,
true, constructor, decorations); constructor, decorations);
OnVariableBuilt(var); OnVariableBuilt(var);
return var; return var;
} }
@ -81,8 +81,8 @@ Variable* Builder::Const(const Source& source,
type::Type* type, type::Type* type,
Expression* constructor, Expression* constructor,
VariableDecorationList decorations) { VariableDecorationList decorations) {
auto* var = create<Variable>(source, mod->RegisterSymbol(name), name, storage, auto* var = create<Variable>(source, mod->RegisterSymbol(name), storage, type,
type, true, constructor, decorations); true, constructor, decorations);
OnVariableBuilt(var); OnVariableBuilt(var);
return var; return var;
} }

View File

@ -166,7 +166,7 @@ class TypesBuilder {
/// @param type the alias type /// @param type the alias type
/// @returns the alias pointer /// @returns the alias pointer
type::Alias* alias(const std::string& name, type::Type* type) const { type::Alias* alias(const std::string& name, type::Type* type) const {
return mod_->create<type::Alias>(mod_->RegisterSymbol(name), name, type); return mod_->create<type::Alias>(mod_->RegisterSymbol(name), type);
} }
/// @return the tint AST pointer to type `T` with the given StorageClass. /// @return the tint AST pointer to type `T` with the given StorageClass.
@ -180,7 +180,7 @@ class TypesBuilder {
/// @param impl the struct implementation /// @param impl the struct implementation
/// @returns a struct pointer /// @returns a struct pointer
type::Struct* struct_(const std::string& name, ast::Struct* impl) const { type::Struct* struct_(const std::string& name, ast::Struct* impl) const {
return mod_->create<type::Struct>(mod_->RegisterSymbol(name), name, impl); return mod_->create<type::Struct>(mod_->RegisterSymbol(name), impl);
} }
private: private:
@ -227,21 +227,20 @@ class Builder {
/// @param name the identifier name /// @param name the identifier name
/// @return an IdentifierExpression with the given name /// @return an IdentifierExpression with the given name
IdentifierExpression* Expr(const std::string& name) { IdentifierExpression* Expr(const std::string& name) {
return create<IdentifierExpression>(mod->RegisterSymbol(name), name); return create<IdentifierExpression>(mod->RegisterSymbol(name));
} }
/// @param source the source information /// @param source the source information
/// @param name the identifier name /// @param name the identifier name
/// @return an IdentifierExpression with the given name /// @return an IdentifierExpression with the given name
IdentifierExpression* Expr(const Source& source, const std::string& name) { IdentifierExpression* Expr(const Source& source, const std::string& name) {
return create<IdentifierExpression>(source, mod->RegisterSymbol(name), return create<IdentifierExpression>(source, mod->RegisterSymbol(name));
name);
} }
/// @param name the identifier name /// @param name the identifier name
/// @return an IdentifierExpression with the given name /// @return an IdentifierExpression with the given name
IdentifierExpression* Expr(const char* name) { IdentifierExpression* Expr(const char* name) {
return create<IdentifierExpression>(mod->RegisterSymbol(name), name); return create<IdentifierExpression>(mod->RegisterSymbol(name));
} }
/// @param value the boolean value /// @param value the boolean value
@ -620,9 +619,9 @@ class Builder {
type::Type* type, type::Type* type,
ast::StatementList body, ast::StatementList body,
ast::FunctionDecorationList decorations) { ast::FunctionDecorationList decorations) {
return mod->create<ast::Function>( return mod->create<ast::Function>(source, mod->RegisterSymbol(name), params,
source, mod->RegisterSymbol(name), name, params, type, type, create<ast::BlockStatement>(body),
create<ast::BlockStatement>(body), decorations); decorations);
} }
/// Creates a Function /// Creates a Function
@ -637,7 +636,7 @@ class Builder {
type::Type* type, type::Type* type,
ast::StatementList body, ast::StatementList body,
ast::FunctionDecorationList decorations) { ast::FunctionDecorationList decorations) {
return create<ast::Function>(mod->RegisterSymbol(name), name, params, type, return create<ast::Function>(mod->RegisterSymbol(name), params, type,
create<ast::BlockStatement>(body), create<ast::BlockStatement>(body),
decorations); decorations);
} }
@ -650,8 +649,8 @@ class Builder {
StructMember* Member(const Source& source, StructMember* Member(const Source& source,
const std::string& name, const std::string& name,
type::Type* type) { type::Type* type) {
return mod->create<StructMember>(source, mod->RegisterSymbol(name), name, return mod->create<StructMember>(source, mod->RegisterSymbol(name), type,
type, StructMemberDecorationList{}); StructMemberDecorationList{});
} }
/// Creates a StructMember /// Creates a StructMember
@ -659,8 +658,8 @@ class Builder {
/// @param type the struct member type /// @param type the struct member type
/// @returns the struct member pointer /// @returns the struct member pointer
StructMember* Member(const std::string& name, type::Type* type) { StructMember* Member(const std::string& name, type::Type* type) {
return mod->create<StructMember>(source_, mod->RegisterSymbol(name), name, return mod->create<StructMember>(source_, mod->RegisterSymbol(name), type,
type, StructMemberDecorationList{}); StructMemberDecorationList{});
} }
/// Creates a StructMember /// Creates a StructMember
@ -671,8 +670,8 @@ class Builder {
StructMember* Member(const std::string& name, StructMember* Member(const std::string& name,
type::Type* type, type::Type* type,
StructMemberDecorationList decos) { StructMemberDecorationList decos) {
return mod->create<StructMember>(source_, mod->RegisterSymbol(name), name, return mod->create<StructMember>(source_, mod->RegisterSymbol(name), type,
type, decos); decos);
} }
/// Creates a new Node owned by the Module, with the explicit Source. /// Creates a new Node owned by the Module, with the explicit Source.

View File

@ -32,14 +32,12 @@ namespace ast {
Function::Function(const Source& source, Function::Function(const Source& source,
Symbol symbol, Symbol symbol,
const std::string& name,
VariableList params, VariableList params,
type::Type* return_type, type::Type* return_type,
BlockStatement* body, BlockStatement* body,
FunctionDecorationList decorations) FunctionDecorationList decorations)
: Base(source), : Base(source),
symbol_(symbol), symbol_(symbol),
name_(name),
params_(std::move(params)), params_(std::move(params)),
return_type_(return_type), return_type_(return_type),
body_(body), body_(body),
@ -228,7 +226,7 @@ const Statement* Function::get_last_statement() const {
Function* Function::Clone(CloneContext* ctx) const { Function* Function::Clone(CloneContext* ctx) const {
return ctx->mod->create<Function>( return ctx->mod->create<Function>(
ctx->Clone(source()), ctx->Clone(symbol()), name_, ctx->Clone(params_), ctx->Clone(source()), ctx->Clone(symbol()), ctx->Clone(params_),
ctx->Clone(return_type_), ctx->Clone(body_), ctx->Clone(decorations_)); ctx->Clone(return_type_), ctx->Clone(body_), ctx->Clone(decorations_));
} }
@ -240,7 +238,7 @@ bool Function::IsValid() const {
if (body_ == nullptr || !body_->IsValid()) { if (body_ == nullptr || !body_->IsValid()) {
return false; return false;
} }
if (name_.length() == 0 || !symbol_.IsValid()) { if (!symbol_.IsValid()) {
return false; return false;
} }
if (return_type_ == nullptr) { if (return_type_ == nullptr) {

View File

@ -54,14 +54,12 @@ class Function : public Castable<Function, Node> {
/// Create a function /// Create a function
/// @param source the variable source /// @param source the variable source
/// @param symbol the function symbol /// @param symbol the function symbol
/// @param name the function name
/// @param params the function parameters /// @param params the function parameters
/// @param return_type the return type /// @param return_type the return type
/// @param body the function body /// @param body the function body
/// @param decorations the function decorations /// @param decorations the function decorations
Function(const Source& source, Function(const Source& source,
Symbol symbol, Symbol symbol,
const std::string& name,
VariableList params, VariableList params,
type::Type* return_type, type::Type* return_type,
BlockStatement* body, BlockStatement* body,
@ -73,8 +71,6 @@ class Function : public Castable<Function, Node> {
/// @returns the function symbol /// @returns the function symbol
Symbol symbol() const { return symbol_; } Symbol symbol() const { return symbol_; }
/// @returns the function name
const std::string& name_for_clone() { return name_; }
/// @returns the function params /// @returns the function params
const VariableList& params() const { return params_; } const VariableList& params() const { return params_; }
@ -184,7 +180,7 @@ class Function : public Castable<Function, Node> {
/// @return the newly cloned node /// @return the newly cloned node
Function* Clone(CloneContext* ctx) const override; Function* Clone(CloneContext* ctx) const override;
/// @returns true if the name and type are both present /// @returns true if the symbol and type are both present
bool IsValid() const override; bool IsValid() const override;
/// Writes a representation of the node to the output stream /// Writes a representation of the node to the output stream
@ -203,7 +199,6 @@ class Function : public Castable<Function, Node> {
ReferencedSampledTextureVariablesImpl(bool multisampled) const; ReferencedSampledTextureVariablesImpl(bool multisampled) const;
Symbol const symbol_; Symbol const symbol_;
std::string const name_;
VariableList const params_; VariableList const params_;
type::Type* const return_type_; type::Type* const return_type_;
BlockStatement* const body_; BlockStatement* const body_;

View File

@ -22,10 +22,8 @@ TINT_INSTANTIATE_CLASS_ID(tint::ast::IdentifierExpression);
namespace tint { namespace tint {
namespace ast { namespace ast {
IdentifierExpression::IdentifierExpression(const Source& source, IdentifierExpression::IdentifierExpression(const Source& source, Symbol sym)
Symbol sym, : Base(source), sym_(sym) {}
const std::string& name)
: Base(source), sym_(sym), name_(name) {}
IdentifierExpression::IdentifierExpression(IdentifierExpression&&) = default; IdentifierExpression::IdentifierExpression(IdentifierExpression&&) = default;
@ -33,7 +31,7 @@ IdentifierExpression::~IdentifierExpression() = default;
IdentifierExpression* IdentifierExpression::Clone(CloneContext* ctx) const { IdentifierExpression* IdentifierExpression::Clone(CloneContext* ctx) const {
return ctx->mod->create<IdentifierExpression>(ctx->Clone(source()), return ctx->mod->create<IdentifierExpression>(ctx->Clone(source()),
ctx->Clone(symbol()), name_); ctx->Clone(symbol()));
} }
bool IdentifierExpression::IsValid() const { bool IdentifierExpression::IsValid() const {

View File

@ -16,7 +16,6 @@
#define SRC_AST_IDENTIFIER_EXPRESSION_H_ #define SRC_AST_IDENTIFIER_EXPRESSION_H_
#include <memory> #include <memory>
#include <string>
#include <utility> #include <utility>
#include "src/ast/expression.h" #include "src/ast/expression.h"
@ -32,10 +31,7 @@ class IdentifierExpression : public Castable<IdentifierExpression, Expression> {
/// Constructor /// Constructor
/// @param source the source /// @param source the source
/// @param sym the symbol for the identifier /// @param sym the symbol for the identifier
/// @param name the name IdentifierExpression(const Source& source, Symbol sym);
IdentifierExpression(const Source& source,
Symbol sym,
const std::string& name);
/// Move constructor /// Move constructor
IdentifierExpression(IdentifierExpression&&); IdentifierExpression(IdentifierExpression&&);
~IdentifierExpression() override; ~IdentifierExpression() override;
@ -82,7 +78,6 @@ class IdentifierExpression : public Castable<IdentifierExpression, Expression> {
IdentifierExpression(const IdentifierExpression&) = delete; IdentifierExpression(const IdentifierExpression&) = delete;
Symbol const sym_; Symbol const sym_;
std::string const name_;
Intrinsic intrinsic_ = Intrinsic::kNone; // Semantic info Intrinsic intrinsic_ = Intrinsic::kNone; // Semantic info
std::unique_ptr<intrinsic::Signature> intrinsic_sig_; // Semantic info std::unique_ptr<intrinsic::Signature> intrinsic_sig_; // Semantic info

View File

@ -25,12 +25,10 @@ namespace ast {
StructMember::StructMember(const Source& source, StructMember::StructMember(const Source& source,
const Symbol& sym, const Symbol& sym,
const std::string& name,
type::Type* type, type::Type* type,
StructMemberDecorationList decorations) StructMemberDecorationList decorations)
: Base(source), : Base(source),
symbol_(sym), symbol_(sym),
name_(name),
type_(type), type_(type),
decorations_(std::move(decorations)) {} decorations_(std::move(decorations)) {}
@ -57,13 +55,13 @@ uint32_t StructMember::offset() const {
} }
StructMember* StructMember::Clone(CloneContext* ctx) const { StructMember* StructMember::Clone(CloneContext* ctx) const {
return ctx->mod->create<StructMember>( return ctx->mod->create<StructMember>(ctx->Clone(source()),
ctx->Clone(source()), ctx->Clone(symbol_), name_, ctx->Clone(type_), ctx->Clone(symbol_), ctx->Clone(type_),
ctx->Clone(decorations_)); ctx->Clone(decorations_));
} }
bool StructMember::IsValid() const { bool StructMember::IsValid() const {
if (name_.empty() || type_ == nullptr || !symbol_.IsValid()) { if (type_ == nullptr || !symbol_.IsValid()) {
return false; return false;
} }
for (auto* deco : decorations_) { for (auto* deco : decorations_) {

View File

@ -17,7 +17,6 @@
#include <memory> #include <memory>
#include <ostream> #include <ostream>
#include <string>
#include <utility> #include <utility>
#include <vector> #include <vector>
@ -35,12 +34,10 @@ class StructMember : public Castable<StructMember, Node> {
/// Create a new struct member statement /// Create a new struct member statement
/// @param source The input source for the struct member statement /// @param source The input source for the struct member statement
/// @param sym The struct member symbol /// @param sym The struct member symbol
/// @param name The struct member name
/// @param type The struct member type /// @param type The struct member type
/// @param decorations The struct member decorations /// @param decorations The struct member decorations
StructMember(const Source& source, StructMember(const Source& source,
const Symbol& sym, const Symbol& sym,
const std::string& name,
type::Type* type, type::Type* type,
StructMemberDecorationList decorations); StructMemberDecorationList decorations);
/// Move constructor /// Move constructor
@ -81,7 +78,6 @@ class StructMember : public Castable<StructMember, Node> {
StructMember(const StructMember&) = delete; StructMember(const StructMember&) = delete;
Symbol const symbol_; Symbol const symbol_;
std::string const name_;
type::Type* const type_; type::Type* const type_;
StructMemberDecorationList const decorations_; StructMemberDecorationList const decorations_;
}; };

View File

@ -25,8 +25,8 @@ namespace tint {
namespace ast { namespace ast {
namespace type { namespace type {
Alias::Alias(const Symbol& sym, const std::string& name, Type* subtype) Alias::Alias(const Symbol& sym, Type* subtype)
: symbol_(sym), name_(name), subtype_(subtype) { : symbol_(sym), subtype_(subtype) {
assert(subtype_); assert(subtype_);
} }
@ -47,8 +47,7 @@ uint64_t Alias::BaseAlignment(MemoryLayout mem_layout) const {
} }
Alias* Alias::Clone(CloneContext* ctx) const { Alias* Alias::Clone(CloneContext* ctx) const {
return ctx->mod->create<Alias>(ctx->Clone(symbol()), name_, return ctx->mod->create<Alias>(ctx->Clone(symbol()), ctx->Clone(subtype_));
ctx->Clone(subtype_));
} }
} // namespace type } // namespace type

View File

@ -29,9 +29,8 @@ class Alias : public Castable<Alias, Type> {
public: public:
/// Constructor /// Constructor
/// @param sym the symbol for the alias /// @param sym the symbol for the alias
/// @param name the alias name
/// @param subtype the alias'd type /// @param subtype the alias'd type
Alias(const Symbol& sym, const std::string& name, Type* subtype); Alias(const Symbol& sym, Type* subtype);
/// Move constructor /// Move constructor
Alias(Alias&&); Alias(Alias&&);
/// Destructor /// Destructor
@ -42,7 +41,7 @@ class Alias : public Castable<Alias, Type> {
/// @returns the alias type /// @returns the alias type
Type* type() const { return subtype_; } Type* type() const { return subtype_; }
/// @returns the name for this type /// @returns the type_name for this type
std::string type_name() const override; std::string type_name() const override;
/// @param mem_layout type of memory layout to use in calculation. /// @param mem_layout type of memory layout to use in calculation.
@ -62,7 +61,6 @@ class Alias : public Castable<Alias, Type> {
private: private:
Symbol const symbol_; Symbol const symbol_;
std::string const name_;
Type* const subtype_; Type* const subtype_;
}; };

View File

@ -30,8 +30,8 @@ namespace tint {
namespace ast { namespace ast {
namespace type { namespace type {
Struct::Struct(const Symbol& sym, const std::string& name, ast::Struct* impl) Struct::Struct(const Symbol& sym, ast::Struct* impl)
: symbol_(sym), name_(name), struct_(impl) {} : symbol_(sym), struct_(impl) {}
Struct::Struct(Struct&&) = default; Struct::Struct(Struct&&) = default;
@ -84,8 +84,7 @@ uint64_t Struct::BaseAlignment(MemoryLayout mem_layout) const {
} }
Struct* Struct::Clone(CloneContext* ctx) const { Struct* Struct::Clone(CloneContext* ctx) const {
return ctx->mod->create<Struct>(ctx->Clone(symbol()), name_, return ctx->mod->create<Struct>(ctx->Clone(symbol()), ctx->Clone(struct_));
ctx->Clone(struct_));
} }
} // namespace type } // namespace type

View File

@ -31,9 +31,8 @@ class Struct : public Castable<Struct, Type> {
public: public:
/// Constructor /// Constructor
/// @param sym the symbol representing the struct /// @param sym the symbol representing the struct
/// @param name the name of the struct
/// @param impl the struct data /// @param impl the struct data
Struct(const Symbol& sym, const std::string& name, ast::Struct* impl); Struct(const Symbol& sym, ast::Struct* impl);
/// Move constructor /// Move constructor
Struct(Struct&&); Struct(Struct&&);
~Struct() override; ~Struct() override;
@ -44,7 +43,7 @@ class Struct : public Castable<Struct, Type> {
/// @returns true if the struct has a block decoration /// @returns true if the struct has a block decoration
bool IsBlockDecorated() const { return struct_->IsBlockDecorated(); } bool IsBlockDecorated() const { return struct_->IsBlockDecorated(); }
/// @returns the struct name /// @returns the struct
ast::Struct* impl() const { return struct_; } ast::Struct* impl() const { return struct_; }
/// @returns the name for the type /// @returns the name for the type
@ -67,7 +66,6 @@ class Struct : public Castable<Struct, Type> {
private: private:
Symbol const symbol_; Symbol const symbol_;
std::string const name_;
ast::Struct* const struct_; ast::Struct* const struct_;
uint64_t LargestMemberBaseAlignment(MemoryLayout mem_layout) const; uint64_t LargestMemberBaseAlignment(MemoryLayout mem_layout) const;

View File

@ -27,7 +27,6 @@ namespace ast {
Variable::Variable(const Source& source, Variable::Variable(const Source& source,
const Symbol& sym, const Symbol& sym,
const std::string& name,
StorageClass sc, StorageClass sc,
type::Type* type, type::Type* type,
bool is_const, bool is_const,
@ -35,7 +34,6 @@ Variable::Variable(const Source& source,
VariableDecorationList decorations) VariableDecorationList decorations)
: Base(source), : Base(source),
symbol_(sym), symbol_(sym),
name_(name),
type_(type), type_(type),
is_const_(is_const), is_const_(is_const),
constructor_(constructor), constructor_(constructor),
@ -85,13 +83,13 @@ uint32_t Variable::constant_id() const {
Variable* Variable::Clone(CloneContext* ctx) const { Variable* Variable::Clone(CloneContext* ctx) const {
return ctx->mod->create<Variable>(ctx->Clone(source()), ctx->Clone(symbol_), return ctx->mod->create<Variable>(ctx->Clone(source()), ctx->Clone(symbol_),
name_, storage_class(), ctx->Clone(type()), storage_class(), ctx->Clone(type()),
is_const_, ctx->Clone(constructor()), is_const_, ctx->Clone(constructor()),
ctx->Clone(decorations_)); ctx->Clone(decorations_));
} }
bool Variable::IsValid() const { bool Variable::IsValid() const {
if (name_.length() == 0 || !symbol_.IsValid()) { if (!symbol_.IsValid()) {
return false; return false;
} }
if (type_ == nullptr) { if (type_ == nullptr) {

View File

@ -17,7 +17,6 @@
#include <memory> #include <memory>
#include <ostream> #include <ostream>
#include <string>
#include <utility> #include <utility>
#include <vector> #include <vector>
@ -83,7 +82,6 @@ class Variable : public Castable<Variable, Node> {
/// Create a variable /// Create a variable
/// @param source the variable source /// @param source the variable source
/// @param sym the variable symbol /// @param sym the variable symbol
/// @param name the variables name
/// @param sc the variable storage class /// @param sc the variable storage class
/// @param type the value type /// @param type the value type
/// @param is_const true if the variable is const /// @param is_const true if the variable is const
@ -91,7 +89,6 @@ class Variable : public Castable<Variable, Node> {
/// @param decorations the variable decorations /// @param decorations the variable decorations
Variable(const Source& source, Variable(const Source& source,
const Symbol& sym, const Symbol& sym,
const std::string& name,
StorageClass sc, StorageClass sc,
type::Type* type, type::Type* type,
bool is_const, bool is_const,
@ -166,7 +163,6 @@ class Variable : public Castable<Variable, Node> {
Variable(const Variable&) = delete; Variable(const Variable&) = delete;
Symbol const symbol_; Symbol const symbol_;
std::string const name_;
// The value type if a const or formal paramter, and the store type if a var // The value type if a const or formal paramter, and the store type if a var
type::Type* const type_; type::Type* const type_;
bool const is_const_; bool const is_const_;

View File

@ -787,7 +787,7 @@ void FunctionEmitter::PushGuard(const std::string& guard_name,
const auto& top = statements_stack_.back(); const auto& top = statements_stack_.back();
auto* cond = create<ast::IdentifierExpression>( auto* cond = create<ast::IdentifierExpression>(
Source{}, ast_module_.RegisterSymbol(guard_name), guard_name); Source{}, ast_module_.RegisterSymbol(guard_name));
auto* builder = AddStatementBuilder<IfStatementBuilder>(cond); auto* builder = AddStatementBuilder<IfStatementBuilder>(cond);
PushNewStatementBlock( PushNewStatementBlock(
@ -862,8 +862,8 @@ bool FunctionEmitter::Emit() {
auto* body = create<ast::BlockStatement>(Source{}, statements); auto* body = create<ast::BlockStatement>(Source{}, statements);
ast_module_.AddFunction( ast_module_.AddFunction(
create<ast::Function>(decl.source, ast_module_.RegisterSymbol(decl.name), create<ast::Function>(decl.source, ast_module_.RegisterSymbol(decl.name),
decl.name, std::move(decl.params), decl.return_type, std::move(decl.params), decl.return_type, body,
body, std::move(decl.decorations))); std::move(decl.decorations)));
// Maintain the invariant by repopulating the one and only element. // Maintain the invariant by repopulating the one and only element.
statements_stack_.clear(); statements_stack_.clear();
@ -2013,8 +2013,8 @@ TypedExpression FunctionEmitter::MakeExpression(uint32_t id) {
auto name = namer_.Name(id); auto name = namer_.Name(id);
return TypedExpression{ return TypedExpression{
parser_impl_.ConvertType(def_use_mgr_->GetDef(id)->type_id()), parser_impl_.ConvertType(def_use_mgr_->GetDef(id)->type_id()),
create<ast::IdentifierExpression>( create<ast::IdentifierExpression>(Source{},
Source{}, ast_module_.RegisterSymbol(name), name)}; ast_module_.RegisterSymbol(name))};
} }
if (singly_used_values_.count(id)) { if (singly_used_values_.count(id)) {
auto expr = std::move(singly_used_values_[id]); auto expr = std::move(singly_used_values_[id]);
@ -2034,10 +2034,9 @@ TypedExpression FunctionEmitter::MakeExpression(uint32_t id) {
case SpvOpVariable: { case SpvOpVariable: {
// This occurs for module-scope variables. // This occurs for module-scope variables.
auto name = namer_.Name(inst->result_id()); auto name = namer_.Name(inst->result_id());
return TypedExpression{ return TypedExpression{parser_impl_.ConvertType(inst->type_id()),
parser_impl_.ConvertType(inst->type_id()),
create<ast::IdentifierExpression>( create<ast::IdentifierExpression>(
Source{}, ast_module_.RegisterSymbol(name), name)}; Source{}, ast_module_.RegisterSymbol(name))};
} }
default: default:
break; break;
@ -2269,7 +2268,6 @@ bool FunctionEmitter::EmitIfStart(const BlockInfo& block_info) {
auto* guard_var = auto* guard_var =
create<ast::Variable>(Source{}, // source create<ast::Variable>(Source{}, // source
ast_module_.RegisterSymbol(guard_name), // symbol ast_module_.RegisterSymbol(guard_name), // symbol
guard_name, // name
ast::StorageClass::kFunction, // storage_class ast::StorageClass::kFunction, // storage_class
parser_impl_.Bool(), // type parser_impl_.Bool(), // type
false, // is_const false, // is_const
@ -2676,7 +2674,7 @@ ast::Statement* FunctionEmitter::MakeBranchDetailed(
return create<ast::AssignmentStatement>( return create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>( create<ast::IdentifierExpression>(
Source{}, ast_module_.RegisterSymbol(flow_guard), flow_guard), Source{}, ast_module_.RegisterSymbol(flow_guard)),
MakeFalse(Source{})); MakeFalse(Source{}));
} }
@ -2798,7 +2796,6 @@ bool FunctionEmitter::EmitStatementsInBasicBlock(const BlockInfo& block_info,
auto* var = create<ast::Variable>( auto* var = create<ast::Variable>(
Source{}, // source Source{}, // source
ast_module_.RegisterSymbol(phi_var_name), // symbol ast_module_.RegisterSymbol(phi_var_name), // symbol
phi_var_name, // name
ast::StorageClass::kFunction, // storage_class ast::StorageClass::kFunction, // storage_class
parser_impl_.ConvertType(def_inst->type_id()), // type parser_impl_.ConvertType(def_inst->type_id()), // type
false, // is_const false, // is_const
@ -2837,7 +2834,7 @@ bool FunctionEmitter::EmitStatementsInBasicBlock(const BlockInfo& block_info,
AddStatement(create<ast::AssignmentStatement>( AddStatement(create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>( create<ast::IdentifierExpression>(
Source{}, ast_module_.RegisterSymbol(var_name), var_name), Source{}, ast_module_.RegisterSymbol(var_name)),
expr.expr)); expr.expr));
} }
} }
@ -2874,8 +2871,8 @@ bool FunctionEmitter::EmitConstDefOrWriteToHoistedVar(
// Emit an assignment of the expression to the hoisted variable. // Emit an assignment of the expression to the hoisted variable.
AddStatement(create<ast::AssignmentStatement>( AddStatement(create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>( create<ast::IdentifierExpression>(Source{},
Source{}, ast_module_.RegisterSymbol(name), namer_.Name(result_id)), ast_module_.RegisterSymbol(name)),
ast_expr.expr)); ast_expr.expr));
return true; return true;
} }
@ -3014,8 +3011,7 @@ bool FunctionEmitter::EmitStatement(const spvtools::opt::Instruction& inst) {
TypedExpression expr{ TypedExpression expr{
parser_impl_.ConvertType(inst.type_id()), parser_impl_.ConvertType(inst.type_id()),
create<ast::IdentifierExpression>( create<ast::IdentifierExpression>(
Source{}, ast_module_.RegisterSymbol(def_info->phi_var), Source{}, ast_module_.RegisterSymbol(def_info->phi_var))};
def_info->phi_var)};
return EmitConstDefOrWriteToHoistedVar(inst, expr); return EmitConstDefOrWriteToHoistedVar(inst, expr);
} }
@ -3074,8 +3070,7 @@ TypedExpression FunctionEmitter::MaybeEmitCombinatorialValue(
create<ast::CallExpression>( create<ast::CallExpression>(
Source{}, Source{},
create<ast::IdentifierExpression>( create<ast::IdentifierExpression>(
Source{}, ast_module_.RegisterSymbol(unary_builtin_name), Source{}, ast_module_.RegisterSymbol(unary_builtin_name)),
unary_builtin_name),
std::move(params))}; std::move(params))};
} }
@ -3181,7 +3176,7 @@ TypedExpression FunctionEmitter::EmitGlslStd450ExtInst(
} }
auto* func = create<ast::IdentifierExpression>( auto* func = create<ast::IdentifierExpression>(
Source{}, ast_module_.RegisterSymbol(name), name); Source{}, ast_module_.RegisterSymbol(name));
ast::ExpressionList operands; ast::ExpressionList operands;
ast::type::Type* first_operand_type = nullptr; ast::type::Type* first_operand_type = nullptr;
// All parameters to GLSL.std.450 extended instructions are IDs. // All parameters to GLSL.std.450 extended instructions are IDs.
@ -3207,20 +3202,20 @@ ast::IdentifierExpression* FunctionEmitter::Swizzle(uint32_t i) {
} }
const char* names[] = {"x", "y", "z", "w"}; const char* names[] = {"x", "y", "z", "w"};
return create<ast::IdentifierExpression>( return create<ast::IdentifierExpression>(
Source{}, ast_module_.RegisterSymbol(names[i & 3]), names[i & 3]); Source{}, ast_module_.RegisterSymbol(names[i & 3]));
} }
ast::IdentifierExpression* FunctionEmitter::PrefixSwizzle(uint32_t n) { ast::IdentifierExpression* FunctionEmitter::PrefixSwizzle(uint32_t n) {
switch (n) { switch (n) {
case 1: case 1:
return create<ast::IdentifierExpression>( return create<ast::IdentifierExpression>(Source{},
Source{}, ast_module_.RegisterSymbol("x"), "x"); ast_module_.RegisterSymbol("x"));
case 2: case 2:
return create<ast::IdentifierExpression>( return create<ast::IdentifierExpression>(
Source{}, ast_module_.RegisterSymbol("xy"), "xy"); Source{}, ast_module_.RegisterSymbol("xy"));
case 3: case 3:
return create<ast::IdentifierExpression>( return create<ast::IdentifierExpression>(
Source{}, ast_module_.RegisterSymbol("xyz"), "xyz"); Source{}, ast_module_.RegisterSymbol("xyz"));
default: default:
break; break;
} }
@ -3315,7 +3310,7 @@ TypedExpression FunctionEmitter::MakeAccessChain(
auto name = namer_.Name(base_id); auto name = namer_.Name(base_id);
current_expr.expr = create<ast::IdentifierExpression>( current_expr.expr = create<ast::IdentifierExpression>(
Source{}, ast_module_.RegisterSymbol(name), name); Source{}, ast_module_.RegisterSymbol(name));
current_expr.type = parser_impl_.ConvertType(ptr_ty_id); current_expr.type = parser_impl_.ConvertType(ptr_ty_id);
} }
} }
@ -3408,7 +3403,7 @@ TypedExpression FunctionEmitter::MakeAccessChain(
auto name = auto name =
namer_.GetMemberName(pointee_type_id, uint32_t(index_const_val)); namer_.GetMemberName(pointee_type_id, uint32_t(index_const_val));
auto* member_access = create<ast::IdentifierExpression>( auto* member_access = create<ast::IdentifierExpression>(
Source{}, ast_module_.RegisterSymbol(name), name); Source{}, ast_module_.RegisterSymbol(name));
next_expr = create<ast::MemberAccessorExpression>( next_expr = create<ast::MemberAccessorExpression>(
Source{}, current_expr.expr, member_access); Source{}, current_expr.expr, member_access);
@ -3529,7 +3524,7 @@ TypedExpression FunctionEmitter::MakeCompositeExtract(
} }
auto name = namer_.GetMemberName(current_type_id, uint32_t(index_val)); auto name = namer_.GetMemberName(current_type_id, uint32_t(index_val));
auto* member_access = create<ast::IdentifierExpression>( auto* member_access = create<ast::IdentifierExpression>(
Source{}, ast_module_.RegisterSymbol(name), name); Source{}, ast_module_.RegisterSymbol(name));
next_expr = create<ast::MemberAccessorExpression>( next_expr = create<ast::MemberAccessorExpression>(
Source{}, current_expr.expr, member_access); Source{}, current_expr.expr, member_access);
@ -3933,7 +3928,7 @@ bool FunctionEmitter::EmitFunctionCall(const spvtools::opt::Instruction& inst) {
// We ignore function attributes such as Inline, DontInline, Pure, Const. // We ignore function attributes such as Inline, DontInline, Pure, Const.
auto name = namer_.Name(inst.GetSingleWordInOperand(0)); auto name = namer_.Name(inst.GetSingleWordInOperand(0));
auto* function = create<ast::IdentifierExpression>( auto* function = create<ast::IdentifierExpression>(
Source{}, ast_module_.RegisterSymbol(name), name); Source{}, ast_module_.RegisterSymbol(name));
ast::ExpressionList params; ast::ExpressionList params;
for (uint32_t iarg = 1; iarg < inst.NumInOperands(); ++iarg) { for (uint32_t iarg = 1; iarg < inst.NumInOperands(); ++iarg) {
@ -3962,7 +3957,7 @@ TypedExpression FunctionEmitter::MakeIntrinsicCall(
ss << intrinsic; ss << intrinsic;
auto name = ss.str(); auto name = ss.str();
auto* ident = create<ast::IdentifierExpression>( auto* ident = create<ast::IdentifierExpression>(
Source{}, ast_module_.RegisterSymbol(name), name); Source{}, ast_module_.RegisterSymbol(name));
ident->set_intrinsic(intrinsic); ident->set_intrinsic(intrinsic);
ast::ExpressionList params; ast::ExpressionList params;
@ -4009,7 +4004,7 @@ TypedExpression FunctionEmitter::MakeSimpleSelect(
create<ast::CallExpression>( create<ast::CallExpression>(
Source{}, Source{},
create<ast::IdentifierExpression>( create<ast::IdentifierExpression>(
Source{}, ast_module_.RegisterSymbol("select"), "select"), Source{}, ast_module_.RegisterSymbol("select")),
std::move(params))}; std::move(params))};
} }
return {}; return {};
@ -4035,7 +4030,7 @@ bool FunctionEmitter::EmitImageAccess(const spvtools::opt::Instruction& inst) {
} }
auto name = namer_.Name(image->result_id()); auto name = namer_.Name(image->result_id());
params.push_back(create<ast::IdentifierExpression>( params.push_back(create<ast::IdentifierExpression>(
Source{}, ast_module_.RegisterSymbol(name), name)); Source{}, ast_module_.RegisterSymbol(name)));
const auto opcode = inst.opcode(); const auto opcode = inst.opcode();
if (IsSampledImageAccess(opcode)) { if (IsSampledImageAccess(opcode)) {
@ -4048,7 +4043,7 @@ bool FunctionEmitter::EmitImageAccess(const spvtools::opt::Instruction& inst) {
} }
auto param_name = namer_.Name(sampler->result_id()); auto param_name = namer_.Name(sampler->result_id());
params.push_back(create<ast::IdentifierExpression>( params.push_back(create<ast::IdentifierExpression>(
Source{}, ast_module_.RegisterSymbol(param_name), param_name)); Source{}, ast_module_.RegisterSymbol(param_name)));
} }
ast::type::Pointer* texture_ptr_type = ast::type::Pointer* texture_ptr_type =
@ -4214,7 +4209,7 @@ bool FunctionEmitter::EmitImageAccess(const spvtools::opt::Instruction& inst) {
} }
auto* ident = create<ast::IdentifierExpression>( auto* ident = create<ast::IdentifierExpression>(
Source{}, ast_module_.RegisterSymbol(builtin_name), builtin_name); Source{}, ast_module_.RegisterSymbol(builtin_name));
auto* call_expr = auto* call_expr =
create<ast::CallExpression>(Source{}, ident, std::move(params)); create<ast::CallExpression>(Source{}, ident, std::move(params));
@ -4556,14 +4551,14 @@ TypedExpression FunctionEmitter::MakeArrayLength(
} }
auto* member_ident = create<ast::IdentifierExpression>( auto* member_ident = create<ast::IdentifierExpression>(
Source{}, ast_module_.RegisterSymbol(field_name), field_name); Source{}, ast_module_.RegisterSymbol(field_name));
auto* member_access = create<ast::MemberAccessorExpression>( auto* member_access = create<ast::MemberAccessorExpression>(
Source{}, MakeExpression(struct_ptr_id).expr, member_ident); Source{}, MakeExpression(struct_ptr_id).expr, member_ident);
// Generate the intrinsic function call. // Generate the intrinsic function call.
std::string call_ident_str = "arrayLength"; std::string call_ident_str = "arrayLength";
auto* call_ident = create<ast::IdentifierExpression>( auto* call_ident = create<ast::IdentifierExpression>(
Source{}, ast_module_.RegisterSymbol(call_ident_str), call_ident_str); Source{}, ast_module_.RegisterSymbol(call_ident_str));
call_ident->set_intrinsic(ast::Intrinsic::kArrayLength); call_ident->set_intrinsic(ast::Intrinsic::kArrayLength);
ast::ExpressionList params{member_access}; ast::ExpressionList params{member_access};

View File

@ -948,8 +948,8 @@ ast::type::Type* ParserImpl::ConvertType(
} }
const auto member_name = namer_.GetMemberName(type_id, member_index); const auto member_name = namer_.GetMemberName(type_id, member_index);
auto* ast_struct_member = create<ast::StructMember>( auto* ast_struct_member = create<ast::StructMember>(
Source{}, ast_module_.RegisterSymbol(member_name), member_name, Source{}, ast_module_.RegisterSymbol(member_name), ast_member_ty,
ast_member_ty, std::move(ast_member_decorations)); std::move(ast_member_decorations));
ast_members.push_back(ast_struct_member); ast_members.push_back(ast_struct_member);
} }
if (is_per_vertex_struct) { if (is_per_vertex_struct) {
@ -965,7 +965,7 @@ ast::type::Type* ParserImpl::ConvertType(
auto name = namer_.GetName(type_id); auto name = namer_.GetName(type_id);
auto* result = ast_module_.create<ast::type::Struct>( auto* result = ast_module_.create<ast::type::Struct>(
ast_module_.RegisterSymbol(name), name, ast_struct); ast_module_.RegisterSymbol(name), ast_struct);
id_to_type_[type_id] = result; id_to_type_[type_id] = result;
if (num_non_writable_members == members.size()) { if (num_non_writable_members == members.size()) {
read_only_struct_types_.insert(result); read_only_struct_types_.insert(result);
@ -1132,7 +1132,7 @@ void ParserImpl::MaybeGenerateAlias(uint32_t type_id,
} }
const auto name = namer_.GetName(type_id); const auto name = namer_.GetName(type_id);
auto* ast_alias_type = ast_module_.create<ast::type::Alias>( auto* ast_alias_type = ast_module_.create<ast::type::Alias>(
ast_module_.RegisterSymbol(name), name, ast_underlying_type); ast_module_.RegisterSymbol(name), ast_underlying_type);
// Record this new alias as the AST type for this SPIR-V ID. // Record this new alias as the AST type for this SPIR-V ID.
id_to_type_[type_id] = ast_alias_type; id_to_type_[type_id] = ast_alias_type;
ast_module_.AddConstructedType(ast_alias_type); ast_module_.AddConstructedType(ast_alias_type);
@ -1311,7 +1311,6 @@ ast::Variable* ParserImpl::MakeVariable(
std::string name = namer_.Name(id); std::string name = namer_.Name(id);
return create<ast::Variable>(Source{}, // source return create<ast::Variable>(Source{}, // source
ast_module_.RegisterSymbol(name), // symbol ast_module_.RegisterSymbol(name), // symbol
name, // name
sc, // storage_class sc, // storage_class
type, // type type, // type
is_const, // is_const is_const, // is_const

View File

@ -434,7 +434,6 @@ Maybe<ast::Variable*> ParserImpl::global_variable_decl(
return create<ast::Variable>(decl->source, // source return create<ast::Variable>(decl->source, // source
module_.RegisterSymbol(decl->name), // symbol module_.RegisterSymbol(decl->name), // symbol
decl->name, // name
decl->storage_class, // storage_class decl->storage_class, // storage_class
decl->type, // type decl->type, // type
false, // is_const false, // is_const
@ -463,7 +462,6 @@ Maybe<ast::Variable*> ParserImpl::global_constant_decl() {
return create<ast::Variable>(decl->source, // source return create<ast::Variable>(decl->source, // source
module_.RegisterSymbol(decl->name), // symbol module_.RegisterSymbol(decl->name), // symbol
decl->name, // name
ast::StorageClass::kNone, // storage_class ast::StorageClass::kNone, // storage_class
decl->type, // type decl->type, // type
true, // is_const true, // is_const
@ -941,7 +939,7 @@ Maybe<ast::type::Type*> ParserImpl::type_alias() {
return add_error(peek(), "invalid type alias"); return add_error(peek(), "invalid type alias");
auto* alias = module_.create<ast::type::Alias>( auto* alias = module_.create<ast::type::Alias>(
module_.RegisterSymbol(name.value), name.value, type.value); module_.RegisterSymbol(name.value), type.value);
register_constructed(name.value, alias); register_constructed(name.value, alias);
return alias; return alias;
@ -1195,7 +1193,7 @@ Maybe<std::unique_ptr<ast::type::Struct>> ParserImpl::struct_decl(
return Failure::kErrored; return Failure::kErrored;
return std::make_unique<ast::type::Struct>( return std::make_unique<ast::type::Struct>(
module_.RegisterSymbol(name.value), name.value, module_.RegisterSymbol(name.value),
create<ast::Struct>(source, std::move(body.value), create<ast::Struct>(source, std::move(body.value),
std::move(struct_decos.value))); std::move(struct_decos.value)));
} }
@ -1249,9 +1247,9 @@ Expect<ast::StructMember*> ParserImpl::expect_struct_member(
if (!expect("struct member", Token::Type::kSemicolon)) if (!expect("struct member", Token::Type::kSemicolon))
return Failure::kErrored; return Failure::kErrored;
return create<ast::StructMember>( return create<ast::StructMember>(decl->source,
decl->source, module_.RegisterSymbol(decl->name), decl->name, decl->type, module_.RegisterSymbol(decl->name),
std::move(member_decos.value)); decl->type, std::move(member_decos.value));
} }
// function_decl // function_decl
@ -1287,8 +1285,8 @@ Maybe<ast::Function*> ParserImpl::function_decl(ast::DecorationList& decos) {
return Failure::kErrored; return Failure::kErrored;
return create<ast::Function>( return create<ast::Function>(
header->source, module_.RegisterSymbol(header->name), header->name, header->source, module_.RegisterSymbol(header->name), header->params,
header->params, header->return_type, body.value, func_decos.value); header->return_type, body.value, func_decos.value);
} }
// function_type_decl // function_type_decl
@ -1358,7 +1356,6 @@ Expect<ast::VariableList> ParserImpl::expect_param_list() {
auto* var = auto* var =
create<ast::Variable>(decl->source, // source create<ast::Variable>(decl->source, // source
module_.RegisterSymbol(decl->name), // symbol module_.RegisterSymbol(decl->name), // symbol
decl->name, // name
ast::StorageClass::kNone, // storage_class ast::StorageClass::kNone, // storage_class
decl->type, // type decl->type, // type
true, // is_const true, // is_const
@ -1630,7 +1627,6 @@ Maybe<ast::VariableDeclStatement*> ParserImpl::variable_stmt() {
auto* var = auto* var =
create<ast::Variable>(decl->source, // source create<ast::Variable>(decl->source, // source
module_.RegisterSymbol(decl->name), // symbol module_.RegisterSymbol(decl->name), // symbol
decl->name, // name
ast::StorageClass::kNone, // storage_class ast::StorageClass::kNone, // storage_class
decl->type, // type decl->type, // type
true, // is_const true, // is_const
@ -1660,7 +1656,6 @@ Maybe<ast::VariableDeclStatement*> ParserImpl::variable_stmt() {
auto* var = auto* var =
create<ast::Variable>(decl->source, // source create<ast::Variable>(decl->source, // source
module_.RegisterSymbol(decl->name), // symbol module_.RegisterSymbol(decl->name), // symbol
decl->name, // name
decl->storage_class, // storage_class decl->storage_class, // storage_class
decl->type, // type decl->type, // type
false, // is_const false, // is_const
@ -2046,10 +2041,10 @@ Maybe<ast::CallStatement*> ParserImpl::func_call_stmt() {
return Failure::kErrored; return Failure::kErrored;
return create<ast::CallStatement>( return create<ast::CallStatement>(
Source{}, create<ast::CallExpression>( Source{},
source, create<ast::CallExpression>(source,
create<ast::IdentifierExpression>( create<ast::IdentifierExpression>(
source, module_.RegisterSymbol(name), name), source, module_.RegisterSymbol(name)),
std::move(params))); std::move(params)));
} }
@ -2122,7 +2117,7 @@ Maybe<ast::Expression*> ParserImpl::primary_expression() {
if (match(Token::Type::kIdentifier)) if (match(Token::Type::kIdentifier))
return create<ast::IdentifierExpression>( return create<ast::IdentifierExpression>(
t.source(), module_.RegisterSymbol(t.to_str()), t.to_str()); t.source(), module_.RegisterSymbol(t.to_str()));
auto type = type_decl(); auto type = type_decl();
if (type.errored) if (type.errored)
@ -2198,7 +2193,7 @@ Maybe<ast::Expression*> ParserImpl::postfix_expr(ast::Expression* prefix) {
return postfix_expr(create<ast::MemberAccessorExpression>( return postfix_expr(create<ast::MemberAccessorExpression>(
ident.source, prefix, ident.source, prefix,
create<ast::IdentifierExpression>( create<ast::IdentifierExpression>(
ident.source, module_.RegisterSymbol(ident.value), ident.value))); ident.source, module_.RegisterSymbol(ident.value))));
} }
return prefix; return prefix;

View File

@ -45,7 +45,7 @@ TEST_F(ParserImplTest, TypeDecl_ParsesType) {
TEST_F(ParserImplTest, TypeDecl_ParsesStruct_Ident) { TEST_F(ParserImplTest, TypeDecl_ParsesStruct_Ident) {
auto p = parser("type a = B"); auto p = parser("type a = B");
ast::type::Struct str(p->get_module().RegisterSymbol("B"), "B", {}); ast::type::Struct str(p->get_module().RegisterSymbol("B"), {});
p->register_constructed("B", &str); p->register_constructed("B", &str);
auto t = p->type_alias(); auto t = p->type_alias();

View File

@ -50,7 +50,7 @@ TEST_F(ParserImplTest, TypeDecl_Identifier) {
auto* int_type = mod.create<ast::type::I32>(); auto* int_type = mod.create<ast::type::I32>();
auto* alias_type = auto* alias_type =
mod.create<ast::type::Alias>(mod.RegisterSymbol("A"), "A", int_type); mod.create<ast::type::Alias>(mod.RegisterSymbol("A"), int_type);
p->register_constructed("A", alias_type); p->register_constructed("A", alias_type);

View File

@ -53,7 +53,6 @@ Transform::Output EmitVertexPointSize::Run(ast::Module* in) {
auto* pointsize_var = out.module.create<ast::Variable>( auto* pointsize_var = out.module.create<ast::Variable>(
Source{}, // source Source{}, // source
out.module.RegisterSymbol(kPointSizeVar), // symbol out.module.RegisterSymbol(kPointSizeVar), // symbol
kPointSizeVar, // name
ast::StorageClass::kOutput, // storage_class ast::StorageClass::kOutput, // storage_class
f32, // type f32, // type
false, // is_const false, // is_const
@ -69,7 +68,7 @@ Transform::Output EmitVertexPointSize::Run(ast::Module* in) {
auto* one = out.module.create<ast::ScalarConstructorExpression>( auto* one = out.module.create<ast::ScalarConstructorExpression>(
Source{}, out.module.create<ast::FloatLiteral>(Source{}, f32, 1.0f)); Source{}, out.module.create<ast::FloatLiteral>(Source{}, f32, 1.0f));
auto* pointsize_ident = out.module.create<ast::IdentifierExpression>( auto* pointsize_ident = out.module.create<ast::IdentifierExpression>(
Source{}, out.module.RegisterSymbol(kPointSizeVar), kPointSizeVar); Source{}, out.module.RegisterSymbol(kPointSizeVar));
auto* pointsize_assign = out.module.create<ast::AssignmentStatement>( auto* pointsize_assign = out.module.create<ast::AssignmentStatement>(
Source{}, pointsize_ident, one); Source{}, pointsize_ident, one);

View File

@ -67,7 +67,6 @@ ast::Variable* clone_variable_with_new_name(ast::CloneContext* ctx,
return ctx->mod->create<ast::Variable>( return ctx->mod->create<ast::Variable>(
ctx->Clone(in->source()), // source ctx->Clone(in->source()), // source
ctx->mod->RegisterSymbol(new_name), // symbol ctx->mod->RegisterSymbol(new_name), // symbol
new_name, // name
in->storage_class(), // storage_class in->storage_class(), // storage_class
ctx->Clone(in->type()), // type ctx->Clone(in->type()), // type
in->is_const(), // is_const in->is_const(), // is_const
@ -205,8 +204,8 @@ ast::Variable* FirstIndexOffset::AddUniformBuffer(ast::Module* mod) {
member_dec.push_back( member_dec.push_back(
mod->create<ast::StructMemberOffsetDecoration>(Source{}, offset)); mod->create<ast::StructMemberOffsetDecoration>(Source{}, offset));
members.push_back(mod->create<ast::StructMember>( members.push_back(mod->create<ast::StructMember>(
Source{}, mod->RegisterSymbol(kFirstVertexName), kFirstVertexName, Source{}, mod->RegisterSymbol(kFirstVertexName), u32_type,
u32_type, std::move(member_dec))); std::move(member_dec)));
vertex_index_offset_ = offset; vertex_index_offset_ = offset;
offset += 4; offset += 4;
} }
@ -216,8 +215,8 @@ ast::Variable* FirstIndexOffset::AddUniformBuffer(ast::Module* mod) {
member_dec.push_back( member_dec.push_back(
mod->create<ast::StructMemberOffsetDecoration>(Source{}, offset)); mod->create<ast::StructMemberOffsetDecoration>(Source{}, offset));
members.push_back(mod->create<ast::StructMember>( members.push_back(mod->create<ast::StructMember>(
Source{}, mod->RegisterSymbol(kFirstInstanceName), kFirstInstanceName, Source{}, mod->RegisterSymbol(kFirstInstanceName), u32_type,
u32_type, std::move(member_dec))); std::move(member_dec)));
instance_index_offset_ = offset; instance_index_offset_ = offset;
offset += 4; offset += 4;
} }
@ -226,13 +225,12 @@ ast::Variable* FirstIndexOffset::AddUniformBuffer(ast::Module* mod) {
decos.push_back(mod->create<ast::StructBlockDecoration>(Source{})); decos.push_back(mod->create<ast::StructBlockDecoration>(Source{}));
auto* struct_type = mod->create<ast::type::Struct>( auto* struct_type = mod->create<ast::type::Struct>(
mod->RegisterSymbol(kStructName), kStructName, mod->RegisterSymbol(kStructName),
mod->create<ast::Struct>(Source{}, std::move(members), std::move(decos))); mod->create<ast::Struct>(Source{}, std::move(members), std::move(decos)));
auto* idx_var = mod->create<ast::Variable>( auto* idx_var = mod->create<ast::Variable>(
Source{}, // source Source{}, // source
mod->RegisterSymbol(kBufferName), // symbol mod->RegisterSymbol(kBufferName), // symbol
kBufferName, // name
ast::StorageClass::kUniform, // storage_class ast::StorageClass::kUniform, // storage_class
struct_type, // type struct_type, // type
false, // is_const false, // is_const
@ -254,22 +252,21 @@ ast::VariableDeclStatement* FirstIndexOffset::CreateFirstIndexOffset(
const std::string& field_name, const std::string& field_name,
ast::Variable* buffer_var, ast::Variable* buffer_var,
ast::Module* mod) { ast::Module* mod) {
auto* buffer = mod->create<ast::IdentifierExpression>( auto* buffer =
Source{}, buffer_var->symbol(), mod->SymbolToName(buffer_var->symbol())); mod->create<ast::IdentifierExpression>(Source{}, buffer_var->symbol());
auto lhs_name = kIndexOffsetPrefix + original_name; auto lhs_name = kIndexOffsetPrefix + original_name;
auto* constructor = mod->create<ast::BinaryExpression>( auto* constructor = mod->create<ast::BinaryExpression>(
Source{}, ast::BinaryOp::kAdd, Source{}, ast::BinaryOp::kAdd,
mod->create<ast::IdentifierExpression>( mod->create<ast::IdentifierExpression>(Source{},
Source{}, mod->RegisterSymbol(lhs_name), lhs_name), mod->RegisterSymbol(lhs_name)),
mod->create<ast::MemberAccessorExpression>( mod->create<ast::MemberAccessorExpression>(
Source{}, buffer, Source{}, buffer,
mod->create<ast::IdentifierExpression>( mod->create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol(field_name), field_name))); Source{}, mod->RegisterSymbol(field_name))));
auto* var = auto* var =
mod->create<ast::Variable>(Source{}, // source mod->create<ast::Variable>(Source{}, // source
mod->RegisterSymbol(original_name), // symbol mod->RegisterSymbol(original_name), // symbol
original_name, // name
ast::StorageClass::kNone, // storage_class ast::StorageClass::kNone, // storage_class
mod->create<ast::type::U32>(), // type mod->create<ast::type::U32>(), // type
true, // is_const true, // is_const

View File

@ -32,7 +32,7 @@ ast::Function* Transform::CloneWithStatementsAtStart(
statements.emplace_back(ctx->Clone(s)); statements.emplace_back(ctx->Clone(s));
} }
return ctx->mod->create<ast::Function>( return ctx->mod->create<ast::Function>(
ctx->Clone(in->source()), ctx->Clone(in->symbol()), in->name_for_clone(), ctx->Clone(in->source()), ctx->Clone(in->symbol()),
ctx->Clone(in->params()), ctx->Clone(in->return_type()), ctx->Clone(in->params()), ctx->Clone(in->return_type()),
ctx->mod->create<ast::BlockStatement>(ctx->Clone(in->body()->source()), ctx->mod->create<ast::BlockStatement>(ctx->Clone(in->body()->source()),
statements), statements),

View File

@ -168,7 +168,6 @@ void VertexPulling::State::FindOrInsertVertexIndexIfUsed() {
auto* var = out->create<ast::Variable>( auto* var = out->create<ast::Variable>(
Source{}, // source Source{}, // source
out->RegisterSymbol(vertex_index_name), // symbol out->RegisterSymbol(vertex_index_name), // symbol
vertex_index_name, // name
ast::StorageClass::kInput, // storage_class ast::StorageClass::kInput, // storage_class
GetI32Type(), // type GetI32Type(), // type
false, // is_const false, // is_const
@ -216,7 +215,6 @@ void VertexPulling::State::FindOrInsertInstanceIndexIfUsed() {
auto* var = out->create<ast::Variable>( auto* var = out->create<ast::Variable>(
Source{}, // source Source{}, // source
out->RegisterSymbol(instance_index_name), // symbol out->RegisterSymbol(instance_index_name), // symbol
instance_index_name, // name
ast::StorageClass::kInput, // storage_class ast::StorageClass::kInput, // storage_class
GetI32Type(), // type GetI32Type(), // type
false, // is_const false, // is_const
@ -244,7 +242,6 @@ void VertexPulling::State::ConvertVertexInputVariablesToPrivate() {
v = out->create<ast::Variable>( v = out->create<ast::Variable>(
Source{}, // source Source{}, // source
v->symbol(), // symbol v->symbol(), // symbol
out->SymbolToName(v->symbol()), // name
ast::StorageClass::kPrivate, // storage_class ast::StorageClass::kPrivate, // storage_class
v->type(), // type v->type(), // type
false, // is_const false, // is_const
@ -273,14 +270,14 @@ void VertexPulling::State::AddVertexStorageBuffers() {
out->create<ast::StructMemberOffsetDecoration>(Source{}, 0u)); out->create<ast::StructMemberOffsetDecoration>(Source{}, 0u));
members.push_back(out->create<ast::StructMember>( members.push_back(out->create<ast::StructMember>(
Source{}, out->RegisterSymbol(kStructBufferName), kStructBufferName, Source{}, out->RegisterSymbol(kStructBufferName), internal_array_type,
internal_array_type, std::move(member_dec))); std::move(member_dec)));
ast::StructDecorationList decos; ast::StructDecorationList decos;
decos.push_back(out->create<ast::StructBlockDecoration>(Source{})); decos.push_back(out->create<ast::StructBlockDecoration>(Source{}));
auto* struct_type = out->create<ast::type::Struct>( auto* struct_type = out->create<ast::type::Struct>(
out->RegisterSymbol(kStructName), kStructName, out->RegisterSymbol(kStructName),
out->create<ast::Struct>(Source{}, std::move(members), std::move(decos))); out->create<ast::Struct>(Source{}, std::move(members), std::move(decos)));
for (uint32_t i = 0; i < cfg.vertex_state.size(); ++i) { for (uint32_t i = 0; i < cfg.vertex_state.size(); ++i) {
@ -289,7 +286,6 @@ void VertexPulling::State::AddVertexStorageBuffers() {
auto* var = out->create<ast::Variable>( auto* var = out->create<ast::Variable>(
Source{}, // source Source{}, // source
out->RegisterSymbol(name), // symbol out->RegisterSymbol(name), // symbol
name, // name
ast::StorageClass::kStorageBuffer, // storage_class ast::StorageClass::kStorageBuffer, // storage_class
struct_type, // type struct_type, // type
false, // is_const false, // is_const
@ -315,7 +311,6 @@ ast::BlockStatement* VertexPulling::State::CreateVertexPullingPreamble() const {
Source{}, out->create<ast::Variable>( Source{}, out->create<ast::Variable>(
Source{}, // source Source{}, // source
out->RegisterSymbol(kPullingPosVarName), // symbol out->RegisterSymbol(kPullingPosVarName), // symbol
kPullingPosVarName, // name
ast::StorageClass::kFunction, // storage_class ast::StorageClass::kFunction, // storage_class
GetI32Type(), // type GetI32Type(), // type
false, // is_const false, // is_const
@ -343,7 +338,7 @@ ast::BlockStatement* VertexPulling::State::CreateVertexPullingPreamble() const {
: instance_index_name; : instance_index_name;
// Identifier to index by // Identifier to index by
auto* index_identifier = out->create<ast::IdentifierExpression>( auto* index_identifier = out->create<ast::IdentifierExpression>(
Source{}, out->RegisterSymbol(name), name); Source{}, out->RegisterSymbol(name));
// An expression for the start of the read in the buffer in bytes // An expression for the start of the read in the buffer in bytes
auto* pos_value = out->create<ast::BinaryExpression>( auto* pos_value = out->create<ast::BinaryExpression>(
@ -362,7 +357,7 @@ ast::BlockStatement* VertexPulling::State::CreateVertexPullingPreamble() const {
stmts.emplace_back(out->create<ast::AssignmentStatement>( stmts.emplace_back(out->create<ast::AssignmentStatement>(
Source{}, Source{},
out->create<ast::IdentifierExpression>( out->create<ast::IdentifierExpression>(
Source{}, out->RegisterSymbol(ident_name), ident_name), Source{}, out->RegisterSymbol(ident_name)),
AccessByFormat(i, attribute_desc.format))); AccessByFormat(i, attribute_desc.format)));
} }
} }
@ -377,7 +372,7 @@ ast::Expression* VertexPulling::State::GenUint(uint32_t value) const {
ast::Expression* VertexPulling::State::CreatePullingPositionIdent() const { ast::Expression* VertexPulling::State::CreatePullingPositionIdent() const {
return out->create<ast::IdentifierExpression>( return out->create<ast::IdentifierExpression>(
Source{}, out->RegisterSymbol(kPullingPosVarName), kPullingPosVarName); Source{}, out->RegisterSymbol(kPullingPosVarName));
} }
ast::Expression* VertexPulling::State::AccessByFormat( ast::Expression* VertexPulling::State::AccessByFormat(
@ -421,10 +416,9 @@ ast::Expression* VertexPulling::State::AccessU32(uint32_t buffer,
out->create<ast::MemberAccessorExpression>( out->create<ast::MemberAccessorExpression>(
Source{}, Source{},
out->create<ast::IdentifierExpression>( out->create<ast::IdentifierExpression>(
Source{}, out->RegisterSymbol(vbuf_name), vbuf_name), Source{}, out->RegisterSymbol(vbuf_name)),
out->create<ast::IdentifierExpression>( out->create<ast::IdentifierExpression>(
Source{}, out->RegisterSymbol(kStructBufferName), Source{}, out->RegisterSymbol(kStructBufferName))),
kStructBufferName)),
out->create<ast::BinaryExpression>(Source{}, ast::BinaryOp::kDivide, pos, out->create<ast::BinaryExpression>(Source{}, ast::BinaryOp::kDivide, pos,
GenUint(4))); GenUint(4)));
} }