From c20be71c105e75de5cd05ec9f53ac9c33f1e3379 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 8 Oct 2025 17:54:55 -0600 Subject: [PATCH] Fix the API for MIPSAssembleOpcode to remove a global --- Core/Debugger/WebSocket/DisasmSubscriber.cpp | 6 ++-- Core/MIPS/MIPSAnalyst.cpp | 2 -- Core/MIPS/MIPSAsm.cpp | 30 +++++------------ Core/MIPS/MIPSAsm.h | 6 ++-- Core/MIPS/MIPSDebugInterface.h | 3 +- UI/ImDebugger/ImDisasmView.cpp | 2 +- Windows/Debugger/CtrlDisAsmView.cpp | 34 ++++++++------------ unittest/JitHarness.cpp | 5 +-- 8 files changed, 33 insertions(+), 55 deletions(-) diff --git a/Core/Debugger/WebSocket/DisasmSubscriber.cpp b/Core/Debugger/WebSocket/DisasmSubscriber.cpp index b8e4473b98..2758183b8a 100644 --- a/Core/Debugger/WebSocket/DisasmSubscriber.cpp +++ b/Core/Debugger/WebSocket/DisasmSubscriber.cpp @@ -478,8 +478,10 @@ void WebSocketDisasmState::Assemble(DebuggerRequest &req) { if (!req.ParamString("code", &code)) return; - if (!MIPSAsm::MipsAssembleOpcode(code.c_str(), currentDebugMIPS, address)) - return req.Fail(StringFromFormat("Could not assemble: %s", MIPSAsm::GetAssembleError().c_str())); + std::string error; + if (!MipsAssembleOpcode(code, currentDebugMIPS, address, &error)) { + return req.Fail(StringFromFormat("Could not assemble: %s", error.c_str())); + } JsonWriter &json = req.Respond(); Reporting::NotifyDebugger(); diff --git a/Core/MIPS/MIPSAnalyst.cpp b/Core/MIPS/MIPSAnalyst.cpp index 516a3bb6a8..590d605b6a 100644 --- a/Core/MIPS/MIPSAnalyst.cpp +++ b/Core/MIPS/MIPSAnalyst.cpp @@ -22,8 +22,6 @@ #include #include "ext/cityhash/city.h" -#include "ext/xxhash.h" - #include "Common/File/FileUtil.h" #include "Common/Log.h" #include "Common/StringUtils.h" diff --git a/Core/MIPS/MIPSAsm.cpp b/Core/MIPS/MIPSAsm.cpp index 99ee2bbde6..19b4cc7123 100644 --- a/Core/MIPS/MIPSAsm.cpp +++ b/Core/MIPS/MIPSAsm.cpp @@ -11,17 +11,7 @@ #include "Core/MemMapHelpers.h" #include "Core/MIPS/MIPSAsm.h" -namespace MIPSAsm -{ - static std::string errorText; - -std::string GetAssembleError() -{ - return errorText; -} - -class PspAssemblerFile: public AssemblerFile -{ +class PspAssemblerFile : public AssemblerFile { public: PspAssemblerFile() { address = 0; @@ -30,7 +20,7 @@ public: bool open(bool onlyCheck) override{ return true; }; void close() override { }; bool isOpen() override { return true; }; - bool write(void* data, size_t length) override { + bool write(void *data, size_t length) override { if (!Memory::IsValidAddress((u32)(address+length-1))) return false; @@ -58,7 +48,7 @@ private: fs::path dummyFilename_; }; -bool MipsAssembleOpcode(const char *line, DebugInterface *cpu, u32 address) { +bool MipsAssembleOpcode(std::string_view line, DebugInterface *cpu, u32 address, std::string *error) { std::vector errors; char str[64]; @@ -75,14 +65,12 @@ bool MipsAssembleOpcode(const char *line, DebugInterface *cpu, u32 address) { g_symbolMap->GetLabels(args.labels); } - errorText.clear(); - if (!runArmips(args)) - { - for (size_t i = 0; i < errors.size(); i++) - { - errorText += errors[i]; + error->clear(); + if (!runArmips(args)) { + for (size_t i = 0; i < errors.size(); i++) { + (*error) += errors[i]; if (i != errors.size() - 1) - errorText += "\n"; + error->push_back('\n'); } return false; @@ -90,5 +78,3 @@ bool MipsAssembleOpcode(const char *line, DebugInterface *cpu, u32 address) { return true; } - -} // namespace diff --git a/Core/MIPS/MIPSAsm.h b/Core/MIPS/MIPSAsm.h index 27bf3eef08..2a2fe9298c 100644 --- a/Core/MIPS/MIPSAsm.h +++ b/Core/MIPS/MIPSAsm.h @@ -1,8 +1,6 @@ #pragma once +#include #include "Core/Debugger/DebugInterface.h" -namespace MIPSAsm { - bool MipsAssembleOpcode(const char* line, DebugInterface* cpu, u32 address); - std::string GetAssembleError(); -} +bool MipsAssembleOpcode(std::string_view line, DebugInterface* cpu, u32 address, std::string *error); diff --git a/Core/MIPS/MIPSDebugInterface.h b/Core/MIPS/MIPSDebugInterface.h index e4356ddee1..bf7f81380a 100644 --- a/Core/MIPS/MIPSDebugInterface.h +++ b/Core/MIPS/MIPSDebugInterface.h @@ -24,8 +24,7 @@ #include "Core/Debugger/DebugInterface.h" -class MIPSDebugInterface : public DebugInterface -{ +class MIPSDebugInterface : public DebugInterface { MIPSState *cpu; public: MIPSDebugInterface(MIPSState *_cpu) { cpu = _cpu; } diff --git a/UI/ImDebugger/ImDisasmView.cpp b/UI/ImDebugger/ImDisasmView.cpp index 7d5b42acd5..995eda7d11 100644 --- a/UI/ImDebugger/ImDisasmView.cpp +++ b/UI/ImDebugger/ImDisasmView.cpp @@ -100,7 +100,7 @@ void ImDisasmView::assembleOpcode(u32 address, const std::string &defaultText) { // try to assemble the input if it failed } - result = MIPSAsm::MipsAssembleOpcode(op.c_str(), debugger, address); + result = MIPSAsm::MipsAssembleOpcode(op, debugger, address); Reporting::NotifyDebugger(); if (result == true) { diff --git a/Windows/Debugger/CtrlDisAsmView.cpp b/Windows/Debugger/CtrlDisAsmView.cpp index c16613dcca..d6c932db9d 100644 --- a/Windows/Debugger/CtrlDisAsmView.cpp +++ b/Windows/Debugger/CtrlDisAsmView.cpp @@ -277,19 +277,19 @@ void CtrlDisAsmView::assembleOpcode(u32 address, const std::string &defaultText) // try to assemble the input if it failed } - result = MIPSAsm::MipsAssembleOpcode(op.c_str(), debugger, address); + std::string error; + result = MipsAssembleOpcode(op, debugger, address, &error); Reporting::NotifyDebugger(); - if (result == true) - { + if (result) { scanVisibleFunctions(); - if (address == curAddress) - gotoAddr(g_disassemblyManager.getNthNextAddress(curAddress,1)); - + if (address == curAddress) { + gotoAddr(g_disassemblyManager.getNthNextAddress(curAddress, 1)); + } redraw(); } else { - std::wstring error = ConvertUTF8ToWString(MIPSAsm::GetAssembleError()); - MessageBox(wnd,error.c_str(),L"Error",MB_OK); + std::wstring werror = ConvertUTF8ToWString(error.c_str()); + MessageBox(wnd, werror.c_str(), L"Error", MB_OK); } } @@ -299,34 +299,28 @@ void CtrlDisAsmView::drawBranchLine(HDC hdc, std::map &addressPositions int topY; int bottomY; - if (line.first < windowStart) - { + if (line.first < windowStart) { topY = -1; - } else if (line.first >= windowEnd) - { + } else if (line.first >= windowEnd) { topY = rect.bottom+1; } else { topY = addressPositions[line.first] + rowHeight/2; } - if (line.second < windowStart) - { + if (line.second < windowStart) { bottomY = -1; - } else if (line.second >= windowEnd) - { + } else if (line.second >= windowEnd) { bottomY = rect.bottom+1; } else { bottomY = addressPositions[line.second] + rowHeight/2; } - if ((topY < 0 && bottomY < 0) || (topY > rect.bottom && bottomY > rect.bottom)) - { + if ((topY < 0 && bottomY < 0) || (topY > rect.bottom && bottomY > rect.bottom)) { return; } // highlight line in a different color if it affects the currently selected opcode - if (line.first == curAddress || line.second == curAddress) - { + if (line.first == curAddress || line.second == curAddress) { pen = CreatePen(0,0,0x257AFA); } else { pen = CreatePen(0,0,0xFF3020); diff --git a/unittest/JitHarness.cpp b/unittest/JitHarness.cpp index b7ab4137a5..7dbf9eef7d 100644 --- a/unittest/JitHarness.cpp +++ b/unittest/JitHarness.cpp @@ -166,10 +166,11 @@ bool TestJit() { *p++ = 0xD03C0000 | (1 << 7) | (1 << 15) | (7 << 8); *p++ = 0xD03C0000 | (1 << 7) | (1 << 15) | (7 << 8); */ + std::string error; for (size_t j = 0; j < ARRAY_SIZE(lines); ++j) { p++; - if (!MIPSAsm::MipsAssembleOpcode(lines[j], currentDebugMIPS, addr)) { - printf("ERROR: %s\n", MIPSAsm::GetAssembleError().c_str()); + if (!MipsAssembleOpcode(lines[j], currentDebugMIPS, addr, &error)) { + printf("ERROR: %s\n", error.c_str()); compileSuccess = false; } addr += 4;