|
| 1 | +(* |
| 2 | + * Pass Simulation Framework — Definitions |
| 3 | + * |
| 4 | + * Generic block→function lifting for pass correctness proofs, |
| 5 | + * parameterized by state relation R. |
| 6 | + * |
| 7 | + * TOP-LEVEL: |
| 8 | + * lift_result — lift state relation R through exec_result |
| 9 | + * block_map_transform — MAP f over block instructions |
| 10 | + * function_map_transform — MAP bt over function blocks |
| 11 | + * inst_simulates — per-instruction simulation predicate (param by R) |
| 12 | + * block_simulates — whole-block simulation predicate (param by R) |
| 13 | + *) |
| 14 | + |
| 15 | +Theory passSimulationDefs |
| 16 | +Ancestors |
| 17 | + stateEquiv execEquiv venomSem venomInst |
| 18 | + |
| 19 | +(* ===== Result relation ===== *) |
| 20 | + |
| 21 | +(* Lift state relation R through exec_result. |
| 22 | + result_equiv = lift_result state_equiv |
| 23 | + result_equiv_except fresh = lift_result (state_equiv_except fresh) *) |
| 24 | +Definition lift_result_def: |
| 25 | + lift_result R (OK s1) (OK s2) = R s1 s2 /\ |
| 26 | + lift_result R (Halt s1) (Halt s2) = R s1 s2 /\ |
| 27 | + lift_result R (Revert s1) (Revert s2) = R s1 s2 /\ |
| 28 | + lift_result R (Error e1) (Error e2) = T /\ |
| 29 | + lift_result R _ _ = F |
| 30 | +End |
| 31 | + |
| 32 | +(* ===== Transform definitions ===== *) |
| 33 | + |
| 34 | +(* Level 1: 1:1 instruction mapping *) |
| 35 | +Definition block_map_transform_def: |
| 36 | + block_map_transform f bb = |
| 37 | + bb with bb_instructions := MAP f bb.bb_instructions |
| 38 | +End |
| 39 | + |
| 40 | +(* Function transform: apply block transform to all blocks *) |
| 41 | +Definition function_map_transform_def: |
| 42 | + function_map_transform bt fn = |
| 43 | + fn with fn_blocks := MAP bt fn.fn_blocks |
| 44 | +End |
| 45 | + |
| 46 | +(* ===== Simulation predicates (parameterized by R) ===== *) |
| 47 | + |
| 48 | +(* Level 1: per-instruction simulation. |
| 49 | + f preserves lift_result R for every instruction and state, |
| 50 | + and preserves the is_terminator property. *) |
| 51 | +Definition inst_simulates_def: |
| 52 | + inst_simulates R f <=> |
| 53 | + (!inst s. lift_result R (step_inst inst s) (step_inst (f inst) s)) /\ |
| 54 | + (!inst. is_terminator inst.inst_opcode = |
| 55 | + is_terminator (f inst).inst_opcode) |
| 56 | +End |
| 57 | + |
| 58 | +(* Level 2: whole-block simulation. |
| 59 | + Running the transformed block gives an R-related result. *) |
| 60 | +Definition block_simulates_def: |
| 61 | + block_simulates R bt <=> |
| 62 | + !bb s. lift_result R (run_block bb s) (run_block (bt bb) s) |
| 63 | +End |
0 commit comments