working AST
This commit is contained in:
parent
7c6379c62d
commit
9e9039af05
13 changed files with 962 additions and 36 deletions
|
|
@ -3,23 +3,22 @@
|
|||
|
||||
#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;
|
||||
|
||||
string getComment() const;
|
||||
|
||||
std::shared_ptr<Mnemonic> getMnemonic() const;
|
||||
|
||||
string toString() const;
|
||||
|
||||
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;
|
||||
|
|
@ -27,5 +26,73 @@ protected:
|
|||
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);
|
||||
}
|
||||
|
||||
#endif // NODE_H
|
||||
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue