kit

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

abi_internal.h (2673B)


      1 #ifndef KIT_ABI_INTERNAL_H
      2 #define KIT_ABI_INTERNAL_H
      3 
      4 #include "abi/abi.h"
      5 
      6 /* Internal: per-ABI dispatch table.
      7  *
      8  * Selected by abi_init based on (target.arch, target.os). The pieces here
      9  * are the parts that vary by ABI; the C-standard-driven scalar profile and
     10  * record layout live in abi.c and are shared. */
     11 
     12 typedef struct ABIVtable {
     13   /* Compute the ABIFuncInfo for a function type. The cache wrapper in
     14    * abi.c calls this once per CgTypeId and memoizes the result. */
     15   ABIFuncInfo* (*compute_func_info)(TargetABI*, KitCgTypeId fn);
     16   /* Optional. Return the byte width of each lane when a scalar has to be
     17    * lowered by generic CG as multiple addressable machine-word lanes, or 0
     18    * when the target ABI treats it as one scalar value. */
     19   u32 (*scalar_split_lane_size)(TargetABI*, KitCgTypeId);
     20   ABITypeInfo va_list_info;
     21   ABIVaListInfo va_list_layout;
     22   /* Stack-probe granularity. 0 = the target OS auto-grows the stack on any
     23    * access below SP, so no probe is needed (Linux/macOS/FreeBSD). Non-zero =
     24    * the page size the prologue must touch, in descending order, before a
     25    * single large `sub sp` jumps past uncommitted guard pages (Windows). */
     26   u32 stack_probe_interval;
     27 } ABIVtable;
     28 
     29 /* Per-ABI vtables exposed by their TUs. */
     30 extern const ABIVtable aapcs64_vtable;
     31 extern const ABIVtable sysv_x64_vtable;
     32 extern const ABIVtable rv64_vtable;
     33 extern const ABIVtable rv32_vtable;
     34 extern const ABIVtable wasm32_vtable;
     35 /* Apple Darwin variants — selected when (arch, os) matches.  See
     36  * abi.c::select_vtable. */
     37 extern const ABIVtable apple_arm64_vtable;
     38 extern const ABIVtable apple_x64_vtable;
     39 /* Windows variants — selected when os == KIT_OS_WINDOWS. */
     40 extern const ABIVtable win64_x64_vtable;
     41 extern const ABIVtable aapcs64_windows_vtable;
     42 
     43 const ABIVtable* abi_vtable_lookup(KitArchKind arch, KitObjFmt obj);
     44 
     45 /* Shared TargetABI internals. The struct definition is here so each ABI
     46  * TU can reach into the per-TU caches via TargetABI*. abi.c owns the
     47  * cache plumbing; the per-ABI TUs only allocate ABIFuncInfo / record
     48  * builders out of c->tu. */
     49 typedef struct FuncInfoCacheEntry FuncInfoCacheEntry;
     50 typedef struct RecordLayoutCacheEntry RecordLayoutCacheEntry;
     51 
     52 struct FuncInfoCacheEntry {
     53   KitCgTypeId fn;
     54   ABIFuncInfo* info;
     55   FuncInfoCacheEntry* next;
     56 };
     57 
     58 struct RecordLayoutCacheEntry {
     59   KitCgTypeId ty;
     60   ABIRecordLayout* layout;
     61   RecordLayoutCacheEntry* next;
     62 };
     63 
     64 struct TargetABI {
     65   Compiler* c;
     66   const ABIVtable* vt;
     67   FuncInfoCacheEntry* fn_cache;
     68   RecordLayoutCacheEntry* rec_cache;
     69 };
     70 
     71 /* Shared helpers exposed to per-ABI TUs. */
     72 ABITypeInfo abi_internal_type_info(TargetABI*, KitCgTypeId);
     73 
     74 #endif