GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/main.c Lines: 14 14 100.0 %
Date: 2020-10-03 10:30:04 Branches: 2 2 100.0 %

Line Branch Exec Source
1
#include <signal.h>
2
#include "gwion_util.h"
3
#include "gwion_ast.h"
4
#include "gwion_env.h"
5
#include "vm.h"
6
#include "gwion.h"
7
#include "arg.h"
8
9
1
static void sig(int unused NUSED) {
10
#ifdef BUILD_ON_WINDOWS
11
  exit(EXIT_FAILURE);
12
#else
13
1
  pthread_kill(pthread_self(), SIGTERM);
14
1
  pthread_exit(NULL);
15
#endif
16
}
17
18
#ifdef __AFL_HAVE_MANUAL_CONTROL
19
20
static void afl_run(const Gwion gwion) {
21
  gw_seed(gwion->vm->rand, 0);
22
  __AFL_INIT();
23
  while (__AFL_LOOP(256)) {
24
    FILE* f = fdopen(0, "r");
25
    push_global(gwion, "[afl]");
26
    if(compile_file(gwion, "afl", f))
27
      gwion_run(gwion);
28
    pop_global(gwion);
29
  }
30
}
31
32
#define gwion_run(a) { afl_run(a); return 0; }
33
#endif
34
35
716
int main(int argc, char** argv) {
36
716
  Arg arg = { .arg={.argc=argc, .argv=argv}, .loop=-1 };
37
716
  signal(SIGINT, sig);
38
716
  signal(SIGTERM, sig);
39
716
  struct Gwion_ gwion = {};
40
716
  const m_bool ini = gwion_ini(&gwion, &arg);
41
716
  arg_release(&arg);
42
716
  if(ini > 0)
43
713
    gwion_run(&gwion);
44
715
  gwion_end(&gwion);
45
#ifndef BUILD_ON_WINDOWS
46
715
  pthread_exit(NULL);
47
#endif
48
  return EXIT_SUCCESS;
49
}