| 1 | // Convert targets using the old CPUState reset to DeviceState reset |
| 2 | // |
| 3 | // Copyright Linaro Ltd 2020 |
| 4 | // This work is licensed under the terms of the GNU GPLv2 or later. |
| 5 | // |
| 6 | // spatch --macro-file scripts/cocci-macro-file.h \ |
| 7 | // --sp-file scripts/coccinelle/cpu-reset.cocci \ |
| 8 | // --keep-comments --smpl-spacing --in-place --include-headers --dir target |
| 9 | // |
| 10 | // For simplicity we assume some things about the code we're modifying |
| 11 | // that happen to be true for all our targets: |
| 12 | // * all cpu_class_set_parent_reset() callsites have a 'DeviceClass *dc' local |
| 13 | // * the parent reset field in the target CPU class is 'parent_reset' |
| 14 | // * no reset function already has a 'dev' local |
| 15 | |
| 16 | @@ |
| 17 | identifier cpu, x; |
| 18 | typedef CPUState; |
| 19 | @@ |
| 20 | struct x { |
| 21 | ... |
| 22 | - void (*parent_reset)(CPUState *cpu); |
| 23 | + DeviceReset parent_reset; |
| 24 | ... |
| 25 | }; |
| 26 | @ rule1 @ |
| 27 | identifier resetfn; |
| 28 | expression resetfield; |
| 29 | identifier cc; |
| 30 | @@ |
| 31 | - cpu_class_set_parent_reset(cc, resetfn, resetfield) |
| 32 | + device_class_set_parent_reset(dc, resetfn, resetfield) |
| 33 | @@ |
| 34 | identifier rule1.resetfn; |
| 35 | identifier cpu, cc; |
| 36 | typedef CPUState, DeviceState; |
| 37 | @@ |
| 38 | -resetfn(CPUState *cpu) |
| 39 | -{ |
| 40 | +resetfn(DeviceState *dev) |
| 41 | +{ |
| 42 | + CPUState *cpu = CPU(dev); |
| 43 | <... |
| 44 | - cc->parent_reset(cpu); |
| 45 | + cc->parent_reset(dev); |
| 46 | ...> |
| 47 | } |