diff options
| -rw-r--r-- | simple-reg.c | 6 | ||||
| -rw-r--r-- | simple-reg.h | 4 | ||||
| -rw-r--r-- | simplex86.c | 64 | ||||
| -rw-r--r-- | simplex86.h | 12 |
4 files changed, 43 insertions, 43 deletions
diff --git a/simple-reg.c b/simple-reg.c index 89ba29a..686e5c3 100644 --- a/simple-reg.c +++ b/simple-reg.c @@ -29,7 +29,7 @@ find_reg (op_t reg, int n_registers, const op_t *registers) */ void reg_alloc_init (reg_alloc_t *reg_alloc, - asm_t *as, + fragment_t *as, int n_registers, const op_t *registers, int register_size, reg_alloc_t *parent, int n_preserved, ...) @@ -122,7 +122,7 @@ reg_alloc_alloc (reg_alloc_t *reg_alloc) int n_stack_bytes = reg_alloc->n_registers * reg_alloc->register_size; - x86_asm ( + fragment_assemble ( reg_alloc->as, "sub", rsp, IMM (n_stack_bytes), NULL); @@ -135,7 +135,7 @@ reg_alloc_alloc (reg_alloc_t *reg_alloc) reg_alloc->info[i].spill_loc = spill_loc; reg_alloc->n_spills++; - x86_asm ( + fragment_assemble ( reg_alloc->as, "mov", spill_loc, reg_alloc->info[i].reg, NULL); diff --git a/simple-reg.h b/simple-reg.h index 768c10b..24389d1 100644 --- a/simple-reg.h +++ b/simple-reg.h @@ -27,7 +27,7 @@ struct reg_info_t struct reg_alloc_t { reg_alloc_t *parent; - asm_t *as; + fragment_t *as; reg_info_t info[MAX_REGISTERS]; int n_registers; @@ -45,7 +45,7 @@ struct reg_alloc_t */ void reg_alloc_init (reg_alloc_t *reg_alloc, - asm_t *as, + fragment_t *as, int n_registers, const op_t *registers, int register_size, reg_alloc_t *parent, int n_preserved, ...); diff --git a/simplex86.c b/simplex86.c index 1094c03..a64669d 100644 --- a/simplex86.c +++ b/simplex86.c @@ -326,7 +326,7 @@ struct annotation_t int alignment; }; -struct asm_t +struct fragment_t { code_manager_t * code_manager; bool_t error; @@ -336,16 +336,16 @@ struct asm_t }; static void -asm_mark_error (asm_t *a, const char *error) +asm_mark_error (fragment_t *a, const char *error) { printf ("Error: %s\n", error); /* FIXME: mark @a as in error and delete all state */ } -asm_t * -x86_asm_new (void) +fragment_t * +fragment_new (void) { - asm_t *a; + fragment_t *a; if (!(a = malloc (sizeof *a))) goto oom_assembler; @@ -419,7 +419,7 @@ emit_imm8 (uint8_t *code, int32_t imm) } static void -fixup_jumps (asm_t *as) +fixup_jumps (fragment_t *frag) { int i, j, displacement; annotation_t *annotations; @@ -446,7 +446,7 @@ fixup_jumps (asm_t *as) * until nothing changes. It will need to know the initial alignment of the * final destination. */ - annotations = array_get_data (&as->annotations, &n_annotations); + annotations = array_get_data (&frag->annotations, &n_annotations); /* Match refs to labels */ for (i = 0; i < n_annotations; ++i) @@ -485,7 +485,7 @@ fixup_jumps (asm_t *as) displacement = 0; a = annotations; - begin = array_get_data (&as->code, &n_bytes); + begin = array_get_data (&frag->code, &n_bytes); end = begin + n_bytes; for (c = begin; c < end; ++c) { @@ -526,12 +526,12 @@ fixup_jumps (asm_t *as) *(c - displacement) = *c; } - array_delete_tail (&as->code, displacement); + array_delete_tail (&frag->code, displacement); } while (displacement); /* Patch in the offsets */ - code = array_get_data (&as->code, NULL); + code = array_get_data (&frag->code, NULL); for (i = 0; i < n_annotations; ++i) { annotation_t *ref; @@ -559,7 +559,7 @@ fixup_jumps (asm_t *as) } uint8_t * -x86_asm_emit (asm_t *a) +fragment_emit (fragment_t *a) { uint8_t *writable, *executable; uint8_t *result = NULL; @@ -993,12 +993,12 @@ need_rex (int n_ops, op_t ops[4], uint8_t *w) } static void -add_annotation (asm_t *as, annotation_type_t type, const char *label, +add_annotation (fragment_t *frag, annotation_type_t type, const char *label, int alignment, size_t offset) { annotation_t *info; - if (!array_append (&as->annotations, 1, &info)) + if (!array_append (&frag->annotations, 1, &info)) { /* FIXME: mark eerror */ return; @@ -1057,7 +1057,7 @@ emit_imm (uint8_t *c, arg_type_t size, int32_t immediate) } static void -emit (asm_t *as, const inst_t *inst, op_t ops[4]) +emit (fragment_t *frag, const inst_t *inst, op_t ops[4]) { uint8_t tmp[16]; uint8_t code[16]; @@ -1283,12 +1283,12 @@ emit (asm_t *as, const inst_t *inst, op_t ops[4]) break; } - array_get_data (&as->code, &offset); + array_get_data (&frag->code, &offset); if (ann_pos) { add_annotation ( - as, ann_type, ann_name, ann_alignment, offset + (ann_pos - code)); + frag, ann_type, ann_name, ann_alignment, offset + (ann_pos - code)); } printf ("offset %lx: ", offset); @@ -1296,7 +1296,7 @@ emit (asm_t *as, const inst_t *inst, op_t ops[4]) printf ("%02x ", *d); printf ("\n"); - array_append (&as->code, c - code, &d); + array_append (&frag->code, c - code, &d); memcpy (d, code, c - code); } @@ -1315,7 +1315,7 @@ match (const inst_t *inst, op_t ops[4]) } static void -generate (asm_t *as, const char *name, const inst_t *inst, op_t ops[4]) +generate (fragment_t *frag, const char *name, const inst_t *inst, op_t ops[4]) { do { @@ -1324,18 +1324,18 @@ generate (asm_t *as, const char *name, const inst_t *inst, op_t ops[4]) if (strcmp (name, inst->name) != 0) break; - emit (as, inst, ops); + emit (frag, inst, ops); return; } } while (++inst < instructions + N_INST); printf ("unknown %s\n", name); - asm_mark_error (as, "Unknown instruction"); + asm_mark_error (frag, "Unknown instruction"); abort(); } void -x86_asm (asm_t *as, const char *name, ...) +fragment_assemble (fragment_t *frag, const char *name, ...) { int i; va_list va; @@ -1353,7 +1353,7 @@ x86_asm (asm_t *as, const char *name, ...) for (i = 0; i < inst->n_operands; ++i) ops[i] = va_arg (va, op_t); - generate (as, name, inst, ops); + generate (frag, name, inst, ops); break; } } @@ -1361,7 +1361,7 @@ x86_asm (asm_t *as, const char *name, ...) if (i == N_INST) { printf ("Instruction %s does not exist\n", name); - asm_mark_error (as, "Non-existent instruction"); + asm_mark_error (frag, "Non-existent instruction"); break; } @@ -1379,13 +1379,13 @@ dummy (void) } static bool_t -avx_supported (asm_t *as) +avx_supported (fragment_t *frag) { uint8_t *code; typedef int (* func) (void); - x86_asm ( - as, + fragment_assemble ( + frag, "push", rcx, "push", rdx, "mov", eax, IMM (1), @@ -1409,7 +1409,7 @@ avx_supported (asm_t *as) "ret", NULL); - code = x86_asm_emit (as); + code = fragment_emit (frag); return ((func)code)(); } @@ -1417,15 +1417,15 @@ avx_supported (asm_t *as) int main () { - asm_t *as = x86_asm_new (); + fragment_t *frag = fragment_new (); uint8_t *code; uint8_t sandbox[1024]; printf ("AVX supported: %s\n", - avx_supported (as)? "yes" : "no"); + avx_supported (frag)? "yes" : "no"); - x86_asm ( - as, + fragment_assemble ( + frag, DEFINE_LABEL ("begin"), "add", edx, ebx, @@ -1545,7 +1545,7 @@ main () NULL); - code = x86_asm_emit (as); + code = fragment_emit (frag); printf ("Size: %lu\n", sizeof (instructions)); diff --git a/simplex86.h b/simplex86.h index 21d0620..e0b3fd5 100644 --- a/simplex86.h +++ b/simplex86.h @@ -3,15 +3,15 @@ #include <stdint.h> -typedef struct asm_t asm_t; +typedef struct fragment_t fragment_t; /* Public API */ -asm_t * x86_asm_new (void); -uint8_t *x86_asm_emit (asm_t *a); -void x86_asm (asm_t *a, - const char *name, - ...); +fragment_t *fragment_new (void); +uint8_t * fragment_emit (fragment_t *a); +void fragment_assemble (fragment_t *a, + const char *name, + ...); /* Operands */ |
