intel: Move tools/decoder.[ch] to common/gen_decoder.[ch].
[mesa.git] / src / intel / tools / aubinator.c
index 05eb3d1be944efda14b2019faa5773f21858b03a..68fd18cd684b64db49c448ec83da4b4c13cb8208 100644 (file)
@@ -39,7 +39,7 @@
 
 #include "util/macros.h"
 
-#include "decoder.h"
+#include "common/gen_decoder.h"
 #include "intel_aub.h"
 #include "gen_disasm.h"
 
@@ -96,76 +96,11 @@ valid_offset(uint32_t offset)
 }
 
 static void
-print_dword_val(struct gen_field_iterator *iter, uint64_t offset,
-                int *dword_num)
+decode_group(struct gen_group *strct, const uint32_t *p, int starting_dword)
 {
-   struct gen_field *f;
-
-   f = iter->group->fields[iter->i - 1];
-   const int dword = f->start / 32;
-
-   if (*dword_num != dword) {
-      fprintf(outfile, "0x%08"PRIx64":  0x%08x : Dword %d\n",
-              offset + 4 * dword,  iter->p[dword], dword);
-      *dword_num = dword;
-   }
-}
-
-static char *
-print_iterator_values(struct gen_field_iterator *iter, int *idx)
-{
-    char *token = NULL;
-    if (strstr(iter->value, "struct") == NULL) {
-       fprintf(outfile, "    %s: %s\n", iter->name, iter->value);
-    } else {
-        token = strtok(iter->value, " ");
-        if (token != NULL) {
-            token = strtok(NULL, " ");
-            *idx = atoi(strtok(NULL, ">"));
-        } else {
-            token = NULL;
-        }
-        fprintf(outfile, "    %s:<struct %s>\n", iter->name, token);
-    }
-    return token;
-}
-
-static void
-decode_group(struct gen_spec *spec, struct gen_group *strct,
-             const uint32_t *p, int starting_dword)
-{
-   struct gen_field_iterator iter;
-   char *token = NULL;
-   int idx = 0, dword_num = 0;
-   uint64_t offset = 0;
-
-   if (option_print_offsets)
-      offset = (void *) p - gtt;
-   else
-      offset = 0;
-
-   gen_field_iterator_init(&iter, strct, p,
-                           option_color == COLOR_ALWAYS);
-   while (gen_field_iterator_next(&iter)) {
-      idx = 0;
-      print_dword_val(&iter, offset, &dword_num);
-      if (dword_num >= starting_dword)
-         token = print_iterator_values(&iter, &idx);
-      if (token != NULL) {
-         fprintf(outfile, "0x%08"PRIx64":  0x%08x : Dword %d\n",
-                 offset + 4 * idx, p[idx], idx);
-         struct gen_group *struct_val = gen_spec_find_struct(spec, token);
-         decode_group(spec, struct_val, &p[idx], 0);
-         token = NULL;
-      }
-   }
-}
-
-static void
-decode_structure(struct gen_spec *spec, struct gen_group *strct,
-                 const uint32_t *p)
-{
-   decode_group(spec, strct, p, 0);
+   uint64_t offset = option_print_offsets ? (void *) p - gtt : 0;
+   gen_print_group(outfile, strct, offset, p, starting_dword,
+                   option_color == COLOR_ALWAYS);
 }
 
 static void
@@ -195,7 +130,7 @@ dump_binding_table(struct gen_spec *spec, uint32_t offset)
          fprintf(outfile, "pointer %u: %08x\n", i, pointers[i]);
       }
 
-      decode_structure(spec, surface_state, gtt + start);
+      decode_group(surface_state, gtt + start, 0);
    }
 }
 
