aboutsummaryrefslogtreecommitdiff
path: root/boot
diff options
context:
space:
mode:
Diffstat (limited to 'boot')
-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 },