Fix the API for MIPSAssembleOpcode to remove a global

This commit is contained in:
Henrik Rydgård
2025-10-08 17:54:55 -06:00
parent 7d42c7b650
commit c20be71c10
8 changed files with 33 additions and 55 deletions
+4 -2
View File
@@ -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();
-2
View File
@@ -22,8 +22,6 @@
#include <mutex>
#include "ext/cityhash/city.h"
#include "ext/xxhash.h"
#include "Common/File/FileUtil.h"
#include "Common/Log.h"
#include "Common/StringUtils.h"
+8 -22
View File
@@ -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<std::string> 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
+2 -4
View File
@@ -1,8 +1,6 @@
#pragma once
#include <string_view>
#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);
+1 -2
View File
@@ -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; }
+1 -1
View File
@@ -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)
{
+14 -20
View File
@@ -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<u32,int> &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);
+3 -2
View File
@@ -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;