forked from jatovm/jato
-
Notifications
You must be signed in to change notification settings - Fork 2
/
compiler.h
119 lines (96 loc) · 3.41 KB
/
compiler.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
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
#ifndef __JIT_COMPILER_H
#define __JIT_COMPILER_H
#include <jit/compilation-unit.h>
#include <jit/basic-block.h>
#include <vm/buffer.h>
#include <vm/stack.h>
#include <vm/vm.h>
#include <pthread.h>
#include <stdbool.h>
struct compilation_unit;
struct expression;
struct statement;
struct buffer;
struct fixup_site {
/* Compilation unit to which relcall_insn belongs */
struct compilation_unit *cu;
/* We need this, because we don't have native pointer at
instruction selection */
struct insn *relcall_insn;
struct list_head fixup_list_node;
};
struct jit_trampoline {
struct buffer *objcode;
struct list_head fixup_site_list;
/* This mutex is protecting operations on fixup_site_list */
pthread_mutex_t mutex;
};
struct parse_context {
struct compilation_unit *cu;
struct basic_block *bb;
struct bytecode_buffer *buffer;
unsigned char *code;
unsigned long offset;
unsigned long code_size;
unsigned char opc;
};
void convert_expression(struct parse_context *ctx, struct expression *expr);
void convert_statement(struct parse_context *ctx, struct statement *stmt);
int compile(struct compilation_unit *);
int analyze_control_flow(struct compilation_unit *);
int convert_to_ir(struct compilation_unit *);
int analyze_liveness(struct compilation_unit *);
int select_instructions(struct compilation_unit *cu);
int allocate_registers(struct compilation_unit *cu);
int insert_spill_reload_insns(struct compilation_unit *cu);
int emit_machine_code(struct compilation_unit *);
void *jit_magic_trampoline(struct compilation_unit *);
struct jit_trampoline *alloc_jit_trampoline(void);
struct jit_trampoline *build_jit_trampoline(struct compilation_unit *);
void free_jit_trampoline(struct jit_trampoline *);
int jit_prepare_method(struct methodblock *);
struct fixup_site *alloc_fixup_site(void);
void free_fixup_site(struct fixup_site *);
void trampoline_add_fixup_site(struct jit_trampoline *, struct fixup_site *);
unsigned char *fixup_site_addr(struct fixup_site *);
const char *method_symbol(struct methodblock *method, char *symbol, size_t len);
static inline const char *cu_symbol(struct compilation_unit *cu, char *symbol, size_t len)
{
return method_symbol(cu->method, symbol, len);
}
static inline void *cu_native_ptr(struct compilation_unit *cu)
{
return buffer_ptr(cu->objcode);
}
static inline unsigned long cu_native_size(struct compilation_unit *cu)
{
return buffer_offset(cu->objcode);
}
static inline void *method_native_ptr(struct methodblock *method)
{
return buffer_ptr(method->compilation_unit->objcode);
}
static inline void *method_trampoline_ptr(struct methodblock *method)
{
return buffer_ptr(method->trampoline->objcode);
}
bool is_jit_method(unsigned long eip);
void fixup_direct_calls(struct jit_trampoline *trampoline, unsigned long target);
extern bool opt_trace_method;
extern bool opt_trace_cfg;
extern bool opt_trace_tree_ir;
extern bool opt_trace_lir;
extern bool opt_trace_liveness;
extern bool opt_trace_regalloc;
extern bool opt_trace_machine_code;
extern bool opt_trace_magic_trampoline;
extern bool opt_trace_bytecode_offset;
void trace_magic_trampoline(struct compilation_unit *);
void trace_method(struct compilation_unit *);
void trace_cfg(struct compilation_unit *);
void trace_tree_ir(struct compilation_unit *);
void trace_lir(struct compilation_unit *);
void trace_liveness(struct compilation_unit *);
void trace_regalloc(struct compilation_unit *);
void trace_machine_code(struct compilation_unit *);
#endif