aboutsummaryrefslogtreecommitdiff
path: root/src/common.h
blob: e93e920c11290e38d5a3eef1a3e4e1c66ac01a09 (plain) (blame)
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#ifndef EJIT_COMMON_H
#define EJIT_COMMON_H

#include <stdbool.h>
#include "vec.h"

enum ejit_opcode {
	MOVI,
	MOVR,
	MOVR_F,

	LDI8,
	LDI16,
	LDI32,
	LDI64,
	LDIU8,
	LDIU16,
	LDIU32,
	LDIU64,
	LDIF,
	LDID,

	LDXI8,
	LDXI16,
	LDXI32,
	LDXI64,
	LDXIU8,
	LDXIU16,
	LDXIU32,
	LDXIU64,
	LDXIF,
	LDXID,

	STI8,
	STI16,
	STI32,
	STI64,
	STIU8,
	STIU16,
	STIU32,
	STIU64,
	STIF,
	STID,

	STXI8,
	STXI16,
	STXI32,
	STXI64,
	STXIU8,
	STXIU16,
	STXIU32,
	STXIU64,
	STXIF,
	STXID,

	ADDR,
	ADDR_F,
	SUBR,
	SUBR_F,

	BLTR,

	PARAM,
	PARAM_F,

	ARG,
	ARG_I,
	ARG_F,
	ARG_FI,

	ESCAPEI,
	ESCAPEI_F,

	CALLI,
	CALLI_F,

	RET,
	RET_I,
	RET_F,
	RET_FI,

	RETVAL,
	RETVAL_F,

	START,
	END,

	OPCODE_COUNT,
};

struct ejit_insn {
	union {
		enum ejit_opcode op;
		void *addr;
	};

	size_t r0;
	size_t r1;
	union {
		size_t r2;
		void *p;
		long o;
		double d;
	};
};

struct ejit_func {
	struct vec insns;
	enum ejit_type rtype;

	size_t gpr;
	size_t fpr;

	void *arena;
	size_t size;
};


union interp_ret {
	long r;
	double d;
};

union interp_ret ejit_interp(struct ejit_func *f, size_t argc, struct ejit_arg args[argc], bool run, void ***labels_wb);

bool ejit_compile(struct ejit_func *f);

#endif /* EJIT_COMMON_H */