ASL dumping

This commit is contained in:
Lander Gallastegi 2025-02-18 18:29:37 +01:00 committed by Lander Gallastegi
parent e100783357
commit 85334a924a
4 changed files with 45 additions and 4 deletions

View File

@ -842,6 +842,7 @@ set(SHADER_RECOMPILER src/shader_recompiler/exception.h
src/shader_recompiler/ir/passes/shared_memory_barrier_pass.cpp
src/shader_recompiler/ir/passes/shared_memory_to_storage_pass.cpp
src/shader_recompiler/ir/passes/ssa_rewrite_pass.cpp
src/shader_recompiler/ir/abstract_syntax_list.cpp
src/shader_recompiler/ir/abstract_syntax_list.h
src/shader_recompiler/ir/attribute.cpp
src/shader_recompiler/ir/attribute.h

View File

@ -0,0 +1,30 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "abstract_syntax_list.h"
namespace Shader::IR {
std::string DumpASLNode(const AbstractSyntaxNode& node, const std::map<const Block*, size_t>& block_to_index, const std::map<const Inst*, size_t>& inst_to_index) {
switch (node.type) {
case AbstractSyntaxNode::Type::Block:
return fmt::format("Block: ${}", block_to_index.at(node.data.block));
case AbstractSyntaxNode::Type::If:
return fmt::format("If: cond = %{}, body = ${}, merge = ${}", inst_to_index.at(node.data.if_node.cond.Inst()), block_to_index.at(node.data.if_node.body), block_to_index.at(node.data.if_node.merge));
case AbstractSyntaxNode::Type::EndIf:
return fmt::format("EndIf: merge = ${}", block_to_index.at(node.data.end_if.merge));
case AbstractSyntaxNode::Type::Loop:
return fmt::format("Loop: body = ${}, continue = ${}, merge = ${}", block_to_index.at(node.data.loop.body), block_to_index.at(node.data.loop.continue_block), block_to_index.at(node.data.loop.merge));
case AbstractSyntaxNode::Type::Repeat:
return fmt::format("Repeat: cond = %{}, header = ${}, merge = ${}", inst_to_index.at(node.data.repeat.cond.Inst()), block_to_index.at(node.data.repeat.loop_header), block_to_index.at(node.data.repeat.merge));
case AbstractSyntaxNode::Type::Break:
return fmt::format("Break: cond = %{}, merge = ${}, skip = ${}", inst_to_index.at(node.data.break_node.cond.Inst()), block_to_index.at(node.data.break_node.merge), block_to_index.at(node.data.break_node.skip));
case AbstractSyntaxNode::Type::Return:
return "Return";
case AbstractSyntaxNode::Type::Unreachable:
UNREACHABLE();
};
UNREACHABLE();
}
} // namespace Shader::IR

View File

@ -4,6 +4,7 @@
#pragma once
#include <vector>
#include <map>
#include "shader_recompiler/ir/value.h"
namespace Shader::IR {
@ -53,4 +54,6 @@ struct AbstractSyntaxNode {
};
using AbstractSyntaxList = std::vector<AbstractSyntaxNode>;
std::string DumpASLNode(const AbstractSyntaxNode& node, const std::map<const Block*, size_t>& block_to_index, const std::map<const Inst*, size_t>& inst_to_index);
} // namespace Shader::IR

View File

@ -26,9 +26,8 @@ void DumpProgram(const Program& program, const Info& info) {
if (!std::filesystem::exists(dump_dir)) {
std::filesystem::create_directories(dump_dir);
}
const auto filename = fmt::format("{}_{:#018x}.irprogram.txt", info.stage, info.pgm_hash);
const auto file = IOFile{dump_dir / filename, FileAccessMode::Write, FileType::TextFile};
const auto ir_filename = fmt::format("{}_{:#018x}.irprogram.txt", info.stage, info.pgm_hash);
const auto ir_file = IOFile{dump_dir / ir_filename, FileAccessMode::Write, FileType::TextFile};
size_t index{0};
std::map<const IR::Inst*, size_t> inst_to_index;
@ -41,7 +40,15 @@ void DumpProgram(const Program& program, const Info& info) {
for (const auto& block : program.blocks) {
std::string s = IR::DumpBlock(*block, block_to_index, inst_to_index, index) + '\n';
file.WriteString(s);
ir_file.WriteString(s);
}
const auto asl_filename = fmt::format("{}_{:#018x}.asl.txt", info.stage, info.pgm_hash);
const auto asl_file = IOFile{dump_dir / asl_filename, FileAccessMode::Write, FileType::TextFile};
for (const auto& node : program.syntax_list) {
std::string s = IR::DumpASLNode(node, block_to_index, inst_to_index) + '\n';
asl_file.WriteString(s);
}
}