refactor(std): use format on windows (#80)

This commit is contained in:
Xenxo Espasandín 2023-02-27 20:09:31 +01:00 committed by GitHub
parent 9318c6e0ae
commit b44a51d8ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 17 deletions

View File

@ -1782,7 +1782,7 @@ auto decompiler::decompile_aborts(stmt_list& stm) -> void
} }
else else
{ {
fmt::print("WARNING: unresolved jump to '{}', maybe incomplete for loop\n", jmp); std::cout << fmt::format("WARNING: unresolved jump to '{}', maybe incomplete for loop\n", jmp);
} }
} }
} }
@ -3221,7 +3221,7 @@ auto decompiler::process_expr_asm_access(expr& exp, scope& scp) -> void
if (scp.vars.size() <= index) if (scp.vars.size() <= index)
{ {
fmt::print("WARNING: bad local var access\n"); std::cout << fmt::format("WARNING: bad local var access\n");
} }
else else
{ {

View File

@ -27,9 +27,14 @@
#include <unordered_set> #include <unordered_set>
#include <vector> #include <vector>
using namespace std::literals; #if _WIN32
#include <format>
namespace fmt = std;
#else
#include "fmt/core.h" #include "fmt/core.h"
#endif
using namespace std::literals;
namespace xsk namespace xsk
{ {

View File

@ -188,7 +188,7 @@ auto assemble_file(game game, fs::path file, fs::path rel) -> void
auto path = fs::path{ "compiled" } / rel; auto path = fs::path{ "compiled" } / rel;
utils::file::save(path, outbin.first.data, outbin.first.size); utils::file::save(path, outbin.first.data, outbin.first.size);
utils::file::save(path.replace_extension(".cgsc.stack"), outbin.second.data, outbin.second.size); utils::file::save(path.replace_extension(".cgsc.stack"), outbin.second.data, outbin.second.size);
fmt::print("compiled {}\n", rel.generic_string()); std::cout << fmt::format("compiled {}\n", rel.generic_string());
} }
else else
{ {
@ -208,7 +208,7 @@ auto assemble_file(game game, fs::path file, fs::path rel) -> void
auto result = script.serialize(); auto result = script.serialize();
utils::file::save(fs::path{ "compiled" } / rel, result); utils::file::save(fs::path{ "compiled" } / rel, result);
fmt::print("compiled {}\n", rel.generic_string()); std::cout << fmt::format("compiled {}\n", rel.generic_string());
} }
} }
} }
@ -256,7 +256,7 @@ auto disassemble_file(game game, fs::path file, fs::path rel) -> void
auto outsrc = contexts[game]->source().dump(*outasm); auto outsrc = contexts[game]->source().dump(*outasm);
utils::file::save(fs::path{ "disassembled" } / rel, outsrc); utils::file::save(fs::path{ "disassembled" } / rel, outsrc);
fmt::print("disassembled {}\n", rel.generic_string()); std::cout << fmt::format("disassembled {}\n", rel.generic_string());
} }
catch (std::exception const& e) catch (std::exception const& e)
{ {
@ -284,7 +284,7 @@ auto compile_file(game game, fs::path file, fs::path rel) -> void
auto path = fs::path{ "compiled" } / rel; auto path = fs::path{ "compiled" } / rel;
utils::file::save(path, outbin.first.data, outbin.first.size); utils::file::save(path, outbin.first.data, outbin.first.size);
utils::file::save(path.replace_extension(".cgsc.stack"), outbin.second.data, outbin.second.size); utils::file::save(path.replace_extension(".cgsc.stack"), outbin.second.data, outbin.second.size);
fmt::print("compiled {}\n", rel.generic_string()); std::cout << fmt::format("compiled {}\n", rel.generic_string());
} }
else else
{ {
@ -304,7 +304,7 @@ auto compile_file(game game, fs::path file, fs::path rel) -> void
auto result = script.serialize(); auto result = script.serialize();
utils::file::save(fs::path{ "compiled" } / rel, result); utils::file::save(fs::path{ "compiled" } / rel, result);
fmt::print("compiled {}\n", rel.generic_string()); std::cout << fmt::format("compiled {}\n", rel.generic_string());
} }
} }
} }
@ -353,7 +353,7 @@ auto decompile_file(game game, fs::path file, fs::path rel) -> void
auto outsrc = contexts[game]->source().dump(*outast); auto outsrc = contexts[game]->source().dump(*outast);
utils::file::save(fs::path{ "decompiled" } / rel, outsrc); utils::file::save(fs::path{ "decompiled" } / rel, outsrc);
fmt::print("decompiled {}\n", rel.generic_string()); std::cout << fmt::format("decompiled {}\n", rel.generic_string());
} }
catch (std::exception const& e) catch (std::exception const& e)
{ {
@ -374,7 +374,7 @@ auto parse_file(game game, fs::path file, fs::path rel) -> void
auto prog = contexts[game]->source().parse_program(file.string(), data); auto prog = contexts[game]->source().parse_program(file.string(), data);
utils::file::save(fs::path{ "parsed" } / rel, contexts[game]->source().dump(*prog)); utils::file::save(fs::path{ "parsed" } / rel, contexts[game]->source().dump(*prog));
fmt::print("parsed {}\n", rel.generic_string()); std::cout << fmt::format("parsed {}\n", rel.generic_string());
} }
catch (std::exception const& e) catch (std::exception const& e)
{ {
@ -422,13 +422,13 @@ auto rename_file(game game, fs::path file, fs::path rel) -> void
auto data = utils::file::read(file); auto data = utils::file::read(file);
utils::file::save(fs::path{ "renamed" } / rel, data); utils::file::save(fs::path{ "renamed" } / rel, data);
fmt::print("renamed {} -> {}\n", file.filename().generic_string(), rel.generic_string()); std::cout << fmt::format("renamed {} -> {}\n", file.filename().generic_string(), rel.generic_string());
if (zt) if (zt)
{ {
auto stack = utils::file::read(file.replace_extension(".cgsc.stack")); auto stack = utils::file::read(file.replace_extension(".cgsc.stack"));
utils::file::save(fs::path{ "renamed" } / rel.replace_extension(".cgsc.stack"), stack); utils::file::save(fs::path{ "renamed" } / rel.replace_extension(".cgsc.stack"), stack);
fmt::print("renamed {} -> {}\n", file.filename().generic_string(), rel.generic_string()); std::cout << fmt::format("renamed {} -> {}\n", file.filename().generic_string(), rel.generic_string());
} }
} }
catch (std::exception const& e) catch (std::exception const& e)
@ -661,7 +661,7 @@ void assemble_file(game game, fs::path const& file, fs::path rel)
assembler.assemble(file.string(), data); assembler.assemble(file.string(), data);
utils::file::save(fs::path{ "assembled" } / rel, assembler.output()); utils::file::save(fs::path{ "assembled" } / rel, assembler.output());
fmt::print("assembled {}\n", rel.generic_string()); std::cout << fmt::format("assembled {}\n", rel.generic_string());
} }
catch (std::exception const& e) catch (std::exception const& e)
{ {
@ -684,7 +684,7 @@ void disassemble_file(game game, fs::path const& file, fs::path rel)
disassembler.disassemble(file.string(), data); disassembler.disassemble(file.string(), data);
utils::file::save(fs::path{ "disassembled" } / rel, disassembler.output_raw()); utils::file::save(fs::path{ "disassembled" } / rel, disassembler.output_raw());
fmt::print("disassembled {}\n", rel.generic_string()); std::cout << fmt::format("disassembled {}\n", rel.generic_string());
} }
catch (std::exception const& e) catch (std::exception const& e)
{ {
@ -713,7 +713,7 @@ void compile_file(game game, fs::path const& file, fs::path rel)
assembler.assemble(file.string(), assembly); assembler.assemble(file.string(), assembly);
utils::file::save(fs::path{ "compiled" } / rel, assembler.output()); utils::file::save(fs::path{ "compiled" } / rel, assembler.output());
fmt::print("compiled {}\n", rel.generic_string()); std::cout << fmt::format("compiled {}\n", rel.generic_string());
} }
catch (std::exception const& e) catch (std::exception const& e)
{ {
@ -742,7 +742,7 @@ void decompile_file(game game, fs::path const& file, fs::path rel)
decompiler.decompile(file.string(), output); decompiler.decompile(file.string(), output);
utils::file::save(fs::path{ "decompiled" } / rel, decompiler.output()); utils::file::save(fs::path{ "decompiled" } / rel, decompiler.output());
fmt::print("decompiled {}\n", rel.generic_string()); std::cout << fmt::format("decompiled {}\n", rel.generic_string());
} }
catch (std::exception const& e) catch (std::exception const& e)
{ {