aboutsummaryrefslogtreecommitdiff
path: root/qtmips_cli
diff options
context:
space:
mode:
authorPavel Pisa <pisa@cmp.felk.cvut.cz>2019-07-17 21:03:36 +0200
committerPavel Pisa <pisa@cmp.felk.cvut.cz>2019-07-17 21:03:36 +0200
commit94095c7890f491d7023b1a69b3f088be8c05e898 (patch)
tree4e609f0253430361d084586e15dddcacd7c84e80 /qtmips_cli
parent4885535c9e1da9b1a718125273bfe76933c7fff8 (diff)
downloadqtmips-94095c7890f491d7023b1a69b3f088be8c05e898.tar.gz
qtmips-94095c7890f491d7023b1a69b3f088be8c05e898.tar.bz2
qtmips-94095c7890f491d7023b1a69b3f088be8c05e898.zip
Enable CLI version to use simple assembler.
Signed-off-by: Pavel Pisa <pisa@cmp.felk.cvut.cz>
Diffstat (limited to 'qtmips_cli')
-rw-r--r--qtmips_cli/main.cpp49
-rw-r--r--qtmips_cli/msgreport.cpp76
-rw-r--r--qtmips_cli/msgreport.h58
-rw-r--r--qtmips_cli/qtmips_cli.pro6
4 files changed, 184 insertions, 5 deletions
diff --git a/qtmips_cli/main.cpp b/qtmips_cli/main.cpp
index 82296ed..08696b4 100644
--- a/qtmips_cli/main.cpp
+++ b/qtmips_cli/main.cpp
@@ -35,11 +35,15 @@
#include <QCoreApplication>
#include <QCommandLineParser>
+#include <QFile>
+#include <QTextStream>
#include <cctype>
#include <iostream>
#include <fstream>
#include "tracer.h"
#include "reporter.h"
+#include "msgreport.h"
+#include "simpleasm.h"
using namespace machine;
using namespace std;
@@ -49,9 +53,10 @@ void create_parser(QCommandLineParser &p) {
p.addHelpOption();
p.addVersionOption();
- p.addPositionalArgument("FILE", "Input ELF executable file");
+ p.addPositionalArgument("FILE", "Input ELF executable file or assembler source");
// p.addOptions({}); available only from Qt 5.4+
+ p.addOption({"asm", "Treat provided file argument as assembler source."});
p.addOption({"pipelined", "Configure CPU to use five stage pipeline."});
p.addOption({"no-delay-slot", "Disable jump delay slot."});
p.addOption({{"trace-fetch", "tr-fetch"}, "Trace fetched instruction (for both pipelined and not core)."});
@@ -315,18 +320,50 @@ void load_ranges(QtMipsMachine &machine, const QStringList &ranges) {
}
}
+bool assemble(QtMipsMachine &machine, MsgReport &msgrep, QString filename) {
+ SymbolTableDb symtab(machine.symbol_table_rw(true));
+ machine::MemoryAccess *mem = machine.physical_address_space_rw();
+ if (mem == nullptr) {
+ return false;
+ }
+ machine.cache_sync();
+ SimpleAsm sasm;
+
+ sasm.connect(&sasm, SIGNAL(report_message(messagetype::Type,QString,int,int,QString,QString)),
+ &msgrep, SLOT(report_message(messagetype::Type,QString,int,int,QString,QString)));
+
+ sasm.setup(mem, &symtab, 0x80020000);
+
+ QFile input_file(filename);
+ if (!input_file.open(QIODevice::ReadOnly)) {
+ cout << "cannot open filename " << filename.toLocal8Bit().data() << endl;
+ return false;
+ }
+
+ QTextStream in(&input_file);
+ for (int ln = 1; !in.atEnd(); ln++) {
+ QString line = in.readLine();
+ sasm.process_line(line, filename, ln);
+ }
+ input_file.close();
+
+ return sasm.finish();
+}
+
int main(int argc, char *argv[]) {
QCoreApplication app(argc, argv);
app.setApplicationName("qtmips_cli");
- app.setApplicationVersion("0.1");
+ app.setApplicationVersion("0.7");
QCommandLineParser p;
create_parser(p);
p.process(app);
+ bool asm_source = p.isSet("asm");
+
MachineConfig cc;
configure_machine(p, cc);
- QtMipsMachine machine(cc, true);
+ QtMipsMachine machine(cc, !asm_source, !asm_source);
Tracer tr(&machine);
configure_tracer(p, tr);
@@ -334,6 +371,12 @@ int main(int argc, char *argv[]) {
Reporter r(&app, &machine);
configure_reporter(p, r, machine.symbol_table());
+ if (asm_source) {
+ MsgReport msgrep(&app);
+ if (!assemble(machine, msgrep, p.positionalArguments()[0]))
+ exit(1);
+ }
+
load_ranges(machine, p.values("load-range"));
machine.play();
diff --git a/qtmips_cli/msgreport.cpp b/qtmips_cli/msgreport.cpp
new file mode 100644
index 0000000..bd5f478
--- /dev/null
+++ b/qtmips_cli/msgreport.cpp
@@ -0,0 +1,76 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*******************************************************************************
+ * QtMips - MIPS 32-bit Architecture Subset Simulator
+ *
+ * Implemented to support following courses:
+ *
+ * B35APO - Computer Architectures
+ * https://cw.fel.cvut.cz/wiki/courses/b35apo
+ *
+ * B4M35PAP - Advanced Computer Architectures
+ * https://cw.fel.cvut.cz/wiki/courses/b4m35pap/start
+ *
+ * Copyright (c) 2017-2019 Karel Koci<cynerd@email.cz>
+ * Copyright (c) 2019 Pavel Pisa <pisa@cmp.felk.cvut.cz>
+ *
+ * Faculty of Electrical Engineering (http://www.fel.cvut.cz)
+ * Czech Technical University (http://www.cvut.cz/)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ ******************************************************************************/
+
+#include "msgreport.h"
+#include <iostream>
+#include <fstream>
+#include <iomanip>
+#include <typeinfo>
+
+using namespace std;
+
+MsgReport::MsgReport(QCoreApplication *app) : Super(app) {
+
+}
+
+void MsgReport::report_message(messagetype::Type type, QString file,
+ int line, int column, QString text, QString hint) {
+ (void)hint;
+
+ QString typestr = "error";
+ switch (type) {
+ case messagetype::ERROR:
+ typestr = "error";
+ break;
+ case messagetype::WARNING:
+ typestr = "warning";
+ break;
+ case messagetype::INFO:
+ typestr = "info";
+ break;
+ default:
+ return;
+ }
+
+ cout << file.toLocal8Bit().data() << ":";
+ if (line != 0)
+ cout << line << ":";
+ if (column != 0)
+ cout << column << ":";
+
+ cout << typestr.toLocal8Bit().data() << ":";
+ cout << text.toLocal8Bit().data();
+ cout << endl;
+}
diff --git a/qtmips_cli/msgreport.h b/qtmips_cli/msgreport.h
new file mode 100644
index 0000000..b1b8f70
--- /dev/null
+++ b/qtmips_cli/msgreport.h
@@ -0,0 +1,58 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*******************************************************************************
+ * QtMips - MIPS 32-bit Architecture Subset Simulator
+ *
+ * Implemented to support following courses:
+ *
+ * B35APO - Computer Architectures
+ * https://cw.fel.cvut.cz/wiki/courses/b35apo
+ *
+ * B4M35PAP - Advanced Computer Architectures
+ * https://cw.fel.cvut.cz/wiki/courses/b4m35pap/start
+ *
+ * Copyright (c) 2017-2019 Karel Koci<cynerd@email.cz>
+ * Copyright (c) 2019 Pavel Pisa <pisa@cmp.felk.cvut.cz>
+ *
+ * Faculty of Electrical Engineering (http://www.fel.cvut.cz)
+ * Czech Technical University (http://www.cvut.cz/)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ ******************************************************************************/
+
+#ifndef MSGREPORT_H
+#define MSGREPORT_H
+
+#include <QObject>
+#include <QVector>
+#include <QString>
+#include <QCoreApplication>
+#include "messagetype.h"
+
+class MsgReport : public QObject {
+ Q_OBJECT
+
+ using Super = QObject;
+
+public:
+ MsgReport(QCoreApplication *app);
+
+public slots:
+ void report_message(messagetype::Type type, QString file, int line, int column, QString text, QString hint);
+
+};
+
+#endif // MSGREPORT_H
diff --git a/qtmips_cli/qtmips_cli.pro b/qtmips_cli/qtmips_cli.pro
index 6cc1909..ea692ec 100644
--- a/qtmips_cli/qtmips_cli.pro
+++ b/qtmips_cli/qtmips_cli.pro
@@ -33,8 +33,10 @@ DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += \
main.cpp \
tracer.cpp \
- reporter.cpp
+ reporter.cpp \
+ msgreport.cpp
HEADERS += \
tracer.h \
- reporter.h
+ reporter.h \
+ msgreport.h