Adds better packing defines.
This commit is contained in:
parent
02bc1933ab
commit
2328ce6408
2 changed files with 13 additions and 14 deletions
14
libvm/exp.h
14
libvm/exp.h
|
@ -1,9 +1,9 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#if defined(__gcc)
|
#if defined(_MSC_VER)
|
||||||
#define PACKED __attribute__ ((packed))
|
#define EXP_PACKED_STRUCT
|
||||||
#else
|
#else
|
||||||
#define PACKED
|
#define EXP_PACKED_STRUCT __attribute__ ((packed))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
@ -19,7 +19,7 @@ struct expfile
|
||||||
uint32_t numSections; // Number of sections
|
uint32_t numSections; // Number of sections
|
||||||
uint32_t posMeta; // File pointer of first metadata entry
|
uint32_t posMeta; // File pointer of first metadata entry
|
||||||
uint32_t posSections; // File pointer of first section definition;
|
uint32_t posSections; // File pointer of first section definition;
|
||||||
} PACKED;
|
} EXP_PACKED_STRUCT;
|
||||||
|
|
||||||
struct expsection
|
struct expsection
|
||||||
{
|
{
|
||||||
|
@ -28,13 +28,13 @@ struct expsection
|
||||||
uint32_t start; // File pointer to the begin of the section
|
uint32_t start; // File pointer to the begin of the section
|
||||||
uint32_t length; // Length of the section in bytes
|
uint32_t length; // Length of the section in bytes
|
||||||
char name[64]; // Name of the section, null terminated c-string
|
char name[64]; // Name of the section, null terminated c-string
|
||||||
} PACKED;
|
} EXP_PACKED_STRUCT;
|
||||||
|
|
||||||
struct expstring
|
struct expstring
|
||||||
{
|
{
|
||||||
uint32_t start; // File pointer to the start of the string
|
uint32_t start; // File pointer to the start of the string
|
||||||
uint32_t length; // Length of the string in bytes.
|
uint32_t length; // Length of the string in bytes.
|
||||||
} PACKED;
|
} EXP_PACKED_STRUCT;
|
||||||
|
|
||||||
struct expmeta
|
struct expmeta
|
||||||
{
|
{
|
||||||
|
@ -45,7 +45,7 @@ struct expmeta
|
||||||
int32_t i; // int32_t
|
int32_t i; // int32_t
|
||||||
struct expstring s; // ExpString
|
struct expstring s; // ExpString
|
||||||
} value; // Value of the metadata
|
} value; // Value of the metadata
|
||||||
} PACKED;
|
} EXP_PACKED_STRUCT;
|
||||||
|
|
||||||
typedef struct expfile expfile_t;
|
typedef struct expfile expfile_t;
|
||||||
typedef struct expsection expsection_t;
|
typedef struct expsection expsection_t;
|
||||||
|
|
13
libvm/vm.h
13
libvm/vm.h
|
@ -3,13 +3,12 @@
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
|
||||||
#if defined(__gcc)
|
#if defined(_MSC_VER)
|
||||||
#define PACKED __attribute__ ((packed))
|
#define VM_PACKED_STRUCT
|
||||||
#else
|
#else
|
||||||
#define PACKED
|
#define VM_PACKED_STRUCT __attribute__ ((packed))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#else
|
#else
|
||||||
|
@ -86,10 +85,10 @@ struct instruction
|
||||||
unsigned int flags : 1;
|
unsigned int flags : 1;
|
||||||
unsigned int output : 2;
|
unsigned int output : 2;
|
||||||
uint32_t argument;
|
uint32_t argument;
|
||||||
} PACKED ;
|
} VM_PACKED_STRUCT ;
|
||||||
|
|
||||||
static_assert(sizeof(Instruction) == 8, "Instruction must be 8 bytes large.");
|
static_assert(sizeof(struct instruction) == 8, "Instruction must be 8 bytes large.");
|
||||||
static_assert(offsetof(Instruction, argument) == 4, "Argument must be must be 8 bytes large.");
|
static_assert(offsetof(struct instruction, argument) == 4, "Argument must be must be 8 bytes large.");
|
||||||
|
|
||||||
struct spu
|
struct spu
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue