#include "assembler.h" using namespace std::string_literals; namespace { std::unordered_map ops; } bool registerOp(const std::string& mnemonic, FactoryFunction f) { if (ops.contains(mnemonic)) { std::cerr << "Warning: mnemonic |" << mnemonic << "| already registered." << std::endl; return false; } //std::cout << "Registering mnemonic |" << mnemonic << "|." << std::endl; ops[mnemonic] = f; return true; } std::string mangleName(const std::string& s, const Asm::Args& args) { std::string result {s}; for (const auto& arg: args) { result += "_"s + arg.type().name(); } return result; } std::shared_ptr makeOp(const std::string& mnemonic, const Asm::Args& args) { std::string mangled{mangleName(mnemonic, args)}; const auto& i{ops.find(mangled)}; if (i == ops.end()) throw std::runtime_error("Instruction "s + mangled + " not implemented."); return i->second(args); } std::shared_ptr makeOp(const std::string& mnemonic) { Asm::Args dummy; // empty list of arguments return makeOp(mnemonic, dummy); } std::shared_ptr