2021-05-05 07:19:08 +02:00
|
|
|
// Copyright 2021 yuzu Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <string>
|
2021-05-07 11:31:30 +02:00
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
#include <fmt/format.h>
|
2021-05-05 07:19:08 +02:00
|
|
|
|
|
|
|
#include "shader_recompiler/backend/glasm/reg_alloc.h"
|
|
|
|
|
2021-05-07 11:31:30 +02:00
|
|
|
namespace Shader::IR {
|
|
|
|
class Inst;
|
2021-05-08 21:28:52 +02:00
|
|
|
struct Program;
|
|
|
|
} // namespace Shader::IR
|
2021-05-07 11:31:30 +02:00
|
|
|
|
2021-05-05 07:19:08 +02:00
|
|
|
namespace Shader::Backend::GLASM {
|
|
|
|
|
|
|
|
class EmitContext {
|
|
|
|
public:
|
2021-05-08 21:28:52 +02:00
|
|
|
explicit EmitContext(IR::Program& program);
|
2021-05-05 07:19:08 +02:00
|
|
|
|
2021-05-07 11:31:30 +02:00
|
|
|
template <typename... Args>
|
2021-05-09 08:11:34 +02:00
|
|
|
void Add(const char* format_str, IR::Inst& inst, Args&&... args) {
|
|
|
|
code += fmt::format(format_str, reg_alloc.Define(inst), std::forward<Args>(args)...);
|
2021-05-07 11:31:30 +02:00
|
|
|
// TODO: Remove this
|
|
|
|
code += '\n';
|
|
|
|
}
|
|
|
|
|
2021-05-09 23:03:01 +02:00
|
|
|
template <typename... Args>
|
|
|
|
void LongAdd(const char* format_str, IR::Inst& inst, Args&&... args) {
|
|
|
|
code += fmt::format(format_str, reg_alloc.LongDefine(inst), std::forward<Args>(args)...);
|
|
|
|
// TODO: Remove this
|
|
|
|
code += '\n';
|
|
|
|
}
|
|
|
|
|
2021-05-07 11:31:30 +02:00
|
|
|
template <typename... Args>
|
2021-05-09 08:11:34 +02:00
|
|
|
void Add(const char* format_str, Args&&... args) {
|
|
|
|
code += fmt::format(format_str, std::forward<Args>(args)...);
|
2021-05-07 11:31:30 +02:00
|
|
|
// TODO: Remove this
|
|
|
|
code += '\n';
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string code;
|
|
|
|
RegAlloc reg_alloc{*this};
|
2021-05-05 07:19:08 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Shader::Backend::GLASM
|