From 139dcf818566f9f2a48d95cdab9ad9e2ac7c7978 Mon Sep 17 00:00:00 2001 From: Pavel Pisa Date: Wed, 17 Jul 2019 19:48:43 +0200 Subject: Simple assembler moved to separate class which is independent on Qt GUI API. Signed-off-by: Pavel Pisa --- qtmips_machine/instruction.cpp | 19 ++++++++++--------- qtmips_machine/instruction.h | 10 ++++++---- qtmips_machine/qtmipsmachine.cpp | 10 ++++++---- qtmips_machine/qtmipsmachine.h | 1 + qtmips_machine/symboltable.cpp | 6 ++++++ qtmips_machine/symboltable.h | 2 ++ 6 files changed, 31 insertions(+), 17 deletions(-) (limited to 'qtmips_machine') diff --git a/qtmips_machine/instruction.cpp b/qtmips_machine/instruction.cpp index b30901f..547c666 100644 --- a/qtmips_machine/instruction.cpp +++ b/qtmips_machine/instruction.cpp @@ -1111,7 +1111,7 @@ static int parse_reg_from_string(QString str, uint *chars_taken = nullptr) static void reloc_append(RelocExpressionList *reloc, QString fl, uint32_t inst_addr, std::int64_t offset, const ArgumentDesc *adesc, uint *chars_taken = nullptr, - int line = 0, int options = 0) { + QString filename = "", int line = 0, int options = 0) { uint bits = IMF_SUB_GET_BITS(adesc->loc); uint shift = IMF_SUB_GET_SHIFT(adesc->loc); QString expression = ""; @@ -1130,7 +1130,7 @@ static void reloc_append(RelocExpressionList *reloc, QString fl, uint32_t inst_a } reloc->append(new RelocExpression(inst_addr, expression, offset, - adesc->min, adesc->max, shift, bits, adesc->shift, line, options)); + adesc->min, adesc->max, shift, bits, adesc->shift, filename, line, options)); if (chars_taken != nullptr) { *chars_taken = i; } @@ -1141,7 +1141,7 @@ static void reloc_append(RelocExpressionList *reloc, QString fl, uint32_t inst_a ssize_t Instruction::code_from_string(std::uint32_t *code, size_t buffsize, QString inst_base, QStringList &inst_fields, QString &error, std::uint32_t inst_addr, RelocExpressionList *reloc, - int line, bool pseudo_opt, int options) + QString filename, int line, bool pseudo_opt, int options) { const char *err = "unknown instruction"; if (str_to_instruction_code_map.isEmpty()) @@ -1236,7 +1236,7 @@ ssize_t Instruction::code_from_string(std::uint32_t *code, size_t buffsize, need_reloc = true; } if (need_reloc && (reloc != nullptr)) { - reloc_append(reloc, fl, inst_addr, val, adesc, &chars_taken, line, options); + reloc_append(reloc, fl, inst_addr, val, adesc, &chars_taken, filename, line, options); val = 0; } break; @@ -1263,7 +1263,7 @@ ssize_t Instruction::code_from_string(std::uint32_t *code, size_t buffsize, need_reloc = true; } if (need_reloc && (reloc != nullptr)) { - reloc_append(reloc, fl, inst_addr, val, adesc, &chars_taken, line, options); + reloc_append(reloc, fl, inst_addr, val, adesc, &chars_taken, filename, line, options); val = 0; } break; @@ -1328,14 +1328,14 @@ ssize_t Instruction::code_from_string(std::uint32_t *code, size_t buffsize, } else if (pseudo_opt) { if (((inst_base == "LA") || (inst_base == "LI")) && (inst_fields.size() == 2)) { if(code_from_string(code, buffsize, "LUI", inst_fields, error, - inst_addr, reloc, line, false, + inst_addr, reloc, filename, line, false, CFS_OPTION_SILENT_MASK + 16) < 0) { error = QString("error in LUI element of " + inst_base); return -1; } inst_fields.insert(1, inst_fields.at(0)); if (code_from_string(code + 1, buffsize - 4, "ORI", inst_fields, error, - inst_addr + 4, reloc, line, false, + inst_addr + 4, reloc, filename, line, false, CFS_OPTION_SILENT_MASK + 0) < 0) { error = QString("error in ORI element of " + inst_base); return -1; @@ -1353,7 +1353,8 @@ ssize_t Instruction::code_from_string(std::uint32_t *code, size_t buffsize, ssize_t Instruction::code_from_string(std::uint32_t *code, size_t buffsize, QString str, QString &error, std::uint32_t inst_addr, - RelocExpressionList *reloc, int line, bool pseudo_opt, int options) + RelocExpressionList *reloc, QString filename, int line, + bool pseudo_opt, int options) { int k = 0, l; while (k < str.count()) { @@ -1379,7 +1380,7 @@ ssize_t Instruction::code_from_string(std::uint32_t *code, size_t buffsize, } return code_from_string(code, buffsize, inst_base, inst_fields, error, inst_addr, - reloc, line, pseudo_opt, options); + reloc, filename, line, pseudo_opt, options); } bool Instruction::update(std::int64_t val, RelocExpression *relocexp) { diff --git a/qtmips_machine/instruction.h b/qtmips_machine/instruction.h index b07a0e8..2ecd0c4 100644 --- a/qtmips_machine/instruction.h +++ b/qtmips_machine/instruction.h @@ -78,8 +78,8 @@ enum InstructionFlags { struct RelocExpression { inline RelocExpression(std::int32_t location, QString expression, std::int64_t offset, std::int64_t min, - std::int64_t max, unsigned lsb_bit, unsigned bits, unsigned shift, int line, - int options) { + std::int64_t max, unsigned lsb_bit, unsigned bits, unsigned shift, + QString filename, int line, int options) { this->location = location; this->expression = expression; this->offset = offset; @@ -88,6 +88,7 @@ struct RelocExpression { this->lsb_bit = lsb_bit; this->bits = bits; this->shift = shift; + this->filename = filename; this->line = line; this->options = options; } @@ -99,6 +100,7 @@ struct RelocExpression { unsigned lsb_bit; unsigned bits; unsigned shift; + QString filename; int line; int options; }; @@ -152,11 +154,11 @@ public: QString inst_base, QStringList &inst_fields, QString &error, std::uint32_t inst_addr = 0, RelocExpressionList *reloc = nullptr, - int line = 0, bool pseudo_opt = false, int options = 0); + QString filename = "", int line = 0, bool pseudo_opt = false, int options = 0); static ssize_t code_from_string(std::uint32_t *code, size_t buffsize, QString str, QString &error, std::uint32_t inst_addr = 0, - RelocExpressionList *reloc = nullptr, + RelocExpressionList *reloc = nullptr, QString filename = "", int line = 0, bool pseudo_opt = false, int options = 0); bool update(std::int64_t val, RelocExpression *relocexp); diff --git a/qtmips_machine/qtmipsmachine.cpp b/qtmips_machine/qtmipsmachine.cpp index e838429..b726bba 100644 --- a/qtmips_machine/qtmipsmachine.cpp +++ b/qtmips_machine/qtmipsmachine.cpp @@ -193,7 +193,6 @@ void QtMipsMachine::cache_sync() { cch_data->sync(); } - const PhysAddrSpace *QtMipsMachine::physical_address_space() { return physaddrspace; } @@ -214,19 +213,22 @@ LcdDisplay *QtMipsMachine::peripheral_lcd_display() { return perip_lcd_display; } -const SymbolTable *QtMipsMachine::symbol_table(bool create) { +SymbolTable *QtMipsMachine::symbol_table_rw(bool create) { if (create && (symtab == nullptr)) symtab = new SymbolTable; return symtab; } +const SymbolTable *QtMipsMachine::symbol_table(bool create) { + return symbol_table_rw(create); +} + void QtMipsMachine::set_symbol(QString name, std::uint32_t value, std::uint32_t size, unsigned char info, unsigned char other) { if (symtab == nullptr) symtab = new SymbolTable; - symtab->remove_symbol(name); - symtab->add_symbol(name, value, size, info, other); + symtab->set_symbol(name, value, size, info, other); } const Core *QtMipsMachine::core() { diff --git a/qtmips_machine/qtmipsmachine.h b/qtmips_machine/qtmipsmachine.h index e5bbdb3..7092ec3 100644 --- a/qtmips_machine/qtmipsmachine.h +++ b/qtmips_machine/qtmipsmachine.h @@ -77,6 +77,7 @@ public: PeripSpiLed *peripheral_spi_led(); LcdDisplay *peripheral_lcd_display(); const SymbolTable *symbol_table(bool create = false); + SymbolTable *symbol_table_rw(bool create = false); void set_symbol(QString name, std::uint32_t value, std::uint32_t size, unsigned char info = 0, unsigned char other = 0); const Core *core(); diff --git a/qtmips_machine/symboltable.cpp b/qtmips_machine/symboltable.cpp index d26491f..987b35f 100644 --- a/qtmips_machine/symboltable.cpp +++ b/qtmips_machine/symboltable.cpp @@ -75,6 +75,12 @@ void SymbolTable::remove_symbol(QString name) { delete p_ste; } +void SymbolTable::set_symbol(QString name, std::uint32_t value, std::uint32_t size, + unsigned char info, unsigned char other) { + remove_symbol(name); + add_symbol(name, value, size, info, other); +} + bool SymbolTable::name_to_value(std::uint32_t &value, QString name) const { SymbolTableEntry *p_ste = map_name_to_symbol.value(name); if (p_ste == nullptr) { diff --git a/qtmips_machine/symboltable.h b/qtmips_machine/symboltable.h index 0c33ac3..ece92a9 100644 --- a/qtmips_machine/symboltable.h +++ b/qtmips_machine/symboltable.h @@ -65,6 +65,8 @@ public: void add_symbol(QString name, std::uint32_t value, std::uint32_t size, unsigned char info = 0, unsigned char other = 0); + void set_symbol(QString name, std::uint32_t value, std::uint32_t size, + unsigned char info = 0, unsigned char other = 0); void remove_symbol(QString name); QStringList *names() const; public slots: -- cgit v1.2.3