isaspec: Add callback after decoding an instruction
authorConnor Abbott <cwabbott0@gmail.com>
Fri, 23 Jun 2023 11:49:32 +0000 (13:49 +0200)
committerMarge Bot <emma+marge@anholt.net>
Fri, 28 Jul 2023 18:41:58 +0000 (18:41 +0000)
This will be used by afuc for printing register decodings in a comment.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23949>

src/compiler/isaspec/isaspec.h
src/compiler/isaspec/isaspec_decode_impl.c
src/freedreno/ir3/disasm-a3xx.c
src/freedreno/isa/ir3-disasm.c

index da4ed3f..74902ed 100644 (file)
@@ -102,7 +102,12 @@ struct isa_decode_options {
        /**
         * Callback prior to instruction decode
         */
-       void (*instr_cb)(void *data, unsigned n, void *instr);
+       void (*pre_instr_cb)(void *data, unsigned n, void *instr);
+
+       /**
+        * Callback after instruction decode
+        */
+       void (*post_instr_cb)(void *data, unsigned n, void *instr);
 
        /**
         * callback for undefined instructions
index 3b97931..3fd356b 100644 (file)
@@ -768,8 +768,8 @@ decode(struct decode_state *state, void *bin, int sz)
                         */
                        if ((BITSET_TEST(state->call_targets, state->n) || entrypoint) &&
                            state->n != 0) {
-                               if (state->options->instr_cb) {
-                                       state->options->instr_cb(state->options->cbdata,
+                               if (state->options->pre_instr_cb) {
+                                       state->options->pre_instr_cb(state->options->cbdata,
                                                        state->n, instr.bitset);
                                }
                                isa_print(&state->print, "\n");
@@ -777,8 +777,8 @@ decode(struct decode_state *state, void *bin, int sz)
 
                        while (state->next_entrypoint != state->end_entrypoint &&
                               state->next_entrypoint->offset == state->n) {
-                               if (state->options->instr_cb) {
-                                       state->options->instr_cb(state->options->cbdata,
+                               if (state->options->pre_instr_cb) {
+                                       state->options->pre_instr_cb(state->options->cbdata,
                                                        state->n, instr.bitset);
                                }
                                isa_print(&state->print, "%s:\n", state->next_entrypoint->name);
@@ -786,24 +786,24 @@ decode(struct decode_state *state, void *bin, int sz)
                        }
 
                        if (BITSET_TEST(state->call_targets, state->n)) {
-                               if (state->options->instr_cb) {
-                                       state->options->instr_cb(state->options->cbdata,
+                               if (state->options->pre_instr_cb) {
+                                       state->options->pre_instr_cb(state->options->cbdata,
                                                        state->n, instr.bitset);
                                }
                                isa_print(&state->print, "fxn%d:\n", state->n);
                        }
 
                        if (BITSET_TEST(state->branch_targets, state->n)) {
-                               if (state->options->instr_cb) {
-                                       state->options->instr_cb(state->options->cbdata,
+                               if (state->options->pre_instr_cb) {
+                                       state->options->pre_instr_cb(state->options->cbdata,
                                                        state->n, instr.bitset);
                                }
                                isa_print(&state->print, "l%d:\n", state->n);
                        }
                }
 
-               if (state->options->instr_cb) {
-                       state->options->instr_cb(state->options->cbdata, state->n, instr.bitset);
+               if (state->options->pre_instr_cb) {
+                       state->options->pre_instr_cb(state->options->cbdata, state->n, instr.bitset);
                }
 
                const struct isa_bitset *b = find_bitset(state, __instruction, instr);
@@ -825,6 +825,11 @@ decode(struct decode_state *state, void *bin, int sz)
                } else {
                        errors = 0;
                }
+
+               if (state->options->post_instr_cb) {
+                       state->options->post_instr_cb(state->options->cbdata, state->n, instr.bitset);
+               }
+
                isa_print(&state->print, "\n");
 
                pop_scope(scope);
index a3b09e6..b2f16a4 100644 (file)
@@ -581,7 +581,7 @@ disasm_a3xx_stat(uint32_t *dwords, int sizedwords, int level, FILE *out,
       .max_errors = 5,
       .branch_labels = true,
       .field_cb = disasm_field_cb,
-      .instr_cb = disasm_instr_cb,
+      .pre_instr_cb = disasm_instr_cb,
    };
    struct disasm_ctx ctx = {
       .out = out,
index b1a1a1f..d49f238 100644 (file)
@@ -50,7 +50,7 @@ main(int argc, char **argv)
        isa_decode(raw, sz, stdout, &(struct isa_decode_options) {
                .show_errors = true,
                .branch_labels = true,
-               .instr_cb = disasm_instr_cb,
+               .pre_instr_cb = disasm_instr_cb,
        });
 
        return 0;