From 3ae2547df9d1d69e10394a3a0902bb21371d9b51 Mon Sep 17 00:00:00 2001 From: lvntky Date: Sat, 22 Jun 2024 13:18:03 +0300 Subject: [PATCH] [bugfix] multiple definiton error for logging fixed --- cmake/SourcesAndHeaders.cmake | 4 ++++ include/cvm/execute_engine/cvm_execute.hpp | 23 ++++++++++++++++++++++ include/cvm/log.hpp | 13 +++++------- src/execute_engine/cvm_execute.cpp | 1 + src/log.cpp | 9 +++++++++ src/main.cpp | 2 -- 6 files changed, 42 insertions(+), 10 deletions(-) create mode 100644 include/cvm/execute_engine/cvm_execute.hpp create mode 100644 src/execute_engine/cvm_execute.cpp create mode 100644 src/log.cpp diff --git a/cmake/SourcesAndHeaders.cmake b/cmake/SourcesAndHeaders.cmake index d2eddd8..e72e1cf 100644 --- a/cmake/SourcesAndHeaders.cmake +++ b/cmake/SourcesAndHeaders.cmake @@ -1,6 +1,8 @@ set(sources + src/log.cpp src/classfile/classfile.cpp src/stack/frame.cpp + src/execute_engine/cvm_execute.cpp ) @@ -11,6 +13,7 @@ set(exe_sources set(headers include/cvm/fmt_commons.hpp + include/cvm/log.hpp include/cvm/banner.hpp include/cvm/classfile/classfile.hpp include/cvm/classfile/cp_info.hpp @@ -19,6 +22,7 @@ set(headers include/cvm/classfile/field_info.hpp include/cvm/stack/frame.hpp include/cvm/stack/cvm_stack.hpp + include/cvm/execute_engine/cvm_execute.hpp ) diff --git a/include/cvm/execute_engine/cvm_execute.hpp b/include/cvm/execute_engine/cvm_execute.hpp new file mode 100644 index 0000000..4de2f97 --- /dev/null +++ b/include/cvm/execute_engine/cvm_execute.hpp @@ -0,0 +1,23 @@ +#ifndef __CVM_EXECUTE_HPP__ +#define __CVM_EXECUTE_HPP__ + +#include +#include +#include + +#include "../classfile/classfile.hpp" +#include "../log.hpp" + +class CVM +{ + public: + CVM() = default; + void execute(const Classfile& cf, const std::string& methodName); + + private: + std::string getUtf8FromConstantPool(const Classfile& cf, uint16_t index); + const method_info* findMehodByName(const Classfile& cf, const std::string& methodName); + const uint8_t* getByteCode(const method_info* methodInfo); +}; + +#endif //__CVM_EXECUTE_HPP__ diff --git a/include/cvm/log.hpp b/include/cvm/log.hpp index 6286f68..9e1c3eb 100644 --- a/include/cvm/log.hpp +++ b/include/cvm/log.hpp @@ -2,16 +2,13 @@ #define __LOG_HPP__ #include + #include -#define LOG_OK "OK" -#define LOG_NOK "NOK" +#define LOG_OK "OK" +#define LOG_NOK "NOK" #define DEBUG_ENABLED 0 -void setLevel() { - if(DEBUG_ENABLED) { - spdlog::set_level(spdlog::level::debug); +void setLevel(); - } -} -#endif //__LOG_HPP__ +#endif //__LOG_HPP__ diff --git a/src/execute_engine/cvm_execute.cpp b/src/execute_engine/cvm_execute.cpp new file mode 100644 index 0000000..159f0c2 --- /dev/null +++ b/src/execute_engine/cvm_execute.cpp @@ -0,0 +1 @@ +#include "../../include/cvm/execute_engine/cvm_execute.hpp" diff --git a/src/log.cpp b/src/log.cpp new file mode 100644 index 0000000..5c11b67 --- /dev/null +++ b/src/log.cpp @@ -0,0 +1,9 @@ +#include "../include/cvm/log.hpp" + +void setLevel() +{ + if (DEBUG_ENABLED) + { + spdlog::set_level(spdlog::level::debug); + } +} diff --git a/src/main.cpp b/src/main.cpp index 18ed92d..e43523b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -37,7 +37,5 @@ int main(int argc, char** argv) classFile.close(); - Frame frame(10, 10); - fmt::print("frame: {}", frame.getOperandStackSize()); return 0; }