GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/emit/emitter.c Lines: 28 28 100.0 %
Date: 2020-09-14 00:22:58 Branches: 2 2 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
#include "escape.h"
9
10
844
static ANEW ANN VM_Code emit_code(const Emitter emit) {
11
844
  Code* const c = emit->code;
12
844
  const VM_Code code = new_vm_code(emit->gwion->mp, &c->instr, c->stack_depth,
13
      c->flag, c->name);
14
844
  return code;
15
}
16
17
714
ANEW Emitter new_emitter(MemPool p) {
18
714
  Emitter emit = (Emitter)mp_calloc(p, Emitter);
19
714
  vector_init(&emit->stack);
20
714
  emit->info = (struct EmitterInfo_*)mp_calloc(p, EmitterInfo);
21
714
  vector_init(&emit->info->pure);
22
714
  emit->info->escape = escape_table(p);
23
714
  emit->info->emit_code = emit_code;
24
714
  emit->info->finalyzer = EOC;
25
714
  return emit;
26
}
27
28
713
ANN void free_emitter(MemPool p, Emitter a) {
29
713
  vector_release(&a->stack);
30
713
  vector_release(&a->info->pure);
31
713
  mp_free2(p, 256, a->info->escape);
32
713
  mp_free(p, EmitterInfo, a->info);
33
713
  mp_free(p, Emitter, a);
34
713
}
35
36
__attribute__((returns_nonnull))
37
19754
ANN2(1) Instr emit_add_instr(const Emitter emit, const f_instr f) {
38
19754
  const Instr instr = mp_calloc(emit->gwion->mp, Instr);
39
19754
  if((m_uint)f < 255)
40
19512
    instr->opcode = (m_uint)f;
41
  else {
42
242
    instr->opcode = eOP_MAX;
43
242
    instr->execute = f;
44
  }
45
19754
  vector_add(&emit->code->instr, (vtype)instr);
46
19754
  return instr;
47
}