Skip to content

Commit

Permalink
DSPTool: Fix missing error when redefining labels
Browse files Browse the repository at this point in the history
The logging was broken in 958cbf3 (DSPTool doesn't use dolphin's logging system, so it just produced nothing; the same thing affected comparing before 693a29f).

AssemblerError::LabelAlreadyExists (previously ERR_LABEL_EXISTS) simply was never used.
  • Loading branch information
Pokechu22 committed Feb 5, 2023
1 parent aece99f commit a244cb8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
5 changes: 4 additions & 1 deletion Source/Core/Core/DSP/DSPAssembler.cpp
Expand Up @@ -912,7 +912,10 @@ bool DSPAssembler::AssemblePass(const std::string& text, int pass)
}
}
if (pass == 1)
m_labels.RegisterLabel(label, lval);
{
if (!m_labels.RegisterLabel(label, lval))
ShowError(AssemblerError::LabelAlreadyExists);
}
}

if (opcode == nullptr)
Expand Down
19 changes: 13 additions & 6 deletions Source/Core/Core/DSP/LabelMap.cpp
Expand Up @@ -42,16 +42,23 @@ void LabelMap::RegisterDefaults()
}
}

void LabelMap::RegisterLabel(std::string label, u16 lval, LabelType type)
bool LabelMap::RegisterLabel(std::string label, u16 lval, LabelType type)
{
const std::optional<u16> old_value = GetLabelValue(label);
if (old_value && old_value != lval)
if (old_value)
{
WARN_LOG_FMT(AUDIO, "Redefined label {} to {:04x} - old value {:04x}\n", label, lval,
*old_value);
DeleteLabel(label);
if (old_value != lval)
{
fmt::print("Attempted to redefine label {} from {:04x} to {:04x}\n", label, lval, *old_value);
return false;
}
else
{
return true;
}
}
labels.emplace_back(std::move(label), lval, type);
return true;
}

void LabelMap::DeleteLabel(std::string_view label)
Expand All @@ -77,7 +84,7 @@ std::optional<u16> LabelMap::GetLabelValue(std::string_view name, LabelType type
}
else
{
WARN_LOG_FMT(AUDIO, "Wrong label type requested. {}\n", name);
fmt::print("Wrong label type requested. {}\n", name);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Core/DSP/LabelMap.h
Expand Up @@ -27,7 +27,7 @@ class LabelMap
~LabelMap();

void RegisterDefaults();
void RegisterLabel(std::string label, u16 lval, LabelType type = LABEL_VALUE);
bool RegisterLabel(std::string label, u16 lval, LabelType type = LABEL_VALUE);
void DeleteLabel(std::string_view label);
std::optional<u16> GetLabelValue(std::string_view name, LabelType type = LABEL_ANY) const;
void Clear();
Expand Down

0 comments on commit a244cb8

Please sign in to comment.