| 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 | 746 | static ANEW ANN VM_Code emit_code(const Emitter emit) { | |
| 11 | 746 | Code *const c = emit->code; | |
| 12 | 746 | const bool has_values = m_vector_size(&c->live_values); | |
| 13 | 746 | const VM_Code code = new_vmcode(emit->gwion->mp, &c->instr, | |
| 14 | has_values ? &c->live_values : NULL, c->name, | ||
| 15 |
2/2✓ Branch 0 taken 168 times.
✓ Branch 1 taken 578 times.
|
746 | c->stack_depth, false, emit->info->dump); |
| 16 |
2/2✓ Branch 0 taken 168 times.
✓ Branch 1 taken 578 times.
|
746 | if (has_values) c->live_values.ptr = NULL; |
| 17 | 746 | return code; | |
| 18 | } | ||
| 19 | |||
| 20 | 707 | ANEW Emitter new_emitter(MemPool p) { | |
| 21 | 707 | Emitter emit = (Emitter)mp_calloc(p, Emitter); | |
| 22 | 707 | vector_init(&emit->stack); | |
| 23 | 707 | emit->info = (struct EmitterInfo_ *)mp_calloc(p, EmitterInfo); | |
| 24 | 707 | vector_init(&emit->info->pure); | |
| 25 | 707 | emit->info->escape = escape_table(p); | |
| 26 | 707 | emit->info->emit_code = emit_code; | |
| 27 | 707 | return emit; | |
| 28 | } | ||
| 29 | |||
| 30 | 707 | ANN void free_emitter(MemPool p, Emitter a) { | |
| 31 | 707 | vector_release(&a->stack); | |
| 32 | 707 | vector_release(&a->info->pure); | |
| 33 | 707 | mp_free2(p, 256, a->info->escape); | |
| 34 | 707 | mp_free(p, EmitterInfo, a->info); | |
| 35 | 707 | mp_free(p, Emitter, a); | |
| 36 | 707 | } | |
| 37 | |||
| 38 | __attribute__((returns_nonnull)) ANN2(1) Instr | ||
| 39 | 14392 | new_instr(const MemPool mp, const f_instr f) { | |
| 40 | 14392 | const Instr instr = mp_calloc(mp, Instr); | |
| 41 |
2/2✓ Branch 0 taken 14111 times.
✓ Branch 1 taken 281 times.
|
14392 | if ((m_uint)f < 255) |
| 42 | 14111 | instr->opcode = (m_uint)f; | |
| 43 | else { | ||
| 44 | 281 | instr->opcode = eOP_MAX; | |
| 45 | 281 | instr->execute = f; | |
| 46 | } | ||
| 47 | 14392 | return instr; | |
| 48 | } | ||
| 49 | __attribute__((returns_nonnull)) ANN2(1) Instr | ||
| 50 | 14392 | emit_add_instr(const Emitter emit, const f_instr f) { | |
| 51 | 14392 | const Instr instr = new_instr(emit->gwion->mp, f); | |
| 52 | 14392 | vector_add(&emit->code->instr, (vtype)instr); | |
| 53 | 14392 | return instr; | |
| 54 | } | ||
| 55 | |||
| 56 | 19 | ANN2(1) void emit_fast_except(const Emitter emit, const ValueFrom *vf, const loc_t loc) { | |
| 57 | 19 | const Instr instr = emit_add_instr(emit, fast_except); | |
| 58 |
1/2✓ Branch 0 taken 19 times.
✗ Branch 1 not taken.
|
19 | if(vf) { |
| 59 | 19 | struct FastExceptInfo *info = mp_malloc2(emit->gwion->mp, sizeof(struct FastExceptInfo)); | |
| 60 | 19 | info->file = emit->env->name; | |
| 61 | 19 | info->loc = loc; | |
| 62 | 19 | info->file2 = vf->filename; | |
| 63 | 19 | info->loc2 = vf->loc; | |
| 64 | 19 | instr->m_val2 = (m_uint)info; | |
| 65 | } | ||
| 66 | 19 | } | |
| 67 |