/* * Copyright (c) 2020 Romain Dolbeau * MIT License * See the LICENSE file at the top level of this software distribution for details. */ #ifndef __INST_HPP__ #define __INST_HPP__ #include #include class instruction { public: const std::string name; const std::string opname; const std::string key; const std::string group; std::set extensions; public: instruction(std::string n, std::string o, std::string k, std::string g ) : name(n), opname(o), key(k), group(g) { } void addExt(std::string e) { extensions.insert(e); } bool operator ==(const instruction &b) const { return name.compare(b.name) == 0; } bool match(const std::string toadd) const { if (toadd.compare(name) == 0) return true; for (const std::string extension : extensions) if (toadd.compare(extension) == 0) return true; return false; } bool isWord(void) const { return name[name.length()-1] == 'W'; } bool isImm(void) const { int indice = name.length()-1; if (isWord()) indice --; while ((indice > 0) && (name[indice] >= '0') && (name[indice] <= '9')) indice --; return name[indice] == 'I'; } std::string ctrlName() const { return "CTRL_" + group + "_" + opname; } std::string keyName() const { return name + "_KEY"; } }; #endif // __INST_HPP__