diff options
author | Pavel Pisa <pisa@cmp.felk.cvut.cz> | 2019-08-22 13:47:41 +0200 |
---|---|---|
committer | Pavel Pisa <pisa@cmp.felk.cvut.cz> | 2019-08-22 13:47:41 +0200 |
commit | 6c09f661b83dd13a8403243c1441efa5c4900538 (patch) | |
tree | fe32eed92f284d08455461c02c158226d760ac4c /qtmips_asm | |
parent | a385be02219abc1fd751908e559286dc1a370e12 (diff) | |
download | qtmips-6c09f661b83dd13a8403243c1441efa5c4900538.tar.gz qtmips-6c09f661b83dd13a8403243c1441efa5c4900538.tar.bz2 qtmips-6c09f661b83dd13a8403243c1441efa5c4900538.zip |
In include, use content from editor if file is already open.
This allows to assemble from modified include files without
need to save their content the first.
Signed-off-by: Pavel Pisa <pisa@cmp.felk.cvut.cz>
Diffstat (limited to 'qtmips_asm')
-rw-r--r-- | qtmips_asm/simpleasm.cpp | 34 | ||||
-rw-r--r-- | qtmips_asm/simpleasm.h | 10 |
2 files changed, 31 insertions, 13 deletions
diff --git a/qtmips_asm/simpleasm.cpp b/qtmips_asm/simpleasm.cpp index ad720b9..223b34d 100644 --- a/qtmips_asm/simpleasm.cpp +++ b/qtmips_asm/simpleasm.cpp @@ -256,16 +256,9 @@ bool SimpleAsm::process_line(QString line, QString filename, 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); + if (!process_file(incname, error_ptr)) { 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; - } + error = QString("error in included file: \"%1\"").arg(incname); } } if (!res) { @@ -567,6 +560,29 @@ bool SimpleAsm::process_line(QString line, QString filename, return true; } +bool SimpleAsm::process_file(QString filename, QString *error_ptr) { + QString error; + bool res = true; + QFile srcfile(filename); + if (!srcfile.open(QFile::ReadOnly | QFile::Text)) { + error = QString("cannot open file: \"%1\"").arg(filename); + emit report_message(messagetype::MSG_ERROR, "", 0, 0, error, ""); + error_occured = true; + if (error_ptr != nullptr) + *error_ptr = error; + return false; + } + for (int ln = 1; !srcfile.atEnd(); ln++) { + QString line = srcfile.readLine(); + if ((line.count() > 0) && (line.at(line.count() - 1) == '\n')) + line.truncate(line.count() - 1); + if (!process_line(line, filename, ln, error_ptr)) + res = false; + } + srcfile.close(); + return res; +} + bool SimpleAsm::finish(QString *error_ptr) { bool error_reported = false; foreach(machine::RelocExpression *r, reloc) { diff --git a/qtmips_asm/simpleasm.h b/qtmips_asm/simpleasm.h index f97904d..ac06ca1 100644 --- a/qtmips_asm/simpleasm.h +++ b/qtmips_asm/simpleasm.h @@ -36,8 +36,8 @@ #ifndef SIMPLEASM_H #define SIMPLEASM_H -#include <QString> -#include <QStringList> +#include <QString> +#include <QStringList> #include "fixmatheval.h" #include "qtmipsmachine.h" #include "messagetype.h" @@ -71,11 +71,13 @@ public: void setup(machine::MemoryAccess *mem, SymbolTableDb *symtab, std::uint32_t address); bool process_line(QString line, QString filename = "", int line_number = 0, QString *error_ptr = nullptr); + virtual bool process_file(QString filename, QString *error_ptr = nullptr); bool finish(QString *error_ptr = nullptr); -private: - QStringList include_stack; +protected: bool error_occured; bool fatal_occured; +private: + QStringList include_stack; SymbolTableDb *symtab; machine::MemoryAccess *mem; machine::RelocExpressionList reloc; |