stage.mx raw
1 package iskra
2
3 import "git.smesh.lol/iskradb/lattice"
4
5 // Stage tags prepended to the key's high byte.
6 const (
7 StageSRC uint8 = 0x01
8 StageAST uint8 = 0x02
9 StageIR uint8 = 0x03
10 StageASM uint8 = 0x04
11 StageBIN uint8 = 0x05
12 )
13
14 // MakeCodeKey encodes stage in the high 8 bits and the FNV hash in the lower 56 bits.
15 func MakeCodeKey(stage uint8, hash uint64) lattice.Key {
16 return lattice.Key((uint64(stage) << 56) | (hash & 0x00FFFFFFFFFFFFFF))
17 }
18
19 func KeyStage(key lattice.Key) uint8 {
20 return uint8(uint64(key) >> 56)
21 }
22
23 func KeyHash(key lattice.Key) uint64 {
24 return uint64(key) & 0x00FFFFFFFFFFFFFF
25 }
26
27 // NameKey builds a lattice.Key from stage and the segment's name.
28 func NameKey(stage uint8, name string) lattice.Key {
29 return MakeCodeKey(stage, HashBytes(name))
30 }
31
32 func StageName(s uint8) string {
33 switch s {
34 case StageSRC:
35 return "SRC"
36 case StageAST:
37 return "AST"
38 case StageIR:
39 return "IR"
40 case StageASM:
41 return "ASM"
42 case StageBIN:
43 return "BIN"
44 }
45 return "?"
46 }
47