kit

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

abi_apple_arm64.c (2107B)


      1 /* Apple ARM64 (Darwin) ABI dispatch.
      2  *
      3  * Vtable selection keys on (target.arch, target.os);
      4  * (ARM_64, MACOS) lands here instead of
      5  * AAPCS64.  The two ABIs diverge in:
      6  *
      7  *   1. va_list shape — Apple ARM64 `__builtin_va_list` is plain
      8  *      `char*`; AAPCS64 is a five-field struct.  Overridden here.
      9  *
     10  *   2. Variadics on stack — Apple ARM64 passes ALL variadic arguments
     11  *      on the stack (no v0-v7 / x0-x7 routing for the `...` portion of
     12  *      the arglist).  This is a *call-site* divergence — the fixed
     13  *      params classify identically to AAPCS64, so compute_func_info
     14  *      delegates to the AAPCS64 classifier and then sets the
     15  *      ABIFuncInfo.vararg_on_stack trait that the cg backend reads
     16  *      when synthesizing variadic-arg ABIArgInfos.
     17  *
     18  *   3. Stack-arg promotion — fixed small integer arguments passed on the
     19  *      stack are promoted to 4 bytes minimum (`char`/`short` occupy 4
     20  *      stack bytes). Variadic arguments still occupy 8-byte slots so a
     21  *      plain `char*` va_list can advance uniformly. */
     22 
     23 #include "abi/abi_internal.h"
     24 #include "core/core.h"
     25 
     26 extern ABIFuncInfo* aapcs64_compute_func_info(TargetABI*, KitCgTypeId);
     27 
     28 static ABIFuncInfo* apple_arm64_compute_func_info(TargetABI* a,
     29                                                   KitCgTypeId fn) {
     30   /* Phase 2: spell out the Darwin variadic / stack-arg-promotion
     31    * deltas.  For now the AAPCS64 classifier produces ABI-correct
     32    * output for the fixed-args-only programs in the v1 cg suite,
     33    * and we layer on the vararg-on-stack trait so the cg backend
     34    * routes the `...` portion to the stack without keying on the
     35    * target OS itself. */
     36   ABIFuncInfo* info = aapcs64_compute_func_info(a, fn);
     37   info->vararg_on_stack = 1;
     38   info->stack_arg_min_align = 4;
     39   info->vararg_stack_arg_min_align = 8;
     40   return info;
     41 }
     42 
     43 const ABIVtable apple_arm64_vtable = {
     44     .compute_func_info = apple_arm64_compute_func_info,
     45     .va_list_info = {8, 8, ABI_SC_PTR, 0, 0, 0},
     46     .va_list_layout = {.type = {8, 8, ABI_SC_PTR, 0, 0, 0},
     47                        .kind = ABI_VA_LIST_POINTER},
     48 };