IR-code utilities

The ppci.irutils module contains function to handle IR-code such as read_module() and verify_module(). Also the Builder serves as a helper class to construct ir modules.

Module reference

Some utilities for ir-code.

class ppci.irutils.Builder

Base class for ir code generators

emit(instruction: ppci.ir.Instruction) → ppci.ir.Instruction

Append an instruction to the current block

new_block(name=None)

Create a new block and add it to the current function

exception ppci.irutils.IrParseException
class ppci.irutils.Reader

Read IR-code from file

define_value(v)

Define a value

parse_assignment()

Parse an instruction with shape ‘ty’ ‘name’ ‘=’ …

parse_block(function)

Read a single block from file

parse_function()

Parse a function or procedure

parse_module()

Entry for recursive descent parser

parse_statement()

Parse a single instruction line

parse_type()

Parse a single type

read(f) → ppci.ir.Module

Read ir code from file f

class ppci.irutils.Verifier

Checks an ir module for correctness

block_dominates(one: ppci.ir.Block, another: ppci.ir.Block)

Check if this block dominates other block

instruction_dominates(one, another)

Checks if one instruction dominates another instruction

verify(module)

Verifies a module for some sanity

verify_block(block)

Verify block for correctness

verify_block_termination(block)

Verify that the block is terminated correctly

verify_function(function)

Verify all blocks in the function

verify_instruction(instruction, block)

Verify that instruction belongs to block and that all uses are preceeded by defs

verify_subroutine_call(instruction)

Check some properties of a function call

class ppci.irutils.Writer(file=None, extra_indent='')

Write ir-code to file

write(module: ppci.ir.Module, verify=True)

Write ir-code to file f

ppci.irutils.print_module(module, file=None, verify=True)

Print an ir-module as text

ppci.irutils.read_module(f) → ppci.ir.Module

Read an ir-module from file.

Parameters:f – A file like object ready to be read in text modus.
Returns:The loaded ir-module.
ppci.irutils.split_block(block, pos=None, newname='splitblock')

Split a basic block into two which are connected

ppci.irutils.verify_module(module: ppci.ir.Module)

Check if the module is properly constructed