kit

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

frontend.c (1668B)


      1 #include <kit/frontend.h>
      2 #include <setjmp.h>
      3 #include <stdarg.h>
      4 
      5 #include "core/core.h"
      6 #include "core/profile.h"
      7 
      8 KitStatus kit_frontend_run(KitCompiler* c, KitFrontendRunFn fn, void* user) {
      9   PanicFrame panic;
     10   KitStatus rc;
     11   if (!c || !fn) return KIT_INVALID;
     12   compiler_panic_push(c, &panic);
     13   if (setjmp(panic.env)) {
     14     compiler_run_cleanups(c);
     15     compiler_panic_pop(c, &panic);
     16     return KIT_ERR;
     17   }
     18   rc = fn(c, user);
     19   compiler_panic_pop(c, &panic);
     20   return rc;
     21 }
     22 
     23 void kit_frontend_profile_scope_begin(KitCompiler* c, KitProfileScope scope) {
     24   profile_scope_begin((Compiler*)c, scope);
     25 }
     26 
     27 void kit_frontend_profile_scope_end(KitCompiler* c, KitProfileScope scope) {
     28   profile_scope_end((Compiler*)c, scope);
     29 }
     30 
     31 void kit_frontend_profile_count(KitCompiler* c, KitProfileCounter counter,
     32                                 uint64_t value) {
     33   profile_count((Compiler*)c, counter, (u64)value);
     34 }
     35 
     36 void kit_frontend_profile_define_scope(KitCompiler* c, KitProfileScope scope,
     37                                        const char* name) {
     38   profile_define_scope((Compiler*)c, scope, name);
     39 }
     40 
     41 void kit_frontend_profile_define_counter(KitCompiler* c,
     42                                          KitProfileCounter counter,
     43                                          const char* name) {
     44   profile_define_counter((Compiler*)c, counter, name);
     45 }
     46 
     47 void kit_frontend_fatal(KitCompiler* c, KitSrcLoc loc, const char* fmt, ...) {
     48   va_list ap;
     49   va_start(ap, fmt);
     50   kit_frontend_vfatal(c, loc, fmt, ap);
     51 }
     52 
     53 void kit_frontend_vfatal(KitCompiler* c, KitSrcLoc loc, const char* fmt,
     54                          va_list ap) {
     55   compiler_panicv((Compiler*)c, loc, fmt, ap);
     56 }