struct Label -> label_t

This commit is contained in:
2024-12-24 23:21:01 +00:00
parent 9fb9413c45
commit f4e0be8977

View File

@@ -9,10 +9,10 @@
#include <string.h>
// Structure representing a loop operative as indices into an ASM label array.
struct Label
typedef struct
{
u64 cur, next;
};
} label_t;
// A table which translates brainfuck operations into generic assembly code (I
// love C's array indexing)
@@ -41,11 +41,11 @@ static const struct
// Linear search in the ASM label array for a label with the current AST
// relative index
i64 get_abs_label(u64, struct Label *, u64);
i64 get_abs_label(u64, label_t *, u64);
// Translate an AST relative jump to a specific ASM label, storing the current
// and next items in given pointers.
void ast_ref_to_asm_label(u64, struct Label *, u64, i64 *, i64 *);
void ast_ref_to_asm_label(u64, label_t *, u64, i64 *, i64 *);
void asm_translate_nodes(vec_t *asm_buffer, struct PResult nodes,
const char *src_name)
@@ -60,14 +60,14 @@ void asm_translate_nodes(vec_t *asm_buffer, struct PResult nodes,
MEMORY_DEFAULT);
// First pass: Setup the ASM label array
struct Label labels[nodes.labels ? nodes.labels * 2 : 1];
label_t labels[nodes.labels ? nodes.labels * 2 : 1];
if (nodes.labels)
{
u64 label_ptr = 0;
for (size_t i = 0; i < nodes.size; ++i)
if (nodes.nodes[i].type == LIN || nodes.nodes[i].type == LOUT)
labels[label_ptr++] =
(struct Label){.cur = i, .next = nodes.nodes[i].loop_ref};
(label_t){.cur = i, .next = nodes.nodes[i].loop_ref};
}
// Second pass: Translating to assembly
@@ -128,7 +128,7 @@ void asm_translate_nodes(vec_t *asm_buffer, struct PResult nodes,
/* Implementations for throwaway functions */
i64 get_abs_label(u64 ref, struct Label *labels, u64 size)
i64 get_abs_label(u64 ref, label_t *labels, u64 size)
{
for (u64 i = 0; i < size; ++i)
if (labels[i].cur == ref)
@@ -136,7 +136,7 @@ i64 get_abs_label(u64 ref, struct Label *labels, u64 size)
return -1;
}
void ast_ref_to_asm_label(u64 ref, struct Label *labels, u64 size, i64 *cur,
void ast_ref_to_asm_label(u64 ref, label_t *labels, u64 size, i64 *cur,
i64 *next)
{
*cur = get_abs_label(ref, labels, size);