working AST

This commit is contained in:
zanostro 2025-12-10 18:02:06 +01:00
parent 7c6379c62d
commit 9e9039af05
13 changed files with 962 additions and 36 deletions

View file

@ -1,16 +1,45 @@
// mnemonic.h
#ifndef MNEMONIC_H
#define MNEMONIC_H
#include <cstdint>
#include <string>
#include <vector>
#include <variant>
using std::string;
#include "opcode.h"
struct Empty {};
struct Register { int num; };
struct Immediate { int value; };
struct SymbolRef {
std::string name;
bool indexed = false;
bool immediate = false;
bool indirect = false;
};
using Operand = std::variant<Empty, Register, Immediate, SymbolRef>;
class Mnemonic {
public:
string toString() const;
Mnemonic(std::uint8_t opcode, InstructionType type, bool extended)
: _opcode(opcode), _extended(extended), _type(type) {}
std::uint8_t opcode() const { return _opcode; }
bool extended() const { return _extended; }
InstructionType type() const { return _type; }
std::vector<Operand>& operands() { return _operands; }
const std::vector<Operand>& operands() const { return _operands; }
std::string toString() const;
private:
std::uint8_t _opcode;
bool _extended;
InstructionType _type;
std::vector<Operand> _operands;
};
#endif // MNEMONIC_H
#endif // MNEMONIC_H