summaryrefslogtreecommitdiffstats
path: root/src/cmd/compile/internal/inline/inlheur/funcprop_string.go
blob: d16e4d3378194b01882d91340d44af24840eed42 (plain)
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
// Copyright 2023 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package inlheur

import (
	"fmt"
	"strings"
)

func (fp *FuncProps) String() string {
	return fp.ToString("")
}

func (fp *FuncProps) ToString(prefix string) string {
	var sb strings.Builder
	if fp.Flags != 0 {
		fmt.Fprintf(&sb, "%sFlags %s\n", prefix, fp.Flags)
	}
	flagSliceToSB[ParamPropBits](&sb, fp.ParamFlags,
		prefix, "ParamFlags")
	flagSliceToSB[ResultPropBits](&sb, fp.ResultFlags,
		prefix, "ResultFlags")
	return sb.String()
}

func flagSliceToSB[T interface {
	~uint32
	String() string
}](sb *strings.Builder, sl []T, prefix string, tag string) {
	var sb2 strings.Builder
	foundnz := false
	fmt.Fprintf(&sb2, "%s%s\n", prefix, tag)
	for i, e := range sl {
		if e != 0 {
			foundnz = true
		}
		fmt.Fprintf(&sb2, "%s  %d %s\n", prefix, i, e.String())
	}
	if foundnz {
		sb.WriteString(sb2.String())
	}
}