diff options
author | dec05eba <dec05eba@protonmail.com> | 2019-09-14 01:45:31 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-07-25 14:36:46 +0200 |
commit | 35200031e88c65da6a0bde563f20d95c1dd4f464 (patch) | |
tree | b1159960ca7ba78a42f6ef203f99d2b1a1c26641 /include | |
parent | 7d663615b2a44715e7447a40cae467d7d4e38b9c (diff) |
Use struct for bytecode header instead of pointer arithmetic
Diffstat (limited to 'include')
-rw-r--r-- | include/bytecode/bytecode.h | 11 | ||||
-rw-r--r-- | include/std/misc.h | 25 |
2 files changed, 36 insertions, 0 deletions
diff --git a/include/bytecode/bytecode.h b/include/bytecode/bytecode.h index a93fe4f..83d62b9 100644 --- a/include/bytecode/bytecode.h +++ b/include/bytecode/bytecode.h @@ -83,6 +83,17 @@ typedef u8 AmalOpcodeType; /* TODO: Make sure this pragma pack works on all platforms */ #pragma pack(push, 1) typedef struct { + u32 magic_number; /* AMAL_BYTECODE_MAGIC_NUMBER */ + u8 major_version; + u8 minor_version; + u8 patch_version; + u8 endian; /* 0 = little endian, 1 = big endian */ +} BytecodeHeader; +#pragma pack(pop) + +/* TODO: Make sure this pragma pack works on all platforms */ +#pragma pack(push, 1) +typedef struct { u32 func_offset; u8 num_params; u32 params_num_pointers; diff --git a/include/std/misc.h b/include/std/misc.h index a9bd5b6..03d7972 100644 --- a/include/std/misc.h +++ b/include/std/misc.h @@ -1,6 +1,31 @@ #ifndef AMALGAM_MISC_H #define AMALGAM_MISC_H +#include "types.h" +#include <sys/types.h> + +#if defined(__BYTE_ORDER) + #if __BYTE_ORDER == __LITTLE_ENDIAN + #define AMAL_LITTLE_ENDIAN + #elif __BYTE_ORDER == __BIG_ENDIAN + #define AMAL_BIG_ENDIAN + #endif +#elif defined(__BYTE_ORDER__) + #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ + #define AMAL_LITTLE_ENDIAN + #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ + #define AMAL_BIG_ENDIAN + #endif +#endif + +#if !defined(AMAL_LITTLE_ENDIAN) && !defined(AMAL_BIG_ENDIAN) +#error Unsupported endian, neither little or big endian +#endif + +u16 byteswap16(u16 value); +u32 byteswap32(u32 value); +u64 byteswap64(u64 value); + #ifndef AMAL_PEDANTIC #include "log.h" #endif |