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