kit

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

compile_engine.h (3836B)


      1 #ifndef KIT_DRIVER_COMPILE_ENGINE_H
      2 #define KIT_DRIVER_COMPILE_ENGINE_H
      3 
      4 #include <kit/cg.h>
      5 #include <kit/compile.h>
      6 #include <kit/object.h>
      7 #include <kit/preprocess.h>
      8 #include <stdint.h>
      9 
     10 /* Language-neutral "compile one source" step shared by `cc` and `compile`.
     11  *
     12  * Builds a KitCompileSession for `lang`, compiles `bytes` (labelled `name`),
     13  * and then either:
     14  *   - returns the object builder via `obj_out` (caller owns it; used by the
     15  *     link and check paths), or
     16  *   - emits the result to `emit_out`, routed by code->emit_*: object bytes by
     17  *     default, `.s` assembly for emit_asm_source, or — for emit_c_source /
     18  *     emit_ir — the writer is wired onto the CG and the builder is dropped.
     19  * Exactly one of `emit_out` / `obj_out` must be non-NULL.
     20  *
     21  *   code, diagnostics : common per-compile settings (required).
     22  *   pp                : preprocessor settings, applied to preprocessor-enabled
     23  *                       frontends; NULL for none.
     24  *   lang_extra        : opaque per-frontend options for language_options
     25  *                       (e.g. KitWasmCompileOptions*); NULL when the frontend
     26  *                       has none.
     27  *
     28  * Returns the compile/emit KitStatus. */
     29 KitStatus driver_compile_run(KitCompiler* compiler, KitLanguage lang,
     30                              const KitCodeOptions* code,
     31                              const KitDiagnosticOptions* diagnostics,
     32                              const KitPreprocessOptions* pp,
     33                              const void* lang_extra, KitSlice name,
     34                              const KitSlice* bytes, KitWriter* emit_out,
     35                              KitObjBuilder** obj_out);
     36 
     37 typedef struct DriverCompileSource {
     38   KitLanguage lang;
     39   KitSlice name;
     40   KitSlice bytes;
     41   const KitPreprocessOptions* pp;
     42   const void* lang_extra;
     43 } DriverCompileSource;
     44 
     45 typedef struct DriverCompileObjects {
     46   /* Caller-allocated capacity for at least nsources objects. Filled compactly.
     47    */
     48   KitObjBuilder** objs;
     49   uint32_t nobjs;
     50   /* Caller-allocated nsources-entry maps. source_obj_index[i] is the compact
     51    * object index for source i. source_order_keep[i] is true only for the source
     52    * position that should contribute an order/archive member; later semantic LTO
     53    * sources map to the same object and have keep=false. */
     54   uint32_t* source_obj_index;
     55   uint8_t* source_order_keep;
     56   struct DriverCompilePendingLto* pending_lto;
     57 } DriverCompileObjects;
     58 
     59 typedef struct DriverCompileBatchOptions {
     60   uint8_t output_kind;          /* KitCgOutputKind */
     61   uint8_t interposition_policy; /* KitCgInterpositionPolicy */
     62   uint8_t defer_lto_finish;
     63   uint8_t pad[1];
     64 } DriverCompileBatchOptions;
     65 
     66 typedef struct DriverCompilePendingLto {
     67   KitObjBuilder* obj;
     68   KitCg* cg;
     69   uint32_t obj_index;
     70   uint8_t active;
     71   uint8_t pad[3];
     72 } DriverCompilePendingLto;
     73 
     74 /* Compile a batch of sources for a link/archive/relocatable output. When
     75  * code->lto is set, KIT_FRONTEND_LTO_CG frontends emit into one shared KitCg
     76  * unit and KIT_FRONTEND_LTO_OPAQUE/NONE frontends still compile as ordinary
     77  * per-source objects. */
     78 KitStatus driver_compile_sources_run(KitCompiler* compiler,
     79                                      const KitCodeOptions* code,
     80                                      const KitDiagnosticOptions* diagnostics,
     81                                      const DriverCompileSource* sources,
     82                                      uint32_t nsources,
     83                                      const DriverCompileBatchOptions* batch,
     84                                      DriverCompileObjects* out);
     85 
     86 KitStatus driver_compile_pending_lto_finish(
     87     DriverCompilePendingLto* pending, const DriverCompileBatchOptions* batch,
     88     const KitCgSym* preserved_symbols, uint32_t npreserved_symbols);
     89 
     90 void driver_compile_pending_lto_abort(DriverCompilePendingLto* pending);
     91 
     92 #endif