aboutsummaryrefslogtreecommitdiff
path: root/src/common.h
blob: 1f52f76373b37ad56d74adbdbf4fa37fdaac8817 (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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#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,
	ADDI,

	SUBR,
	SUBR_F,
	SUBI,

	MULR,
	DIVR,
	NEGR,

	EQR,
	LTR,

	BLTR,
	BNEI,
	BEQI,
	BGTI,
	JMP,

	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;
	struct vec labels;
	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 */