Update to C++20 (#3193)

Just putting this here for consideration, I'm personally not in a big
rush to get it.

---------

Co-authored-by: Tyler Wilding <xtvaser@gmail.com>
This commit is contained in:
Ziemas 2024-02-17 20:14:23 +01:00 committed by GitHub
parent 269c19548b
commit 4afefc5a82
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
19 changed files with 95 additions and 83 deletions

View File

@ -1,7 +1,7 @@
# Top Level CMakeLists.txt
cmake_minimum_required(VERSION 3.10)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 20)
project(jak)
include(CTest)
@ -39,7 +39,6 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
-fcxx-exceptions \
-fexceptions \
-fdiagnostics-color=always \
-std=c++17 \
-mavx \
-Wall \
-Wno-c++11-narrowing \
@ -217,7 +216,6 @@ build_third_party_lib(sqlite3 sqlite3)
# build tree-sitter parser
include_directories(third-party/tree-sitter/tree-sitter/lib/include)
include_directories(third-party/tree-sitter/tree-sitter-opengoal/include)
build_third_party_lib(tree-sitter tree-sitter)
# native OS dialogs for error messages

View File

@ -34,6 +34,7 @@ class GlobalProfiler {
};
struct ScopedEvent {
ScopedEvent(GlobalProfiler* _prof) : prof(_prof){};
ScopedEvent(const ScopedEvent&) = delete;
ScopedEvent& operator=(const ScopedEvent&) = delete;
GlobalProfiler* prof = nullptr;

View File

@ -61,13 +61,13 @@ void log(level log_level, const std::string& format, Args&&... args) {
#else
now.tim = time(nullptr);
#endif
std::string formatted_message = fmt::format(format, std::forward<Args>(args)...);
std::string formatted_message = fmt::format(fmt::runtime(format), std::forward<Args>(args)...);
internal::log_message(log_level, now, formatted_message.c_str());
}
template <typename... Args>
void print(const std::string& format, Args&&... args) {
std::string formatted_message = fmt::format(format, std::forward<Args>(args)...);
std::string formatted_message = fmt::format(fmt::runtime(format), std::forward<Args>(args)...);
internal::log_print(formatted_message.c_str());
}
template <typename... Args>

View File

@ -28,7 +28,7 @@ template <typename... Args>
}
throw std::runtime_error(
fmt::format("Type Error: {}", fmt::format(str, std::forward<Args>(args)...)));
fmt::format("Type Error: {}", fmt::format(fmt::runtime(str), std::forward<Args>(args)...)));
}
} // namespace

View File

@ -386,7 +386,7 @@ std::string split_path_at(const fs::path& path, const std::vector<std::string>&
split_str += folder + "/";
#endif
}
const auto& path_str = path.u8string();
const auto& path_str = path.string();
return path_str.substr(path_str.find(split_str) + split_str.length());
}

View File

