Enable InsertBefore to work on global declarations

Use it for entry point IO sanitizing transforms to fix cases where structures were being inserted before type aliases that they reference.

Also fixes up some ordering issues with the FirstIndexOffset
transform.

Change-Id: I50d472ccb844b388f69914dcecbc0fcda1a579ed
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/45000
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Auto-Submit: James Price <jrprice@google.com>
This commit is contained in:
James Price
2021-03-17 09:26:04 +00:00
committed by Commit Bot service account
parent 4f4a285750
commit 4f4534df3a
10 changed files with 125 additions and 43 deletions

View File

@@ -25,7 +25,7 @@ namespace ast {
Module::Module(const Source& source) : Base(source) {}
Module::Module(const Source& source, std::vector<CastableBase*> global_decls)
Module::Module(const Source& source, std::vector<Cloneable*> global_decls)
: Base(source), global_declarations_(std::move(global_decls)) {
for (auto* decl : global_declarations_) {
if (decl == nullptr) {
@@ -54,14 +54,14 @@ Module* Module::Clone(CloneContext* ctx) const {
}
void Module::Copy(CloneContext* ctx, const Module* src) {
for (auto* decl : src->global_declarations_) {
for (auto* decl : ctx->Clone(src->global_declarations_)) {
assert(decl);
if (auto* ty = decl->As<type::Type>()) {
AddConstructedType(ctx->Clone(ty));
AddConstructedType(ty);
} else if (auto* func = decl->As<Function>()) {
AddFunction(ctx->Clone(func));
AddFunction(func);
} else if (auto* var = decl->As<Variable>()) {
AddGlobalVariable(ctx->Clone(var));
AddGlobalVariable(var);
} else {
TINT_ICE(ctx->dst->Diagnostics()) << "Unknown global declaration type";
}

View File

@@ -35,13 +35,13 @@ class Module : public Castable<Module, Node> {
/// @param source the source of the module
/// @param global_decls the list of global types, functions, and variables, in
/// the order they were declared in the source program
Module(const Source& source, std::vector<CastableBase*> global_decls);
Module(const Source& source, std::vector<Cloneable*> global_decls);
/// Destructor
~Module() override;
/// @returns the ordered global declarations for the translation unit
const std::vector<CastableBase*>& GlobalDeclarations() const {
const std::vector<Cloneable*>& GlobalDeclarations() const {
return global_declarations_;
}
@@ -108,7 +108,7 @@ class Module : public Castable<Module, Node> {
std::string to_str(const semantic::Info& sem) const;
private:
std::vector<CastableBase*> global_declarations_;
std::vector<Cloneable*> global_declarations_;
std::vector<type::Type*> constructed_types_;
FunctionList functions_;
VariableList global_variables_;