aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPavel Pisa <pisa@cmp.felk.cvut.cz>2019-08-22 12:18:33 +0200
committerPavel Pisa <pisa@cmp.felk.cvut.cz>2019-08-22 12:18:33 +0200
commita385be02219abc1fd751908e559286dc1a370e12 (patch)
tree8f681f58c1121fea4a5ee252a04f83d643a988a7
parent4dd9058da959ef5adb33de2689a85d84270f07b3 (diff)
downloadqtmips-a385be02219abc1fd751908e559286dc1a370e12.tar.gz
qtmips-a385be02219abc1fd751908e559286dc1a370e12.tar.bz2
qtmips-a385be02219abc1fd751908e559286dc1a370e12.zip
Provide support for include directive in simple assembler.
Signed-off-by: Pavel Pisa <pisa@cmp.felk.cvut.cz>
-rw-r--r--qtmips_asm/simpleasm.cpp59
-rw-r--r--qtmips_asm/simpleasm.h2
2 files changed, 59 insertions, 2 deletions
diff --git a/qtmips_asm/simpleasm.cpp b/qtmips_asm/simpleasm.cpp
index 0deea6f..ad720b9 100644
--- a/qtmips_asm/simpleasm.cpp
+++ b/qtmips_asm/simpleasm.cpp
@@ -34,6 +34,9 @@
******************************************************************************/
#include <QObject>
+#include <QFile>
+#include <QDir>
+#include <QFileInfo>
#include "simpleasm.h"
@@ -122,8 +125,14 @@ bool SimpleAsm::process_line(QString line, QString filename,
if (!final)
ch = line.at(pos);
if (!in_quotes) {
- if (ch == '#')
- final = true;
+ if (ch == '#') {
+ if (line.mid(pos).startsWith("#include")) {
+ if ((line.count() > pos + 8) && !line.at(pos + 8).isSpace())
+ final = true;
+ } else {
+ final = true;
+ }
+ }
if (ch == ';')
final = true;
if (ch == '/') {
@@ -226,6 +235,49 @@ bool SimpleAsm::process_line(QString line, QString filename,
return true;
}
+ if (op == "#INCLUDE") {
+ bool res = true;
+ QString incname;
+ if ((operands.count() != 1) || operands.at(0).isEmpty()) {
+ error = "the single file has to be specified for include";
+ emit report_message(messagetype::MSG_ERROR, filename, line_number, 0, error, "");
+ error_occured = true;
+ if (error_ptr != nullptr)
+ *error_ptr = error;
+ return false;
+ }
+ incname = operands.at(0);
+ if (incname.at(0) == '"')
+ incname = incname.mid(1, incname.count() - 2);
+ QFileInfo fi(QFileInfo(filename).dir(), incname);
+ incname = fi.filePath();
+ include_stack.append(filename);
+ if (include_stack.contains(incname)) {
+ error = QString("recursive include of file: \"%1\"").arg(incname);
+ res = false;
+ } else {
+ QFile incfile(incname);
+ if (!incfile.open(QFile::ReadOnly | QFile::Text)) {
+ error = QString("cannot open file: \"%1\"").arg(incname);
+ res = false;
+ } else for (int ln = 1; !incfile.atEnd(); ln++) {
+ QString line = incfile.readLine();
+ if (!process_line(line, incname, ln, error_ptr)) {
+ res = false;
+ break;
+ }
+ }
+ }
+ if (!res) {
+ emit report_message(messagetype::MSG_ERROR, filename, line_number, 0, error, "");
+ error_occured = true;
+ if (error_ptr != nullptr)
+ if (error_ptr->isEmpty())
+ *error_ptr = error;
+ }
+ include_stack.removeLast();
+ return res;
+ }
if ((op == ".DATA") || (op == ".TEXT") ||
(op == ".GLOBL") || (op == ".END") ||
(op == ".ENT")) {
@@ -388,6 +440,9 @@ bool SimpleAsm::process_line(QString line, QString filename,
case '\\':
ch = '\\';
break;
+ case '0':
+ ch = 0x00;
+ break;
case 'r':
ch = 0x0d;
break;
diff --git a/qtmips_asm/simpleasm.h b/qtmips_asm/simpleasm.h
index 773aa39..f97904d 100644
--- a/qtmips_asm/simpleasm.h
+++ b/qtmips_asm/simpleasm.h
@@ -37,6 +37,7 @@
#define SIMPLEASM_H
#include <QString>
+#include <QStringList>
#include "fixmatheval.h"
#include "qtmipsmachine.h"
#include "messagetype.h"
@@ -72,6 +73,7 @@ public:
int line_number = 0, QString *error_ptr = nullptr);
bool finish(QString *error_ptr = nullptr);
private:
+ QStringList include_stack;
bool error_occured;
bool fatal_occured;
SymbolTableDb *symtab;