GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/pass.c Lines: 34 34 100.0 %
Date: 2020-09-14 20:46:08 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
1435
ANN void pass_register(const Gwion gwion, const m_str name, const compilation_pass pass) {
15
1435
  const Symbol sym = insert_symbol(gwion->st, name);
16
1435
  map_set(&gwion->data->passes->map, (vtype)sym, (vtype)pass);
17
1435
}
18
19
719
ANN m_bool pass_set(const Gwion gwion, const Vector passes) {
20
719
  const Vector v = &gwion->data->passes->vec;
21
719
  vector_clear(v);
22
2153
  for(m_uint i = 0; i < vector_size(passes); ++i) {
23
1436
    const m_str name = (m_str)vector_at(passes, i);
24
1436
    const Symbol sym = insert_symbol(gwion->st, name);
25
1436
    const compilation_pass pass = (compilation_pass)map_get(&gwion->data->passes->map, (vtype)sym);
26
1436
    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
1434
    vector_add(v, (vtype)pass);
32
  }
33
717
  return GW_OK;
34
}
35
36
717
ANN void pass_default(const Gwion gwion) {
37
  struct Vector_ v;
38
717
  vector_init(&v);
39
2151
  for(m_uint i = 0; i < NPASS; ++i) {
40
1434
    vector_add(&v, (vtype)default_passes_name[i]);
41
1434
    pass_register(gwion, default_passes_name[i], default_passes[i]);
42
  }
43
717
  pass_set(gwion, &v);
44
717
  vector_release(&v);
45
717
}
46
47
48
715
ANEW ANN struct Passes_* new_passes(MemPool mp) {
49
715
  struct Passes_ *a = mp_calloc(mp, Passes);
50
715
  map_init(&a->map);
51
715
  vector_init(&a->vec);
52
715
  return a;
53
}
54
55
714
ANN void free_passes(struct Passes_ *a) {
56
714
  map_release(&a->map);
57
714
  vector_release(&a->vec);
58
714
}