kit

kit
git clone https://git.ryansepassi.com/git/kit.git
Log | Files | Refs | README

arch.c (1384B)


      1 /* Public arch register name API. */
      2 
      3 #include "arch/arch.h"
      4 
      5 #include <kit/arch.h>
      6 #include <stddef.h>
      7 
      8 KitSlice kit_arch_register_name(KitArchKind arch, uint32_t dwarf_idx) {
      9   const ArchImpl* impl = arch_lookup(arch);
     10   const char* nm;
     11   if (!impl || !impl->register_name) return KIT_SLICE_NULL;
     12   nm = impl->register_name(dwarf_idx);
     13   return kit_slice_cstr(nm);
     14 }
     15 
     16 KitStatus kit_arch_register_index(KitArchKind arch, KitSlice name,
     17                                   uint32_t* idx_out) {
     18   const ArchImpl* impl;
     19   /* Internal register tables compare NUL-terminated names; name.s comes from
     20    * argv/interned/arena slices that carry a NUL at name.len. */
     21   if (!name.s || !idx_out) return KIT_INVALID;
     22   impl = arch_lookup(arch);
     23   if (!impl || !impl->register_index) return KIT_UNSUPPORTED;
     24   return impl->register_index(name.s, idx_out) == 0 ? KIT_OK : KIT_NOT_FOUND;
     25 }
     26 
     27 uint32_t kit_arch_register_count(KitArchKind arch) {
     28   const ArchImpl* impl = arch_lookup(arch);
     29   if (!impl || !impl->register_count) return 0;
     30   return impl->register_count();
     31 }
     32 
     33 KitStatus kit_arch_register_at(KitArchKind arch, uint32_t idx,
     34                                KitArchReg* out) {
     35   const ArchImpl* impl;
     36   if (!out) return KIT_INVALID;
     37   impl = arch_lookup(arch);
     38   if (!impl || !impl->register_at) return KIT_UNSUPPORTED;
     39   return impl->register_at(idx, out) == 0 ? KIT_OK : KIT_NOT_FOUND;
     40 }