public inbox for ~johnnyrichard/olang-devel@lists.sr.ht
 help / color / mirror / code / Atom feed
* [olang/patches/.build.yml] build success
  2024-10-17  0:20 ` [PATCH olang v1 3/3] codegen: remove linux from codegen namespace Johnny Richard
@ 2024-10-16 22:22   ` builds.sr.ht
  0 siblings, 0 replies; 6+ messages in thread
From: builds.sr.ht @ 2024-10-16 22:22 UTC (permalink / raw)
  To: Johnny Richard; +Cc: ~johnnyrichard/olang-devel

olang/patches/.build.yml: SUCCESS in 30s

[cli: enable object file binary compilation][0] from [Johnny Richard][1]

[0]: https://lists.sr.ht/~johnnyrichard/olang-devel/patches/55511
[1]: mailto:johnny@johnnyrichard.com

✓ #1352183 SUCCESS olang/patches/.build.yml https://builds.sr.ht/~johnnyrichard/job/1352183

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH olang v1 0/3] cli: enable object file binary compilation
  2024-10-17  0:19 [PATCH olang v1 0/3] cli: enable object file binary compilation Johnny Richard
@ 2024-10-16 22:25 ` Carlos Maniero
  2024-10-17  0:19 ` [PATCH olang v1 1/3] codegen: link olang binary with libc by default Johnny Richard
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Carlos Maniero @ 2024-10-16 22:25 UTC (permalink / raw)
  To: Johnny Richard, ~johnnyrichard/olang-devel

Applied! Great work!

To git.sr.ht:~johnnyrichard/olang
   df8420f..160969f  main -> main

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH olang v1 0/3] cli: enable object file binary compilation
@ 2024-10-17  0:19 Johnny Richard
  2024-10-16 22:25 ` Carlos Maniero
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Johnny Richard @ 2024-10-17  0:19 UTC (permalink / raw)
  To: ~johnnyrichard/olang-devel; +Cc: Johnny Richard

Johnny Richard (3):
  codegen: link olang binary with libc by default
  cli: add option -c to compile without linking
  codegen: remove linux from codegen namespace

 docs/man/man1/olc.1                           |   6 +
 src/cli.c                                     |   3 +
 src/cli.h                                     |   3 +-
 ...egen_linux_aarch64.c => codegen_aarch64.c} |  16 +-
 ...egen_linux_aarch64.h => codegen_aarch64.h} |   2 +-
 ...odegen_linux_x86_64.c => codegen_x86_64.c} | 254 +++++++-----------
 ...odegen_linux_x86_64.h => codegen_x86_64.h} |   6 +-
 src/main.c                                    |  37 +--
 8 files changed, 135 insertions(+), 192 deletions(-)
 rename src/{codegen_linux_aarch64.c => codegen_aarch64.c} (88%)
 rename src/{codegen_linux_aarch64.h => codegen_aarch64.h} (91%)
 rename src/{codegen_linux_x86_64.c => codegen_x86_64.c} (77%)
 rename src/{codegen_linux_x86_64.h => codegen_x86_64.h} (82%)


base-commit: df8420f27dd88669bc3c9c21903c79669903a414
-- 
2.46.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH olang v1 1/3] codegen: link olang binary with libc by default
  2024-10-17  0:19 [PATCH olang v1 0/3] cli: enable object file binary compilation Johnny Richard
  2024-10-16 22:25 ` Carlos Maniero
