Skip to main content

Utilities for dealing with live register analysis in GTIRB functions

Project description

gtirb-live-register-analysis

Overview

The gtirb-live-register-analysis package provides a Python API for live register analysis of GTIRB functions. A simple interface is also provided for working with gtirb-rewriting patches.

Supported ABIs

ISA File Format
X64 (x86-64) ELF

Getting Started

Generic Usage

from gtirb_live_register_analysis import LiveRegisterManager

reg_manager = LiveRegisterManager(module)

# Analyze function of interest
reg_manager.analyze(function)

# The sets of live and free registers can then be retrieved
live_regs = reg_manager.live_registers(function, block, instruction_idx)
free_regs = reg_manager.free_registers(function, block, instruction_idx)

Use with gtirb-rewriting patches

Wrap the decorator function around a patch function to assign free registers to be used as scratch registers. When there are not enough free registers, the library falls back to gtirb-rewriting, which generates code to spill/restore the excess registers to stack.

@reg_manager.allocate_registers(function, block, instruction_idx)
@patch_constraints(x86_syntax=X86Syntax.INTEL, scratch_registers=6)
def my_patch(self, ctx: InsertionContext):
    reg1, reg2, reg3, reg4, reg5, reg6 = ctx.scratch_registers
    return f"""
        xor {reg1}, {reg1}
        xor {reg2}, {reg2}
        xor {reg3}, {reg3}
        xor {reg4}, {reg4}
        xor {reg5}, {reg5}
        xor {reg6}, {reg6}
    """

rewriting_ctx.insert_at(block, offset, Patch.from_function(my_patch))

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gtirb-live-register-analysis-0.0.7.tar.gz (17.1 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file gtirb-live-register-analysis-0.0.7.tar.gz.

File metadata

File hashes

Hashes for gtirb-live-register-analysis-0.0.7.tar.gz
Algorithm Hash digest
SHA256 c10f2f7c605a2532b23eee0cd2eb8561767392270efccd61fd57cd2b40ebc929
MD5 0144061eaabef19cfdfa13b398580afa
BLAKE2b-256 9efb658690aa05438cb054c862f96a3601780fa096b43e684aa825e5c31803eb

See more details on using hashes here.

File details

Details for the file gtirb_live_register_analysis-0.0.7-py3-none-any.whl.

File metadata

File hashes

Hashes for gtirb_live_register_analysis-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 21af944713f2ef1b3cced8141786018f75ea5e918bb6e1772c890a265a6757dd
MD5 0930e774a808f973f964e0da71e3de27
BLAKE2b-256 619f62b34710840ca00fb02941bcb48b899aa00abb6c527d2762c2aa0dd9dfe5

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page