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