Remove asm_write_init and asm_write_exit
Just inline into asm_translate_nodes
This commit is contained in:
45
assembler.c
45
assembler.c
@@ -47,16 +47,18 @@ i64 get_abs_label(u64, struct Label *, u64);
|
|||||||
// 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, struct Label *, u64, i64 *, i64 *);
|
||||||
|
|
||||||
// Write the initial boilerplate of the assembly file
|
|
||||||
void asm_write_init(vec_t *asm_buffer);
|
|
||||||
|
|
||||||
// Write the exit code boilerplate for the assembly file
|
|
||||||
void asm_write_exit(vec_t *asm_buffer);
|
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
asm_write_init(asm_buffer);
|
vec_append_fmt(asm_buffer,
|
||||||
|
"section .bss\n"
|
||||||
|
" memory resb %d\n"
|
||||||
|
"section .text\n"
|
||||||
|
"global _start\n"
|
||||||
|
"_start:\n"
|
||||||
|
" mov r9, memory\n",
|
||||||
|
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];
|
struct Label labels[nodes.labels ? nodes.labels * 2 : 1];
|
||||||
if (nodes.labels)
|
if (nodes.labels)
|
||||||
@@ -116,7 +118,12 @@ void asm_translate_nodes(vec_t *asm_buffer, struct PResult nodes,
|
|||||||
}
|
}
|
||||||
vec_append_fmt(asm_buffer, format_string, current_label, next_label);
|
vec_append_fmt(asm_buffer, format_string, current_label, next_label);
|
||||||
}
|
}
|
||||||
asm_write_exit(asm_buffer);
|
|
||||||
|
vec_append(asm_buffer,
|
||||||
|
" mov rax, 60\n"
|
||||||
|
" mov rdi, 0\n"
|
||||||
|
" syscall\n",
|
||||||
|
37);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Implementations for throwaway functions */
|
/* Implementations for throwaway functions */
|
||||||
@@ -138,28 +145,6 @@ void ast_ref_to_asm_label(u64 ref, struct Label *labels, u64 size, i64 *cur,
|
|||||||
*next = get_abs_label(labels[*cur].next, labels, size);
|
*next = get_abs_label(labels[*cur].next, labels, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write the initial boilerplate of the assembly file
|
|
||||||
void asm_write_init(vec_t *asm_buffer)
|
|
||||||
{
|
|
||||||
const char format_string[] = "section .bss\n"
|
|
||||||
" memory resb %d\n"
|
|
||||||
"section .text\n"
|
|
||||||
"global _start\n"
|
|
||||||
"_start:\n"
|
|
||||||
" mov r9, memory\n";
|
|
||||||
vec_append_fmt(asm_buffer, format_string, MEMORY_DEFAULT);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Write the exit code for the assembly file
|
|
||||||
void asm_write_exit(vec_t *asm_buffer)
|
|
||||||
{
|
|
||||||
vec_append(asm_buffer,
|
|
||||||
" mov rax, 60\n"
|
|
||||||
" mov rdi, 0\n"
|
|
||||||
" syscall\n",
|
|
||||||
37);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* The system calling code - not exactly pretty, but it is what it is. */
|
/* The system calling code - not exactly pretty, but it is what it is. */
|
||||||
|
|
||||||
void asm_write(const char *asm_name, vec_t *asm_buffer)
|
void asm_write(const char *asm_name, vec_t *asm_buffer)
|
||||||
|
|||||||
Reference in New Issue
Block a user