Skip to content

An experimental LLVM-IR code fragment generator using the SMT solver Z3.

Notifications You must be signed in to change notification settings

silab-nitkc/pukeko

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pukeko

pukeko is an experimental code fragment generator. Pukeko takes an assembly opcode name, and returns a code fragment that has the same function as the input opcode. The code fragments are generated using the SMT solver Z3.

Requirements

  • Python 3.9 (or higher)
  • z3py
  • docopt

Usage

Overview:
    Generates an LLVM IR-like code fragment that can replace the input opcode.

Usage:
    generate <opname> [-l <L>] [-a] [-f]

Options:
    opname  : Opcode name of target instruction (add, sub, or, and, xor)
    -l <L>  : Length of instruction sequence to be generated [default: 10]
    -f      : Output formulas
    -a      : (Experimental) Generate all possible instruction sequences

Example

python generate.py add -l 5 -f

Example of application

This is an example of replacing an add instruction of an LLVM IR program with a code fragment generated by pukeko.

  %1 = load i32, i32* %x, align 4
  %2 = load i32, i32* %x, align 4
- %3 = add i32 %1, %2
+ %3 = and i32 %1, %2
+ %4 = and i32 %3, %2
+ %5 = sub i32 %4, %3
+ %6 = and i32 %1, %5
+ %7 = and i32 %1, %6
+ %8 = or i32 %7, %6
+ %9 = sub i32 %8, %5
+ %10 = and i32 %1, %9
+ %11 = or i32 %10, %1
+ %12 = add i32 %11, %2

About

An experimental LLVM-IR code fragment generator using the SMT solver Z3.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published