summaryrefslogtreecommitdiffhomepage
path: root/intel.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'intel.cpp')
-rw-r--r--intel.cpp136
1 files changed, 0 insertions, 136 deletions
diff --git a/intel.cpp b/intel.cpp
index 7ef6be3..9dac6c0 100644
--- a/intel.cpp
+++ b/intel.cpp
@@ -314,142 +314,6 @@ namespace {
} // namespace
-class Chunk
-{
-public:
- virtual ~Chunk(){}
- virtual std::vector<uint8_t> getCode() = 0;
- virtual size_t size() = 0; ///< returns size in bytes
-};
-
-class Label: public Chunk
-{
-public:
- Label(const std::string& name) : m_name(name) {}
- std::string name(){return m_name;}
- std::vector<uint8_t> getCode() override { return {}; }
- size_t size() override { return 0; }
-
-private:
- std::string m_name;
-};
-
-class Data: public Chunk
-{
-public:
- Data(std::vector<uint8_t> data): m_data(data) {}
- virtual ~Data(){}
-
- std::vector<uint8_t> getCode() override
- {
- return m_data;
- }
-
- size_t size() override
- {
- return m_data.size();
- }
-
-protected:
- std::vector<uint8_t> m_data;
-};
-
-class Segment: public std::vector<std::shared_ptr<Chunk>>
-{
- size_t getAddressOfLabel(const std::string& label)
- {
- size_t address{0};
- auto i{begin()};
- while (i != end()) {
- Chunk& chunk{**i};
- address += chunk.size();
- if (typeid(chunk) == typeid(Label)) {
- if (dynamic_cast<Label&>(chunk).name() == label) {
- return address;
- }
- }
- }
-
- throw std::runtime_error("Bad label: "s + label);
- }
-};
-
-class Op: public Chunk
-{
-public:
- virtual ~Op(){};
- virtual bool optimize() = 0; ///< returns true if changed
-};
-
-using AsmArgs = std::vector<std::any>; // 0th element is mnemonic
-using FactoryFunction = std::function<std::shared_ptr<Op>(AsmArgs&)>;
-
-std::unordered_map<std::string, FactoryFunction> ops;
-
-bool registerOp(const std::string& mnemonic, FactoryFunction f)
-{
- if (ops.contains(mnemonic)) {
- std::cout << "Warning: mnemonic |" << mnemonic << "| already registered." << std::endl;
- return false;
- }
-
- std::cout << "Registering mnemonic |" << mnemonic << "|." << std::endl;
-
- ops[mnemonic] = f;
-
- return true;
-}
-
-class OpSimple: public Op
-{
-public:
- OpSimple(std::vector<uint8_t> machine_code): machine_code(machine_code) {}
-
- std::vector<uint8_t> getCode() override
- {
- return machine_code;
- }
-
- size_t size() override
- {
- return machine_code.size();
- }
-
- bool optimize() override ///< returns true if changed
- {
- return false;
- }
-
-protected:
- std::vector<uint8_t> machine_code;
-};
-
-class Op_nop: public OpSimple
-{
-public:
- Op_nop() : OpSimple({ 0x90 }) {}
-
-};
-
-template<typename T>
-std::string mangleNameOne(const std::string& s)
-{
- return s + "_" + typeid(T).name();
-}
-
-template<typename T, typename... Targs>
-std::string mangleName(const std::string& s)
-{
- if constexpr (sizeof...(Targs) == 0)
- return mangleNameOne<T>(s);
- else
- return mangleName<Targs...>(s + "_" + typeid(T).name());
-}
-
-bool registered { registerOp("nop", [](AsmArgs& args) -> std::shared_ptr<Op>{
- return std::make_shared<Op_nop>();
- }) };
-
class Assembler {
std::unordered_map<std::string, size_t> labels; ///< labels with their positions in instruction list