aboutsummaryrefslogtreecommitdiff
path: root/assembler.c
diff options
context:
space:
mode:
Diffstat (limited to 'assembler.c')
-rw-r--r--assembler.c75
1 files changed, 37 insertions, 38 deletions
diff --git a/assembler.c b/assembler.c
index faf7bb3..3c45a7b 100644
--- a/assembler.c
+++ b/assembler.c
@@ -14,44 +14,6 @@ struct Label
u64 cur, next;
};
-/* First, the functions to call external utilities (badly written, I know). They
- * presume a filled asm_buffer. */
-
-void asm_write(const char *asm_name, vec_t *asm_buffer)
-{
- FILE *fp = fopen(asm_name, "w");
- fwrite(asm_buffer->data, asm_buffer->size, 1, fp);
- fclose(fp);
-}
-
-int asm_assemble(const char *asm_name, const char *objname)
-{
-#ifdef DEBUG
- char *format_str = "yasm -f elf64 -g dwarf2 -o %s %s";
-#else
- char *format_str = "yasm -f elf64 -o %s %s";
-#endif
- char command[snprintf(NULL, 0, format_str, objname, asm_name) + 1];
- sprintf(command, format_str, objname, asm_name);
- return system(command);
-}
-
-int asm_link(const char *objname, const char *outname)
-{
- char *format_str = "ld -o %s %s";
- char command[snprintf(NULL, 0, format_str, outname, objname) + 1];
- sprintf(command, format_str, outname, objname);
- return system(command);
-}
-
-int asm_compile(vec_t *asm_buffer, const char *asm_name, const char *objname,
- const char *outname)
-{
- asm_write(asm_name, asm_buffer);
- asm_assemble(asm_name, objname);
- return asm_link(objname, outname);
-}
-
// A table which translates brainfuck operations into generic assembly code (I
// love C's array indexing)
static const struct
@@ -204,3 +166,40 @@ void asm_write_exit(vec_t *asm_buffer)
" syscall\n",
37);
}
+
+/* The system calling code - not exactly pretty, but it is what it is. */
+
+void asm_write(const char *asm_name, vec_t *asm_buffer)
+{
+ FILE *fp = fopen(asm_name, "w");
+ fwrite(asm_buffer->data, asm_buffer->size, 1, fp);
+ fclose(fp);
+}
+
+int asm_assemble(const char *asm_name, const char *objname)
+{
+#ifdef DEBUG
+ char *format_str = "yasm -f elf64 -g dwarf2 -o %s %s";
+#else
+ char *format_str = "yasm -f elf64 -o %s %s";
+#endif
+ char command[snprintf(NULL, 0, format_str, objname, asm_name) + 1];
+ sprintf(command, format_str, objname, asm_name);
+ return system(command);
+}
+
+int asm_link(const char *objname, const char *outname)
+{
+ char *format_str = "ld -o %s %s";
+ char command[snprintf(NULL, 0, format_str, outname, objname) + 1];
+ sprintf(command, format_str, outname, objname);
+ return system(command);
+}
+
+int asm_compile(vec_t *asm_buffer, const char *asm_name, const char *objname,
+ const char *outname)
+{
+ asm_write(asm_name, asm_buffer);
+ asm_assemble(asm_name, objname);
+ return asm_link(objname, outname);
+}