mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2026-01-31 01:15:17 +01:00
Yellow squiggly lines begone! Done automatically on .cpp files through `run-clang-tidy`, with manual corrections to the mistakes. If an import is directly used, but is technically unnecessary since it's recursively imported by something else, it is *not* removed. The tool doesn't touch .h files, so I did some of them by hand while fixing errors due to old recursive imports. Not everything is removed, but the cleanup should be substantial enough. Because this done on Linux, code that isn't used on it is mostly untouched. (Hopefully no open PR is depending on these imports...)
100 lines
1.9 KiB
C++
100 lines
1.9 KiB
C++
// Copyright 2009 Dolphin Emulator Project
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
#include "Core/DSP/LabelMap.h"
|
|
|
|
#include <algorithm>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include <fmt/base.h>
|
|
|
|
#include "Core/DSP/DSPTables.h"
|
|
|
|
namespace DSP
|
|
{
|
|
struct LabelMap::Label
|
|
{
|
|
Label(std::string lbl, s32 address, LabelType ltype)
|
|
: name(std::move(lbl)), addr(address), type(ltype)
|
|
{
|
|
}
|
|
std::string name;
|
|
s32 addr;
|
|
LabelType type;
|
|
};
|
|
|
|
LabelMap::LabelMap() = default;
|
|
|
|
LabelMap::~LabelMap() = default;
|
|
|
|
void LabelMap::RegisterDefaults()
|
|
{
|
|
for (const auto& reg_name_label : regnames)
|
|
{
|
|
if (reg_name_label.name != nullptr)
|
|
RegisterLabel(reg_name_label.name, reg_name_label.addr);
|
|
}
|
|
|
|
for (const auto& predefined_label : pdlabels)
|
|
{
|
|
if (predefined_label.name != nullptr)
|
|
RegisterLabel(predefined_label.name, predefined_label.addr);
|
|
}
|
|
}
|
|
|
|
bool LabelMap::RegisterLabel(std::string label, u16 lval, LabelType type)
|
|
{
|
|
const std::optional<u16> old_value = GetLabelValue(label);
|
|
if (old_value)
|
|
{
|
|
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)
|
|
{
|
|
const auto iter = std::ranges::find(labels, label, &Label::name);
|
|
|
|
if (iter == labels.cend())
|
|
return;
|
|
|
|
labels.erase(iter);
|
|
}
|
|
|
|
std::optional<u16> LabelMap::GetLabelValue(std::string_view name, LabelType type) const
|
|
{
|
|
for (const auto& label : labels)
|
|
{
|
|
if (name == label.name)
|
|
{
|
|
if ((type & label.type) != 0)
|
|
{
|
|
return label.addr;
|
|
}
|
|
else
|
|
{
|
|
fmt::print("Wrong label type requested. {}\n", name);
|
|
}
|
|
}
|
|
}
|
|
|
|
return std::nullopt;
|
|
}
|
|
|
|
void LabelMap::Clear()
|
|
{
|
|
labels.clear();
|
|
}
|
|
} // namespace DSP
|