diff options
| author | 2019-10-05 08:06:44 -0400 | |
|---|---|---|
| committer | 2019-10-05 08:22:03 -0400 | |
| commit | 8e0c80f26914552e11144bd92dae726b66c3739d (patch) | |
| tree | fc0549a8d69d138bcce209094ce914d63c4f451a /src | |
| parent | Merge pull request #2888 from FernandoS27/decompiler2 (diff) | |
| download | yuzu-8e0c80f26914552e11144bd92dae726b66c3739d.tar.gz yuzu-8e0c80f26914552e11144bd92dae726b66c3739d.tar.xz yuzu-8e0c80f26914552e11144bd92dae726b66c3739d.zip | |
video_core/ast: Supply const accessors for data where applicable
Provides const equivalents of data accessors for use within const
contexts.
Diffstat (limited to 'src')
| -rw-r--r-- | src/video_core/shader/ast.cpp | 66 | ||||
| -rw-r--r-- | src/video_core/shader/ast.h | 12 |
2 files changed, 41 insertions, 37 deletions
diff --git a/src/video_core/shader/ast.cpp b/src/video_core/shader/ast.cpp index 2eb065c3d..87c722682 100644 --- a/src/video_core/shader/ast.cpp +++ b/src/video_core/shader/ast.cpp | |||
| @@ -185,9 +185,7 @@ void ASTZipper::Remove(const ASTNode node) { | |||
| 185 | 185 | ||
| 186 | class ExprPrinter final { | 186 | class ExprPrinter final { |
| 187 | public: | 187 | public: |
| 188 | ExprPrinter() = default; | 188 | void operator()(const ExprAnd& expr) { |
| 189 | |||
| 190 | void operator()(ExprAnd const& expr) { | ||
| 191 | inner += "( "; | 189 | inner += "( "; |
| 192 | std::visit(*this, *expr.operand1); | 190 | std::visit(*this, *expr.operand1); |
| 193 | inner += " && "; | 191 | inner += " && "; |
| @@ -195,7 +193,7 @@ public: | |||
| 195 | inner += ')'; | 193 | inner += ')'; |
| 196 | } | 194 | } |
| 197 | 195 | ||
| 198 | void operator()(ExprOr const& expr) { | 196 | void operator()(const ExprOr& expr) { |
| 199 | inner += "( "; | 197 | inner += "( "; |
| 200 | std::visit(*this, *expr.operand1); | 198 | std::visit(*this, *expr.operand1); |
| 201 | inner += " || "; | 199 | inner += " || "; |
| @@ -203,29 +201,29 @@ public: | |||
| 203 | inner += ')'; | 201 | inner += ')'; |
| 204 | } | 202 | } |
| 205 | 203 | ||
| 206 | void operator()(ExprNot const& expr) { | 204 | void operator()(const ExprNot& expr) { |
| 207 | inner += "!"; | 205 | inner += "!"; |
| 208 | std::visit(*this, *expr.operand1); | 206 | std::visit(*this, *expr.operand1); |
| 209 | } | 207 | } |
| 210 | 208 | ||
| 211 | void operator()(ExprPredicate const& expr) { | 209 | void operator()(const ExprPredicate& expr) { |
| 212 | inner += "P" + std::to_string(expr.predicate); | 210 | inner += "P" + std::to_string(expr.predicate); |
| 213 | } | 211 | } |
| 214 | 212 | ||
| 215 | void operator()(ExprCondCode const& expr) { | 213 | void operator()(const ExprCondCode& expr) { |
| 216 | u32 cc = static_cast<u32>(expr.cc); | 214 | u32 cc = static_cast<u32>(expr.cc); |
| 217 | inner += "CC" + std::to_string(cc); | 215 | inner += "CC" + std::to_string(cc); |
| 218 | } | 216 | } |
| 219 | 217 | ||
| 220 | void operator()(ExprVar const& expr) { | 218 | void operator()(const ExprVar& expr) { |
| 221 | inner += "V" + std::to_string(expr.var_index); | 219 | inner += "V" + std::to_string(expr.var_index); |
| 222 | } | 220 | } |
| 223 | 221 | ||
| 224 | void operator()(ExprBoolean const& expr) { | 222 | void operator()(const ExprBoolean& expr) { |
| 225 | inner += expr.value ? "true" : "false"; | 223 | inner += expr.value ? "true" : "false"; |
| 226 | } | 224 | } |
| 227 | 225 | ||
| 228 | std::string& GetResult() { | 226 | const std::string& GetResult() const { |
| 229 | return inner; | 227 | return inner; |
| 230 | } | 228 | } |
| 231 | 229 | ||
| @@ -234,9 +232,7 @@ public: | |||
| 234 | 232 | ||
| 235 | class ASTPrinter { | 233 | class ASTPrinter { |
| 236 | public: | 234 | public: |
| 237 | ASTPrinter() = default; | 235 | void operator()(const ASTProgram& ast) { |
| 238 | |||
| 239 | void operator()(ASTProgram& ast) { | ||
| 240 | scope++; | 236 | scope++; |
| 241 | inner += "program {\n"; | 237 | inner += "program {\n"; |
| 242 | ASTNode current = ast.nodes.GetFirst(); | 238 | ASTNode current = ast.nodes.GetFirst(); |
| @@ -248,7 +244,7 @@ public: | |||
| 248 | scope--; | 244 | scope--; |
| 249 | } | 245 | } |
| 250 | 246 | ||
| 251 | void operator()(ASTIfThen& ast) { | 247 | void operator()(const ASTIfThen& ast) { |
| 252 | ExprPrinter expr_parser{}; | 248 | ExprPrinter expr_parser{}; |
| 253 | std::visit(expr_parser, *ast.condition); | 249 | std::visit(expr_parser, *ast.condition); |
| 254 | inner += Ident() + "if (" + expr_parser.GetResult() + ") {\n"; | 250 | inner += Ident() + "if (" + expr_parser.GetResult() + ") {\n"; |
| @@ -262,7 +258,7 @@ public: | |||
| 262 | inner += Ident() + "}\n"; | 258 | inner += Ident() + "}\n"; |
| 263 | } | 259 | } |
| 264 | 260 | ||
| 265 | void operator()(ASTIfElse& ast) { | 261 | void operator()(const ASTIfElse& ast) { |
| 266 | inner += Ident() + "else {\n"; | 262 | inner += Ident() + "else {\n"; |
| 267 | scope++; | 263 | scope++; |
| 268 | ASTNode current = ast.nodes.GetFirst(); | 264 | ASTNode current = ast.nodes.GetFirst(); |
| @@ -274,34 +270,34 @@ public: | |||
| 274 | inner += Ident() + "}\n"; | 270 | inner += Ident() + "}\n"; |
| 275 | } | 271 | } |
| 276 | 272 | ||
| 277 | void operator()(ASTBlockEncoded& ast) { | 273 | void operator()(const ASTBlockEncoded& ast) { |
| 278 | inner += Ident() + "Block(" + std::to_string(ast.start) + ", " + std::to_string(ast.end) + | 274 | inner += Ident() + "Block(" + std::to_string(ast.start) + ", " + std::to_string(ast.end) + |
| 279 | ");\n"; | 275 | ");\n"; |
| 280 | } | 276 | } |
| 281 | 277 | ||
| 282 | void operator()(ASTBlockDecoded& ast) { | 278 | void operator()(const ASTBlockDecoded& ast) { |
| 283 | inner += Ident() + "Block;\n"; | 279 | inner += Ident() + "Block;\n"; |
| 284 | } | 280 | } |
| 285 | 281 | ||
| 286 | void operator()(ASTVarSet& ast) { | 282 | void operator()(const ASTVarSet& ast) { |
| 287 | ExprPrinter expr_parser{}; | 283 | ExprPrinter expr_parser{}; |
| 288 | std::visit(expr_parser, *ast.condition); | 284 | std::visit(expr_parser, *ast.condition); |
| 289 | inner += | 285 | inner += |
| 290 | Ident() + "V" + std::to_string(ast.index) + " := " + expr_parser.GetResult() + ";\n"; | 286 | Ident() + "V" + std::to_string(ast.index) + " := " + expr_parser.GetResult() + ";\n"; |
| 291 | } | 287 | } |
| 292 | 288 | ||
| 293 | void operator()(ASTLabel& ast) { | 289 | void operator()(const ASTLabel& ast) { |
| 294 | inner += "Label_" + std::to_string(ast.index) + ":\n"; | 290 | inner += "Label_" + std::to_string(ast.index) + ":\n"; |
| 295 | } | 291 | } |
| 296 | 292 | ||
| 297 | void operator()(ASTGoto& ast) { | 293 | void operator()(const ASTGoto& ast) { |
| 298 | ExprPrinter expr_parser{}; | 294 | ExprPrinter expr_parser{}; |
| 299 | std::visit(expr_parser, *ast.condition); | 295 | std::visit(expr_parser, *ast.condition); |
| 300 | inner += Ident() + "(" + expr_parser.GetResult() + ") -> goto Label_" + | 296 | inner += Ident() + "(" + expr_parser.GetResult() + ") -> goto Label_" + |
| 301 | std::to_string(ast.label) + ";\n"; | 297 | std::to_string(ast.label) + ";\n"; |
| 302 | } | 298 | } |
| 303 | 299 | ||
| 304 | void operator()(ASTDoWhile& ast) { | 300 | void operator()(const ASTDoWhile& ast) { |
| 305 | ExprPrinter expr_parser{}; | 301 | ExprPrinter expr_parser{}; |
| 306 | std::visit(expr_parser, *ast.condition); | 302 | std::visit(expr_parser, *ast.condition); |
| 307 | inner += Ident() + "do {\n"; | 303 | inner += Ident() + "do {\n"; |
| @@ -315,14 +311,14 @@ public: | |||
| 315 | inner += Ident() + "} while (" + expr_parser.GetResult() + ");\n"; | 311 | inner += Ident() + "} while (" + expr_parser.GetResult() + ");\n"; |
| 316 | } | 312 | } |
| 317 | 313 | ||
| 318 | void operator()(ASTReturn& ast) { | 314 | void operator()(const ASTReturn& ast) { |
| 319 | ExprPrinter expr_parser{}; | 315 | ExprPrinter expr_parser{}; |
| 320 | std::visit(expr_parser, *ast.condition); | 316 | std::visit(expr_parser, *ast.condition); |
| 321 | inner += Ident() + "(" + expr_parser.GetResult() + ") -> " + | 317 | inner += Ident() + "(" + expr_parser.GetResult() + ") -> " + |
| 322 | (ast.kills ? "discard" : "exit") + ";\n"; | 318 | (ast.kills ? "discard" : "exit") + ";\n"; |
| 323 | } | 319 | } |
| 324 | 320 | ||
| 325 | void operator()(ASTBreak& ast) { | 321 | void operator()(const ASTBreak& ast) { |
| 326 | ExprPrinter expr_parser{}; | 322 | ExprPrinter expr_parser{}; |
| 327 | std::visit(expr_parser, *ast.condition); | 323 | std::visit(expr_parser, *ast.condition); |
| 328 | inner += Ident() + "(" + expr_parser.GetResult() + ") -> break;\n"; | 324 | inner += Ident() + "(" + expr_parser.GetResult() + ") -> break;\n"; |
| @@ -341,7 +337,7 @@ public: | |||
| 341 | std::visit(*this, *node->GetInnerData()); | 337 | std::visit(*this, *node->GetInnerData()); |
| 342 | } | 338 | } |
| 343 | 339 | ||
| 344 | std::string& GetResult() { | 340 | const std::string& GetResult() const { |
| 345 | return inner; | 341 | return inner; |
| 346 | } | 342 | } |
| 347 | 343 | ||
| @@ -696,7 +692,7 @@ class ASTClearer { | |||
| 696 | public: | 692 | public: |
| 697 | ASTClearer() = default; | 693 | ASTClearer() = default; |
| 698 | 694 | ||
| 699 | void operator()(ASTProgram& ast) { | 695 | void operator()(const ASTProgram& ast) { |
| 700 | ASTNode current = ast.nodes.GetFirst(); | 696 | ASTNode current = ast.nodes.GetFirst(); |
| 701 | while (current) { | 697 | while (current) { |
| 702 | Visit(current); | 698 | Visit(current); |
| @@ -704,7 +700,7 @@ public: | |||
| 704 | } | 700 | } |
| 705 | } | 701 | } |
| 706 | 702 | ||
| 707 | void operator()(ASTIfThen& ast) { | 703 | void operator()(const ASTIfThen& ast) { |
| 708 | ASTNode current = ast.nodes.GetFirst(); | 704 | ASTNode current = ast.nodes.GetFirst(); |
| 709 | while (current) { | 705 | while (current) { |
| 710 | Visit(current); | 706 | Visit(current); |
| @@ -712,7 +708,7 @@ public: | |||
| 712 | } | 708 | } |
| 713 | } | 709 | } |
| 714 | 710 | ||
| 715 | void operator()(ASTIfElse& ast) { | 711 | void operator()(const ASTIfElse& ast) { |
| 716 | ASTNode current = ast.nodes.GetFirst(); | 712 | ASTNode current = ast.nodes.GetFirst(); |
| 717 | while (current) { | 713 | while (current) { |
| 718 | Visit(current); | 714 | Visit(current); |
| @@ -720,19 +716,19 @@ public: | |||
| 720 | } | 716 | } |
| 721 | } | 717 | } |
| 722 | 718 | ||
| 723 | void operator()(ASTBlockEncoded& ast) {} | 719 | void operator()([[maybe_unused]] const ASTBlockEncoded& ast) {} |
| 724 | 720 | ||
| 725 | void operator()(ASTBlockDecoded& ast) { | 721 | void operator()(ASTBlockDecoded& ast) { |
| 726 | ast.nodes.clear(); | 722 | ast.nodes.clear(); |
| 727 | } | 723 | } |
| 728 | 724 | ||
| 729 | void operator()(ASTVarSet& ast) {} | 725 | void operator()([[maybe_unused]] const ASTVarSet& ast) {} |
| 730 | 726 | ||
| 731 | void operator()(ASTLabel& ast) {} | 727 | void operator()([[maybe_unused]] const ASTLabel& ast) {} |
| 732 | 728 | ||
| 733 | void operator()(ASTGoto& ast) {} | 729 | void operator()([[maybe_unused]] const ASTGoto& ast) {} |
| 734 | 730 | ||
| 735 | void operator()(ASTDoWhile& ast) { | 731 | void operator()(const ASTDoWhile& ast) { |
| 736 | ASTNode current = ast.nodes.GetFirst(); | 732 | ASTNode current = ast.nodes.GetFirst(); |
| 737 | while (current) { | 733 | while (current) { |
| 738 | Visit(current); | 734 | Visit(current); |
| @@ -740,11 +736,11 @@ public: | |||
| 740 | } | 736 | } |
| 741 | } | 737 | } |
| 742 | 738 | ||
| 743 | void operator()(ASTReturn& ast) {} | 739 | void operator()([[maybe_unused]] const ASTReturn& ast) {} |
| 744 | 740 | ||
| 745 | void operator()(ASTBreak& ast) {} | 741 | void operator()([[maybe_unused]] const ASTBreak& ast) {} |
| 746 | 742 | ||
| 747 | void Visit(ASTNode& node) { | 743 | void Visit(const ASTNode& node) { |
| 748 | std::visit(*this, *node->GetInnerData()); | 744 | std::visit(*this, *node->GetInnerData()); |
| 749 | node->Clear(); | 745 | node->Clear(); |
| 750 | } | 746 | } |
diff --git a/src/video_core/shader/ast.h b/src/video_core/shader/ast.h index ba234138e..39f500284 100644 --- a/src/video_core/shader/ast.h +++ b/src/video_core/shader/ast.h | |||
| @@ -48,11 +48,11 @@ public: | |||
| 48 | 48 | ||
| 49 | void Init(ASTNode first, ASTNode parent); | 49 | void Init(ASTNode first, ASTNode parent); |
| 50 | 50 | ||
| 51 | ASTNode GetFirst() { | 51 | ASTNode GetFirst() const { |
| 52 | return first; | 52 | return first; |
| 53 | } | 53 | } |
| 54 | 54 | ||
| 55 | ASTNode GetLast() { | 55 | ASTNode GetLast() const { |
| 56 | return last; | 56 | return last; |
| 57 | } | 57 | } |
| 58 | 58 | ||
| @@ -177,6 +177,10 @@ public: | |||
| 177 | return &data; | 177 | return &data; |
| 178 | } | 178 | } |
| 179 | 179 | ||
| 180 | const ASTData* GetInnerData() const { | ||
| 181 | return &data; | ||
| 182 | } | ||
| 183 | |||
| 180 | ASTNode GetNext() const { | 184 | ASTNode GetNext() const { |
| 181 | return next; | 185 | return next; |
| 182 | } | 186 | } |
| @@ -189,6 +193,10 @@ public: | |||
| 189 | return *manager; | 193 | return *manager; |
| 190 | } | 194 | } |
| 191 | 195 | ||
| 196 | const ASTZipper& GetManager() const { | ||
| 197 | return *manager; | ||
| 198 | } | ||
| 199 | |||
| 192 | std::optional<u32> GetGotoLabel() const { | 200 | std::optional<u32> GetGotoLabel() const { |
| 193 | auto inner = std::get_if<ASTGoto>(&data); | 201 | auto inner = std::get_if<ASTGoto>(&data); |
| 194 | if (inner) { | 202 | if (inner) { |