kit

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

lang_registry.c (2394B)


      1 /* Language frontend registry.
      2  *
      3  * This file is the *only* place in libkit that checks
      4  * KIT_LANG_*_ENABLED. It runs during compiler construction and wires
      5  * each compiled-in frontend's vtable into c->frontends[] so the public
      6  * compile/pipeline paths can dispatch by KitLanguage without any
      7  * host-side bootstrap.
      8  *
      9  * The asm frontend lives inside the codegen substrate, but automatic
     10  * registration is gated by KIT_LANG_ASM_ENABLED.
     11  *
     12  * Third parties may still call kit_register_frontend() to install or
     13  * override any slot after construction; that public API is unchanged.
     14  */
     15 
     16 #include "api/lang_registry.h"
     17 
     18 #include <kit/compile.h>
     19 
     20 #include "kit/config.h"
     21 
     22 /* Defined in src/api/compile.c, alongside the asm frontend's
     23  * new/compile/free functions. Treated as part of the codegen substrate
     24  * (no per-frontend lang/ directory), so its declaration lives here
     25  * rather than in a public header. */
     26 #if KIT_LANG_ASM_ENABLED
     27 extern const KitFrontendVTable kit_asm_frontend_vtable;
     28 #endif
     29 
     30 #if KIT_LANG_C_ENABLED
     31 #include "c/c.h"
     32 #endif
     33 #if KIT_LANG_TOY_ENABLED
     34 #include "toy/toy.h"
     35 #endif
     36 #if KIT_LANG_WASM_ENABLED
     37 #include "wasm/wasm.h"
     38 #endif
     39 
     40 KitStatus lang_registry_init(KitCompiler* c) {
     41 #if KIT_LANG_ASM_ENABLED
     42   {
     43     KitStatus st =
     44         kit_register_frontend(c, KIT_LANG_ASM, &kit_asm_frontend_vtable);
     45     if (st != KIT_OK) return st;
     46   }
     47 #endif
     48 #if KIT_LANG_C_ENABLED
     49   {
     50     KitStatus st =
     51         kit_register_frontend(c, KIT_LANG_C, &kit_c_frontend_vtable);
     52     if (st != KIT_OK) return st;
     53   }
     54 #endif
     55 #if KIT_LANG_TOY_ENABLED
     56   {
     57     KitStatus st =
     58         kit_register_frontend(c, KIT_LANG_TOY, &kit_toy_frontend_vtable);
     59     if (st != KIT_OK) return st;
     60   }
     61 #endif
     62 #if KIT_LANG_WASM_ENABLED
     63   {
     64     KitStatus st =
     65         kit_register_frontend(c, KIT_LANG_WASM, &kit_wasm_frontend_vtable);
     66     if (st != KIT_OK) return st;
     67   }
     68 #endif
     69   return KIT_OK;
     70 }
     71 
     72 const KitFrontendVTable* lang_registry_vtable(KitLanguage lang) {
     73   switch (lang) {
     74 #if KIT_LANG_ASM_ENABLED
     75     case KIT_LANG_ASM:
     76       return &kit_asm_frontend_vtable;
     77 #endif
     78 #if KIT_LANG_C_ENABLED
     79     case KIT_LANG_C:
     80       return &kit_c_frontend_vtable;
     81 #endif
     82 #if KIT_LANG_TOY_ENABLED
     83     case KIT_LANG_TOY:
     84       return &kit_toy_frontend_vtable;
     85 #endif
     86 #if KIT_LANG_WASM_ENABLED
     87     case KIT_LANG_WASM:
     88       return &kit_wasm_frontend_vtable;
     89 #endif
     90     default:
     91       break;
     92   }
     93   return NULL;
     94 }