-
Notifications
You must be signed in to change notification settings - Fork 5
/
imm.h
41 lines (37 loc) · 1.96 KB
/
imm.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#ifndef IMM_H
#define IMM_H
#include "types.h"
#include <assert.h>
typedef struct
{
int nbits;
union
{
int64_t dq;
int32_t dd;
int16_t dw;
int8_t db;
};
bool is_unsigned;
} imm_t;
#define DECLARE_IMM_CAST(TYPE) \
static TYPE imm_cast_##TYPE(imm_t* imm) \
{ \
switch (imm->nbits) \
{ \
case 8: \
return (TYPE)imm->db; \
case 16: \
return (TYPE)imm->dw; \
case 32: \
return (TYPE)imm->dd; \
case 64: \
return (TYPE)imm->dq; \
} \
return 0; \
}
DECLARE_IMM_CAST(int8_t)
DECLARE_IMM_CAST(int16_t)
DECLARE_IMM_CAST(int32_t)
DECLARE_IMM_CAST(int64_t)
#endif