Bytecode pattern detector that identifies loops, counters, accumulators, swaps, conditionals, and more in FLUX programs.
flux-signatures is a Python module that analyzes FLUX bytecode to detect common programming patterns — loops, counters, accumulators, multiply-accumulate (MAC), swap idioms, conditional branches, stack-heavy code, and more. It produces a SignatureResult with confidence scores, complexity estimates, and cycle predictions.
Static analysis complements dynamic tools in the FLUX toolchain:
flux-decompilershows what instructions exist; signatures shows what patterns they formflux-timelineconfirms patterns dynamically; signatures detects them staticallyflux-profilermeasures performance; signatures estimates complexity beforehandflux-coverageensures all patterns are exercised in testingflux-debuggeruses pattern knowledge to set intelligent breakpoints
| Feature | Description |
|---|---|
| Loop Detection | Identifies backward jumps (95% confidence) |
| Counter Pattern | DEC + JNZ combinations |
| Accumulator/MAC | ADD/MUL with feedback to self |
| Swap Idiom | PUSH, PUSH, POP, POP register exchange |
| Conditional Branches | CMP + JZ/JNZ combinations |
| Complexity Score | 0.0–1.0 based on loops, branches, arithmetic |
| Cycle Estimation | Rough execution cycle prediction |
| Markdown Reports | to_markdown() for human-readable analysis |
| Tag System | Automatic tagging (loop, counter, accumulator, etc.) |
from flux_signatures import SignatureDetector
detector = SignatureDetector()
# Analyze a factorial loop
bytecode = [0x18, 0, 6, 0x18, 1, 1, 0x22, 1, 1, 0, 0x09, 0, 0x3D, 0, -6, 0, 0x00]
result = detector.analyze(bytecode)
print(f"Complexity: {result.complexity_score:.0%}")
print(f"Estimated cycles: {result.estimated_cycles}")
print(f"Tags: {', '.join(result.tags)}")
for pattern in result.patterns:
print(f" {pattern.pattern_type.value}: {pattern.description} "
f"({pattern.confidence:.0%} confidence)")
# Generate markdown report
print(result.to_markdown())python -m pytest tests/ -v
# or
python signatures.pyflux-decompiler— Bytecode to assemblyflux-timeline— Dynamic execution tracingflux-profiler— Performance profilingflux-coverage— Code coverage analysisflux-debugger— Interactive step debugger
Part of the SuperInstance FLUX fleet.