Helper function for rendering assembly.
(self, listing: Sequence[InsnLike], pc: int, prediction: Prophecy)
| 147 | print(f'SP + {offset:#04x} │ {address:#010x} : {value_str}{f" {RARROW} {deref_str}" if deref_str else ""}') |
| 148 | |
| 149 | def render_assembly(self, listing: Sequence[InsnLike], pc: int, prediction: Prophecy) -> None: |
| 150 | """Helper function for rendering assembly. |
| 151 | """ |
| 152 | |
| 153 | def __render_asm_line(insn: InsnLike) -> str: |
| 154 | """Helper function for rendering assembly instructions, indicates where we are and |
| 155 | the branch prediction provided by branch predictor |
| 156 | """ |
| 157 | |
| 158 | trace_line = f"{insn.address:#010x} │ {insn.bytes.hex():18s} {insn.mnemonic:12} {insn.op_str:35s}" |
| 159 | |
| 160 | cursor = '' # current instruction cursor |
| 161 | brmark = '' # branching mark |
| 162 | |
| 163 | if insn.address == pc: |
| 164 | cursor = CURSOR |
| 165 | |
| 166 | if prediction.going: |
| 167 | # branch target might be None in case it should have been |
| 168 | # read from memory but that memory could not be reached |
| 169 | bmark = '?' if prediction.where is None else (GOING_DN if prediction.where > pc else GOING_UP) |
| 170 | |
| 171 | # apply some colors |
| 172 | brmark = f'{color.RED}{bmark}{color.RESET}' |
| 173 | |
| 174 | # <DEBUG> |
| 175 | where = '?' if prediction.where is None else f'{prediction.where:#010x}' |
| 176 | |
| 177 | print(f'prediction: {f"taken, {where}" if prediction.going else "not taken"}') |
| 178 | # </DEBUG> |
| 179 | |
| 180 | return f"{brmark:1s} {cursor:1s} {color.DARKGRAY}{trace_line}{color.RESET}" |
| 181 | |
| 182 | for insn in listing: |
| 183 | print(__render_asm_line(insn)) |
| 184 | |
| 185 | |
| 186 | class ContextRender(Context, Render): |
no outgoing calls
no test coverage detected