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¶
Link two ir-modules, such that external references are resolved.
-
ppci.irutils.link.ir_link(ir_modules, name='linked') → ppci.ir.Module¶ Link IR-modules into a single module.
Example:
>>> from ppci import ir >>> from ppci.irutils import ir_link >>> m1 = ir.Module('m1') >>> m2 = ir.Module('m2') >>> m3 = ir_link([m1, m2])
Note that the original modules are not usable after this action.
TODO: TBD: do not modify source modules?
Functions to add instrumentation to IR code.
-
ppci.irutils.instrument.add_tracer(ir_module, trace_function_name='trace')¶ Instrument the given ir-module with a call tracer function
Constructing IR.
-
class
ppci.irutils.builder.Builder¶ Helper class for IR-code generators.
This class can assist in the generation of IR-code. It’s purpose is to simplify the language frontend, as well as to hide a bit of IR classes from the frontends.
-
emit(instruction: ppci.ir.Instruction) → ppci.ir.Instruction¶ Append an instruction to the current block
-
emit_add(a, b, ty)¶ Emit addition operation.
-
emit_binop(a, op, b, ty)¶ Emit a binary operation.
Parameters: - a – operand 1
- op – the operation to perform.
- b – operand 2, can be either a value or an int.
- ty – The type of a, b and the result.
Returns: The result value of the binary operation.
-
emit_cast(value, ty)¶ Emit a type cast instruction.
-
emit_const(value, ty)¶ Emit a constant.
-
emit_exit()¶ Emit exit instruction.
-
emit_jump(block)¶ Emit a jump instruction to the given block.
-
emit_load(address, ty, volatile=False)¶ Emit a load instruction.
-
emit_mul(a, b, ty)¶ Emit multiplication operation.
-
emit_return(value)¶ Emit a return instruction.
-
emit_sub(a, b, ty)¶ Emit subtract operation.
-
new_block(name=None)¶ Create a new block and add it to the current function
-
new_function(name, binding, return_ty)¶ Create a new function.
-
new_procedure(name, binding)¶ Create a new procedure.
-
set_location(location)¶ Set the current source code location.
All instructions emitted from now on will be associated with the given sourcecode.
-
use_location(location)¶ Use the location for all code generated within a context.
-
-
ppci.irutils.builder.split_block(block, pos=None, newname='splitblock')¶ Split a basic block into two which are connected.
Note to take care of phi instructions of successors and make sure to update those phi instructions.