@@ -307,7 +242,7 @@ dump_samplers(struct gen_spec *spec, uint32_t offset)
    start = dynamic_state_base + offset;
    for (i = 0; i < 4; i++) {
       fprintf(outfile, "sampler state %d\n", i);
-      decode_structure(spec, sampler_state, gtt + start + i * 16);
+      decode_group(sampler_state, gtt + start + i * 16, 0);
    }
 }
 
@@ -331,7 +266,7 @@ handle_media_interface_descriptor_load(struct gen_spec *spec, uint32_t *p)
    descriptors = gtt + start;
    for (i = 0; i < length; i++, descriptors += 8) {
       fprintf(outfile, "descriptor %u: %08x\n", i, *descriptors);
-      decode_structure(spec, descriptor_structure, descriptors);
+      decode_group(descriptor_structure, descriptors, 0);
 
       start = instruction_base + descriptors[0];
       if (!valid_offset(start)) {
@@ -599,7 +534,7 @@ handle_3dstate_viewport_state_pointers_cc(struct gen_spec *spec, uint32_t *p)
    start = dynamic_state_base + (p[1] & ~0x1fu);
    for (uint32_t i = 0; i < 4; i++) {
       fprintf(outfile, "viewport %d\n", i);
-      decode_structure(spec, cc_viewport, gtt + start + i * 8);
+      decode_group(cc_viewport, gtt + start + i * 8, 0);
    }
 }
 
@@ -615,7 +550,7 @@ handle_3dstate_viewport_state_pointers_sf_clip(struct gen_spec *spec,
    start = dynamic_state_base + (p[1] & ~0x3fu);
    for (uint32_t i = 0; i < 4; i++) {
       fprintf(outfile, "viewport %d\n", i);
-      decode_structure(spec, sf_clip_viewport, gtt + start + i * 64);
+      decode_group(sf_clip_viewport, gtt + start + i * 64, 0);
    }
 }
 
@@ -628,7 +563,7 @@ handle_3dstate_blend_state_pointers(struct gen_spec *spec, uint32_t *p)
    blend_state = gen_spec_find_struct(spec, "BLEND_STATE");
 
    start = dynamic_state_base + (p[1] & ~0x3fu);
-   decode_structure(spec, blend_state, gtt + start);
+   decode_group(blend_state, gtt + start, 0);
 }
 
 static void
@@ -640,7 +575,7 @@ handle_3dstate_cc_state_pointers(struct gen_spec *spec, uint32_t *p)
    cc_state = gen_spec_find_struct(spec, "COLOR_CALC_STATE");
 
    start = dynamic_state_base + (p[1] & ~0x3fu);
-   decode_structure(spec, cc_state, gtt + start);
+   decode_group(cc_state, gtt + start, 0);
 }
 
 static void
@@ -652,7 +587,7 @@ handle_3dstate_scissor_state_pointers(struct gen_spec *spec, uint32_t *p)
    scissor_rect = gen_spec_find_struct(spec, "SCISSOR_RECT");
 
    start = dynamic_state_base + (p[1] & ~0x1fu);
-   decode_structure(spec, scissor_rect, gtt + start);
+   decode_group(scissor_rect, gtt + start, 0);
 }
 
 static void
@@ -663,7 +598,7 @@ handle_load_register_imm(struct gen_spec *spec, uint32_t *p)
    if (reg != NULL) {
       fprintf(outfile, "register %s (0x%x): 0x%x\n",
               reg->name, reg->register_offset, p[2]);
-      decode_structure(spec, reg, &p[2]);
+      decode_group(reg, &p[2], 0);
    }
 }
 
@@ -787,7 +722,7 @@ parse_commands(struct gen_spec *spec, uint32_t *cmds, int size, int engine)
               gen_group_get_name(inst), reset_color);
 
       if (option_full_decode) {
-         decode_group(spec, inst, p, 1);
+         decode_group(inst, p, 1);
 
          for (i = 0; i < ARRAY_LENGTH(custom_handlers); i++) {
             if (gen_group_get_opcode(inst) == custom_handlers[i].opcode)