From dce00ea47fd4100df97349fd2bf998169b05b74a Mon Sep 17 00:00:00 2001 From: Pavel Pisa Date: Tue, 2 Jul 2019 15:00:17 +0200 Subject: Change instruction parsing to allow multiple words pseudo-operations. Signed-off-by: Pavel Pisa --- qtmips_gui/mainwindow.cpp | 15 ++++++++++----- qtmips_gui/programmodel.cpp | 3 +-- 2 files changed, 11 insertions(+), 7 deletions(-) (limited to 'qtmips_gui') diff --git a/qtmips_gui/mainwindow.cpp b/qtmips_gui/mainwindow.cpp index c9d89d9..3301367 100644 --- a/qtmips_gui/mainwindow.cpp +++ b/qtmips_gui/mainwindow.cpp @@ -606,16 +606,21 @@ void MainWindow::compile_source() { } if (line.isEmpty()) continue; - machine::Instruction inst; - inst = machine::Instruction::from_string(line, &ok, address, &reloc, ln); - if (!ok) { + std::uint32_t inst[2] = {0, 0}; + ssize_t size = machine::Instruction::code_from_string(inst, 8, line, + address, &reloc, ln, true); + if (size < 0) { QMessageBox::critical(this, "QtMips Error", tr("line %1 instruction %2 parse error.") .arg(QString::number(ln), line)); + ok = false; break; } - mem->write_word(address, inst.data()); - address += 4; + std::uint32_t *p = inst; + for (ssize_t l = 0; l < size; l += 4) { + mem->write_word(address, *(p++)); + address += 4; + } } SymbolTableDb symtab(machine->symbol_table()); foreach(machine::RelocExpression *r, reloc) { diff --git a/qtmips_gui/programmodel.cpp b/qtmips_gui/programmodel.cpp index 64dffb8..0f3341f 100644 --- a/qtmips_gui/programmodel.cpp +++ b/qtmips_gui/programmodel.cpp @@ -274,8 +274,7 @@ bool ProgramModel::setData(const QModelIndex & index, const QVariant & value, in mem->write_word(address, data); break; case 3: - data = machine::Instruction::from_string(value.toString(), &ok, address).data(); - if (!ok) + if (machine::Instruction::code_from_string(&data, 4, value.toString(), address) < 0) return false; mem->write_word(address, data); break; -- cgit v1.2.3