Documentation
¶
Index ¶
- Constants
- Variables
- func BuildProgram(initialPkgs []*packages.Package) (*ssa.Program, error)
- func BuildSSAFromPackages(initialPkgs []*packages.Package) (*ssa.Program, *ssa.Package, error)deprecated
- func FieldName(x ssa.Value, index int) string
- func IsComparisonOp(op token.Token) bool
- func IsConst(v ssa.Value, target constant.Value) bool
- func ReleaseCanonicalizer(c *Canonicalizer)
- func StableFuncName(fn *ssa.Function) string
- type Canonicalizer
- func (c *Canonicalizer) AnalyzeLoops(fn *ssa.Function)
- func (c *Canonicalizer) ApplyVirtualControlFlowFromState(swappedBlocks map[*ssa.BasicBlock]bool, ...)
- func (c *Canonicalizer) CanonicalizeFunction(fn *ssa.Function) string
- func (c *Canonicalizer) NormalizeInductionVariables()
- func (c *Canonicalizer) NormalizeOperand(v ssa.Value, context ssa.Instruction) string
- type LiteralPolicy
- type TypeParamRenamer
Constants ¶
const MaxLoopAnalysisDepth = 64
MaxLoopAnalysisDepth prevents stack overflow attacks from deeply nested loops during IV normalization.
const MaxRenamerDepth = 20
Variables ¶
var DefaultLiteralPolicy = LiteralPolicy{ AbstractControlFlowComparisons: true, KeepSmallIntegerIndices: true, KeepReturnStatusValues: true, KeepStringLiterals: false, SmallIntMin: -16, SmallIntMax: 16, AbstractOtherTypes: true, }
DefaultLiteralPolicy preserves small integers used for indexing and status codes while masking magic numbers and large constants.
var KeepAllLiteralsPolicy = LiteralPolicy{ AbstractControlFlowComparisons: false, KeepSmallIntegerIndices: true, KeepReturnStatusValues: true, KeepStringLiterals: true, SmallIntMin: math.MinInt64, SmallIntMax: math.MaxInt64, AbstractOtherTypes: false, }
KeepAllLiteralsPolicy is designed for testing or exact matching.
Functions ¶
func BuildProgram ¶ added in v7.5.0
BuildProgram builds the SSA program of the loaded packages: their bodies, and their dependencies' members without bodies. Package errors don't stop it, since SSA skips ill-typed packages, but it fails when the first package could not be built, with the packages' errors in the message.
func BuildSSAFromPackages
deprecated
func FieldName ¶
FieldName names field index of x's struct type, where x is a struct or a pointer to one, as Field and FieldAddr select it. A field is identified by its name, not its position: reordering a struct's fields must not change a function that reads them, and reading a different field that moved into the old one's position must. Falls back to "#index" when x's type is not a struct.
func IsComparisonOp ¶
IsComparisonOp identifies strict comparison operators.
func ReleaseCanonicalizer ¶
func ReleaseCanonicalizer(c *Canonicalizer)
func StableFuncName ¶
StableFuncName is fn.RelString(nil), except that a generic instance's receiver and type arguments are rendered as instanceType renders them, so the name does not depend on which caller SSA built the instance for first.
Types ¶
type Canonicalizer ¶
type Canonicalizer struct {
Policy LiteralPolicy
StrictMode bool
VirtualizedInstrs map[ssa.Instruction]bool
// contains filtered or unexported fields
}
func AcquireCanonicalizer ¶
func AcquireCanonicalizer(policy LiteralPolicy) *Canonicalizer
func NewCanonicalizer ¶
func NewCanonicalizer(policy LiteralPolicy) *Canonicalizer
func (*Canonicalizer) AnalyzeLoops ¶
func (c *Canonicalizer) AnalyzeLoops(fn *ssa.Function)
func (*Canonicalizer) ApplyVirtualControlFlowFromState ¶
func (c *Canonicalizer) ApplyVirtualControlFlowFromState(swappedBlocks map[*ssa.BasicBlock]bool, virtualBinOps map[*ssa.BinOp]token.Token)
func (*Canonicalizer) CanonicalizeFunction ¶
func (c *Canonicalizer) CanonicalizeFunction(fn *ssa.Function) string
func (*Canonicalizer) NormalizeInductionVariables ¶
func (c *Canonicalizer) NormalizeInductionVariables()
func (*Canonicalizer) NormalizeOperand ¶
func (c *Canonicalizer) NormalizeOperand(v ssa.Value, context ssa.Instruction) string
type LiteralPolicy ¶
type LiteralPolicy struct {
AbstractControlFlowComparisons bool
KeepSmallIntegerIndices bool
KeepReturnStatusValues bool
KeepStringLiterals bool
SmallIntMin int64
SmallIntMax int64
AbstractOtherTypes bool
}
LiteralPolicy defines the configurable strategy for determining which literal values should be abstracted into placeholders during canonicalization.
func (*LiteralPolicy) IsSmallInt ¶
func (p *LiteralPolicy) IsSmallInt(c constant.Value) bool
IsSmallInt checks if the constant fits within the configured small integer range.
func (*LiteralPolicy) ShouldAbstract ¶
func (p *LiteralPolicy) ShouldAbstract(c *ssa.Const, usageContext ssa.Instruction) bool
ShouldAbstract decides whether a given constant should be replaced by a placeholder.
type TypeParamRenamer ¶
type TypeParamRenamer struct {
// contains filtered or unexported fields
}
TypeParamRenamer rewrites the type parameters in scope in a generic function, its receiver's and its enclosing functions', to placeholders named by position ("$0", "$1"), so a type-parameter rename such as List[T] to List[E] does not change how the function's types are rendered. It substitutes type objects rather than text, so a field, method or package-level type that shares a type parameter's name is left as is.
func NewTypeParamRenamer ¶
func NewTypeParamRenamer(fn *ssa.Function) *TypeParamRenamer
NewTypeParamRenamer returns the renamer for fn, or nil when no type parameter is in scope; a nil renamer leaves every type unchanged.