98 lines
2.2 KiB
C++
98 lines
2.2 KiB
C++
#ifndef NODE_H
|
|
#define NODE_H
|
|
|
|
#include <string>
|
|
#include <memory>
|
|
#include <vector>
|
|
#include <variant>
|
|
#include <cstdint>
|
|
#include "mnemonic.h"
|
|
|
|
using std::string;
|
|
|
|
class Node {
|
|
public:
|
|
virtual ~Node() = default;
|
|
|
|
string getLabel() const { return _label; }
|
|
string getComment() const { return _comment; }
|
|
std::shared_ptr<Mnemonic> getMnemonic() const { return _mnemonic; }
|
|
|
|
virtual string toString() const;
|
|
|
|
protected:
|
|
string _label;
|
|
std::shared_ptr<Mnemonic> _mnemonic;
|
|
string _comment;
|
|
};
|
|
|
|
class InstructionNode : public Node {
|
|
public:
|
|
InstructionNode(string label,
|
|
std::shared_ptr<Mnemonic> mnemonic,
|
|
string comment) {
|
|
_label = std::move(label);
|
|
_mnemonic = std::move(mnemonic);
|
|
_comment = std::move(comment);
|
|
}
|
|
|
|
string toString() const override;
|
|
};
|
|
|
|
class CommentNode : public Node {
|
|
public:
|
|
explicit CommentNode(string text) {
|
|
_comment = std::move(text);
|
|
}
|
|
|
|
string toString() const override;
|
|
};
|
|
|
|
enum class DirectiveKind {
|
|
START, END, BASE, NOBASE, EQU, ORG, LTORG,
|
|
EXTDEF, EXTREF, CSECT
|
|
};
|
|
|
|
using DirectiveArg = std::variant<std::monostate, int, std::string, std::vector<std::string>>;
|
|
|
|
class DirectiveNode : public Node {
|
|
public:
|
|
DirectiveNode(string label, DirectiveKind kind, DirectiveArg arg, string comment)
|
|
: _kind(kind), _arg(std::move(arg)) {
|
|
_label = std::move(label);
|
|
_comment = std::move(comment);
|
|
}
|
|
|
|
DirectiveKind kind() const { return _kind; }
|
|
const DirectiveArg& arg() const { return _arg; }
|
|
|
|
string toString() const override;
|
|
|
|
private:
|
|
DirectiveKind _kind;
|
|
DirectiveArg _arg;
|
|
};
|
|
|
|
enum class DataKind { WORD, BYTE, RESW, RESB };
|
|
|
|
using DataValue = std::variant<std::monostate, int, std::vector<uint8_t>>;
|
|
|
|
class DataNode : public Node {
|
|
public:
|
|
DataNode(string label, DataKind kind, DataValue value, string comment)
|
|
: _kind(kind), _value(std::move(value)) {
|
|
_label = std::move(label);
|
|
_comment = std::move(comment);
|
|
}
|
|
|
|
DataKind kind() const { return _kind; }
|
|
const DataValue& value() const { return _value; }
|
|
|
|
string toString() const override;
|
|
|
|
private:
|
|
DataKind _kind;
|
|
DataValue _value;
|
|
};
|
|
|
|
#endif // NODE_H
|