From 7b49d17f90f26394a116348befb5edcdffcedcb6 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Sat, 17 Oct 2020 17:37:50 +0200 Subject: Add ret and int --- asm/assembler.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'asm/assembler.cpp') diff --git a/asm/assembler.cpp b/asm/assembler.cpp index 275bd4a..7a9f6cf 100644 --- a/asm/assembler.cpp +++ b/asm/assembler.cpp @@ -1,7 +1,13 @@ #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)) { @@ -15,3 +21,31 @@ bool registerOp(const std::string& mnemonic, FactoryFunction f) return true; } + +std::string mangleName(const std::string& s, AsmArgs& 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, AsmArgs& 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) +{ + AsmArgs dummy; // empty list of arguments + return makeOp(mnemonic, dummy); +} -- cgit v1.2.3