forked from thoughtpolice/dynasm-example
-
Notifications
You must be signed in to change notification settings - Fork 1
/
bc.c
32 lines (27 loc) · 743 Bytes
/
bc.c
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
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
#include "bc.h"
/* Here we use BcMode + BytecodeDef to define the operand encoding
table */
uint16_t bc_encodings[] = {
/* Extra #define to append comma for enum so we can reuse BcMode */
#define BcMode1(op, name, p1, p2) BcMode(op,name,p1,p2),
BytecodeDef(BcMode1)
#undef BcMode1
};
/* Generate functions for encoding values */
#define BcInst(op, name, p1, p2) \
bc_inst_t enc_bc_##name(bc_param_t par1, \
bc_param_t par2) { \
\
bc_inst_t r = 0; \
r |= par2; r = r << 24; \
r |= par1; r = r << 8; \
r |= op; \
return r; \
}
BytecodeDef(BcInst)
#undef BcInst