PowerPC/Expression: Pass System to EvaluateCondition().

This commit is contained in:
Admiral H. Curtiss 2023-03-28 20:39:02 +02:00
parent 0a88c2329a
commit 18f8ae37ab
No known key found for this signature in database
GPG Key ID: F051B4C4044F33FB
6 changed files with 27 additions and 23 deletions

View File

@ -16,6 +16,7 @@
#include "Core/PowerPC/Expression.h"
#include "Core/PowerPC/JitInterface.h"
#include "Core/PowerPC/MMU.h"
#include "Core/PowerPC/PowerPC.h"
#include "Core/System.h"
bool BreakPoints::IsAddressBreakPoint(u32 address) const
@ -352,14 +353,14 @@ bool MemChecks::OverlapsMemcheck(u32 address, u32 length) const
});
}
bool TMemCheck::Action(Common::DebugInterface* debug_interface, u64 value, u32 addr, bool write,
size_t size, u32 pc)
bool TMemCheck::Action(Core::System& system, Common::DebugInterface* debug_interface, u64 value,
u32 addr, bool write, size_t size, u32 pc)
{
if (!is_enabled)
return false;
if (((write && is_break_on_write) || (!write && is_break_on_read)) &&
EvaluateCondition(this->condition))
EvaluateCondition(system, this->condition))
{
if (log_on_hit)
{

View File

@ -45,8 +45,8 @@ struct TMemCheck
std::optional<Expression> condition;
// returns whether to break
bool Action(Common::DebugInterface* debug_interface, u64 value, u32 addr, bool write, size_t size,
u32 pc);
bool Action(Core::System& system, Common::DebugInterface* debug_interface, u64 value, u32 addr,
bool write, size_t size, u32 pc);
};
// Code breakpoints.

View File

@ -267,21 +267,22 @@ std::optional<Expression> Expression::TryParse(std::string_view text)
return Expression{text, std::move(ex), std::move(vars)};
}
double Expression::Evaluate() const
double Expression::Evaluate(Core::System& system) const
{
SynchronizeBindings(SynchronizeDirection::From);
SynchronizeBindings(system, SynchronizeDirection::From);
double result = expr_eval(m_expr.get());
SynchronizeBindings(SynchronizeDirection::To);
SynchronizeBindings(system, SynchronizeDirection::To);
Reporting(result);
return result;
}
void Expression::SynchronizeBindings(SynchronizeDirection dir) const
void Expression::SynchronizeBindings(Core::System& system, SynchronizeDirection dir) const
{
auto& ppc_state = system.GetPPCState();
auto bind = m_binds.begin();
for (auto* v = m_vars->head; v != nullptr; v = v->next, ++bind)
{
@ -293,25 +294,25 @@ void Expression::SynchronizeBindings(SynchronizeDirection dir) const
break;
case VarBindingType::GPR:
if (dir == SynchronizeDirection::From)
v->value = static_cast<double>(PowerPC::ppcState.gpr[bind->index]);
v->value = static_cast<double>(ppc_state.gpr[bind->index]);
else
PowerPC::ppcState.gpr[bind->index] = static_cast<u32>(static_cast<s64>(v->value));
ppc_state.gpr[bind->index] = static_cast<u32>(static_cast<s64>(v->value));
break;
case VarBindingType::FPR:
if (dir == SynchronizeDirection::From)
v->value = PowerPC::ppcState.ps[bind->index].PS0AsDouble();
v->value = ppc_state.ps[bind->index].PS0AsDouble();
else
PowerPC::ppcState.ps[bind->index].SetPS0(v->value);
ppc_state.ps[bind->index].SetPS0(v->value);
break;
case VarBindingType::SPR:
if (dir == SynchronizeDirection::From)
v->value = static_cast<double>(PowerPC::ppcState.spr[bind->index]);
v->value = static_cast<double>(ppc_state.spr[bind->index]);
else
PowerPC::ppcState.spr[bind->index] = static_cast<u32>(static_cast<s64>(v->value));
ppc_state.spr[bind->index] = static_cast<u32>(static_cast<s64>(v->value));
break;
case VarBindingType::PCtr:
if (dir == SynchronizeDirection::From)
v->value = static_cast<double>(PowerPC::ppcState.pc);
v->value = static_cast<double>(ppc_state.pc);
break;
}
}

View File

@ -15,7 +15,8 @@ struct expr_var_list;
namespace Core
{
class CPUThreadGuard;
}
class System;
} // namespace Core
struct ExprDeleter
{
@ -36,7 +37,7 @@ class Expression
public:
static std::optional<Expression> TryParse(std::string_view text);
double Evaluate() const;
double Evaluate(Core::System& system) const;
std::string GetText() const;
@ -64,7 +65,7 @@ private:
Expression(std::string_view text, ExprPointer ex, ExprVarListPointer vars);
void SynchronizeBindings(SynchronizeDirection dir) const;
void SynchronizeBindings(Core::System& system, SynchronizeDirection dir) const;
void Reporting(const double result) const;
std::string m_text;
@ -73,7 +74,7 @@ private:
std::vector<VarBinding> m_binds;
};
inline bool EvaluateCondition(const std::optional<Expression>& condition)
inline bool EvaluateCondition(Core::System& system, const std::optional<Expression>& condition)
{
return !condition || condition->Evaluate() != 0.0;
return !condition || condition->Evaluate(system) != 0.0;
}

View File

@ -545,7 +545,8 @@ void MMU::Memcheck(u32 address, u64 var, bool write, size_t size)
mc->num_hits++;
const bool pause = mc->Action(&debug_interface, var, address, write, size, m_ppc_state.pc);
const bool pause =
mc->Action(m_system, &debug_interface, var, address, write, size, m_ppc_state.pc);
if (!pause)
return;

View File

@ -645,7 +645,7 @@ void CheckBreakPoints()
{
const TBreakPoint* bp = PowerPC::breakpoints.GetBreakpoint(PowerPC::ppcState.pc);
if (!bp || !bp->is_enabled || !EvaluateCondition(bp->condition))
if (!bp || !bp->is_enabled || !EvaluateCondition(Core::System::GetInstance(), bp->condition))
return;
if (bp->break_on_hit)