about summary refs log tree commit diff
path: root/boot/catboot.c
diff options
context:
space:
mode:
authorMel <mel@rnrd.eu>2026-05-03 19:57:36 +0200
committerMel <mel@rnrd.eu>2026-05-03 19:57:36 +0200
commitbb94681272a0ee867f8a1e86cf01a2ac0289e25f (patch)
tree99c3c336e17ba48c70f751f9f3879121c93eee53 /boot/catboot.c
parent74ffd7a95c0894a96ab984e2c4d2cd9c75539af0 (diff)
downloadcatskill-bb94681272a0ee867f8a1e86cf01a2ac0289e25f.tar.zst
catskill-bb94681272a0ee867f8a1e86cf01a2ac0289e25f.zip
Add basic test harness for IR testing
Signed-off-by: Mel <mel@rnrd.eu>
Diffstat (limited to 'boot/catboot.c')
-rw-r--r--boot/catboot.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/boot/catboot.c b/boot/catboot.c
index e78a401..18bf6dc 100644
--- a/boot/catboot.c
+++ b/boot/catboot.c
@@ -56,6 +56,7 @@ usage(void)
         "options:\n"
         "        --test-lex <file>\t output token stream for file\n"
         "        --test-parse <file>\t output abstract syntax tree for file in s-expr format\n"
+        "        --test-lower <file>\t output lowered ir for file in s-expr format\n"
         "        --test-transpile <file>\t output transpiled c language source from file\n"
         "    -?, --help\t\t\t print this help message\n"
         "    -v, --version\t\t print current version\n");
@@ -113,6 +114,30 @@ debug_parse_pass(struct Source_File source_file)
 }
 
 integer
+debug_lower_pass(struct Source_File source_file)
+{
+    struct Lexer lexer;
+    lexer_new(&lexer, source_file.source);
+
+    struct Parser parser;
+    parser_new(&parser, &lexer, source_file);
+
+    struct Tree tree;
+    int parser_result = parser_do_your_thing(&parser, &tree);
+    if (parser_result != 0) {
+        log_error("parser finished with errors\n");
+        return parser_result;
+    }
+
+    // TODO: real lowering isn't quite done yet, just output an
+    // empty unit for now!
+    struct Unit unit = { 0 };
+    printer(&unit);
+
+    return 0;
+}
+
+integer
 debug_transpile_pass(struct Source_File source_file)
 {
     struct Lexer lexer;
@@ -187,6 +212,20 @@ test_parse_command(struct Command_Arguments* arguments)
 }
 
 enum Command_Result
+test_lower_command(struct Command_Arguments* arguments)
+{
+    struct String source = read_file(arguments->input);
+    struct Source_File source_file = {
+        .source = source,
+        .path = string_from_static_c_string(arguments->input),
+    };
+
+    if (debug_lower_pass(source_file)) return COMMAND_FAIL;
+
+    return COMMAND_OK;
+}
+
+enum Command_Result
 test_transpile_command(struct Command_Arguments* arguments)
 {
     struct String source = read_file(arguments->input);
@@ -289,6 +328,7 @@ struct Command_Definition
 struct Command_Definition command_definitions[] = {
     { .name = "test-lex", .function = test_lex_command },
     { .name = "test-parse", .function = test_parse_command },
+    { .name = "test-lower", .function = test_lower_command },
     { .name = "test-transpile", .function = test_transpile_command },
 
     { .name = "version", .short_name = 'v', .function = version_command },