kit

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

link_engine.h (2176B)


      1 #ifndef KIT_DRIVER_LINK_ENGINE_H
      2 #define KIT_DRIVER_LINK_ENGINE_H
      3 
      4 #include <kit/compile.h>
      5 #include <kit/link.h>
      6 #include <kit/object.h>
      7 
      8 #include "compile_engine.h"
      9 
     10 /* Reusable "build a link session, add inputs in command-line order, and emit"
     11  * step shared by `cc` and the `build-*` commands. Every input is already
     12  * loaded/compiled by the caller; path lookup, option parsing, hosted/runtime
     13  * wiring, and the output writer's lifetime stay caller responsibilities.
     14  *
     15  * `order` drives the add sequence: each entry's (kind, index) selects one
     16  * element of the parallel arrays below, so link order matches the command
     17  * line exactly.
     18  *   KIT_LINK_INPUT_OBJ        -> objs[index]      (in-memory builder; borrowed)
     19  *   KIT_LINK_INPUT_OBJ_BYTES  -> obj_bytes[index], labelled obj_names[index]
     20  *   KIT_LINK_INPUT_ARCHIVE    -> archives[index]
     21  *   KIT_LINK_INPUT_DSO        -> dso_bytes[index], labelled dso_names[index]
     22  *
     23  * Arrays whose count is zero may be NULL. */
     24 typedef struct DriverLinkInputs {
     25   KitObjBuilder* const* objs;
     26   uint32_t nobjs;
     27   const KitSlice* obj_names;
     28   const KitSlice* obj_bytes;
     29   uint32_t nobj_bytes;
     30   const KitLinkArchiveInput* archives;
     31   uint32_t narchives;
     32   const KitSlice* dso_names;
     33   const KitSlice* dso_bytes;
     34   uint32_t ndsos;
     35   const KitLinkInputOrder* order;
     36   uint32_t norder;
     37 } DriverLinkInputs;
     38 
     39 /* Open a session with `lopts`, add every input named by `in->order`, and emit
     40  * to `out`. Returns the resulting KitStatus (KIT_OK on success). The session is
     41  * always freed before return; `out` is neither opened nor closed here.
     42  * In-memory builders are borrowed for the duration of the session; callers
     43  * retain ownership and must free them after this returns. */
     44 KitStatus driver_link_engine_emit(KitCompiler* compiler,
     45                                   const KitLinkSessionOptions* lopts,
     46                                   const DriverLinkInputs* in, KitWriter* out);
     47 
     48 KitStatus driver_link_engine_emit_with_lto(
     49     KitCompiler* compiler, const KitLinkSessionOptions* lopts,
     50     const DriverLinkInputs* in, DriverCompilePendingLto* pending_lto,
     51     const DriverCompileBatchOptions* batch, KitWriter* out);
     52 
     53 #endif