@ -150,7 +150,7 @@ class Trie {
};
template <typename T>
Trie<T>::~Trie<T>() {
Trie<T>::~Trie() {
m_root.delete_children();
m_size = 0;
}

View File

@ -36,7 +36,7 @@ class DecompWarnings {
template <typename... Args>
void error_and_throw(const std::string& str, Args&&... args) {
auto text = fmt::format(str, std::forward<Args>(args)...);
auto text = fmt::format(fmt::runtime(str), std::forward<Args>(args)...);
_warning(Warning::Kind::ERR, false, text);
throw std::runtime_error(text);
}
@ -99,7 +99,7 @@ class DecompWarnings {
template <typename... Args>
void _warning(Warning::Kind kind, bool unique, const std::string& str, Args&&... args) {
std::string msg = fmt::format(str, std::forward<Args>(args)...);
std::string msg = fmt::format(fmt::runtime(str), std::forward<Args>(args)...);
if (unique) {
if (unique_warnings.find(msg) != unique_warnings.end()) {
return;

View File

@ -1819,7 +1819,7 @@ class DefpartElement : public FormElement {
case GameVersion::Jak2:
return field_id == 72;
default:
ASSERT_MSG(false, fmt::format("unknown version {} for is_sp_end"));
ASSERT_MSG(false, fmt::format("unknown version for is_sp_end"));
return false;
}
}

View File

@ -36,6 +36,10 @@ Matcher Matcher::reg(Register reg) {
return m;
}
Matcher Matcher::s6() {
return Matcher::reg(Register(Reg::GPR, Reg::S6));
}
Matcher Matcher::op(const GenericOpMatcher& op, const std::vector<Matcher>& args) {
Matcher m;
m.m_kind = Kind::GENERIC_OP;

View File

@ -39,7 +39,7 @@ class Matcher {
static Matcher var_name(const std::string& name);
static Matcher any_label(int match_id = -1);
static Matcher reg(Register reg);
static inline Matcher s6() { return Matcher::reg(Register(Reg::GPR, Reg::S6)); }
static Matcher s6();
static Matcher op(const GenericOpMatcher& op, const std::vector<Matcher>& args);
static Matcher func(const Matcher& match, const std::vector<Matcher>& args);
static Matcher func(const std::string& name, const std::vector<Matcher>& args);

View File

@ -204,7 +204,7 @@ std::string OpenGOALAsm::full_function_name() {
if (func.allows_modifier(MOD::BROADCAST)) {
if (m_instr.cop2_bc != 0xff) {
std::string bc = std::string(1, m_instr.cop2_bc_to_char());
func_name = fmt::format(func_name, bc);
func_name = fmt::format(fmt::runtime(func_name), bc);
}
}
return func_name;

View File

@ -646,24 +646,26 @@ std::string VuDisassembler::to_cpp(const VuInstruction& instr, bool mips2c_forma
instr.dst->to_string(m_label_names),
instr.src.at(0).to_string(m_label_names));
} else if (instr.src.at(0).value() == 0) {
return fmt::format(mips2c_format ? "lq_buffer(Mask::{}, c->vfs[{}].vf, vis[{}]);"
: "lq_buffer(Mask::{}, vu.{}, vu.{});",
mask_to_string(*instr.mask), instr.dst->to_string(m_label_names),
instr.src.at(1).to_string(m_label_names));
return fmt::format(
fmt::runtime(mips2c_format ? "lq_buffer(Mask::{}, c->vfs[{}].vf, vis[{}]);"
: "lq_buffer(Mask::{}, vu.{}, vu.{});"),
mask_to_string(*instr.mask), instr.dst->to_string(m_label_names),
instr.src.at(1).to_string(m_label_names));
} else {
return fmt::format(mips2c_format ? "lq_buffer(Mask::{}, c->vfs[{}].vf, vis[{}] + {});"
: "lq_buffer(Mask::{}, vu.{}, vu.{} + {});",
mask_to_string(*instr.mask), instr.dst->to_string(m_label_names),
instr.src.at(1).to_string(m_label_names),
instr.src.at(0).to_string(m_label_names));
return fmt::format(
fmt::runtime(mips2c_format ? "lq_buffer(Mask::{}, c->vfs[{}].vf, vis[{}] + {});"
: "lq_buffer(Mask::{}, vu.{}, vu.{} + {});"),
mask_to_string(*instr.mask), instr.dst->to_string(m_label_names),
instr.src.at(1).to_string(m_label_names), instr.src.at(0).to_string(m_label_names));
}
goto unknown;
case VuInstrK::LQI:
ASSERT(!instr.src.at(0).is_int_reg(0));
return fmt::format(mips2c_format ? "lq_buffer(Mask::{}, c->vfs[{}].vf, vis[{}]++);"
: "lq_buffer(Mask::{}, vu.{}, vu.{}++);",
mask_to_string(*instr.mask), instr.dst->to_string(m_label_names),
instr.src.at(0).to_string(m_label_names));
return fmt::format(
fmt::runtime(mips2c_format ? "lq_buffer(Mask::{}, c->vfs[{}].vf, vis[{}]++);"
: "lq_buffer(Mask::{}, vu.{}, vu.{}++);"),
mask_to_string(*instr.mask), instr.dst->to_string(m_label_names),
instr.src.at(0).to_string(m_label_names));
case VuInstrK::SQI:
ASSERT(!instr.src.at(0).is_int_reg(0));
if (mips2c_format) {
@ -682,16 +684,18 @@ std::string VuDisassembler::to_cpp(const VuInstruction& instr, bool mips2c_forma
instr.dst->to_string(m_label_names),
instr.src.at(0).to_string(m_label_names));
} else if (instr.src.at(0).value() == 0) {
return fmt::format(mips2c_format ? "sq_buffer(Mask::{}, c->vf_src({}).vf, vis[{}]);"
: "sq_buffer(Mask::{}, vu.{}, vu.{});",
mask_to_string(*instr.mask), instr.dst->to_string(m_label_names),
instr.src.at(1).to_string(m_label_names));
return fmt::format(
fmt::runtime(mips2c_format ? "sq_buffer(Mask::{}, c->vf_src({}).vf, vis[{}]);"
: "sq_buffer(Mask::{}, vu.{}, vu.{});"),
mask_to_string(*instr.mask), instr.dst->to_string(m_label_names),
instr.src.at(1).to_string(m_label_names));
} else {
return fmt::format(mips2c_format ? "sq_buffer(Mask::{}, c->vf_src({}).vf, vis[{}] + {});"
: "sq_buffer(Mask::{}, vu.{}, vu.{} + {});",
mask_to_string(*instr.mask), instr.dst->to_string(m_label_names),
instr.src.at(1).to_string(m_label_names),
instr.src.at(0).to_string(m_label_names));
return fmt::format(
fmt::runtime(mips2c_format ? "sq_buffer(Mask::{}, c->vf_src({}).vf, vis[{}] + {});"
: "sq_buffer(Mask::{}, vu.{}, vu.{} + {});"),
mask_to_string(*instr.mask), instr.dst->to_string(m_label_names),
instr.src.at(1).to_string(m_label_names), instr.src.at(0).to_string(m_label_names));
}
goto unknown;
case VuInstrK::IADDI:
@ -774,10 +778,11 @@ std::string VuDisassembler::to_cpp(const VuInstruction& instr, bool mips2c_forma
}
case VuInstrK::MTIR:
return fmt::format(
mips2c_format ? "vis[{}] = c->vf_src({}).vf.{}_as_u16();" : "vu.{} = vu.{}.{}_as_u16();",
instr.dst->to_string(m_label_names), instr.src.at(0).to_string(m_label_names),
bc_to_part(*instr.first_src_field));
return fmt::format(fmt::runtime(mips2c_format ? "vis[{}] = c->vf_src({}).vf.{}_as_u16();"
: "vu.{} = vu.{}.{}_as_u16();"),
instr.dst->to_string(m_label_names),
instr.src.at(0).to_string(m_label_names),
bc_to_part(*instr.first_src_field));
case VuInstrK::MFIR:
return fmt::format("vu.{}.mfir(Mask::{}, vu.{});", instr.dst->to_string(m_label_names),
@ -821,10 +826,10 @@ std::string VuDisassembler::to_cpp(const VuInstruction& instr, bool mips2c_forma
ASSERT(!instr.src.at(1).is_int_reg(0));
ASSERT(!instr.src.at(0).is_int_reg(0));
ASSERT(!instr.dst->is_int_reg(0));
return fmt::format(mips2c_format ? "vis[{}] = vis[{}] + vis[{}];" : "vu.{} = vu.{} + vu.{};",
instr.dst->to_string(m_label_names),
instr.src.at(0).to_string(m_label_names),
instr.src.at(1).to_string(m_label_names));
return fmt::format(
fmt::runtime(mips2c_format ? "vis[{}] = vis[{}] + vis[{}];" : "vu.{} = vu.{} + vu.{};"),
instr.dst->to_string(m_label_names), instr.src.at(0).to_string(m_label_names),
instr.src.at(1).to_string(m_label_names));
case VuInstrK::ISUB:
return fmt::format("vu.{} = vu.{} - vu.{};", instr.dst->to_string(m_label_names),
instr.src.at(0).to_string(m_label_names),
@ -864,15 +869,17 @@ std::string VuDisassembler::to_cpp(const VuInstruction& instr, bool mips2c_forma
mask_to_string(*instr.mask));
case VuInstrK::MULq:
return fmt::format(mips2c_format ? "c->vfs[{}].vf.mul(Mask::{}, c->vf_src({}).vf, c->Q);"
: "vu.{}.mul(Mask::{}, vu.{}, vu.Q);",
instr.dst->to_string(m_label_names), mask_to_string(*instr.mask),
instr.src.at(0).to_string(m_label_names));
return fmt::format(
fmt::runtime(mips2c_format ? "c->vfs[{}].vf.mul(Mask::{}, c->vf_src({}).vf, c->Q);"
: "vu.{}.mul(Mask::{}, vu.{}, vu.Q);"),
instr.dst->to_string(m_label_names), mask_to_string(*instr.mask),
instr.src.at(0).to_string(m_label_names));
case VuInstrK::MULi:
return fmt::format(mips2c_format ? "c->vfs[{}].vf.mul(Mask::{}, c->vf_src({}).vf, c->I);"
: "vu.{}.mul(Mask::{}, vu.{}, vu.I);",
instr.dst->to_string(m_label_names), mask_to_string(*instr.mask),
instr.src.at(0).to_string(m_label_names));
return fmt::format(
fmt::runtime(mips2c_format ? "c->vfs[{}].vf.mul(Mask::{}, c->vf_src({}).vf, c->I);"
: "vu.{}.mul(Mask::{}, vu.{}, vu.I);"),
instr.dst->to_string(m_label_names), mask_to_string(*instr.mask),
instr.src.at(0).to_string(m_label_names));
case VuInstrK::DIV:
return fmt::format(
"vu.Q = vu.{}.{}() / vu.{}.{}();", instr.src.at(0).to_string(m_label_names),
@ -963,34 +970,36 @@ std::string VuDisassembler::to_cpp(const VuInstruction& instr, bool mips2c_forma
vf_src(instr.src.at(1).to_string(m_label_names), mips2c_format));
case VuInstrK::ADDAbc:
return fmt::format(mips2c_format
? "c->acc.vf.adda(Mask::{}, c->vfs[{}].vf, c->vfs[{}].vf.{}());"
: "vu.acc.adda(Mask::{}, vu.{}, vu.{}.{}());",
mask_to_string(*instr.mask), instr.dst->to_string(m_label_names),
instr.src.at(0).to_string(m_label_names), bc_to_part(*instr.bc));
return fmt::format(
fmt::runtime(mips2c_format
? "c->acc.vf.adda(Mask::{}, c->vfs[{}].vf, c->vfs[{}].vf.{}());"
: "vu.acc.adda(Mask::{}, vu.{}, vu.{}.{}());"),
mask_to_string(*instr.mask), instr.dst->to_string(m_label_names),
instr.src.at(0).to_string(m_label_names), bc_to_part(*instr.bc));
case VuInstrK::MADDA:
return fmt::format("vu.acc.madda(Mask::{}, vu.{}, vu.{});", mask_to_string(*instr.mask),
instr.src.at(0).to_string(m_label_names),
instr.src.at(1).to_string(m_label_names));
case VuInstrK::MADDAbc:
return fmt::format(mips2c_format
? "c->acc.vf.madda(Mask::{}, c->vfs[{}].vf, c->vfs[{}].vf.{}());"
: "vu.acc.madda(Mask::{}, vu.{}, vu.{}.{}());",
mask_to_string(*instr.mask), instr.src.at(0).to_string(m_label_names),
instr.src.at(1).to_string(m_label_names), bc_to_part(*instr.bc));
return fmt::format(
fmt::runtime(mips2c_format
? "c->acc.vf.madda(Mask::{}, c->vfs[{}].vf, c->vfs[{}].vf.{}());"
: "vu.acc.madda(Mask::{}, vu.{}, vu.{}.{}());"),
mask_to_string(*instr.mask), instr.src.at(0).to_string(m_label_names),
instr.src.at(1).to_string(m_label_names), bc_to_part(*instr.bc));
case VuInstrK::MADDbc:
return fmt::format(
mips2c_format
? "c->acc.vf.madd(Mask::{}, c->vfs[{}].vf, c->vf_src({}).vf, c->vf_src({}).vf.{}());"
: "vu.acc.madd(Mask::{}, vu.{}, vu.{}, vu.{}.{}());",
fmt::runtime(mips2c_format ? "c->acc.vf.madd(Mask::{}, c->vfs[{}].vf, c->vf_src({}).vf, "
"c->vf_src({}).vf.{}());"
: "vu.acc.madd(Mask::{}, vu.{}, vu.{}, vu.{}.{}());"),
mask_to_string(*instr.mask), instr.dst->to_string(m_label_names),
instr.src.at(0).to_string(m_label_names), instr.src.at(1).to_string(m_label_names),
bc_to_part(*instr.bc));
case VuInstrK::MSUBbc:
return fmt::format(
mips2c_format
? "c->acc.vf.msub(Mask::{}, c->vfs[{}].vf, c->vf_src({}).vf, c->vf_src({}).vf.{}());"
: "vu.acc.msub(Mask::{}, vu.{}, vu.{}, vu.{}.{}());",
fmt::runtime(mips2c_format ? "c->acc.vf.msub(Mask::{}, c->vfs[{}].vf, c->vf_src({}).vf, "
"c->vf_src({}).vf.{}());"
: "vu.acc.msub(Mask::{}, vu.{}, vu.{}, vu.{}.{}());"),
mask_to_string(*instr.mask), instr.dst->to_string(m_label_names),
instr.src.at(0).to_string(m_label_names), instr.src.at(1).to_string(m_label_names),
bc_to_part(*instr.bc));
@ -1002,11 +1011,12 @@ std::string VuDisassembler::to_cpp(const VuInstruction& instr, bool mips2c_forma
return fmt::format("vu.acc.mula(Mask::{}, vu.{}, vu.Q);", mask_to_string(*instr.mask),
instr.src.at(0).to_string(m_label_names));
case VuInstrK::MULAbc:
return fmt::format(mips2c_format
? "c->acc.vf.mula(Mask::{}, c->vf_src({}).vf, c->vf_src({}).vf.{}());"
: "vu.acc.mula(Mask::{}, vu.{}, vu.{}.{}());",
mask_to_string(*instr.mask), instr.src.at(0).to_string(m_label_names),
instr.src.at(1).to_string(m_label_names), bc_to_part(*instr.bc));
return fmt::format(
fmt::runtime(mips2c_format
? "c->acc.vf.mula(Mask::{}, c->vf_src({}).vf, c->vf_src({}).vf.{}());"
: "vu.acc.mula(Mask::{}, vu.{}, vu.{}.{}());"),
mask_to_string(*instr.mask), instr.src.at(0).to_string(m_label_names),
instr.src.at(1).to_string(m_label_names), bc_to_part(*instr.bc));
case VuInstrK::XGKICK:
return fmt::format("xgkick(vu.{});", instr.src.at(0).to_string(m_label_names));

View File

@ -266,7 +266,7 @@ void process_streamed_audio(const decompiler::Config& config,
for (size_t lang_id = 0; lang_id < audio_files.size(); lang_id++) {
auto& file = audio_files[lang_id];
auto wad_data = file_util::read_binary_file(input_dir / "VAG" / file);
auto suffix = fs::path(file).extension().u8string().substr(1);
auto suffix = fs::path(file).extension().string().substr(1);
bool int_bank_p = suffix.compare("INT") == 0;
langs.push_back(suffix);
for (int i = 0; i < dir_data.entry_count(); i++) {

View File

@ -23,7 +23,7 @@ const std::unordered_map<int, std::string> game_iso_territory_map = {
std::string get_territory_name(int territory) {
ASSERT_MSG(game_iso_territory_map.count(territory),
fmt::format("territory {} not found in territory name map"));
fmt::format("territory {} not found in territory name map", territory));
return game_iso_territory_map.at(territory);
}

View File

@ -1677,9 +1677,7 @@ std::vector<TFragDraw> emulate_tfrag_execution(const level_tools::TFragment& fra
}
end:
[[maybe_unused]] int total_dvert = 0;
for (auto& draw : all_draws) {
total_dvert += draw.verts.size();
draw.tfrag_id = frag.id;
}

View File

@ -8,5 +8,5 @@ class Error : public std::runtime_error {
public:
template <typename... Args>
Error(const std::string& format, Args&&... args)
: std::runtime_error(fmt::format(format, std::forward<Args>(args)...)) {}
};
: std::runtime_error(fmt::format(fmt::runtime(format), std::forward<Args>(args)...)) {}
};

View File

@ -3,6 +3,7 @@
#include "common/goal_constants.h"
#include "goalc/compiler/Env.h"
#include "goalc/compiler/IR.h"
#include "third-party/fmt/core.h"
@ -252,4 +253,4 @@ StaticResult StaticResult::make_func_ref(const FunctionEnv* func, const TypeSpec
result.m_func = func;
result.m_ts = type;
return result;
}
}

View File

@ -206,7 +206,7 @@ goos::Object MakeSystem::handle_basename(const goos::Object& form,
va_check(form, args, {goos::ObjectType::STRING}, {});
fs::path input(args.unnamed.at(0).as_string()->data);
return goos::StringObject::make_new(input.filename().u8string());
return goos::StringObject::make_new(input.filename().string());
}
goos::Object MakeSystem::handle_stem(const goos::Object& form,
@ -216,7 +216,7 @@ goos::Object MakeSystem::handle_stem(const goos::Object& form,
va_check(form, args, {goos::ObjectType::STRING}, {});
fs::path input(args.unnamed.at(0).as_string()->data);
return goos::StringObject::make_new(input.stem().u8string());
return goos::StringObject::make_new(input.stem().string());
}
goos::Object MakeSystem::handle_get_gsrc_path(const goos::Object& form,
@ -276,7 +276,7 @@ goos::Object MakeSystem::handle_set_gsrc_folder(
auto src_files = file_util::find_files_recursively(folder_scan, std::regex(".*\\.gc"));
for (const auto& path : src_files) {
auto name = file_util::base_name_no_ext(path.u8string());
auto name = file_util::base_name_no_ext(path.string());
auto gsrc_path =
file_util::convert_to_unix_path_separators(file_util::split_path_at(path, m_gsrc_folder));
// TODO - this is only "safe" because the current OpenGOAL system requires globally unique

View File

@ -20,7 +20,7 @@ bool CompilerTool::needs_run(const ToolInput& task, const PathMap& path_map) {
throw std::runtime_error(fmt::format("Invalid amount of inputs to {} tool", name()));
}
if (!m_compiler->knows_object_file(fs::path(task.input.at(0)).stem().u8string())) {
if (!m_compiler->knows_object_file(fs::path(task.input.at(0)).stem().string())) {
return true;
}
return Tool::needs_run(task, path_map);