Skip to content

Commit

Permalink
Chore: adjust clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
F0bes committed Mar 28, 2024
1 parent c68a6ac commit 0ed2fac
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 57 deletions.
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ ReflowComments: false
SortIncludes: false
SpaceAfterCStyleCast: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceBeforeParens: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
Expand Down
32 changes: 16 additions & 16 deletions backend/c_code.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
Expand All @@ -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",
Expand All @@ -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";
Expand All @@ -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;
Expand All @@ -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<GifRegister> reg)
{
PRIM prim = dynamic_cast<PRIM&>(*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()],
Expand Down Expand Up @@ -175,10 +175,10 @@ std::string c_code_backend::emit_tex0(c_code_backend* inst, std::shared_ptr<GifR
{
TEX0 tex0 = dynamic_cast<TEX0&>(*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";
Expand Down Expand Up @@ -249,7 +249,7 @@ std::string c_code_backend::emit_finish(c_code_backend* inst, std::shared_ptr<Gi
FINISH finish = dynamic_cast<FINISH&>(*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);
}
Expand Down
56 changes: 28 additions & 28 deletions machine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,27 @@ 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;
}
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;
Expand All @@ -43,27 +43,27 @@ 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;
}
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;
Expand All @@ -78,15 +78,15 @@ bool Machine::TryStartMacro(const std::string name)

bool Machine::TryEndBlockMacro()
{
if (currentBlock)
if(currentBlock)
{
FirstPassOptimize();
backend->emit(currentBlock);
currentBlock = nullptr;
currentBlockMacro = nullptr;
return true;
}
else if (currentMacro)
else if(currentMacro)
{
currentMacro = nullptr;
currentBlockMacro = nullptr;
Expand All @@ -101,15 +101,15 @@ 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;
}
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;
Expand All @@ -124,21 +124,21 @@ 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;
}
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<XYZ2&>(*reg);

Expand All @@ -162,11 +162,11 @@ bool Machine::TryInsertMacro(const std::string name, Vec2 v)
}
bool Machine::TrySetRegister(std::shared_ptr<GifRegister> 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");
}
Expand All @@ -180,7 +180,7 @@ bool Machine::TrySetRegister(std::shared_ptr<GifRegister> reg)

bool Machine::TryPushReg(int32_t i)
{
if (currentBlockMacro && currentRegister)
if(currentBlockMacro && currentRegister)
{
currentRegister->Push(i);
return true;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -236,7 +236,7 @@ bool Machine::TryPushReg(Vec4 v4)

bool Machine::TryApplyModifier(RegModifier mod)
{
if (currentBlockMacro && currentRegister)
if(currentBlockMacro && currentRegister)
{
return currentRegister->ApplyModifier(mod);
}
Expand All @@ -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<GifRegister> 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);
Expand Down
2 changes: 1 addition & 1 deletion registers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

std::shared_ptr<GifRegister> GenReg(GifRegisters reg)
{
switch (reg)
switch(reg)
{
case GifRegisters::PRIM:
return std::make_shared<PRIM>();
Expand Down
14 changes: 7 additions & 7 deletions registers.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -446,21 +446,21 @@ 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);
}

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;
Expand All @@ -483,7 +483,7 @@ struct TEX0 : public GifRegister

bool ApplyModifier(RegModifier mod) override
{
switch (mod)
switch(mod)
{
case CT32:
psm = PSM::CT32;
Expand Down
Loading

0 comments on commit 0ed2fac

Please sign in to comment.