-
Notifications
You must be signed in to change notification settings - Fork 2
/
names.go
41 lines (38 loc) · 916 Bytes
/
names.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
package irutil
import (
"github.com/llir/llvm/ir"
"github.com/llir/llvm/ir/value"
)
// Ident is the global or local identifier of a named value.
type Ident interface {
value.Named
// ID returns the ID of the identifier.
ID() int64
// SetID sets the ID of the identifier.
SetID(id int64)
// IsUnnamed reports whether the identifier is unnamed.
IsUnnamed() bool
}
// ResetNames resets the IDs of unnamed local variables in the given function.
func ResetNames(f *ir.Func) {
for _, param := range f.Params {
// clear ID of unnamed function parameter.
if param.IsUnnamed() {
param.SetName("")
}
}
for _, block := range f.Blocks {
// clear ID of unnamed basic block.
if block.IsUnnamed() {
block.SetName("")
}
for _, inst := range block.Insts {
if inst, ok := inst.(Ident); ok {
// clear ID of unnamed variable.
if inst.IsUnnamed() {
inst.SetName("")
}
}
}
}
}