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