From 2dc4e93462d3ae3e154b1cc9b60aa6f84bfe4a19 Mon Sep 17 00:00:00 2001 From: Roman Korostinskiy <70313618+c71n93@users.noreply.github.com> Date: Fri, 6 Oct 2023 17:06:53 +0300 Subject: [PATCH] Simple interface of Interpreter (#7) Co-authored-by: c71n93 Co-authored-by: levBagryansky <28lev11@gmail.com> --- CMakeLists.txt | 4 +++- include/ChaiVM/interpreter/decoder.hpp | 14 +++++++++++ include/ChaiVM/interpreter/executor.hpp | 8 +++++++ include/ChaiVM/interpreter/instruction.hpp | 27 ++++++++++++++++++++++ include/ChaiVM/interpreter/reg-file.hpp | 8 +++++++ include/ChaiVM/types.hpp | 6 +++++ include/ChaiVM/utils/non-copyable.hpp | 11 +++++++++ src/main.cpp | 1 + 8 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 include/ChaiVM/interpreter/decoder.hpp create mode 100644 include/ChaiVM/interpreter/executor.hpp create mode 100644 include/ChaiVM/interpreter/instruction.hpp create mode 100644 include/ChaiVM/interpreter/reg-file.hpp create mode 100644 include/ChaiVM/types.hpp create mode 100644 include/ChaiVM/utils/non-copyable.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 2e58a84..81e6550 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,8 +2,10 @@ cmake_minimum_required(VERSION 3.26) project(ChaiVM) set(CMAKE_CXX_STANDARD 17) -set(SOURCE_FILES src/main.cpp) +set(SOURCE_FILES src/main.cpp include/ChaiVM/interpreter/instruction.hpp include/ChaiVM/types.hpp include/ChaiVM/interpreter/executor.hpp include/ChaiVM/utils/non-copyable.hpp include/ChaiVM/interpreter/reg-file.hpp) add_subdirectory(third_party) add_subdirectory(test) add_executable(${PROJECT_NAME} ${SOURCE_FILES}) + +include_directories(include) diff --git a/include/ChaiVM/interpreter/decoder.hpp b/include/ChaiVM/interpreter/decoder.hpp new file mode 100644 index 0000000..91913db --- /dev/null +++ b/include/ChaiVM/interpreter/decoder.hpp @@ -0,0 +1,14 @@ +#ifndef CHAIVM_DECODER_HPP +#define CHAIVM_DECODER_HPP + +#include "instruction.hpp" + +using namespace chai::interpreter; + +class Decoder { + +public: + Instruction parse(uint32_t word) ; +}; + +#endif //CHAIVM_DECODER_HPP diff --git a/include/ChaiVM/interpreter/executor.hpp b/include/ChaiVM/interpreter/executor.hpp new file mode 100644 index 0000000..5548273 --- /dev/null +++ b/include/ChaiVM/interpreter/executor.hpp @@ -0,0 +1,8 @@ +#ifndef CHAIVM_EXECUTOR_HPP +#define CHAIVM_EXECUTOR_HPP + +class Executor { + +}; + +#endif //CHAIVM_EXECUTOR_HPP diff --git a/include/ChaiVM/interpreter/instruction.hpp b/include/ChaiVM/interpreter/instruction.hpp new file mode 100644 index 0000000..91ce545 --- /dev/null +++ b/include/ChaiVM/interpreter/instruction.hpp @@ -0,0 +1,27 @@ +#ifndef CHAIVM_INSTRUCTION_HPP +#define CHAIVM_INSTRUCTION_HPP + +#include + +namespace chai::interpreter { + + +using Opcode = uint8_t; +using Register = uint8_t; +using Immediate = uint32_t; + +enum Operation { + Inv, +}; + +struct Instruction { + Operation operation; + Immediate immediate; + Register src; + Register dst; +}; + + +} + +#endif //CHAIVM_INSTRUCTION_HPP diff --git a/include/ChaiVM/interpreter/reg-file.hpp b/include/ChaiVM/interpreter/reg-file.hpp new file mode 100644 index 0000000..8cf98f1 --- /dev/null +++ b/include/ChaiVM/interpreter/reg-file.hpp @@ -0,0 +1,8 @@ +#ifndef CHAIVM_REG_FILE_HPP +#define CHAIVM_REG_FILE_HPP + +class RegisterFIle { + +}; + +#endif //CHAIVM_REG_FILE_HPP diff --git a/include/ChaiVM/types.hpp b/include/ChaiVM/types.hpp new file mode 100644 index 0000000..344e83e --- /dev/null +++ b/include/ChaiVM/types.hpp @@ -0,0 +1,6 @@ +#ifndef CHAIVM_TYPES_HPP +#define CHAIVM_TYPES_HPP + +#include + +#endif //CHAIVM_TYPES_HPP diff --git a/include/ChaiVM/utils/non-copyable.hpp b/include/ChaiVM/utils/non-copyable.hpp new file mode 100644 index 0000000..7a4237f --- /dev/null +++ b/include/ChaiVM/utils/non-copyable.hpp @@ -0,0 +1,11 @@ +#ifndef CHAIVM_NON_COPYABLE_HPP +#define CHAIVM_NON_COPYABLE_HPP + +class INonCopyable { +public: + INonCopyable(const INonCopyable &rhs) = delete; + INonCopyable& operator=(const INonCopyable &rhs) = delete; + virtual ~INonCopyable() = 0; +}; + +#endif //CHAIVM_NON_COPYABLE_HPP diff --git a/src/main.cpp b/src/main.cpp index 7fb2264..7b4895c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,3 +1,4 @@ #include +#include "ChaiVM/interpreter/decoder.hpp" int main() { std::cout << "Hello world" << std::endl; } \ No newline at end of file