diff options
author | Aryadev Chavali <aryadev@aryadevchavali.com> | 2024-12-24 22:57:28 +0000 |
---|---|---|
committer | Aryadev Chavali <aryadev@aryadevchavali.com> | 2024-12-24 22:57:28 +0000 |
commit | 70cfeac9959310944619bcf45f039d48f10f8c20 (patch) | |
tree | 86cc036cb9d39792f090cd2cd2b349f8f605cbc7 | |
parent | 493b98c52447461aca5a5bdc41aca7ef1e8e893b (diff) | |
download | obf-70cfeac9959310944619bcf45f039d48f10f8c20.tar.gz obf-70cfeac9959310944619bcf45f039d48f10f8c20.tar.bz2 obf-70cfeac9959310944619bcf45f039d48f10f8c20.zip |
Move system calling code to the end
-rw-r--r-- | assembler.c | 75 |
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); +} |