Skip to main content

Module codegen_python

Module codegen_python 

Source
Expand description

Shared Python code generation helpers.

Provides reusable functions for emitting Python code from the chipi IR. Used by the IDA backend (and future Binary Ninja backend).

Structs§

DisplayConfig
Configuration for display formatting in generated Python code.

Functions§

apply_transforms_python
Apply chipi transforms to a Python expression.
emit_decode_function
Generate the Python _decode(data) function body using the decision tree.
emit_display_format_helpers
Emit _fmt_signed_hex and _fmt_hex helper functions if needed.
emit_format_function
Generate the _format_insn(itype, fields) Python function. Returns (mnemonic_str, operands_str).
emit_guard_python
Generate a Python guard condition from a Guard.
emit_map_functions_python
Generate Python dict-based map (lookup) functions.
emit_rotate_helpers
Emit a _rotate_right(val, amt, width) Python helper function.
emit_sign_extend_helper
Emit a _sign_extend(val, bits) Python helper function.
emit_subdecoder_python
Generate a Python sub-decoder dispatch function.
escape_python_fstr
Escape a string for use inside Python f-string literals.
escape_python_str
Escape a string for use inside Python string literals.
expr_to_python
Convert a FormatExpr to a Python expression string.
extract_expr_python
Generate a Python expression to extract bits from ranges.
format_pieces_to_python_expr
Convert format pieces to a Python expression (concatenated string). fields_var is the variable name for the fields dict (e.g., “fields”).
leaf_guard_python
Compute a guard condition for a leaf node in Python. Returns None if no guard is needed.
needs_rotate_helpers
Check if any instruction uses rotate builtins.
needs_sign_extend
Check if any instruction uses sign_extend transforms.
to_snake_case
Convert a name to snake_case.