@ 2024-10-17  0:19 ` Johnny Richard
  2024-10-17  0:19 ` [PATCH olang v1 2/3] cli: add option -c to compile without linking Johnny Richard
  2024-10-17  0:20 ` [PATCH olang v1 3/3] codegen: remove linux from codegen namespace Johnny Richard
  3 siblings, 0 replies; 6+ messages in thread
From: Johnny Richard @ 2024-10-17  0:19 UTC (permalink / raw)
  To: ~johnnyrichard/olang-devel; +Cc: Johnny Richard

Signed-off-by: Johnny Richard <johnny@johnnyrichard.com>
---
 src/codegen_linux_x86_64.c | 19 ++-----------------
 src/main.c                 |  2 +-
 2 files changed, 3 insertions(+), 18 deletions(-)

diff --git a/src/codegen_linux_x86_64.c b/src/codegen_linux_x86_64.c
index 83d1d2c..6d38b53 100644
--- a/src/codegen_linux_x86_64.c
+++ b/src/codegen_linux_x86_64.c
@@ -61,9 +61,6 @@ static int x86_call_args[X86_CALL_ARG_SIZE] = { REG_DEST_IDX, REG_SRC_IDX,
                                                 REG_DATA,     REG_R10,
                                                 REG_R8,       REG_R9 };
 
-static void
-codegen_linux_x86_64_emit_start_entrypoint(codegen_x86_64_t *codegen);
-
 static void
 codegen_linux_x86_64_emit_function(codegen_x86_64_t *codegen,
                                    ast_fn_definition_t *fn);
@@ -103,7 +100,7 @@ codegen_linux_x86_64_emit_translation_unit(codegen_x86_64_t *codegen,
                                            ast_node_t *node)
 {
     codegen->label_index = 0;
-    codegen_linux_x86_64_emit_start_entrypoint(codegen);
+    fprintf(codegen->out, ".text\n");
 
     assert(node->kind == AST_NODE_TRANSLATION_UNIT);
     ast_translation_unit_t translation_unit = node->as_translation_unit;
@@ -130,19 +127,6 @@ codegen_linux_x86_64_emit_translation_unit(codegen_x86_64_t *codegen,
     assert(main_found && "main function is required.");
 }
 
-static void
-codegen_linux_x86_64_emit_start_entrypoint(codegen_x86_64_t *codegen)
-{
-    fprintf(codegen->out, ".text\n");
-    fprintf(codegen->out, ".globl _start\n\n");
-
-    fprintf(codegen->out, "_start:\n");
-    fprintf(codegen->out, "    call main\n");
-    fprintf(codegen->out, "    mov %%eax, %%edi\n");
-    fprintf(codegen->out, "    mov $%d, %%eax\n", SYS_exit);
-    fprintf(codegen->out, "    syscall\n");
-}
-
 static size_t
 codegen_linux_x86_64_get_next_label(codegen_x86_64_t *codegen)
 {
@@ -956,6 +940,7 @@ static void
 codegen_linux_x86_64_emit_function(codegen_x86_64_t *codegen,
                                    ast_fn_definition_t *fn_def)
 {
+    fprintf(codegen->out, ".globl " SV_FMT "\n", SV_ARG(fn_def->id));
     codegen->base_offset = 0;
 
     ast_node_t *block_node = fn_def->block;
diff --git a/src/main.c b/src/main.c
index 2b02564..c68fd48 100644
--- a/src/main.c
+++ b/src/main.c
@@ -185,7 +185,7 @@ handle_codegen_linux(cli_opts_t *opts)
     }
 
     sprintf(command,
-            "%s/bin/ld " SV_FMT ".o -o " SV_FMT "",
+            "%s/bin/cc " SV_FMT ".o -o " SV_FMT,
             opts->sysroot,
             SV_ARG(opts->output_bin),
             SV_ARG(opts->output_bin));
-- 
2.46.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH olang v1 2/3] cli: add option -c to compile without linking
  2024-10-17  0:19 [PATCH olang v1 0/3] cli: enable object file binary compilation Johnny Richard
  2024-10-16 22:25 ` Carlos Maniero
  2024-10-17  0:19 ` [PATCH olang v1 1/3] codegen: link olang binary with libc by default Johnny Richard
@ 2024-10-17  0:19 ` Johnny Richard
  2024-10-17  0:20 ` [PATCH olang v1 3/3] codegen: remove linux from codegen namespace Johnny Richard
  3 siblings, 0 replies; 6+ messages in thread
From: Johnny Richard @ 2024-10-17  0:19 UTC (permalink / raw)
  To: ~johnnyrichard/olang-devel; +Cc: Johnny Richard

Signed-off-by: Johnny Richard <johnny@johnnyrichard.com>
---
 docs/man/man1/olc.1        |  6 ++++++
 src/cli.c                  |  3 +++
 src/cli.h                  |  3 ++-
 src/codegen_linux_x86_64.c |  6 ------
 src/main.c                 | 23 +++++++++++++----------
 5 files changed, 24 insertions(+), 17 deletions(-)

diff --git a/docs/man/man1/olc.1 b/docs/man/man1/olc.1
index 5b35f05..c44df5e 100644
--- a/docs/man/man1/olc.1
+++ b/docs/man/man1/olc.1
@@ -33,6 +33,12 @@ Display AST tree to stdout right after syntax analyzes
 .BI \-o\  file
 Compile program into a binary file
 
+.TP
+.BI \-c
+Compile or assemble the source files, but do not link.  The linking stage
+simply  is  not  done.   The ultimate output is in the form of an object file
+for each source file.
+
 .TP
 .BR \-\-save\-temps
 Keep temp files used to compile program
diff --git a/src/cli.c b/src/cli.c
index 2f61acb..afed19b 100644
--- a/src/cli.c
+++ b/src/cli.c
@@ -53,6 +53,8 @@ cli_parse_args(int argc, char **argv)
             opts.options |= CLI_OPT_SAVE_TEMPS;
         } else if (strcmp(arg, "-o") == 0) {
             cli_opts_parse_output(&opts, &args);
+        } else if (strcmp(arg, "-c") == 0) {
+            opts.options |= CLI_OPT_COMPILE_ONLY;
         } else if (strcmp(arg, "--arch") == 0) {
             opts.options |= CLI_OPT_ARCH;
             cli_opts_parse_arch(&opts, &args);
@@ -153,6 +155,7 @@ cli_print_usage(FILE *stream, char *compiler_path)
         "  --sysroot <dir>  System root dir where the GNU Assembler and GNU "
         "Linker are located: default to '/'\n"
         "  -o <file>        Compile program into a binary file\n"
+        "  -c               Assemble the source files, but do not link\n"
         "  --save-temps     Keep temp files used to compile program\n",
         compiler_path);
 }
diff --git a/src/cli.h b/src/cli.h
index 1a93443..ee02adf 100644
--- a/src/cli.h
+++ b/src/cli.h
@@ -43,7 +43,8 @@ typedef enum
     CLI_OPT_SAVE_TEMPS = 1 << 2,
     CLI_OPT_ARCH = 1 << 3,
     CLI_OPT_SYSROOT = 1 << 4,
-    CLI_OPT_DUMP_AST = 1 << 5
+    CLI_OPT_DUMP_AST = 1 << 5,
+    CLI_OPT_COMPILE_ONLY = 1 << 6
 } cli_opt_t;
 
 cli_opts_t
diff --git a/src/codegen_linux_x86_64.c b/src/codegen_linux_x86_64.c
index 6d38b53..6348dad 100644
--- a/src/codegen_linux_x86_64.c
+++ b/src/codegen_linux_x86_64.c
@@ -107,24 +107,18 @@ codegen_linux_x86_64_emit_translation_unit(codegen_x86_64_t *codegen,
 
     list_item_t *item = list_head(translation_unit.decls);
 
-    bool main_found = false;
-
     while (item != NULL) {
         ast_node_t *decl = (ast_node_t *)item->value;
 
         if (decl->kind == AST_NODE_FN_DEF) {
             ast_fn_definition_t fn = decl->as_fn_def;
             codegen_linux_x86_64_emit_function(codegen, &fn);
-
-            main_found = main_found || string_view_eq_to_cstr(fn.id, "main");
         } else {
             assert(0 && "translation unit only supports function declarations");
         }
 
         item = list_next(item);
     }
-
-    assert(main_found && "main function is required.");
 }
 
 static size_t
diff --git a/src/main.c b/src/main.c
index c68fd48..49b2240 100644
--- a/src/main.c
+++ b/src/main.c
@@ -173,10 +173,11 @@ handle_codegen_linux(cli_opts_t *opts)
 
     char command[512];
     sprintf(command,
-            "%s/bin/as %s -o " SV_FMT ".o",
+            "%s/bin/as %s -o " SV_FMT "%s",
             opts->sysroot,
             asm_file,
-            SV_ARG(opts->output_bin));
+            SV_ARG(opts->output_bin),
+            opts->options & CLI_OPT_COMPILE_ONLY ? "" : ".o");
 
     int exit_code = system(command);
 
@@ -184,16 +185,18 @@ handle_codegen_linux(cli_opts_t *opts)
         exit(exit_code);
     }
 
-    sprintf(command,
-            "%s/bin/cc " SV_FMT ".o -o " SV_FMT,
-            opts->sysroot,
-            SV_ARG(opts->output_bin),
-            SV_ARG(opts->output_bin));
+    if (!(opts->options & CLI_OPT_COMPILE_ONLY)) {
+        sprintf(command,
+                "%s/bin/cc " SV_FMT ".o -o " SV_FMT,
+                opts->sysroot,
+                SV_ARG(opts->output_bin),
+                SV_ARG(opts->output_bin));
 
-    exit_code = system(command);
+        exit_code = system(command);
 
-    if (exit_code != 0) {
-        exit(exit_code);
+        if (exit_code != 0) {
+            exit(exit_code);
+        }
     }
 
     if (!(opts->options & CLI_OPT_SAVE_TEMPS)) {
-- 
2.46.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH olang v1 3/3] codegen: remove linux from codegen namespace
  2024-10-17  0:19 [PATCH olang v1 0/3] cli: enable object file binary compilation Johnny Richard
                   ` (2 preceding siblings ...)
  2024-10-17  0:19 ` [PATCH olang v1 2/3] cli: add option -c to compile without linking Johnny Richard
@ 2024-10-17  0:20 ` Johnny Richard
  2024-10-16 22:22   ` [olang/patches/.build.yml] build success builds.sr.ht
  3 siblings, 1 reply; 6+ messages in thread
From: Johnny Richard @ 2024-10-17  0:20 UTC (permalink / raw)
  To: ~johnnyrichard/olang-devel; +Cc: Johnny Richard

Since the codegen is OS dependent, we don't need to tie the compilation
to linux.

Signed-off-by: Johnny Richard <johnny@johnnyrichard.com>
---
 ...egen_linux_aarch64.c => codegen_aarch64.c} |  16 +-
 ...egen_linux_aarch64.h => codegen_aarch64.h} |   2 +-
 ...odegen_linux_x86_64.c => codegen_x86_64.c} | 229 +++++++-----------
 ...odegen_linux_x86_64.h => codegen_x86_64.h} |   6 +-
 src/main.c                                    |  14 +-
 5 files changed, 109 insertions(+), 158 deletions(-)
 rename src/{codegen_linux_aarch64.c => codegen_aarch64.c} (88%)
 rename src/{codegen_linux_aarch64.h => codegen_aarch64.h} (91%)
 rename src/{codegen_linux_x86_64.c => codegen_x86_64.c} (78%)
 rename src/{codegen_linux_x86_64.h => codegen_x86_64.h} (82%)

diff --git a/src/codegen_linux_aarch64.c b/src/codegen_aarch64.c
similarity index 88%
rename from src/codegen_linux_aarch64.c
rename to src/codegen_aarch64.c
index d8187ab..1de238d 100644
--- a/src/codegen_linux_aarch64.c
+++ b/src/codegen_aarch64.c
@@ -18,7 +18,7 @@
 #include <stdint.h>
 #include <stdio.h>
 
-#include "codegen_linux_aarch64.h"
+#include "codegen_aarch64.h"
 #include "list.h"
 
 #define SYS_exit (93)
@@ -36,15 +36,15 @@
  */
 
 static void
-codegen_linux_aarch64_emit_start_entrypoint(FILE *out);
+codegen_aarch64_emit_start_entrypoint(FILE *out);
 
 static void
-codegen_linux_aarch64_emit_function(FILE *out, ast_fn_definition_t *fn);
+codegen_aarch64_emit_function(FILE *out, ast_fn_definition_t *fn);
 
 void
-codegen_linux_aarch64_emit_translation_unit(FILE *out, ast_node_t *node)
+codegen_aarch64_emit_translation_unit(FILE *out, ast_node_t *node)
 {
-    codegen_linux_aarch64_emit_start_entrypoint(out);
+    codegen_aarch64_emit_start_entrypoint(out);
 
     assert(node->kind == AST_NODE_TRANSLATION_UNIT);
     ast_translation_unit_t translation_unit = node->as_translation_unit;
@@ -58,7 +58,7 @@ codegen_linux_aarch64_emit_translation_unit(FILE *out, ast_node_t *node)
 
         if (decl->kind == AST_NODE_FN_DEF) {
             ast_fn_definition_t fn = decl->as_fn_def;
-            codegen_linux_aarch64_emit_function(out, &fn);
+            codegen_aarch64_emit_function(out, &fn);
 
             main_found = main_found || string_view_eq_to_cstr(fn.id, "main");
         } else {
@@ -72,7 +72,7 @@ codegen_linux_aarch64_emit_translation_unit(FILE *out, ast_node_t *node)
 }
 
 static void
-codegen_linux_aarch64_emit_start_entrypoint(FILE *out)
+codegen_aarch64_emit_start_entrypoint(FILE *out)
 {
     fprintf(out, ".text\n");
     fprintf(out, ".globl _start\n\n");
@@ -84,7 +84,7 @@ codegen_linux_aarch64_emit_start_entrypoint(FILE *out)
 }
 
 static void
-codegen_linux_aarch64_emit_function(FILE *out, ast_fn_definition_t *fn)
+codegen_aarch64_emit_function(FILE *out, ast_fn_definition_t *fn)
 {
     ast_node_t *block_node = fn->block;
     assert(block_node->kind == AST_NODE_BLOCK);
diff --git a/src/codegen_linux_aarch64.h b/src/codegen_aarch64.h
similarity index 91%
rename from src/codegen_linux_aarch64.h
rename to src/codegen_aarch64.h
index 03e2f46..3f7e0b0 100644
--- a/src/codegen_linux_aarch64.h
+++ b/src/codegen_aarch64.h
@@ -20,6 +20,6 @@
 #include "ast.h"
 
 void
-codegen_linux_aarch64_emit_translation_unit(FILE *out, ast_node_t *prog);
+codegen_aarch64_emit_translation_unit(FILE *out, ast_node_t *prog);
 
 #endif /* CODEGEN_LINUX_AARCH64_H */
diff --git a/src/codegen_linux_x86_64.c b/src/codegen_x86_64.c
similarity index 78%
rename from src/codegen_linux_x86_64.c
rename to src/codegen_x86_64.c
index 6348dad..6758fc1 100644
--- a/src/codegen_linux_x86_64.c
+++ b/src/codegen_x86_64.c
@@ -18,7 +18,7 @@
 #include <stdint.h>
 #include <stdio.h>
 
-#include "codegen_linux_x86_64.h"
+#include "codegen_x86_64.h"
 #include "list.h"
 #include "map.h"
 #include "scope.h"
@@ -62,20 +62,19 @@ static int x86_call_args[X86_CALL_ARG_SIZE] = { REG_DEST_IDX, REG_SRC_IDX,
                                                 REG_R8,       REG_R9 };
 
 static void
-codegen_linux_x86_64_emit_function(codegen_x86_64_t *codegen,
-                                   ast_fn_definition_t *fn);
+codegen_x86_64_emit_function(codegen_x86_64_t *codegen,
+                             ast_fn_definition_t *fn);
 
 static void
-codegen_linux_x86_64_emit_if(codegen_x86_64_t *codegen, ast_if_stmt_t is_stmt);
+codegen_x86_64_emit_if(codegen_x86_64_t *codegen, ast_if_stmt_t is_stmt);
 
 static void
-codegen_linux_x86_64_put_stack_offset(codegen_x86_64_t *codegen,
-                                      symbol_t *symbol,
-                                      size_t offset);
+codegen_x86_64_put_stack_offset(codegen_x86_64_t *codegen,
+                                symbol_t *symbol,
+                                size_t offset);
 
 static size_t
-codegen_linux_x86_64_get_stack_offset(codegen_x86_64_t *codegen,
-                                      symbol_t *symbol);
+codegen_x86_64_get_stack_offset(codegen_x86_64_t *codegen, symbol_t *symbol);
 
 static size_t
 type_to_bytes(type_t *type);
@@ -84,7 +83,7 @@ static char *
 get_reg_for(x86_64_register_type_t type, size_t bytes);
 
 void
-codegen_linux_x86_64_init(codegen_x86_64_t *codegen, arena_t *arena, FILE *out)
+codegen_x86_64_init(codegen_x86_64_t *codegen, arena_t *arena, FILE *out)
 {
     assert(codegen);
     assert(arena);
@@ -96,8 +95,8 @@ codegen_linux_x86_64_init(codegen_x86_64_t *codegen, arena_t *arena, FILE *out)
 }
 
 void
-codegen_linux_x86_64_emit_translation_unit(codegen_x86_64_t *codegen,
-                                           ast_node_t *node)
+codegen_x86_64_emit_translation_unit(codegen_x86_64_t *codegen,
+                                     ast_node_t *node)
 {
     codegen->label_index = 0;
     fprintf(codegen->out, ".text\n");
@@ -112,7 +111,7 @@ codegen_linux_x86_64_emit_translation_unit(codegen_x86_64_t *codegen,
 
         if (decl->kind == AST_NODE_FN_DEF) {
             ast_fn_definition_t fn = decl->as_fn_def;
-            codegen_linux_x86_64_emit_function(codegen, &fn);
+            codegen_x86_64_emit_function(codegen, &fn);
         } else {
             assert(0 && "translation unit only supports function declarations");
         }
@@ -122,7 +121,7 @@ codegen_linux_x86_64_emit_translation_unit(codegen_x86_64_t *codegen,
 }
 
 static size_t
-codegen_linux_x86_64_get_next_label(codegen_x86_64_t *codegen)
+codegen_x86_64_get_next_label(codegen_x86_64_t *codegen)
 {
     return ++codegen->label_index;
 }
@@ -130,8 +129,7 @@ codegen_linux_x86_64_get_next_label(codegen_x86_64_t *codegen)
 typedef size_t size_in_bytes_t;
 
 static size_in_bytes_t
-codegen_linux_x86_64_emit_expression(codegen_x86_64_t *codegen,
-                                     ast_node_t *expr_node)
+codegen_x86_64_emit_expression(codegen_x86_64_t *codegen, ast_node_t *expr_node)
 {
     switch (expr_node->kind) {
         case AST_NODE_LITERAL: {
@@ -148,8 +146,7 @@ codegen_linux_x86_64_emit_expression(codegen_x86_64_t *codegen,
             symbol_t *symbol = scope_lookup(ref.scope, ref.id);
             assert(symbol);
 
-            size_t offset =
-                codegen_linux_x86_64_get_stack_offset(codegen, symbol);
+            size_t offset = codegen_x86_64_get_stack_offset(codegen, symbol);
 
             size_t bytes = type_to_bytes(symbol->type);
 
@@ -173,7 +170,7 @@ codegen_linux_x86_64_emit_expression(codegen_x86_64_t *codegen,
 
                 ast_node_t *arg_node = (ast_node_t *)item->value;
 
-                codegen_linux_x86_64_emit_expression(codegen, arg_node);
+                codegen_x86_64_emit_expression(codegen, arg_node);
 
                 fprintf(codegen->out,
                         "    push %s\n",
@@ -197,14 +194,12 @@ codegen_linux_x86_64_emit_expression(codegen_x86_64_t *codegen,
                 case AST_BINOP_ADDITION: {
                     fprintf(codegen->out, "    xor %%rax, %%rax\n");
                     size_in_bytes_t rhs_bytes =
-                        codegen_linux_x86_64_emit_expression(codegen,
-                                                             bin_op.rhs);
+                        codegen_x86_64_emit_expression(codegen, bin_op.rhs);
                     fprintf(codegen->out, "    push %%rax\n");
 
                     fprintf(codegen->out, "    xor %%rax, %%rax\n");
                     size_in_bytes_t lhs_bytes =
-                        codegen_linux_x86_64_emit_expression(codegen,
-                                                             bin_op.lhs);
+                        codegen_x86_64_emit_expression(codegen, bin_op.lhs);
 
                     size_in_bytes_t expr_bytes =
                         bytes_max(rhs_bytes, lhs_bytes);
@@ -220,14 +215,12 @@ codegen_linux_x86_64_emit_expression(codegen_x86_64_t *codegen,
                 case AST_BINOP_MULTIPLICATION: {
                     fprintf(codegen->out, "    xor %%rax, %%rax\n");
                     size_in_bytes_t rhs_bytes =
-                        codegen_linux_x86_64_emit_expression(codegen,
-                                                             bin_op.rhs);
+                        codegen_x86_64_emit_expression(codegen, bin_op.rhs);
                     fprintf(codegen->out, "    push %%rax\n");
 
                     fprintf(codegen->out, "    xor %%rax, %%rax\n");
                     size_in_bytes_t lhs_bytes =
-                        codegen_linux_x86_64_emit_expression(codegen,
-                                                             bin_op.lhs);
+                        codegen_x86_64_emit_expression(codegen, bin_op.lhs);
 
                     size_in_bytes_t expr_bytes =
                         bytes_max(rhs_bytes, lhs_bytes);
@@ -242,14 +235,12 @@ codegen_linux_x86_64_emit_expression(codegen_x86_64_t *codegen,
                 case AST_BINOP_DIVISION: {
                     fprintf(codegen->out, "    xor %%rax, %%rax\n");
                     size_in_bytes_t rhs_bytes =
-                        codegen_linux_x86_64_emit_expression(codegen,
-                                                             bin_op.rhs);
+                        codegen_x86_64_emit_expression(codegen, bin_op.rhs);
                     fprintf(codegen->out, "    push %%rax\n");
 
                     fprintf(codegen->out, "    xor %%rax, %%rax\n");
                     size_in_bytes_t lhs_bytes =
-                        codegen_linux_x86_64_emit_expression(codegen,
-                                                             bin_op.lhs);
+                        codegen_x86_64_emit_expression(codegen, bin_op.lhs);
 
                     size_in_bytes_t expr_bytes =
                         bytes_max(rhs_bytes, lhs_bytes);
@@ -265,14 +256,12 @@ codegen_linux_x86_64_emit_expression(codegen_x86_64_t *codegen,
                 case AST_BINOP_REMINDER: {
                     fprintf(codegen->out, "    xor %%rax, %%rax\n");
                     size_in_bytes_t rhs_bytes =
-                        codegen_linux_x86_64_emit_expression(codegen,
-                                                             bin_op.rhs);
+                        codegen_x86_64_emit_expression(codegen, bin_op.rhs);
                     fprintf(codegen->out, "    push %%rax\n");
 
                     fprintf(codegen->out, "    xor %%rax, %%rax\n");
                     size_in_bytes_t lhs_bytes =
-                        codegen_linux_x86_64_emit_expression(codegen,
-                                                             bin_op.lhs);
+                        codegen_x86_64_emit_expression(codegen, bin_op.lhs);
 
                     size_in_bytes_t expr_bytes =
                         bytes_max(rhs_bytes, lhs_bytes);
@@ -292,14 +281,12 @@ codegen_linux_x86_64_emit_expression(codegen_x86_64_t *codegen,
                 case AST_BINOP_SUBTRACTION: {
                     fprintf(codegen->out, "    xor %%rax, %%rax\n");
                     size_in_bytes_t rhs_bytes =
-                        codegen_linux_x86_64_emit_expression(codegen,
-                                                             bin_op.rhs);
+                        codegen_x86_64_emit_expression(codegen, bin_op.rhs);
                     fprintf(codegen->out, "    push %%rax\n");
 
                     fprintf(codegen->out, "    xor %%rax, %%rax\n");
                     size_in_bytes_t lhs_bytes =
-                        codegen_linux_x86_64_emit_expression(codegen,
-                                                             bin_op.lhs);
+                        codegen_x86_64_emit_expression(codegen, bin_op.lhs);
 
                     size_in_bytes_t expr_bytes =
                         bytes_max(rhs_bytes, lhs_bytes);
@@ -315,14 +302,12 @@ codegen_linux_x86_64_emit_expression(codegen_x86_64_t *codegen,
                 case AST_BINOP_CMP_EQ: {
                     fprintf(codegen->out, "    xor %%rax, %%rax\n");
                     size_in_bytes_t rhs_bytes =
-                        codegen_linux_x86_64_emit_expression(codegen,
-                                                             bin_op.rhs);
+                        codegen_x86_64_emit_expression(codegen, bin_op.rhs);
                     fprintf(codegen->out, "    push %%rax\n");
 
                     fprintf(codegen->out, "    xor %%rax, %%rax\n");
                     size_in_bytes_t lhs_bytes =
-                        codegen_linux_x86_64_emit_expression(codegen,
-                                                             bin_op.lhs);
+                        codegen_x86_64_emit_expression(codegen, bin_op.lhs);
 
                     size_in_bytes_t expr_bytes =
                         bytes_max(rhs_bytes, lhs_bytes);
@@ -342,14 +327,12 @@ codegen_linux_x86_64_emit_expression(codegen_x86_64_t *codegen,
                 case AST_BINOP_CMP_LT: {
                     fprintf(codegen->out, "    xor %%rax, %%rax\n");
                     size_in_bytes_t rhs_bytes =
-                        codegen_linux_x86_64_emit_expression(codegen,
-                                                             bin_op.rhs);
+                        codegen_x86_64_emit_expression(codegen, bin_op.rhs);
                     fprintf(codegen->out, "    push %%rax\n");
 
                     fprintf(codegen->out, "    xor %%rax, %%rax\n");
                     size_in_bytes_t lhs_bytes =
-                        codegen_linux_x86_64_emit_expression(codegen,
-                                                             bin_op.lhs);
+                        codegen_x86_64_emit_expression(codegen, bin_op.lhs);
 
                     size_in_bytes_t expr_bytes =
                         bytes_max(rhs_bytes, lhs_bytes);
@@ -369,14 +352,12 @@ codegen_linux_x86_64_emit_expression(codegen_x86_64_t *codegen,
                 case AST_BINOP_CMP_GT: {
                     fprintf(codegen->out, "    xor %%rax, %%rax\n");
                     size_in_bytes_t rhs_bytes =
-                        codegen_linux_x86_64_emit_expression(codegen,
-                                                             bin_op.rhs);
+                        codegen_x86_64_emit_expression(codegen, bin_op.rhs);
                     fprintf(codegen->out, "    push %%rax\n");
 
                     fprintf(codegen->out, "    xor %%rax, %%rax\n");
                     size_in_bytes_t lhs_bytes =
-                        codegen_linux_x86_64_emit_expression(codegen,
-                                                             bin_op.lhs);
+                        codegen_x86_64_emit_expression(codegen, bin_op.lhs);
 
                     size_in_bytes_t expr_bytes =
                         bytes_max(rhs_bytes, lhs_bytes);
@@ -396,14 +377,12 @@ codegen_linux_x86_64_emit_expression(codegen_x86_64_t *codegen,
                 case AST_BINOP_CMP_NEQ: {
                     fprintf(codegen->out, "    xor %%rax, %%rax\n");
                     size_in_bytes_t rhs_bytes =
-                        codegen_linux_x86_64_emit_expression(codegen,
-                                                             bin_op.rhs);
+                        codegen_x86_64_emit_expression(codegen, bin_op.rhs);
                     fprintf(codegen->out, "    push %%rax\n");
 
                     fprintf(codegen->out, "    xor %%rax, %%rax\n");
                     size_in_bytes_t lhs_bytes =
-                        codegen_linux_x86_64_emit_expression(codegen,
-                                                             bin_op.lhs);
+                        codegen_x86_64_emit_expression(codegen, bin_op.lhs);
 
                     size_in_bytes_t expr_bytes =
                         bytes_max(rhs_bytes, lhs_bytes);
@@ -423,14 +402,12 @@ codegen_linux_x86_64_emit_expression(codegen_x86_64_t *codegen,
                 case AST_BINOP_CMP_LEQ: {
                     fprintf(codegen->out, "    xor %%rax, %%rax\n");
                     size_in_bytes_t rhs_bytes =
-                        codegen_linux_x86_64_emit_expression(codegen,
-                                                             bin_op.rhs);
+                        codegen_x86_64_emit_expression(codegen, bin_op.rhs);
                     fprintf(codegen->out, "    push %%rax\n");
 
                     fprintf(codegen->out, "    xor %%rax, %%rax\n");
                     size_in_bytes_t lhs_bytes =
-                        codegen_linux_x86_64_emit_expression(codegen,
-                                                             bin_op.lhs);
+                        codegen_x86_64_emit_expression(codegen, bin_op.lhs);
 
                     size_in_bytes_t expr_bytes =
                         bytes_max(rhs_bytes, lhs_bytes);
@@ -450,14 +427,12 @@ codegen_linux_x86_64_emit_expression(codegen_x86_64_t *codegen,
                 case AST_BINOP_CMP_GEQ: {
                     fprintf(codegen->out, "    xor %%rax, %%rax\n");
                     size_in_bytes_t rhs_bytes =
-                        codegen_linux_x86_64_emit_expression(codegen,
-                                                             bin_op.rhs);
+                        codegen_x86_64_emit_expression(codegen, bin_op.rhs);
                     fprintf(codegen->out, "    push %%rax\n");
 
                     fprintf(codegen->out, "    xor %%rax, %%rax\n");
                     size_in_bytes_t lhs_bytes =
-                        codegen_linux_x86_64_emit_expression(codegen,
-                                                             bin_op.lhs);
+                        codegen_x86_64_emit_expression(codegen, bin_op.lhs);
 
                     size_in_bytes_t expr_bytes =
                         bytes_max(rhs_bytes, lhs_bytes);
@@ -476,13 +451,12 @@ codegen_linux_x86_64_emit_expression(codegen_x86_64_t *codegen,
                 }
                 case AST_BINOP_BITWISE_LSHIFT: {
                     fprintf(codegen->out, "    xor %%rax, %%rax\n");
-                    codegen_linux_x86_64_emit_expression(codegen, bin_op.rhs);
+                    codegen_x86_64_emit_expression(codegen, bin_op.rhs);
                     fprintf(codegen->out, "    push %%rax\n");
 
                     fprintf(codegen->out, "    xor %%rax, %%rax\n");
                     size_in_bytes_t lhs_bytes =
-                        codegen_linux_x86_64_emit_expression(codegen,
-                                                             bin_op.lhs);
+                        codegen_x86_64_emit_expression(codegen, bin_op.lhs);
 
                     fprintf(codegen->out, "    pop %%rcx\n");
                     fprintf(codegen->out,
@@ -493,13 +467,12 @@ codegen_linux_x86_64_emit_expression(codegen_x86_64_t *codegen,
                 }
                 case AST_BINOP_BITWISE_RSHIFT: {
                     fprintf(codegen->out, "    xor %%rax, %%rax\n");
-                    codegen_linux_x86_64_emit_expression(codegen, bin_op.rhs);
+                    codegen_x86_64_emit_expression(codegen, bin_op.rhs);
                     fprintf(codegen->out, "    push %%rax\n");
 
                     fprintf(codegen->out, "    xor %%rax, %%rax\n");
                     size_in_bytes_t lhs_bytes =
-                        codegen_linux_x86_64_emit_expression(codegen,
-                                                             bin_op.lhs);
+                        codegen_x86_64_emit_expression(codegen, bin_op.lhs);
 
                     fprintf(codegen->out, "    pop %%rcx\n");
                     fprintf(codegen->out,
@@ -511,14 +484,12 @@ codegen_linux_x86_64_emit_expression(codegen_x86_64_t *codegen,
                 case AST_BINOP_BITWISE_XOR: {
                     fprintf(codegen->out, "    xor %%rax, %%rax\n");
                     size_in_bytes_t rhs_bytes =
-                        codegen_linux_x86_64_emit_expression(codegen,
-                                                             bin_op.rhs);
+                        codegen_x86_64_emit_expression(codegen, bin_op.rhs);
                     fprintf(codegen->out, "    push %%rax\n");
 
                     fprintf(codegen->out, "    xor %%rax, %%rax\n");
                     size_in_bytes_t lhs_bytes =
-                        codegen_linux_x86_64_emit_expression(codegen,
-                                                             bin_op.lhs);
+                        codegen_x86_64_emit_expression(codegen, bin_op.lhs);
 
                     size_in_bytes_t expr_bytes =
                         bytes_max(rhs_bytes, lhs_bytes);
@@ -534,14 +505,12 @@ codegen_linux_x86_64_emit_expression(codegen_x86_64_t *codegen,
                 case AST_BINOP_BITWISE_AND: {
                     fprintf(codegen->out, "    xor %%rax, %%rax\n");
                     size_in_bytes_t rhs_bytes =
-                        codegen_linux_x86_64_emit_expression(codegen,
-                                                             bin_op.rhs);
+                        codegen_x86_64_emit_expression(codegen, bin_op.rhs);
                     fprintf(codegen->out, "    push %%rax\n");
 
                     fprintf(codegen->out, "    xor %%rax, %%rax\n");
                     size_in_bytes_t lhs_bytes =
-                        codegen_linux_x86_64_emit_expression(codegen,
-                                                             bin_op.lhs);
+                        codegen_x86_64_emit_expression(codegen, bin_op.lhs);
 
                     size_in_bytes_t expr_bytes =
                         bytes_max(rhs_bytes, lhs_bytes);
@@ -557,14 +526,12 @@ codegen_linux_x86_64_emit_expression(codegen_x86_64_t *codegen,
                 case AST_BINOP_BITWISE_OR: {
                     fprintf(codegen->out, "    xor %%rax, %%rax\n");
                     size_in_bytes_t rhs_bytes =
-                        codegen_linux_x86_64_emit_expression(codegen,
-                                                             bin_op.rhs);
+                        codegen_x86_64_emit_expression(codegen, bin_op.rhs);
                     fprintf(codegen->out, "    push %%rax\n");
 
                     fprintf(codegen->out, "    xor %%rax, %%rax\n");
                     size_in_bytes_t lhs_bytes =
-                        codegen_linux_x86_64_emit_expression(codegen,
-                                                             bin_op.lhs);
+                        codegen_x86_64_emit_expression(codegen, bin_op.lhs);
 
                     size_in_bytes_t expr_bytes =
                         bytes_max(rhs_bytes, lhs_bytes);
@@ -578,13 +545,11 @@ codegen_linux_x86_64_emit_expression(codegen_x86_64_t *codegen,
                     return expr_bytes;
                 }
                 case AST_BINOP_LOGICAL_AND: {
-                    size_t label_exit =
-                        codegen_linux_x86_64_get_next_label(codegen);
+                    size_t label_exit = codegen_x86_64_get_next_label(codegen);
 
                     fprintf(codegen->out, "    xor %%rax, %%rax\n");
                     size_in_bytes_t lhs_bytes =
-                        codegen_linux_x86_64_emit_expression(codegen,
-                                                             bin_op.lhs);
+                        codegen_x86_64_emit_expression(codegen, bin_op.lhs);
                     fprintf(codegen->out,
                             "    cmp $0, %s\n",
                             get_reg_for(REG_ACCUMULATOR, lhs_bytes));
@@ -592,8 +557,7 @@ codegen_linux_x86_64_emit_expression(codegen_x86_64_t *codegen,
 
                     fprintf(codegen->out, "    xor %%rax, %%rax\n");
                     size_in_bytes_t rhs_bytes =
-                        codegen_linux_x86_64_emit_expression(codegen,
-                                                             bin_op.rhs);
+                        codegen_x86_64_emit_expression(codegen, bin_op.rhs);
                     fprintf(codegen->out,
                             "    cmp $0, %s\n",
                             get_reg_for(REG_ACCUMULATOR, rhs_bytes));
@@ -604,15 +568,12 @@ codegen_linux_x86_64_emit_expression(codegen_x86_64_t *codegen,
                     return 1;
                 }
                 case AST_BINOP_LOGICAL_OR: {
-                    size_t label_t =
-                        codegen_linux_x86_64_get_next_label(codegen);
-                    size_t label_f =
-                        codegen_linux_x86_64_get_next_label(codegen);
+                    size_t label_t = codegen_x86_64_get_next_label(codegen);
+                    size_t label_f = codegen_x86_64_get_next_label(codegen);
 
                     fprintf(codegen->out, "    xor %%rax, %%rax\n");
                     size_in_bytes_t lhs_bytes =
-                        codegen_linux_x86_64_emit_expression(codegen,
-                                                             bin_op.lhs);
+                        codegen_x86_64_emit_expression(codegen, bin_op.lhs);
                     fprintf(codegen->out,
                             "    cmp $0, %s\n",
                             get_reg_for(REG_ACCUMULATOR, lhs_bytes));
@@ -620,8 +581,7 @@ codegen_linux_x86_64_emit_expression(codegen_x86_64_t *codegen,
 
                     fprintf(codegen->out, "    xor %%rax, %%rax\n");
                     size_in_bytes_t rhs_bytes =
-                        codegen_linux_x86_64_emit_expression(codegen,
-                                                             bin_op.rhs);
+                        codegen_x86_64_emit_expression(codegen, bin_op.rhs);
                     fprintf(codegen->out,
                             "    cmp $0, %s\n",
                             get_reg_for(REG_ACCUMULATOR, rhs_bytes));
@@ -642,12 +602,10 @@ codegen_linux_x86_64_emit_expression(codegen_x86_64_t *codegen,
                             symbol_t *symbol = scope_lookup(scope, ref.id);
                             assert(symbol);
 
-                            size_t offset =
-                                codegen_linux_x86_64_get_stack_offset(codegen,
-                                                                      symbol);
+                            size_t offset = codegen_x86_64_get_stack_offset(
+                                codegen, symbol);
 
-                            codegen_linux_x86_64_emit_expression(codegen,
-                                                                 bin_op.rhs);
+                            codegen_x86_64_emit_expression(codegen, bin_op.rhs);
 
                             size_t type_size = type_to_bytes(symbol->type);
                             fprintf(codegen->out,
@@ -661,14 +619,12 @@ codegen_linux_x86_64_emit_expression(codegen_x86_64_t *codegen,
                                        AST_UNARY_DEREFERENCE &&
                                    "unsupported assignment lhs");
 
-                            codegen_linux_x86_64_emit_expression(codegen,
-                                                                 bin_op.lhs);
+                            codegen_x86_64_emit_expression(codegen, bin_op.lhs);
 
                             fprintf(codegen->out, "    push %%rax\n");
 
-                            size_t type_size =
-                                codegen_linux_x86_64_emit_expression(
-                                    codegen, bin_op.rhs);
+                            size_t type_size = codegen_x86_64_emit_expression(
+                                codegen, bin_op.rhs);
 
                             fprintf(codegen->out, "    pop %%rdx\n");
 
@@ -698,8 +654,7 @@ codegen_linux_x86_64_emit_expression(codegen_x86_64_t *codegen,
             switch (unary_op.kind) {
                 case AST_UNARY_BITWISE_NOT: {
                     size_in_bytes_t expr_bytes =
-                        codegen_linux_x86_64_emit_expression(codegen,
-                                                             unary_op.expr);
+                        codegen_x86_64_emit_expression(codegen, unary_op.expr);
 
                     fprintf(codegen->out,
                             "    not %s\n",
@@ -717,7 +672,7 @@ codegen_linux_x86_64_emit_expression(codegen_x86_64_t *codegen,
                     assert(symbol);
 
                     size_t offset =
-                        codegen_linux_x86_64_get_stack_offset(codegen, symbol);
+                        codegen_x86_64_get_stack_offset(codegen, symbol);
 
                     fprintf(
                         codegen->out, "    lea -%ld(%%rbp), %%rax\n", offset);
@@ -728,8 +683,8 @@ codegen_linux_x86_64_emit_expression(codegen_x86_64_t *codegen,
                     assert(unary_op.expr->kind == AST_NODE_REF &&
                            "unsupported unary expression for dereference (*)");
 
-                    return codegen_linux_x86_64_emit_expression(codegen,
-                                                                unary_op.expr);
+                    return codegen_x86_64_emit_expression(codegen,
+                                                          unary_op.expr);
                 }
                 default: {
                     assert(0 && "unsupported unary operation");
@@ -743,7 +698,7 @@ codegen_linux_x86_64_emit_expression(codegen_x86_64_t *codegen,
     }
 }
 static void
-codegen_linux_x86_64_emit_block(codegen_x86_64_t *codegen, ast_block_t *block)
+codegen_x86_64_emit_block(codegen_x86_64_t *codegen, ast_block_t *block)
 {
     size_t block_offset = codegen->base_offset;
     size_t nodes_len = list_size(block->nodes);
@@ -756,7 +711,7 @@ codegen_linux_x86_64_emit_block(codegen_x86_64_t *codegen, ast_block_t *block)
 
                 ast_node_t *expr = return_stmt.expr;
 
-                codegen_linux_x86_64_emit_expression(codegen, expr);
+                codegen_x86_64_emit_expression(codegen, expr);
 
                 fprintf(codegen->out, "    mov %%rbp, %%rsp\n");
                 fprintf(codegen->out, "    pop %%rbp\n");
@@ -775,12 +730,11 @@ codegen_linux_x86_64_emit_block(codegen_x86_64_t *codegen, ast_block_t *block)
                 size_t type_size = type_to_bytes(symbol->type);
                 codegen->base_offset += type_size;
 
-                codegen_linux_x86_64_put_stack_offset(
+                codegen_x86_64_put_stack_offset(
                     codegen, symbol, codegen->base_offset);
 
                 if (var_def.value) {
-                    codegen_linux_x86_64_emit_expression(codegen,
-                                                         var_def.value);
+                    codegen_x86_64_emit_expression(codegen, var_def.value);
                 }
 
                 fprintf(codegen->out,
@@ -792,12 +746,12 @@ codegen_linux_x86_64_emit_block(codegen_x86_64_t *codegen, ast_block_t *block)
             }
 
             case AST_NODE_BINARY_OP: {
-                codegen_linux_x86_64_emit_expression(codegen, node);
+                codegen_x86_64_emit_expression(codegen, node);
                 break;
             }
 
             case AST_NODE_IF_STMT: {
-                codegen_linux_x86_64_emit_if(codegen, node->as_if_stmt);
+                codegen_x86_64_emit_if(codegen, node->as_if_stmt);
                 break;
             }
 
@@ -807,12 +761,11 @@ codegen_linux_x86_64_emit_block(codegen_x86_64_t *codegen, ast_block_t *block)
                 ast_node_t *cond = while_stmt.cond;
                 ast_node_t *then = while_stmt.then;
 
-                size_t begin_label =
-                    codegen_linux_x86_64_get_next_label(codegen);
-                size_t end_label = codegen_linux_x86_64_get_next_label(codegen);
+                size_t begin_label = codegen_x86_64_get_next_label(codegen);
+                size_t end_label = codegen_x86_64_get_next_label(codegen);
 
                 fprintf(codegen->out, ".L%ld:\n", begin_label);
-                codegen_linux_x86_64_emit_expression(codegen, cond);
+                codegen_x86_64_emit_expression(codegen, cond);
                 fprintf(codegen->out, "    cmp $1, %%rax\n");
                 fprintf(codegen->out, "    jnz .L%ld\n", end_label);
 
@@ -820,7 +773,7 @@ codegen_linux_x86_64_emit_block(codegen_x86_64_t *codegen, ast_block_t *block)
                        "invalid while-then block");
                 ast_block_t then_block = then->as_block;
 
-                codegen_linux_x86_64_emit_block(codegen, &then_block);
+                codegen_x86_64_emit_block(codegen, &then_block);
 
                 fprintf(codegen->out, "    jmp .L%ld\n", begin_label);
                 fprintf(codegen->out, ".L%ld:\n", end_label);
@@ -841,23 +794,23 @@ codegen_linux_x86_64_emit_block(codegen_x86_64_t *codegen, ast_block_t *block)
 }
 
 static void
-codegen_linux_x86_64_emit_if(codegen_x86_64_t *codegen, ast_if_stmt_t if_stmt)
+codegen_x86_64_emit_if(codegen_x86_64_t *codegen, ast_if_stmt_t if_stmt)
 {
     ast_node_t *cond = if_stmt.cond;
     ast_node_t *then = if_stmt.then;
     ast_node_t *_else = if_stmt._else;
 
-    size_t end_if_label = codegen_linux_x86_64_get_next_label(codegen);
-    size_t end_else_label = codegen_linux_x86_64_get_next_label(codegen);
+    size_t end_if_label = codegen_x86_64_get_next_label(codegen);
+    size_t end_else_label = codegen_x86_64_get_next_label(codegen);
 
-    codegen_linux_x86_64_emit_expression(codegen, cond);
+    codegen_x86_64_emit_expression(codegen, cond);
     fprintf(codegen->out, "    cmp $1, %%rax\n");
     fprintf(codegen->out, "    jnz .L%ld\n", end_if_label);
 
     assert(then->kind == AST_NODE_BLOCK && "invalid if-then block");
     ast_block_t then_block = then->as_block;
 
-    codegen_linux_x86_64_emit_block(codegen, &then_block);
+    codegen_x86_64_emit_block(codegen, &then_block);
     fprintf(codegen->out, "    jmp .L%ld\n", end_else_label);
 
     fprintf(codegen->out, ".L%ld:\n", end_if_label);
@@ -865,10 +818,10 @@ codegen_linux_x86_64_emit_if(codegen_x86_64_t *codegen, ast_if_stmt_t if_stmt)
     if (_else != NULL) {
         if (_else->kind == AST_NODE_IF_STMT) {
             ast_if_stmt_t else_if = _else->as_if_stmt;
-            codegen_linux_x86_64_emit_if(codegen, else_if);
+            codegen_x86_64_emit_if(codegen, else_if);
         } else {
             ast_block_t else_block = _else->as_block;
-            codegen_linux_x86_64_emit_block(codegen, &else_block);
+            codegen_x86_64_emit_block(codegen, &else_block);
         }
     }
 
@@ -931,8 +884,8 @@ calculate_fn_local_size(scope_t *scope)
 }
 
 static void
-codegen_linux_x86_64_emit_function(codegen_x86_64_t *codegen,
-                                   ast_fn_definition_t *fn_def)
+codegen_x86_64_emit_function(codegen_x86_64_t *codegen,
+                             ast_fn_definition_t *fn_def)
 {
     fprintf(codegen->out, ".globl " SV_FMT "\n", SV_ARG(fn_def->id));
     codegen->base_offset = 0;
@@ -957,8 +910,7 @@ codegen_linux_x86_64_emit_function(codegen_x86_64_t *codegen,
         codegen->base_offset += 8;
         size_t offset = codegen->base_offset;
 
-        codegen_linux_x86_64_put_stack_offset(
-            codegen, symbol, codegen->base_offset);
+        codegen_x86_64_put_stack_offset(codegen, symbol, codegen->base_offset);
 
         fprintf(codegen->out,
                 "    mov %s, -%ld(%%rbp)\n",
@@ -978,13 +930,13 @@ codegen_linux_x86_64_emit_function(codegen_x86_64_t *codegen,
     assert(block_node->kind == AST_NODE_BLOCK);
     ast_block_t block = block_node->as_block;
 
-    codegen_linux_x86_64_emit_block(codegen, &block);
+    codegen_x86_64_emit_block(codegen, &block);
 }
 
 static void
-codegen_linux_x86_64_put_stack_offset(codegen_x86_64_t *codegen,
-                                      symbol_t *symbol,
-                                      size_t offset)
+codegen_x86_64_put_stack_offset(codegen_x86_64_t *codegen,
+                                symbol_t *symbol,
+                                size_t offset)
 {
 
     size_t *stack_offset = arena_alloc(codegen->arena, sizeof(size_t));
@@ -997,8 +949,7 @@ codegen_linux_x86_64_put_stack_offset(codegen_x86_64_t *codegen,
 }
 
 static size_t
-codegen_linux_x86_64_get_stack_offset(codegen_x86_64_t *codegen,
-                                      symbol_t *symbol)
+codegen_x86_64_get_stack_offset(codegen_x86_64_t *codegen, symbol_t *symbol)
 {
     char symbol_ptr[PTR_HEX_CSTR_SIZE];
     sprintf(symbol_ptr, "%lx", (uintptr_t)symbol);
diff --git a/src/codegen_linux_x86_64.h b/src/codegen_x86_64.h
similarity index 82%
rename from src/codegen_linux_x86_64.h
rename to src/codegen_x86_64.h
index 7e2841d..d4948e1 100644
--- a/src/codegen_linux_x86_64.h
+++ b/src/codegen_x86_64.h
@@ -32,10 +32,10 @@ typedef struct codegen_x86_64
 } codegen_x86_64_t;
 
 void
-codegen_linux_x86_64_init(codegen_x86_64_t *codegen, arena_t *arena, FILE *out);
+codegen_x86_64_init(codegen_x86_64_t *codegen, arena_t *arena, FILE *out);
 
 void
-codegen_linux_x86_64_emit_translation_unit(codegen_x86_64_t *codegen,
-                                           ast_node_t *prog);
+codegen_x86_64_emit_translation_unit(codegen_x86_64_t *codegen,
+                                     ast_node_t *prog);
 
 #endif /* CODEGEN_X86_64_H */
diff --git a/src/main.c b/src/main.c
index 49b2240..685d8ce 100644
--- a/src/main.c
+++ b/src/main.c
@@ -24,8 +24,8 @@
 #include "arena.h"
 #include "checker.h"
 #include "cli.h"
-#include "codegen_linux_aarch64.h"
-#include "codegen_linux_x86_64.h"
+#include "codegen_aarch64.h"
+#include "codegen_x86_64.h"
 #include "lexer.h"
 #include "parser.h"
 #include "pretty_print_ast.h"
@@ -148,15 +148,15 @@ handle_codegen_linux(cli_opts_t *opts)
 
     if (!(opts->options & CLI_OPT_ARCH)) {
         codegen_x86_64_t codegen = { 0 };
-        codegen_linux_x86_64_init(&codegen, &arena, out);
-        codegen_linux_x86_64_emit_translation_unit(&codegen, ast);
+        codegen_x86_64_init(&codegen, &arena, out);
+        codegen_x86_64_emit_translation_unit(&codegen, ast);
     } else {
         if (strcmp(opts->arch, "x86_64") == 0) {
             codegen_x86_64_t codegen = { 0 };
-            codegen_linux_x86_64_init(&codegen, &arena, out);
-            codegen_linux_x86_64_emit_translation_unit(&codegen, ast);
+            codegen_x86_64_init(&codegen, &arena, out);
+            codegen_x86_64_emit_translation_unit(&codegen, ast);
         } else if (strcmp(opts->arch, "aarch64") == 0) {
-            codegen_linux_aarch64_emit_translation_unit(out, ast);
+            codegen_aarch64_emit_translation_unit(out, ast);
         } else {
             fprintf(
                 stderr, "error: architecture '%s' not supported\n", opts->arch);
-- 
2.46.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-10-16 22:25 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-10-17  0:19 [PATCH olang v1 0/3] cli: enable object file binary compilation Johnny Richard
2024-10-16 22:25 ` Carlos Maniero
2024-10-17  0:19 ` [PATCH olang v1 1/3] codegen: link olang binary with libc by default Johnny Richard
2024-10-17  0:19 ` [PATCH olang v1 2/3] cli: add option -c to compile without linking Johnny Richard
2024-10-17  0:20 ` [PATCH olang v1 3/3] codegen: remove linux from codegen namespace Johnny Richard
2024-10-16 22:22   ` [olang/patches/.build.yml] build success builds.sr.ht

Code repositories for project(s) associated with this public inbox

	https://git.johnnyrichard.com/olang.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox