-
Notifications
You must be signed in to change notification settings - Fork 80
/
expr_unary.go
59 lines (47 loc) · 1.36 KB
/
expr_unary.go
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
package constant
import (
"fmt"
"github.com/llir/llvm/ir/types"
)
// --- [ Unary expressions ] ---------------------------------------------------
// ~~~ [ fneg ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ExprFNeg is an LLVM IR fneg expression.
type ExprFNeg struct {
// Operand.
X Constant // floating-point scalar or vector constant
// extra.
// Type of result produced by the constant expression.
Typ types.Type
}
// NewFNeg returns a new fneg expression based on the given operand.
func NewFNeg(x Constant) *ExprFNeg {
e := &ExprFNeg{X: x}
// Compute type.
e.Type()
return e
}
// String returns the LLVM syntax representation of the constant expression as a
// type-value pair.
func (e *ExprFNeg) String() string {
return fmt.Sprintf("%s %s", e.Type(), e.Ident())
}
// Type returns the type of the constant expression.
func (e *ExprFNeg) Type() types.Type {
// Cache type if not present.
if e.Typ == nil {
e.Typ = e.X.Type()
}
return e.Typ
}
// Ident returns the identifier associated with the constant expression.
func (e *ExprFNeg) Ident() string {
// 'fneg' '(' X=TypeConst ')'
return fmt.Sprintf("fneg (%s)", e.X)
}
// Simplify returns an equivalent (and potentially simplified) constant to the
// constant expression.
func (e *ExprFNeg) Simplify() Constant {
//panic("not yet implemented")
// TODO: implement
return e
}