aboutsummaryrefslogtreecommitdiff
path: root/bcode.h
blob: a42f2f982a1c299a72142c92bdce72386db16f45 (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
#ifndef BCGEN_BCODE_H
#define BCGEN_BCODE_H

#include <stddef.h>

typedef unsigned long ubcval_t;
typedef signed long sbcval_t;
typedef float fbcval_t;
typedef double dbcval_t;
typedef size_t bcreloc_t;

typedef union {
	ubcval_t r;
	sbcval_t s;
	fbcval_t f;
	dbcval_t d;
} bcval_t;

struct run_state {
	void* (*op);
	bcval_t *imm;
};

struct compile_state {
	struct run_state s;
	void* (*labels);
	size_t size;
	size_t pc;
};

#include "gen/select.h"

ubcval_t run(struct compile_state *cs);
void init(struct compile_state *cs);
void end(struct compile_state *cs);
void destroy(struct compile_state *cs);

bcval_t label(struct compile_state *cs);
void patch(struct compile_state *cs, bcreloc_t reloc, bcval_t imm);

#endif /* BCGEN_BCODE_H */