Skip to content
← Back

src/ir/temp.ghul

1
namespace IR is
2
use IO.Std
3
4
use Semantic.Types.Type
5
use Values.Value
6
7
class TEMP is
8
_block: IR.Values.BLOCK
9
_next_id: int static
10
_name: string =>
11
if suffix > 0 then
12
".{prefix}.{id}.{suffix}"
13
else
14
".{prefix}.{id}"
15
fi
16
17
id: int
18
prefix: string
19
suffix: int
20
type: Type
21
22
init(block: IR.Values.BLOCK, prefix: string, suffix: int, type: Type) is
23
_block = block
24
self.prefix = prefix
25
self.suffix = suffix
26
27
self.id = get_next_id()
28
self.type = type
29
30
declare()
31
si
32
33
init(block: IR.Values.BLOCK, prefix: string, value: Value) is
34
init(block, prefix, 0, value)
35
si
36
37
init(block: IR.Values.BLOCK, prefix: string, suffix: int, value: Value) is
38
init(block, prefix, suffix, value.type!)
39
40
store(value)
41
si
42
43
init(block: IR.Values.BLOCK, prefix: string, type: Type) is
44
init(block, prefix, 0, type)
45
si
46
47
reset_id() static is
48
_next_id = 0
49
si
50
51
get_next_id() -> int static is
52
let result = _next_id
53
_next_id = _next_id + 1
54
return result
55
si
56
57
declare() is
58
_block.add(Values.DECLARE_LOCAL(_name, type))
59
si
60
61
il_name: string => _name
62
63
load() -> Values.Load.TEMP => Values.Load.TEMP(_name, type)
64
65
store(value: Value) is
66
_block.add(value)
67
68
_block.add(Values.STORE_TEMP(_name, type))
69
si
70
si
71
si