From bb94681272a0ee867f8a1e86cf01a2ac0289e25f Mon Sep 17 00:00:00 2001 From: Mel Date: Sun, 3 May 2026 19:57:36 +0200 Subject: Add basic test harness for IR testing Signed-off-by: Mel --- boot/catboot.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) 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 \t output token stream for file\n" " --test-parse \t output abstract syntax tree for file in s-expr format\n" + " --test-lower \t output lowered ir for file in s-expr format\n" " --test-transpile \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"); @@ -112,6 +113,30 @@ debug_parse_pass(struct Source_File source_file) return parser_result; } +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) { @@ -186,6 +211,20 @@ test_parse_command(struct Command_Arguments* arguments) return COMMAND_OK; } +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) { @@ -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 }, -- cgit 1.4.1