tint: Use resolved source var in the Inspector
This replaces the manual AST traversal code that was used to determine the originating resources for textures and samplers. Change-Id: I463e9dac836ab5d42d9b5559cda5cd35b154e588 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/87608 Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
parent
a9d8da4434
commit
e6d7ea708a
|
@ -864,70 +864,24 @@ void Inspector::GetOriginatingResources(
|
||||||
utils::UniqueVector<const ast::CallExpression*> callsites;
|
utils::UniqueVector<const ast::CallExpression*> callsites;
|
||||||
|
|
||||||
for (size_t i = 0; i < N; i++) {
|
for (size_t i = 0; i < N; i++) {
|
||||||
auto*& expr = exprs[i];
|
const sem::Variable* source_var = sem.Get(exprs[i])->SourceVariable();
|
||||||
// Resolve each of the expressions
|
if (auto* global = source_var->As<sem::GlobalVariable>()) {
|
||||||
while (true) {
|
globals[i] = global;
|
||||||
if (auto* user = sem.Get<sem::VariableUser>(expr)) {
|
} else if (auto* param = source_var->As<sem::Parameter>()) {
|
||||||
auto* var = user->Variable();
|
auto* func = tint::As<sem::Function>(param->Owner());
|
||||||
|
if (func->CallSites().empty()) {
|
||||||
if (auto* global = tint::As<sem::GlobalVariable>(var)) {
|
// One or more of the expressions is a parameter, but this function
|
||||||
// Found the global resource declaration.
|
// is not called. Ignore.
|
||||||
globals[i] = global;
|
return;
|
||||||
break; // Done with this expression.
|
|
||||||
}
|
|
||||||
|
|
||||||
if (auto* local = tint::As<sem::LocalVariable>(var)) {
|
|
||||||
// Chase the variable
|
|
||||||
expr = local->Declaration()->constructor;
|
|
||||||
if (!expr) {
|
|
||||||
TINT_ICE(Inspector, diagnostics_)
|
|
||||||
<< "resource variable had no initializer";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
continue; // Continue chasing the expression in this function
|
|
||||||
}
|
|
||||||
|
|
||||||
if (auto* param = tint::As<sem::Parameter>(var)) {
|
|
||||||
// Gather each of the callers of this function
|
|
||||||
auto* func = tint::As<sem::Function>(param->Owner());
|
|
||||||
if (func->CallSites().empty()) {
|
|
||||||
// One or more of the expressions is a parameter, but this function
|
|
||||||
// is not called. Ignore.
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (auto* call : func->CallSites()) {
|
|
||||||
callsites.add(call->Declaration());
|
|
||||||
}
|
|
||||||
// Need to evaluate each function call with the group of
|
|
||||||
// expressions, so move on to the next expression.
|
|
||||||
parameters[i] = param;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
TINT_ICE(Inspector, diagnostics_)
|
|
||||||
<< "unexpected variable type " << var->TypeInfo().name;
|
|
||||||
}
|
}
|
||||||
|
for (auto* call : func->CallSites()) {
|
||||||
if (auto* unary = tint::As<ast::UnaryOpExpression>(expr)) {
|
callsites.add(call->Declaration());
|
||||||
switch (unary->op) {
|
|
||||||
case ast::UnaryOp::kAddressOf:
|
|
||||||
case ast::UnaryOp::kIndirection:
|
|
||||||
// `*` and `&` are the only valid unary ops for a resource type,
|
|
||||||
// and must be balanced in order for the program to have passed
|
|
||||||
// validation. Just skip past these.
|
|
||||||
expr = unary->expr;
|
|
||||||
continue;
|
|
||||||
default: {
|
|
||||||
TINT_ICE(Inspector, diagnostics_)
|
|
||||||
<< "unexpected unary op on resource: " << unary->op;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
parameters[i] = param;
|
||||||
|
} else {
|
||||||
TINT_ICE(Inspector, diagnostics_)
|
TINT_ICE(Inspector, diagnostics_)
|
||||||
<< "cannot resolve originating resource with expression type "
|
<< "cannot resolve originating resource with expression type "
|
||||||
<< expr->TypeInfo().name;
|
<< exprs[i]->TypeInfo().name;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue