summaryrefslogtreecommitdiff
path: root/src/video_core/shader/ast.cpp
diff options
context:
space:
mode:
authorGravatar Lioncash2019-10-17 19:54:17 -0400
committerGravatar Lioncash2019-10-17 20:26:10 -0400
commit081530686c37afd668b389103a97e573399a83a1 (patch)
tree87ea6d0c95e360cb9f36255146acae883be5a3ed /src/video_core/shader/ast.cpp
parentMerge pull request #2980 from lioncash/warn (diff)
downloadyuzu-081530686c37afd668b389103a97e573399a83a1.tar.gz
yuzu-081530686c37afd668b389103a97e573399a83a1.tar.xz
yuzu-081530686c37afd668b389103a97e573399a83a1.zip
video_core/shader/ast: Make use of fmt where applicable
Makes a few strings nicer to read and also eliminates a bit of string churn with operator+.
Diffstat (limited to 'src/video_core/shader/ast.cpp')
-rw-r--r--src/video_core/shader/ast.cpp28
1 files changed, 14 insertions, 14 deletions
diff --git a/src/video_core/shader/ast.cpp b/src/video_core/shader/ast.cpp
index 436d45f4b..0be048044 100644
--- a/src/video_core/shader/ast.cpp
+++ b/src/video_core/shader/ast.cpp
@@ -4,6 +4,8 @@
4 4
5#include <string> 5#include <string>
6 6
7#include <fmt/format.h>
8
7#include "common/assert.h" 9#include "common/assert.h"
8#include "common/common_types.h" 10#include "common/common_types.h"
9#include "video_core/shader/ast.h" 11#include "video_core/shader/ast.h"
@@ -249,7 +251,7 @@ public:
249 void operator()(const ASTIfThen& ast) { 251 void operator()(const ASTIfThen& ast) {
250 ExprPrinter expr_parser{}; 252 ExprPrinter expr_parser{};
251 std::visit(expr_parser, *ast.condition); 253 std::visit(expr_parser, *ast.condition);
252 inner += Ident() + "if (" + expr_parser.GetResult() + ") {\n"; 254 inner += fmt::format("{}if ({}) {{\n", Ident(), expr_parser.GetResult());
253 scope++; 255 scope++;
254 ASTNode current = ast.nodes.GetFirst(); 256 ASTNode current = ast.nodes.GetFirst();
255 while (current) { 257 while (current) {
@@ -257,7 +259,7 @@ public:
257 current = current->GetNext(); 259 current = current->GetNext();
258 } 260 }
259 scope--; 261 scope--;
260 inner += Ident() + "}\n"; 262 inner += fmt::format("{}}}\n", Ident());
261 } 263 }
262 264
263 void operator()(const ASTIfElse& ast) { 265 void operator()(const ASTIfElse& ast) {
@@ -273,8 +275,7 @@ public:
273 } 275 }
274 276
275 void operator()(const ASTBlockEncoded& ast) { 277 void operator()(const ASTBlockEncoded& ast) {
276 inner += Ident() + "Block(" + std::to_string(ast.start) + ", " + std::to_string(ast.end) + 278 inner += fmt::format("{}Block({}, {});\n", Ident(), ast.start, ast.end);
277 ");\n";
278 } 279 }
279 280
280 void operator()(const ASTBlockDecoded& ast) { 281 void operator()(const ASTBlockDecoded& ast) {
@@ -284,25 +285,24 @@ public:
284 void operator()(const ASTVarSet& ast) { 285 void operator()(const ASTVarSet& ast) {
285 ExprPrinter expr_parser{}; 286 ExprPrinter expr_parser{};
286 std::visit(expr_parser, *ast.condition); 287 std::visit(expr_parser, *ast.condition);
287 inner += 288 inner += fmt::format("{}V{} := {};\n", Ident(), ast.index, expr_parser.GetResult());
288 Ident() + "V" + std::to_string(ast.index) + " := " + expr_parser.GetResult() + ";\n";
289 } 289 }
290 290
291 void operator()(const ASTLabel& ast) { 291 void operator()(const ASTLabel& ast) {
292 inner += "Label_" + std::to_string(ast.index) + ":\n"; 292 inner += fmt::format("Label_{}:\n", ast.index);
293 } 293 }
294 294
295 void operator()(const ASTGoto& ast) { 295 void operator()(const ASTGoto& ast) {
296 ExprPrinter expr_parser{}; 296 ExprPrinter expr_parser{};
297 std::visit(expr_parser, *ast.condition); 297 std::visit(expr_parser, *ast.condition);
298 inner += Ident() + "(" + expr_parser.GetResult() + ") -> goto Label_" + 298 inner +=
299 std::to_string(ast.label) + ";\n"; 299 fmt::format("{}({}) -> goto Label_{};\n", Ident(), expr_parser.GetResult(), ast.label);
300 } 300 }
301 301
302 void operator()(const ASTDoWhile& ast) { 302 void operator()(const ASTDoWhile& ast) {
303 ExprPrinter expr_parser{}; 303 ExprPrinter expr_parser{};
304 std::visit(expr_parser, *ast.condition); 304 std::visit(expr_parser, *ast.condition);
305 inner += Ident() + "do {\n"; 305 inner += fmt::format("{}do {{\n", Ident());
306 scope++; 306 scope++;
307 ASTNode current = ast.nodes.GetFirst(); 307 ASTNode current = ast.nodes.GetFirst();
308 while (current) { 308 while (current) {
@@ -310,20 +310,20 @@ public:
310 current = current->GetNext(); 310 current = current->GetNext();
311 } 311 }
312 scope--; 312 scope--;
313 inner += Ident() + "} while (" + expr_parser.GetResult() + ");\n"; 313 inner += fmt::format("{}}} while ({});\n", Ident(), expr_parser.GetResult());
314 } 314 }
315 315
316 void operator()(const ASTReturn& ast) { 316 void operator()(const ASTReturn& ast) {
317 ExprPrinter expr_parser{}; 317 ExprPrinter expr_parser{};
318 std::visit(expr_parser, *ast.condition); 318 std::visit(expr_parser, *ast.condition);
319 inner += Ident() + "(" + expr_parser.GetResult() + ") -> " + 319 inner += fmt::format("{}({}) -> {};\n", Ident(), expr_parser.GetResult(),
320 (ast.kills ? "discard" : "exit") + ";\n"; 320 ast.kills ? "discard" : "exit");
321 } 321 }
322 322
323 void operator()(const ASTBreak& ast) { 323 void operator()(const ASTBreak& ast) {
324 ExprPrinter expr_parser{}; 324 ExprPrinter expr_parser{};
325 std::visit(expr_parser, *ast.condition); 325 std::visit(expr_parser, *ast.condition);
326 inner += Ident() + "(" + expr_parser.GetResult() + ") -> break;\n"; 326 inner += fmt::format("{}({}) -> break;\n", Ident(), expr_parser.GetResult());
327 } 327 }
328 328
329 std::string& Ident() { 329 std::string& Ident() {