From 74f95aa25f4171538dadbc3d6863135b61d1ea35 Mon Sep 17 00:00:00 2001 From: calcium Date: Mon, 19 Aug 2024 20:05:06 -0400 Subject: [PATCH] Reformatted Utils.h --- include/Utils/Utils.h | 56 +++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/include/Utils/Utils.h b/include/Utils/Utils.h index 2ceddba..3b57f86 100644 --- a/include/Utils/Utils.h +++ b/include/Utils/Utils.h @@ -1,24 +1,32 @@ -#ifndef __JAVA_PARSER_UTILS_UTILS_H -#define __JAVA_PARSER_UTILS_UTILS_H +#ifndef __CAVM_UTILS_UTILS_H +#define __CAVM_UTILS_UTILS_H -#include +#include +#include +#include #include #include -#include +#include +#include + +#define TYPE(x) typeid(x).name() +#define VEC_ELEM_TYPE(x) x.type().name() +#ifdef CAVM_RUNTIME_CHECK_SUPPORT +#define ASSERT(x) assert(x) +#else +#define ASSERT(x) +#endif namespace Utils { -template -ALWAYS_INLINE T M_POW(T x, X power) +template ALWAYS_INLINE T M_POW(T x, X power) { T ret = 1; if (power == 0) return 1; - - for (int i = 0; i < power; i++) { ret *= x; @@ -35,10 +43,9 @@ ALWAYS_INLINE T M_POW(T x, X power) return ret; } -template -ALWAYS_INLINE T Hex2Int(T x) +template ALWAYS_INLINE T Hex2Int(T x) { - T ret = 0; + T ret = 0; int digits = 0; while (x != 0) @@ -52,8 +59,7 @@ ALWAYS_INLINE T Hex2Int(T x) return ret; } -template -ALWAYS_INLINE const char* Int2Hex(T x) +template ALWAYS_INLINE const char *Int2Hex(T x) { constexpr const char *digits[] = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"}; @@ -62,15 +68,15 @@ ALWAYS_INLINE const char* Int2Hex(T x) while (x != 0) { T rem = x % 16; - x = (int)(x / 16); + x = (int)(x / 16); ret.push_back(digits[rem]); } for (int i = 0; i < ret.size() / 2; i++) { - char tmp = ret[i]; - ret[i] = ret[ret.size() - i]; + char tmp = ret[i]; + ret[i] = ret[ret.size() - i]; ret[ret.size() - i] = tmp; } @@ -79,8 +85,7 @@ ALWAYS_INLINE const char* Int2Hex(T x) return data; } -template -ALWAYS_INLINE std::vector Read(std::vector &vec, int start, int end) +template ALWAYS_INLINE std::vector Read(std::vector &vec, int start, int end) { std::vector ret; @@ -92,8 +97,7 @@ ALWAYS_INLINE std::vector Read(std::vector &vec, int start, int end) return ret; } -template -ALWAYS_INLINE std::vector ReadFromStart(std::vector &vec, int end) +template ALWAYS_INLINE std::vector ReadFromStart(std::vector &vec, int end) { std::vector ret = Read(vec, 0, end); for (int i = 0; i < end; i++) @@ -101,9 +105,7 @@ ALWAYS_INLINE std::vector ReadFromStart(std::vector &vec, int end) return ret; } - -template -ALWAYS_INLINE T vecToVal(std::vector &vec) +template ALWAYS_INLINE T vecToVal(std::vector &vec) { if (vec.size() > sizeof(T)) { @@ -120,19 +122,17 @@ ALWAYS_INLINE T vecToVal(std::vector &vec) return ret; } -template -ALWAYS_INLINE T ReadFromStartIntoVal(std::vector &vec, int end) +template ALWAYS_INLINE T ReadFromStartIntoVal(std::vector &vec, int end) { std::vector val = ReadFromStart(vec, end); return vecToVal(val); } -template -ALWAYS_INLINE T ReadFromStartIntoVal(std::vector &vec) +template ALWAYS_INLINE T ReadFromStartIntoVal(std::vector &vec) { std::vector val = ReadFromStart(vec, sizeof(T)); return vecToVal(val); } -} +} // namespace Utils #endif \ No newline at end of file