From: Mikko Rasa Date: Mon, 8 Nov 2021 13:21:18 +0000 (+0200) Subject: Recognize increment/decrement operators as modifying the target variable X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=9978e2f62777795bf478b301aadffdd0ee8cbd41;p=libs%2Fgl.git Recognize increment/decrement operators as modifying the target variable --- diff --git a/source/glsl/reflect.cpp b/source/glsl/reflect.cpp index 6027acde..811679f3 100644 --- a/source/glsl/reflect.cpp +++ b/source/glsl/reflect.cpp @@ -1,4 +1,5 @@ #include +#include #include "reflect.h" using namespace std; @@ -387,16 +388,44 @@ void DependencyCollector::visit(FunctionDeclaration &func) } -set AssignmentCollector::apply(Node &node) +set AssignmentCollector::apply(Node &node) { node.visit(*this); return assigned_variables; } +void AssignmentCollector::visit(VariableReference &var) +{ + if(assignment_target) + assigned_variables.insert(var.declaration); +} + +void AssignmentCollector::visit(InterfaceBlockReference &iface) +{ + if(assignment_target) + assigned_variables.insert(iface.declaration); +} + +void AssignmentCollector::visit(UnaryExpression &unary) +{ + SetFlag set_assignment(assignment_target, (unary.oper->token[1]=='+' || unary.oper->token[1]=='-')); + TraversingVisitor::visit(unary); +} + +void AssignmentCollector::visit(BinaryExpression &binary) +{ + binary.left->visit(*this); + SetFlag clear_assignment(assignment_target, false); + binary.right->visit(*this); +} + void AssignmentCollector::visit(Assignment &assign) { - if(VariableDeclaration *var = dynamic_cast(assign.target.declaration)) - assigned_variables.insert(var); + { + SetFlag set_assignment(assignment_target); + assign.left->visit(*this); + } + assign.right->visit(*this); } } // namespace SL diff --git a/source/glsl/reflect.h b/source/glsl/reflect.h index 5b4170a9..7c4d26c4 100644 --- a/source/glsl/reflect.h +++ b/source/glsl/reflect.h @@ -107,12 +107,17 @@ private: class AssignmentCollector: private TraversingVisitor { private: - std::set assigned_variables; + bool assignment_target = false; + std::set assigned_variables; public: - std::set apply(Node &); + std::set apply(Node &); private: + virtual void visit(VariableReference &); + virtual void visit(InterfaceBlockReference &); + virtual void visit(UnaryExpression &); + virtual void visit(BinaryExpression &); virtual void visit(Assignment &); }; diff --git a/source/glsl/spirv.cpp b/source/glsl/spirv.cpp index 7bec551b..2dcc285c 100644 --- a/source/glsl/spirv.cpp +++ b/source/glsl/spirv.cpp @@ -1873,8 +1873,9 @@ void SpirVGenerator::visit(Iteration &iter) if(iter.init_statement) iter.init_statement->visit(*this); - for(VariableDeclaration *v: AssignmentCollector().apply(iter)) - variable_load_ids.erase(v); + for(Node *n: AssignmentCollector().apply(iter)) + if(VariableDeclaration *var = dynamic_cast(n)) + variable_load_ids.erase(var); Id header_id = next_id++; Id continue_id = next_id++;