github.com/llir/llvm@v0.3.6/ir/metadata/helper.go (about) 1 package metadata 2 3 import ( 4 "strings" 5 6 "github.com/llir/llvm/internal/enc" 7 "github.com/llir/llvm/ir/enum" 8 ) 9 10 // diFlagsString returns the string representation of the given debug 11 // information flags. 12 func diFlagsString(flags enum.DIFlag) string { 13 if flags == enum.DIFlagZero { 14 return flags.String() 15 } 16 var ss []string 17 if flag := flags & 0x3; flag != 0 { 18 ss = append(ss, flag.String()) 19 } 20 for mask := enum.DIFlagFirst; mask <= enum.DIFlagLast; mask <<= 1 { 21 if flags&mask != 0 { 22 ss = append(ss, mask.String()) 23 } 24 } 25 return strings.Join(ss, " | ") 26 } 27 28 // dispFlagsString returns the string representation of the given subprogram 29 // specific flags. 30 func dispFlagsString(flags enum.DISPFlag) string { 31 if flags == enum.DISPFlagZero { 32 return flags.String() 33 } 34 var ss []string 35 for mask := enum.DISPFlagFirst; mask <= enum.DISPFlagLast; mask <<= 1 { 36 if flags&mask != 0 { 37 ss = append(ss, mask.String()) 38 } 39 } 40 return strings.Join(ss, " | ") 41 } 42 43 // TODO: fix string representation for all enums which are defined in the 44 // grammar as `FooEnum | FooInt`, in the same way as dwarfTagString. 45 46 // dwarfTagString returns the string representation of the given Dwarf tag. 47 func dwarfTagString(tag enum.DwarfTag) string { 48 s := tag.String() 49 if strings.HasPrefix(s, "DwarfTag(") && strings.HasSuffix(s, ")") { 50 return s[len("DwarfTag(") : len(s)-len(")")] 51 } 52 return s 53 } 54 55 // quote returns s as a double-quoted string literal. 56 func quote(s string) string { 57 return enc.Quote([]byte(s)) 58 }