1
0
Fork 0
forked from suyu/suyu

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+.
This commit is contained in:
Lioncash 2019-10-17 19:54:17 -04:00
parent 9fe8072c67
commit 081530686c

View file

@ -4,6 +4,8 @@
#include <string> #include <string>
#include <fmt/format.h>
#include "common/assert.h" #include "common/assert.h"
#include "common/common_types.h" #include "common/common_types.h"
#include "video_core/shader/ast.h" #include "video_core/shader/ast.h"
@ -249,7 +251,7 @@ public:
void operator()(const ASTIfThen& ast) { void operator()(const ASTIfThen& ast) {
ExprPrinter expr_parser{}; ExprPrinter expr_parser{};
std::visit(expr_parser, *ast.condition); std::visit(expr_parser, *ast.condition);
inner += Ident() + "if (" + expr_parser.GetResult() + ") {\n"; inner += fmt::format("{}if ({}) {{\n", Ident(), expr_parser.GetResult());
scope++; scope++;
ASTNode current = ast.nodes.GetFirst(); ASTNode current = ast.nodes.GetFirst();
while (current) { while (current) {
@ -257,7 +259,7 @@ public:
current = current->GetNext(); current = current->GetNext();
} }
scope--; scope--;
inner += Ident() + "}\n"; inner += fmt::format("{}}}\n", Ident());
} }
void operator()(const ASTIfElse& ast) { void operator()(const ASTIfElse& ast) {
@ -273,8 +275,7 @@ public:
} }
void operator()(const ASTBlockEncoded& ast) { void operator()(const ASTBlockEncoded& ast) {
inner += Ident() + "Block(" + std::to_string(ast.start) + ", " + std::to_string(ast.end) + inner += fmt::format("{}Block({}, {});\n", Ident(), ast.start, ast.end);
");\n";
} }
void operator()(const ASTBlockDecoded& ast) { void operator()(const ASTBlockDecoded& ast) {
@ -284,25 +285,24 @@ public:
void operator()(const ASTVarSet& ast) { void operator()(const ASTVarSet& ast) {
ExprPrinter expr_parser{}; ExprPrinter expr_parser{};
std::visit(expr_parser, *ast.condition); std::visit(expr_parser, *ast.condition);
inner += inner += fmt::format("{}V{} := {};\n", Ident(), ast.index, expr_parser.GetResult());
Ident() + "V" + std::to_string(ast.index) + " := " + expr_parser.GetResult() + ";\n";
} }
void operator()(const ASTLabel& ast) { void operator()(const ASTLabel& ast) {
inner += "Label_" + std::to_string(ast.index) + ":\n"; inner += fmt::format("Label_{}:\n", ast.index);
} }
void operator()(const ASTGoto& ast) { void operator()(const ASTGoto& ast) {
ExprPrinter expr_parser{}; ExprPrinter expr_parser{};
std::visit(expr_parser, *ast.condition); std::visit(expr_parser, *ast.condition);
inner += Ident() + "(" + expr_parser.GetResult() + ") -> goto Label_" + inner +=
std::to_string(ast.label) + ";\n"; fmt::format("{}({}) -> goto Label_{};\n", Ident(), expr_parser.GetResult(), ast.label);
} }
void operator()(const ASTDoWhile& ast) { void operator()(const ASTDoWhile& ast) {
ExprPrinter expr_parser{}; ExprPrinter expr_parser{};
std::visit(expr_parser, *ast.condition); std::visit(expr_parser, *ast.condition);
inner += Ident() + "do {\n"; inner += fmt::format("{}do {{\n", Ident());
scope++; scope++;
ASTNode current = ast.nodes.GetFirst(); ASTNode current = ast.nodes.GetFirst();
while (current) { while (current) {
@ -310,20 +310,20 @@ public:
current = current->GetNext(); current = current->GetNext();
} }
scope--; scope--;
inner += Ident() + "} while (" + expr_parser.GetResult() + ");\n"; inner += fmt::format("{}}} while ({});\n", Ident(), expr_parser.GetResult());
} }
void operator()(const ASTReturn& ast) { void operator()(const ASTReturn& ast) {
ExprPrinter expr_parser{}; ExprPrinter expr_parser{};
std::visit(expr_parser, *ast.condition); std::visit(expr_parser, *ast.condition);
inner += Ident() + "(" + expr_parser.GetResult() + ") -> " + inner += fmt::format("{}({}) -> {};\n", Ident(), expr_parser.GetResult(),
(ast.kills ? "discard" : "exit") + ";\n"; ast.kills ? "discard" : "exit");
} }
void operator()(const ASTBreak& ast) { void operator()(const ASTBreak& ast) {
ExprPrinter expr_parser{}; ExprPrinter expr_parser{};
std::visit(expr_parser, *ast.condition); std::visit(expr_parser, *ast.condition);
inner += Ident() + "(" + expr_parser.GetResult() + ") -> break;\n"; inner += fmt::format("{}({}) -> break;\n", Ident(), expr_parser.GetResult());
} }
std::string& Ident() { std::string& Ident() {