1package ssa
2
3import (
4 "fmt"
5 "strings"
6)
7
8// Signature is a function prototype.
9type Signature struct {
10 // ID is a unique identifier for this signature used to lookup.
11 ID SignatureID
12 // Params and Results are the types of the parameters and results of the function.
13 Params, Results []Type
14
15 // used is true if this is used by the currently-compiled function.
16 // Debugging only.
17 used bool
18}
19
20// String implements fmt.Stringer.
21func (s *Signature) String() string {
22 str := strings.Builder{}
23 str.WriteString(s.ID.String())
24 str.WriteString(": ")
25 if len(s.Params) > 0 {
26 for _, typ := range s.Params {
27 str.WriteString(typ.String())
28 }
29 } else {
30 str.WriteByte('v')
31 }
32 str.WriteByte('_')
33 if len(s.Results) > 0 {
34 for _, typ := range s.Results {
35 str.WriteString(typ.String())
36 }
37 } else {
38 str.WriteByte('v')
39 }
40 return str.String()
41}
42
43// SignatureID is an unique identifier used to lookup.
44type SignatureID int
45
46// String implements fmt.Stringer.
47func (s SignatureID) String() string {
48 return fmt.Sprintf("sig%d", s)
49}