From 699338864551e619a5b95b69208efc67568ebf4c Mon Sep 17 00:00:00 2001 From: ChUrl Date: Tue, 21 Mar 2023 14:33:15 +0100 Subject: [PATCH] Implement part of the AST structure --- src/ast/nodes/RegNode.cpp | 15 +++++++++++++++ src/ast/nodes/RegNode.h | 22 ++++++++++++++++++++++ src/ast/nodes/RootNode.cpp | 9 +++++++++ src/ast/nodes/RootNode.h | 19 +++++++++++++++++++ 4 files changed, 65 insertions(+) create mode 100644 src/ast/nodes/RegNode.cpp create mode 100644 src/ast/nodes/RegNode.h create mode 100644 src/ast/nodes/RootNode.cpp create mode 100644 src/ast/nodes/RootNode.h diff --git a/src/ast/nodes/RegNode.cpp b/src/ast/nodes/RegNode.cpp new file mode 100644 index 0000000..fc88e33 --- /dev/null +++ b/src/ast/nodes/RegNode.cpp @@ -0,0 +1,15 @@ +// +// Created by christoph on 21.03.23. +// + +#include "RegNode.h" + +RegNode::RegNode(uint8_t reg) : reg(reg) {} + +auto RegNode::compile() const -> uint8_t { + if (reg > 0b110) { + throw "Compile Error: Invalid Register!"; + } + + return reg; +} diff --git a/src/ast/nodes/RegNode.h b/src/ast/nodes/RegNode.h new file mode 100644 index 0000000..0833d03 --- /dev/null +++ b/src/ast/nodes/RegNode.h @@ -0,0 +1,22 @@ +// +// Created by christoph on 21.03.23. +// + +#ifndef LOGISIMASSEMBLER_REGNODE_H +#define LOGISIMASSEMBLER_REGNODE_H + +#include "../Node.h" + +class RegNode : public Node { +public: + RegNode(uint8_t reg); + + ~RegNode() override = default; + + [[nodiscard]] auto compile() const -> uint8_t override; + +private: + uint8_t reg; +}; + +#endif //LOGISIMASSEMBLER_REGNODE_H diff --git a/src/ast/nodes/RootNode.cpp b/src/ast/nodes/RootNode.cpp new file mode 100644 index 0000000..82fa134 --- /dev/null +++ b/src/ast/nodes/RootNode.cpp @@ -0,0 +1,9 @@ +// +// Created by christoph on 21.03.23. +// + +#include "RootNode.h" + +auto RootNode::compile() const -> uint8_t { + return 0; +} diff --git a/src/ast/nodes/RootNode.h b/src/ast/nodes/RootNode.h new file mode 100644 index 0000000..1416acb --- /dev/null +++ b/src/ast/nodes/RootNode.h @@ -0,0 +1,19 @@ +// +// Created by christoph on 21.03.23. +// + +#ifndef LOGISIMASSEMBLER_ROOTNODE_H +#define LOGISIMASSEMBLER_ROOTNODE_H + +#include "../Node.h" + +class RootNode : public Node { +public: + RootNode() = default; + + ~RootNode() override = default; + + [[nodiscard]] auto compile() const -> uint8_t override; +}; + +#endif //LOGISIMASSEMBLER_ROOTNODE_H