[Assembler] Statically assert that ISA type is proper
MODIFY
src/assembler/assembler.h
src/assembler/assembler.h
@@ -40,6 +40,7 @@ namespace AssemblerTmp {
template <typename ISA>
class AssemblerBase {
+ static_assert(std::is_base_of<ISAInfoBase, ISA>::value, "Provided ISA type must derive from ISAInfoBase");
using Instr = Instruction<ISA>;
using InstrMap = std::map<QString, std::shared_ptr<Instr>>;
using InstrVec = std::vector<std::shared_ptr<Instr>>;
@@ -52,6 +53,7 @@ public:
const auto programLines = program.split(QRegExp("[\r\n]"));
return assemble(programLines);
}
+
AssembleResult assemble(const QStringList& programLines) const {
AssembleResult result;
@@ -70,6 +72,7 @@ public:
result.program = program;
return result;
}
+
DisassembleResult disassemble(const QByteArray& program, const uint32_t baseAddress = 0) const {
size_t i = 0;
if (program.size() % sizeof(uint32_t) != 0) {

MODIFY
src/assembler/instruction.h
src/assembler/instruction.h
#include <type_traits>
#include <vector>
#include "binutils.h"
+#include "isainfo.h"
#include "math.h"
namespace Ripes {
@@ -89,6 +90,7 @@ struct Opcode : public Field {
template <typename ISA>
struct Reg : public Field {
+ static_assert(std::is_base_of<ISAInfoBase, ISA>::value, "Provided ISA type must derive from ISAInfoBase");
/**
* @brief Reg
* @param tokenIndex: Index within a list of decoded instruction tokens that corresponds to the register index
@@ -208,6 +210,8 @@ struct Imm : public Field {
template <typename ISA>
class Instruction {
+ static_assert(std::is_base_of<ISAInfoBase, ISA>::value, "Provided ISA type must derive from ISAInfoBase");
+
public:
Instruction(Opcode opcode, const std::vector<std::shared_ptr<Field>>& fields)
: m_opcode(opcode), m_expectedTokens(1 /*opcode*/ + fields.size()), m_fields(fields) {
@@ -270,6 +274,8 @@ private:
template <typename ISA>
class PseudoInstruction {
+ static_assert(std::is_base_of<ISAInfoBase, ISA>::value, "Provided ISA type must derive from ISAInfoBase");
+
public:
PseudoInstruction(
const QString& opcode, const std::vector<std::shared_ptr<Field>>& fields,

MODIFY
src/assembler/matcher.h
src/assembler/matcher.h
@@ -9,6 +9,8 @@ namespace AssemblerTmp {
template <typename ISA>
class Matcher {
+ static_assert(std::is_base_of<ISAInfoBase, ISA>::value, "Provided ISA type must derive from ISAInfoBase");
+
struct MatchNode {
MatchNode(OpPart _matcher) : matcher(_matcher) {}
OpPart matcher;

[Assembler] Statically assert that ISA type is proper