Documentation
¶
Index ¶
- Constants
- Variables
- func BuildSSAFromPackages(initialPkgs []*packages.Package) (*ssa.Program, *ssa.Package, error)
- func IsComparisonOp(op token.Token) bool
- func IsConst(v ssa.Value, target constant.Value) bool
- func ReleaseCanonicalizer(c *Canonicalizer)
- 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
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 BuildSSAFromPackages ¶
BuildSSAFromPackages constructs Static Single Assignment form from loaded Go packages.
func IsComparisonOp ¶
IsComparisonOp identifies strict comparison operators.
func ReleaseCanonicalizer ¶
func ReleaseCanonicalizer(c *Canonicalizer)
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.