Gwion coverage report


Directory: src/
File: src/emit/kind.c
Date: 2023-01-30 18:32:28
Exec Total Coverage
Lines: 16 16 100.0%
Functions: 9 9 100.0%
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 "gwion.h"
6 #include "instr.h"
7 #include "emit.h"
8
9 enum Kind { KIND_INT, KIND_FLOAT, KIND_OTHER, KIND_ADDR, KIND_END };
10
11 1551 static inline enum Kind kindof(const m_uint size, const uint emit_var) {
12
2/2
✓ Branch 0 taken 382 times.
✓ Branch 1 taken 1169 times.
1551 if (emit_var) return KIND_ADDR;
13
4/4
✓ Branch 0 taken 295 times.
✓ Branch 1 taken 874 times.
✓ Branch 2 taken 294 times.
✓ Branch 3 taken 1 times.
1169 return size == SZ_INT ? KIND_INT : size == SZ_FLOAT ? KIND_FLOAT : KIND_OTHER;
14 }
15
16 1551 ANN Instr emit_kind(Emitter emit, const m_uint val, const m_uint size, const bool addr,
17 const f_instr func[]) {
18 1551 const enum Kind kind = kindof(size, addr);
19 1551 const Instr instr = emit_add_instr(emit, func[kind]);
20 1551 instr->m_val = val;
21
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1550 times.
1551 if(kind == KIND_OTHER) instr->m_val2 = size;
22 1551 return instr;
23 }
24
25 static const f_instr regpushimm[KIND_END] = {RegPushImm, RegPushImm2,
26 RegPushImm3, RegPushImm4};
27
28 static const f_instr regpushmem[KIND_END] = {RegPushMem, RegPushMem2,
29 RegPushMem3, RegPushMem4};
30
31 static const f_instr regpushbase[KIND_END] = {RegPushBase, RegPushBase2,
32 RegPushBase3, RegPushBase4};
33
34 static const f_instr dotstatic[KIND_END] = {DotStatic, DotStatic2, DotStatic3,
35 RegPushImm};
36
37 static const f_instr dotmember[KIND_END] = {DotMember, DotMember2, DotMember3,
38 DotMember4};
39
40 static const f_instr structmember[KIND_END] = {
41 StructMember, StructMemberFloat, StructMemberOther, StructMemberAddr};
42
43 static const f_instr unionmember[KIND_END] = {UnionMember, UnionMember2,
44 UnionMember3, UnionMember4};
45
46 // function factory
47 #define kind_func(name) \
48 ANN Instr emit_##name(Emitter emit, const m_uint val, const m_uint size, const bool addr) { \
49 return emit_kind(emit, val, size, addr, name); \
50 }
51
52 124 kind_func(regpushimm);
53 383 kind_func(regpushmem);
54 350 kind_func(regpushbase);
55 59 kind_func(dotstatic);
56 88 kind_func(dotmember);
57 72 kind_func(structmember);
58 8 kind_func(unionmember);
59