// SPDX-License-Identifier: MPL-2.0
#include "memory/pez/pez_debug.h"
#include "kernel/log.h"
SH_STATUS sh_pez_debug_send_alloc(sh_pez_debug_ALLOC *alloc) {
  sh_log_uint8_hex(SH_PEZ_DEBUG_ALLOC_HEADER);
  sh_log_byte('a');
  sh_log_uint32_hex(alloc->size_asked);
  sh_log_byte('a');
  sh_log_uint32_hex(alloc->found_region_start_index);
  sh_log_byte('a');
  sh_log_uint32_hex(alloc->found_region_size);
  sh_log_byte('a');
  sh_log_uint8_hex(alloc->is_exact_fit);
  sh_log_byte('a');
  sh_log_uint32_hex(alloc->remaining_size);
  sh_log_byte('a');
  sh_log_uint32_hex(alloc->new_start);
  sh_log_byte('a');
  sh_log_uint32_hex(alloc->reg_idx);
  sh_log_byte('\n');
  return SH_STATUS_SUCCESS;
}
SH_STATUS sh_pez_debug_send_free(sh_pez_debug_FREE *free) {
  sh_log_uint8_hex(SH_PEZ_DEBUG_FREE_HEADER);
  sh_log_byte('a');
  sh_log_uint32_hex(free->region_start_freeed);
  sh_log_byte('a');
  sh_log_uint32_hex(free->size_freeed);
  sh_log_byte('a');
  sh_log_uint32_hex(free->left_region_idx);
  sh_log_byte('a');
  sh_log_uint32_hex(free->right_region_idx);
  sh_log_byte('a');
  sh_log_uint32_hex(free->left_region_size);
  sh_log_byte('a');
  sh_log_uint32_hex(free->right_region_size);
  sh_log_byte('a');
  sh_log_uint32_hex(free->left_region_start);
  sh_log_byte('a');
  sh_log_uint32_hex(free->right_region_start);
  sh_log_byte('a');
  sh_log_uint32_hex(free->final_inserted_region_idx);
  sh_log_byte('a');
  sh_log_uint32_hex(free->final_inserted_region_start);
  sh_log_byte('a');
  sh_log_uint32_hex(free->final_inserted_region_size);
  sh_log_byte('a');
  sh_log_uint8_hex(free->was_right_region_object_freeed);
  sh_log_byte('a');
  sh_log_uint8_hex(free->was_new_region_object_allocated);
  sh_log_byte('a');
  sh_log_uint32_hex(free->new_reg_obj_start);
  sh_log_byte('a');
  sh_log_uint32_hex(free->new_reg_obj_size);
  sh_log_byte('\n');
  return SH_STATUS_SUCCESS;
}
SH_STATUS sh_pez_debug_send_size_list(sh_pez_debug_SIZE_LIST *size_list) {
  sh_log_uint8_hex(SH_PEZ_DEBUG_SIZE_LIST_HEADER);
  sh_log_byte('a');
  sh_log_uint32_hex(size_list->size);
  sh_log_byte('a');
  sh_log_uint32_hex(size_list->count);
  sh_log_byte('\n');
  for (sh_iter64 i=0;i<size_list->count;i++) {
    sh_log_uint32_hex(size_list->regions[i].start);
    sh_log_byte('a');
    sh_log_uint32_hex(size_list->regions[i].size);
    sh_log_byte('a');
    sh_log_uint32_hex(size_list->regions[i].idx);
    sh_log_byte('a');
    sh_log_uint32_hex(size_list->regions[i].next_idx);
    sh_log_byte('\n');
  }
  sh_log_byte('\n');
  return SH_STATUS_SUCCESS;
}
SH_STATUS sh_pez_debug_send_boundary_radix(sh_pez_debug_BOUNDARY_RADIX *boundary_radix) {
  sh_log_uint8_hex(SH_PEZ_DEBUG_BOUNDARY_RADIX_HEADER);
  sh_log_byte('a');
  sh_log_uint32_hex(boundary_radix->count);
  sh_log_byte('\n');
  for (sh_iter64 i=0;i<boundary_radix->count;i++) {
    sh_log_uint32_hex(boundary_radix->regions[i].pos_start);
    sh_log_byte('a');
    sh_log_uint32_hex(boundary_radix->regions[i].idx_start);
    sh_log_byte('a');
    sh_log_uint32_hex(boundary_radix->regions[i].prev_start);
    sh_log_byte('a');
    sh_log_uint32_hex(boundary_radix->regions[i].pos_end);
    sh_log_byte('a');
    sh_log_uint32_hex(boundary_radix->regions[i].idx_end);
    sh_log_byte('a');
    sh_log_uint32_hex(boundary_radix->regions[i].prev_end);
    sh_log_byte('\n');
  }
  sh_log_byte('\n');
  return SH_STATUS_SUCCESS;
}
SH_STATUS sh_pez_debug_send_bitmap(sh_pez_debug_BITMAP *bitmap) {
  sh_log_uint8_hex(SH_PEZ_DEBUG_BITMAP_REGIONS_HEADER);
  sh_log_byte('a');
  sh_log_uint32_hex(bitmap->count);
  sh_log_byte('\n');
  for (sh_iter64 i=0;i<bitmap->count;i++) {
    sh_log_uint32_hex(bitmap->regions[i].start);
    sh_log_byte('a');
    sh_log_uint32_hex(bitmap->regions[i].size);
    sh_log_byte('\n');
  }
  sh_log_byte('\n');
  return SH_STATUS_SUCCESS;
}
