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§
- Display
Config - 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_hexand_fmt_hexhelper 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_varis the variable name for the fields dict (e.g., “fields”). - leaf_
guard_ python - Compute a guard condition for a leaf node in Python.
Returns
Noneif 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.