From 0ed2fac80d16bd493bd30380ffbe5fd68656999d Mon Sep 17 00:00:00 2001 From: Ty Lamontagne Date: Thu, 28 Mar 2024 17:31:02 -0400 Subject: [PATCH] Chore: adjust clang-format --- .clang-format | 2 +- backend/c_code.cpp | 32 +++++++++++++------------- machine.cpp | 56 +++++++++++++++++++++++----------------------- registers.cpp | 2 +- registers.h | 14 ++++++------ types.h | 8 +++---- 6 files changed, 57 insertions(+), 57 deletions(-) diff --git a/.clang-format b/.clang-format index 892b6ac..839f5d6 100644 --- a/.clang-format +++ b/.clang-format @@ -76,7 +76,7 @@ ReflowComments: false SortIncludes: false SpaceAfterCStyleCast: false SpaceBeforeAssignmentOperators: true -SpaceBeforeParens: ControlStatements +SpaceBeforeParens: false SpaceInEmptyParentheses: false SpacesBeforeTrailingComments: 1 SpacesInAngles: false diff --git a/backend/c_code.cpp b/backend/c_code.cpp index a072593..552ef13 100644 --- a/backend/c_code.cpp +++ b/backend/c_code.cpp @@ -11,21 +11,21 @@ c_code_backend::c_code_backend() noexcept bool c_code_backend::arg_parse(int argc, char** argv) { - for (int i = 0; i < argc; i++) + for(int i = 0; i < argc; i++) { const std::string_view arg = argv[i]; - if (arg.starts_with("--b") && !arg.starts_with("--backend=")) + if(arg.starts_with("--b") && !arg.starts_with("--backend=")) { const std::string_view arg2 = arg.substr(3); - if (arg2.compare("defs") == 0) + if(arg2.compare("defs") == 0) { emit_mode = EmitMode::USE_DEFS; } - else if (arg2.compare("magic") == 0) + else if(arg2.compare("magic") == 0) { emit_mode = EmitMode::USE_MAGIC; } - else if (arg2.compare("help") == 0) + else if(arg2.compare("help") == 0) { print_help(); return false; @@ -51,7 +51,7 @@ void c_code_backend::print_help() const c_code_backend::~c_code_backend() { - if (file != nullptr && file != stdout) + if(file != nullptr && file != stdout) { fclose(file); } @@ -60,9 +60,9 @@ c_code_backend::~c_code_backend() void c_code_backend::emit(GIFBlock* block) { std::string prim_str; - if (block->prim) + if(block->prim) { - if (emit_mode == EmitMode::USE_DEFS) + if(emit_mode == EmitMode::USE_DEFS) { prim_str = fmt::format("GS_SET_PRIM({},{},{},{},0,{},GS_ENABLE,0,0)", PrimTypeStrings[block->prim->GetType()], block->prim->IsGouraud() ? "GS_ENABLE" : "GS_DISABLE", @@ -85,7 +85,7 @@ void c_code_backend::emit(GIFBlock* block) "GIF_SET_TAG({2},1,{3},{4},0,1),GIF_REG_AD,\n\t", (block->registers.size() + 1) * 16, block->name, block->registers.size(), block->prim ? 1 : 0, block->prim ? prim_str : "0"); fmt::print("Emitting block: {}\n", block->name); - for (auto& reg : block->registers) + for(auto& reg : block->registers) { buffer += dispatch_table[reg->GetID()](this, reg); buffer += "\n\t"; @@ -95,16 +95,16 @@ void c_code_backend::emit(GIFBlock* block) buffer.pop_back(); buffer += "\n};\n"; - if (first_emit) + if(first_emit) { - if (output.empty()) + if(output.empty()) { file = stdout; } else { file = fopen(output.c_str(), "w"); - if (file == nullptr) + if(file == nullptr) { logger::error("Failed to open file: %s\n", output.cbegin()); return; @@ -121,7 +121,7 @@ void c_code_backend::emit(GIFBlock* block) std::string c_code_backend::emit_primitive(c_code_backend* inst, std::shared_ptr reg) { PRIM prim = dynamic_cast(*reg); - if (inst->emit_mode == EmitMode::USE_DEFS) + if(inst->emit_mode == EmitMode::USE_DEFS) { return fmt::format("GS_SET_PRIM({},{},{},{},0,{},GS_ENABLE,0,0),GS_REG_PRIM,", PrimTypeStrings[prim.GetType()], @@ -175,10 +175,10 @@ std::string c_code_backend::emit_tex0(c_code_backend* inst, std::shared_ptr(*reg); - if (inst->emit_mode == EmitMode::USE_DEFS) + if(inst->emit_mode == EmitMode::USE_DEFS) { std::string PSM_STR; - switch (tex0.GetPSM()) + switch(tex0.GetPSM()) { case PSM::CT32: PSM_STR = "GS_PSM_32"; @@ -249,7 +249,7 @@ std::string c_code_backend::emit_finish(c_code_backend* inst, std::shared_ptr(*reg); auto val = finish.GetValue(); - if (inst->emit_mode == EmitMode::USE_DEFS) + if(inst->emit_mode == EmitMode::USE_DEFS) { return fmt::format("GS_SET_FINISH({}),GS_REG_FINISH,", val); } diff --git a/machine.cpp b/machine.cpp index fef585a..0d8bbd2 100644 --- a/machine.cpp +++ b/machine.cpp @@ -9,12 +9,12 @@ Machine machine; bool Machine::TryStartBlock(const std::string name) { - if (currentBlock) + if(currentBlock) { logger::error("Still waiting for you to end the block %s\n", currentBlock->name.c_str()); return false; } - else if (currentMacro) + else if(currentMacro) { logger::error("Still waiting for you to end the macro %s\n", currentMacro->name.c_str()); return false; @@ -22,14 +22,14 @@ bool Machine::TryStartBlock(const std::string name) else { auto block_name_dup = std::find_if(blocks.begin(), blocks.end(), [&name](GIFBlock& block) { return block.name == name; }); - if (block_name_dup != blocks.end()) + if(block_name_dup != blocks.end()) { logger::error("Block with name %s already exists\n", name.c_str()); return false; } auto macro_name_dup = macros.find(name); - if (macro_name_dup != macros.end()) + if(macro_name_dup != macros.end()) { logger::error("Macro with name %s already exists\n", name.c_str()); return false; @@ -43,12 +43,12 @@ bool Machine::TryStartBlock(const std::string name) bool Machine::TryStartMacro(const std::string name) { - if (currentMacro) + if(currentMacro) { logger::error("Still waiting for you to end the macro %s\n", currentMacro->name.c_str()); return false; } - else if (currentBlock) + else if(currentBlock) { logger::error("Still waiting for you to end the block %s\n", currentBlock->name.c_str()); return false; @@ -56,14 +56,14 @@ bool Machine::TryStartMacro(const std::string name) else { auto block_name_dup = std::find_if(blocks.begin(), blocks.end(), [&name](GIFBlock& block) { return block.name == name; }); - if (block_name_dup != blocks.end()) + if(block_name_dup != blocks.end()) { logger::error("Block with name %s already exists\n", name.c_str()); return false; } auto macro_name_dup = macros.find(name); - if (macro_name_dup != macros.end()) + if(macro_name_dup != macros.end()) { logger::error("Macro with name %s already exists\n", name.c_str()); return false; @@ -78,7 +78,7 @@ bool Machine::TryStartMacro(const std::string name) bool Machine::TryEndBlockMacro() { - if (currentBlock) + if(currentBlock) { FirstPassOptimize(); backend->emit(currentBlock); @@ -86,7 +86,7 @@ bool Machine::TryEndBlockMacro() currentBlockMacro = nullptr; return true; } - else if (currentMacro) + else if(currentMacro) { currentMacro = nullptr; currentBlockMacro = nullptr; @@ -101,7 +101,7 @@ bool Machine::TryEndBlockMacro() bool Machine::TryInsertMacro(const std::string name) { - if (!currentBlockMacro) + if(!currentBlockMacro) { logger::error("No block or macro to insert macro into\n"); return false; @@ -109,7 +109,7 @@ bool Machine::TryInsertMacro(const std::string name) else { auto macro = macros.find(name); - if (macro != macros.end()) + if(macro != macros.end()) { currentBlockMacro->registers.insert(currentBlock->registers.end(), macro->second.registers.begin(), macro->second.registers.end()); return true; @@ -124,7 +124,7 @@ bool Machine::TryInsertMacro(const std::string name) bool Machine::TryInsertMacro(const std::string name, Vec2 v) { - if (!currentBlockMacro) + if(!currentBlockMacro) { logger::error("No block or macro to insert macro into\n"); return false; @@ -132,13 +132,13 @@ bool Machine::TryInsertMacro(const std::string name, Vec2 v) else { auto macro = macros.find(name); - if (macro != macros.end()) + if(macro != macros.end()) { GIFBlock tmpMacro = GIFBlock(macro->second); - for (auto reg : tmpMacro.registers) + for(auto reg : tmpMacro.registers) { - if (reg->GetID() == 0x05) + if(reg->GetID() == 0x05) { XYZ2 xyz2 = dynamic_cast(*reg); @@ -162,11 +162,11 @@ bool Machine::TryInsertMacro(const std::string name, Vec2 v) } bool Machine::TrySetRegister(std::shared_ptr reg) { - if (!currentBlockMacro) + if(!currentBlockMacro) { logger::error("Not in current block"); } - else if (currentRegister && !currentRegister->Ready()) + else if(currentRegister && !currentRegister->Ready()) { logger::error("Current register is not fulfilled"); } @@ -180,7 +180,7 @@ bool Machine::TrySetRegister(std::shared_ptr reg) bool Machine::TryPushReg(int32_t i) { - if (currentBlockMacro && currentRegister) + if(currentBlockMacro && currentRegister) { currentRegister->Push(i); return true; @@ -194,7 +194,7 @@ bool Machine::TryPushReg(int32_t i) bool Machine::TryPushReg(Vec2 v) { - if (currentBlockMacro && currentRegister) + if(currentBlockMacro && currentRegister) { currentRegister->Push(v); return true; @@ -208,7 +208,7 @@ bool Machine::TryPushReg(Vec2 v) bool Machine::TryPushReg(Vec3 v3) { - if (currentBlockMacro && currentRegister) + if(currentBlockMacro && currentRegister) { currentRegister->Push(v3); return true; @@ -222,7 +222,7 @@ bool Machine::TryPushReg(Vec3 v3) bool Machine::TryPushReg(Vec4 v4) { - if (currentBlockMacro && currentRegister) + if(currentBlockMacro && currentRegister) { currentRegister->Push(v4); return true; @@ -236,7 +236,7 @@ bool Machine::TryPushReg(Vec4 v4) bool Machine::TryApplyModifier(RegModifier mod) { - if (currentBlockMacro && currentRegister) + if(currentBlockMacro && currentRegister) { return currentRegister->ApplyModifier(mod); } @@ -252,18 +252,18 @@ bool Machine::TryApplyModifier(RegModifier mod) void Machine::FirstPassOptimize() { // Dead store Elimination - if (OptimizeConfig[DEAD_STORE_ELIMINATION]) + if(OptimizeConfig[DEAD_STORE_ELIMINATION]) { std::shared_ptr lastReg = nullptr; - for (auto reg : currentBlock->registers) + for(auto reg : currentBlock->registers) { - if (reg->HasSideEffects()) + if(reg->HasSideEffects()) { lastReg = nullptr; } - else if (lastReg) + else if(lastReg) { - if (lastReg->GetID() == reg->GetID()) + if(lastReg->GetID() == reg->GetID()) { logger::info("Dead store elimination: %s", lastReg->GetName().cbegin()); currentBlock->registers.remove(lastReg); diff --git a/registers.cpp b/registers.cpp index a0bdcb7..8d7aacc 100644 --- a/registers.cpp +++ b/registers.cpp @@ -2,7 +2,7 @@ std::shared_ptr GenReg(GifRegisters reg) { - switch (reg) + switch(reg) { case GifRegisters::PRIM: return std::make_shared(); diff --git a/registers.h b/registers.h index e01d405..a911552 100644 --- a/registers.h +++ b/registers.h @@ -202,7 +202,7 @@ struct PRIM : public GifRegister bool ApplyModifier(RegModifier mod) override { std::cout << "Applying modifier: " << mod << std::endl; - switch (mod) + switch(mod) { case Point: type = PrimType::Point; @@ -446,13 +446,13 @@ struct TEX0 : public GifRegister void Push(uint32_t i) override { - if (!tbp.has_value()) + if(!tbp.has_value()) tbp = i; - else if (!tbw.has_value()) + else if(!tbw.has_value()) tbw = i; - else if (!tw.has_value()) + else if(!tw.has_value()) tw = i; - else if (!th.has_value()) + else if(!th.has_value()) th = i; else logger::error("Unsure what you're trying to push to TEX0 (%d)", i); @@ -460,7 +460,7 @@ struct TEX0 : public GifRegister void Push(Vec2 v2) override { - if (!tw.has_value() && !th.has_value()) + if(!tw.has_value() && !th.has_value()) { tw = v2.x; th = v2.y; @@ -483,7 +483,7 @@ struct TEX0 : public GifRegister bool ApplyModifier(RegModifier mod) override { - switch (mod) + switch(mod) { case CT32: psm = PSM::CT32; diff --git a/types.h b/types.h index 89d19b3..d7becb8 100644 --- a/types.h +++ b/types.h @@ -8,9 +8,9 @@ static std::vector vec_split(const std::string& s) { std::vector parts; size_t i, j; - for (i = 0, j = 0; i < s.size(); i++) + for(i = 0, j = 0; i < s.size(); i++) { - if (s[i] == ',') + if(s[i] == ',') { parts.push_back(s.substr(j, i - j)); j = i + 1; @@ -22,11 +22,11 @@ static std::vector vec_split(const std::string& s) static uint32_t vec_parse_segment(const std::string& s) { - if (s.size() > 2 && s[0] == '0' && s[1] == 'x') + if(s.size() > 2 && s[0] == '0' && s[1] == 'x') { return std::stoul(s, nullptr, 16); } - else if (s.find('.') != std::string::npos) + else if(s.find('.') != std::string::npos) { return std::bit_cast(std::stof(s)); }