GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/pass.c Lines: 34 34 100.0 %
Date: 2020-09-14 00:22:58 Branches: 6 6 100.0 %

Line Branch Exec Source
1
#include "gwion_util.h"
2
#include "gwion_ast.h"
3
#include "gwion_env.h"
4
#include "vm.h"
5
#include "instr.h"
6
#include "emit.h"
7
#include "gwion.h"
8
#include "pass.h"
9
10
static const m_str default_passes_name[] = { "check", "emit" };
11
static const compilation_pass default_passes[] = { type_engine_check_prog, emit_ast };
12
#define NPASS sizeof(default_passes)/sizeof(default_passes[0])
13
14
1433
ANN void pass_register(const Gwion gwion, const m_str name, const compilation_pass pass) {
15
1433
  const Symbol sym = insert_symbol(gwion->st, name);
16
1433
  map_set(&gwion->data->passes->map, (vtype)sym, (vtype)pass);
17
1433
}
18
19
718
ANN m_bool pass_set(const Gwion gwion, const Vector passes) {
20
718
  const Vector v = &gwion->data->passes->vec;
21
718
  vector_clear(v);
22
2150
  for(m_uint i = 0; i < vector_size(passes); ++i) {
23
1434
    const m_str name = (m_str)vector_at(passes, i);
24
1434
    const Symbol sym = insert_symbol(gwion->st, name);
25
1434
    const compilation_pass pass = (compilation_pass)map_get(&gwion->data->passes->map, (vtype)sym);
26
1434
    if(!pass) {
27
2
      gw_err("Failed to set compilation passes, back to default\n");
28
2
      pass_default(gwion);
29
2
      return GW_ERROR;
30
    }
31
1432
    vector_add(v, (vtype)pass);
32
  }
33
716
  return GW_OK;
34
}
35
36
716
ANN void pass_default(const Gwion gwion) {
37
  struct Vector_ v;
38
716
  vector_init(&v);
39
2148
  for(m_uint i = 0; i < NPASS; ++i) {
40
1432
    vector_add(&v, (vtype)default_passes_name[i]);
41
1432
    pass_register(gwion, default_passes_name[i], default_passes[i]);
42
  }
43
716
  pass_set(gwion, &v);
44
716
  vector_release(&v);
45
716
}
46
47
48
714
ANEW ANN struct Passes_* new_passes(MemPool mp) {
49
714
  struct Passes_ *a = mp_calloc(mp, Passes);
50
714
  map_init(&a->map);
51
714
  vector_init(&a->vec);
52
714
  return a;
53
}
54
55
713
ANN void free_passes(struct Passes_ *a) {
56
713
  map_release(&a->map);
57
713
  vector_release(&a->vec);
58
713
}