Skip to content
← Back

src/ir/values/int_max_zero.ghul

1
namespace IR.Values is
2
use Semantic.Types.Type
3
4
// An int operand, or zero where it is negative, on the stack. A range
5
// whose end precedes its start yields no elements, and a fused
6
// collect sized at its `to - from` must allocate nothing rather than
7
// ask for a negative length.
8
class INT_MAX_ZERO: Composite is
9
_operand: Value
10
11
type: Type
12
13
init(operand: Value, type: Type) is
14
super.init()
15
16
_operand = operand
17
self.type = type
18
si
19
20
// operand, or zero where the operand is negative
21
expand() -> BLOCK is
22
let expansion = IR.EXPANSION(type)
23
let result = expansion.temp("max_zero", type)
24
25
expansion.store(result, _operand)
26
27
let non_negative = expansion.region()
28
29
expansion.exit_if(non_negative, IR.BRANCH.GE, result.load(), Literal.NUMBER(0, type))
30
expansion.store(result, Literal.NUMBER(0, type))
31
expansion.close(non_negative)
32
33
expansion.add(result.load())
34
35
return expansion.result
36
si
37
38
to_string() -> string => "int-max-zero:({_operand})"
39
si
40
si