ir

package
v3.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 1, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const MaxLoopAnalysisDepth = 64

MaxLoopAnalysisDepth prevents stack overflow attacks from deeply nested loops during IV normalization.

View Source
const MaxRenamerDepth = 20

Variables

View Source
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.

View Source
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

func BuildSSAFromPackages(initialPkgs []*packages.Package) (*ssa.Program, *ssa.Package, error)

BuildSSAFromPackages constructs Static Single Assignment form from loaded Go packages.

func IsComparisonOp

func IsComparisonOp(op token.Token) bool

IsComparisonOp identifies strict comparison operators.

func IsConst

func IsConst(v ssa.Value, target constant.Value) bool

IsConst verifies if an ssa.Value is a constant equal to a given target.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL