1 //===- string.go - Stringer implementation for Type -----------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file implements the Stringer interface for the Type type.
11 //===----------------------------------------------------------------------===//
17 func (t TypeKind
) String() string {
22 return "FloatTypeKind"
24 return "DoubleTypeKind"
25 case X86_FP80TypeKind
:
26 return "X86_FP80TypeKind"
28 return "FP128TypeKind"
29 case PPC_FP128TypeKind
:
30 return "PPC_FP128TypeKind"
32 return "LabelTypeKind"
34 return "IntegerTypeKind"
35 case FunctionTypeKind
:
36 return "FunctionTypeKind"
38 return "StructTypeKind"
40 return "ArrayTypeKind"
42 return "PointerTypeKind"
44 return "VectorTypeKind"
45 case MetadataTypeKind
:
46 return "MetadataTypeKind"
51 func (t Type
) String() string {
52 ts
:= typeStringer
{s
: make(map[Type
]string)}
53 return ts
.typeString(t
)
56 type typeStringer
struct {
60 func (ts
*typeStringer
) typeString(t Type
) string {
61 if s
, ok
:= ts
.s
[t
]; ok
{
67 s
= s
[:len(s
)-len("Kind")]
71 s
+= fmt
.Sprintf("(%v[%v])", ts
.typeString(t
.ElementType()), t
.ArrayLength())
73 s
+= fmt
.Sprintf("(%v)", ts
.typeString(t
.ElementType()))
74 case FunctionTypeKind
:
75 params
:= t
.ParamTypes()
78 s
+= fmt
.Sprintf("%v", ts
.typeString(params
[0]))
79 for i
:= 1; i
< len(params
); i
++ {
80 s
+= fmt
.Sprintf(", %v", ts
.typeString(params
[i
]))
83 s
+= fmt
.Sprintf("):%v", ts
.typeString(t
.ReturnType()))
85 if name
:= t
.StructName(); name
!= "" {
87 s
= fmt
.Sprintf("%%%s: %s", name
, s
)
89 etypes
:= t
.StructElementTypes()
91 if n
:= len(etypes
); n
> 0 {
92 s
+= ts
.typeString(etypes
[0])
93 for i
:= 1; i
< n
; i
++ {
94 s
+= fmt
.Sprintf(", %v", ts
.typeString(etypes
[i
]))
99 s
+= fmt
.Sprintf("(%d bits)", t
.IntTypeWidth())