summaryrefslogtreecommitdiff
path: root/docs/lifecycle/jit.md
blob: 3ef73e01ce926f5e5ed5b0b81d513330d2cd7857 (plain)
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
# Jit

---

Convert Ir Into X64 (X86_64)

## Limitations

### No Segmentation Registers

### No X87 Support

### No access to the upper 8 bits of the lower 16 bits of registers AX, BX, CX, DX

## Required Implicit Registers

Instructions that implicitly modify a register now require the register as an argument

# Operation

Each instruction is written with varardic c functions with `TYPE`, `DATA` syntax

## TYPE

### General Registers Width

### General Register Addresses Width

### General Register Scale

### General Register Id

### General Register Memory Offset

### XMM Registers

### MM Registers

### Immediate Value

### Relative Address

### Label

## DATA

## Object Definitions

```c
kpl_x64_lable(label)

kpl_x64_inst(INSTRUCTION, [TYPE, VALUE]..., END)

kpl_x64_inst_pfx(PREFIX, INSTRUCTION, [TYPE, VALUE]..., END)
```

# Ir Matching

Use tree with sub trees to match Ir operations to JIT functions

1. Match Name
2. Match Args until None or End
3. Run JIT Fn

## Object Definitions

```c
typedef struct _kpl_ir_match {
    int32_t tree_weight;
    union {
        kpl_ir_name ir_name;
        kpl_type_header type_header;
    } match;
    union {
        struct _kpl_ir_match *children;
        void *jit_fn; // TODO
    } next;
    struct _kpl_ir_match *tree_left *tree_right;
} kpl_ir_match;
```