GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/pass.c Lines: 41 41 100.0 %
Date: 2020-09-21 18:02:52 Branches: 8 8 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[][2] = { { type_engine_check_prog, type_engine_clean_prog }, { emit_ast, NULL } };
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[2]) {
15
1435
  compilation_pass *passes = mp_malloc2(gwion->mp, sizeof(compilation_pass)*2);
16
1435
  passes[0] = pass[0];
17
1435
  passes[1] = pass[1];
18
1435
  const Symbol sym = insert_symbol(gwion->st, name);
19
1435
  map_set(&gwion->data->passes->map, (vtype)sym, (vtype)pass);
20
1435
  map_set(&gwion->data->passes->map, (vtype)sym, (vtype)passes);
21
1435
}
22
23
719
ANN m_bool pass_set(const Gwion gwion, const Vector passes) {
24
719
  const Vector v = &gwion->data->passes->vec;
25
719
  vector_clear(v);
26
2153
  for(m_uint i = 0; i < vector_size(passes); ++i) {
27
1436
    const m_str name = (m_str)vector_at(passes, i);
28
1436
    const Symbol sym = insert_symbol(gwion->st, name);
29
1436
    const compilation_pass pass = (compilation_pass)map_get(&gwion->data->passes->map, (vtype)sym);
30
1436
    if(!pass) {
31
2
      gw_err("Failed to set compilation passes, back to default\n");
32
2
      pass_default(gwion);
33
2
      return GW_ERROR;
34
    }
35
1434
    vector_add(v, (vtype)pass);
36
  }
37
717
  return GW_OK;
38
}
39
40
717
ANN void pass_default(const Gwion gwion) {
41
  struct Vector_ v;
42
717
  vector_init(&v);
43
2151
  for(m_uint i = 0; i < NPASS; ++i) {
44
1434
    vector_add(&v, (vtype)default_passes_name[i]);
45
1434
    pass_register(gwion, default_passes_name[i], default_passes[i]);
46
  }
47
717
  pass_set(gwion, &v);
48
717
  vector_release(&v);
49
717
}
50
51
52
715
ANEW ANN struct Passes_* new_passes(MemPool mp) {
53
715
  struct Passes_ *a = mp_calloc(mp, Passes);
54
715
  map_init(&a->map);
55
715
  vector_init(&a->vec);
56
715
  return a;
57
}
58
59
714
ANN void free_passes(const MemPool mp, struct Passes_ *a) {
60
714
  map_release(&a->map);
61
2142
  for(m_uint i = 0; i < vector_size(&a->vec); ++i) {
62
1428
    compilation_pass *passes = (compilation_pass *)vector_at(&a->vec, i);
63
1428
    mp_free2(mp, sizeof(compilation_pass)*2, passes);
64
  }
65
714
  vector_release(&a->vec);
66
714
}