Gwion coverage report


Directory: src/
File: src/pass.c
Date: 2023-01-30 18:32:28
Exec Total Coverage
Lines: 39 39 100.0%
Functions: 5 5 100.0%
Branches: 10 10 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 #include "traverse.h"
10
11 #define N_PASS 2
12 #define N_SCANPASS 4
13
14 static const m_str default_passes_name[2] = {"check", "emit"};
15 static const compilation_pass default_passes[4] = {traverse_ast, emit_ast};
16 static const m_str scan_passes_name[4] = {"scan0", "scan1", "scan2",
17 "type_check"};
18 static const compilation_pass scan_passes[4] = {scan0_ast, scan1_ast, scan2_ast,
19 check_ast};
20
21 4242 ANN void pass_register(const Gwion gwion, const m_str name,
22 const compilation_pass pass) {
23 4242 const Symbol sym = insert_symbol(gwion->st, name);
24 4242 map_set(&gwion->data->passes->map, (vtype)sym, (vtype)pass);
25 4242 }
26
27 709 ANN m_bool pass_set(const Gwion gwion, const Vector passes) {
28 709 const Vector v = &gwion->data->passes->vec;
29 709 vector_clear(v);
30
2/2
✓ Branch 1 taken 1416 times.
✓ Branch 2 taken 707 times.
2123 for (m_uint i = 0; i < vector_size(passes); ++i) {
31 1416 const m_str name = (m_str)vector_at(passes, i);
32 1416 const Symbol sym = insert_symbol(gwion->st, name);
33 1416 const compilation_pass pass =
34 1416 (compilation_pass)map_get(&gwion->data->passes->map, (vtype)sym);
35
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1414 times.
1416 if (!pass) {
36 /*
37 if(!strcmp(name, "none")) {
38 vector_clear(v);
39 return GW_OK;
40 }
41 */
42 2 gw_err("Failed to set compilation passes, back to default\n");
43 2 pass_default(gwion);
44 2 return GW_ERROR;
45 }
46 1414 vector_add(v, (vtype)pass);
47 }
48 707 return GW_OK;
49 }
50
51 707 ANN void pass_default(const Gwion gwion) {
52 struct Vector_ v;
53 707 vector_init(&v);
54
2/2
✓ Branch 0 taken 1414 times.
✓ Branch 1 taken 707 times.
2121 for (m_uint i = 0; i < N_PASS; ++i)
55 1414 vector_add(&v, (vtype)default_passes_name[i]);
56 707 pass_set(gwion, &v);
57 707 vector_release(&v);
58 707 }
59
60 707 ANEW ANN struct Passes_ *new_passes(const Gwion gwion) {
61 707 struct Passes_ *a = gwion->data->passes = mp_calloc(gwion->mp, Passes);
62 707 map_init(&a->map);
63
2/2
✓ Branch 0 taken 1414 times.
✓ Branch 1 taken 707 times.
2121 for (m_uint i = 0; i < N_PASS; ++i)
64 1414 pass_register(gwion, default_passes_name[i], default_passes[i]);
65
2/2
✓ Branch 0 taken 2828 times.
✓ Branch 1 taken 707 times.
3535 for (m_uint i = 0; i < N_SCANPASS; ++i)
66 2828 pass_register(gwion, scan_passes_name[i], scan_passes[i]);
67 707 vector_init(&a->vec);
68 707 return a;
69 }
70
71 707 ANN void free_passes(const MemPool mp, struct Passes_ *a) {
72 707 map_release(&a->map);
73 707 vector_release(&a->vec);
74 707 mp_free(mp, Passes, a);
75 707 }
76