Skip to content

Commit ea607be

Browse files
committed
Process .equ and .set directives and ignore some others.
Signed-off-by: Pavel Pisa <[email protected]>
1 parent 194bbe8 commit ea607be

File tree

1 file changed

+51
-4
lines changed

1 file changed

+51
-4
lines changed

qtmips_gui/mainwindow.cpp

+51-4
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,7 @@ void MainWindow::close_source() {
619619
if (idx >= 0)
620620
central_window->removeTab(idx);
621621
delete editor;
622+
update_open_file_list();
622623
}
623624

624625
class SymbolTableDb : public fixmatheval::FmeSymbolDb {
@@ -701,8 +702,22 @@ void MainWindow::compile_source() {
701702
}
702703
if (line.isEmpty())
703704
continue;
704-
QString op = line.split(" ").at(0).toUpper();
705-
if ((op == ".DATA") || (op == ".CODE")) {
705+
int k = 0, l;
706+
while (k < line.count()) {
707+
if (!line.at(k).isSpace())
708+
break;
709+
k++;
710+
}
711+
l = k;
712+
while (l < line.count()) {
713+
if (!line.at(l).isLetterOrNumber() && !(line.at(l) == '.'))
714+
break;
715+
l++;
716+
}
717+
QString op = line.mid(k, l - k).toUpper();
718+
if ((op == ".DATA") || (op == ".TEXT") ||
719+
(op == ".GLOBL") || (op == ".END") ||
720+
(op == ".ENT")) {
706721
continue;
707722
}
708723
if (op == ".ORG") {
@@ -723,6 +738,38 @@ void MainWindow::compile_source() {
723738
address = value;
724739
continue;
725740
}
741+
if ((op == ".EQU") || (op == ".SET")) {
742+
QStringList operands = line.mid(op.size()).split(",");
743+
if ((operands.count() > 2) || (operands.count() < 1)) {
744+
error_line = ln;
745+
editor->setCursorToLine(error_line);
746+
QMessageBox::critical(this, "QtMips Error",
747+
tr("line %1 .set or .equ incorrect arguments number.")
748+
.arg(QString::number(ln)));
749+
break;
750+
}
751+
QString name = operands.at(0).trimmed();
752+
if ((name == "noat") || (name == "noreored"))
753+
continue;
754+
bool ok;
755+
fixmatheval::FmeValue value = 1;
756+
if (operands.count() > 1) {
757+
fixmatheval::FmeExpression expression;
758+
ok = expression.parse(operands.at(1), error);
759+
if (ok)
760+
ok = expression.eval(value, &symtab, error);
761+
if (!ok) {
762+
error_line = ln;
763+
editor->setCursorToLine(error_line);
764+
QMessageBox::critical(this, "QtMips Error",
765+
tr("line %1 .set or .equ %2 parse error.")
766+
.arg(QString::number(ln), operands.at(1)));
767+
break;
768+
}
769+
}
770+
machine->set_symbol(name, value, 0);
771+
continue;
772+
}
726773
if (op == ".WORD") {
727774
foreach (QString s, line.mid(op.size()).split(",")) {
728775
s = s.simplified();
@@ -788,8 +835,8 @@ void MainWindow::compile_source() {
788835
error_line = r->line;
789836
editor->setCursorToLine(error_line);
790837
QMessageBox::critical(this, "QtMips Error",
791-
tr("instruction update error %1 at line %2, expression %3.")
792-
.arg(error, QString::number(r->line), expression.dump()));
838+
tr("instruction update error %1 at line %2, expression %3 -> value %4.")
839+
.arg(error, QString::number(r->line), expression.dump(), QString::number(value)));
793840
}
794841
}
795842
mem->write_word(r->location, inst.data());

0 commit comments

Comments
 (0)