diff options
Diffstat (limited to 'compiler/main.c')
-rw-r--r-- | compiler/main.c | 97 |
1 files changed, 23 insertions, 74 deletions
diff --git a/compiler/main.c b/compiler/main.c index e614be6..aa3bcdc 100644 --- a/compiler/main.c +++ b/compiler/main.c @@ -183,69 +183,31 @@ print_ptrs(int n_ptrs) } static void -print_alias(struct type *typ) +print_ret(struct ast_node *node) { - printf("alias (%lu bytes, %d pointer(s));\n", typ->size, typ->n_ptrs); -} - -static void -print_enum(struct type *typ) -{ - struct enum_member *mem; + (void)node; - printf("enum {\n"); - - for (size_t r = 0; r < typ->members.n_rows; r++) { - mem = (struct enum_member*)typ->members.rows[r].head; - while (mem != (struct enum_member*)&typ->members.rows[r]) { - printf(" %.*s,\n", (int)mem->name_len, mem->name); - - mem = (struct enum_member*)mem->hashmap_entry.list_entry.next; - } - } - - printf("}\n"); + /* TODO: Print return value */ + printf(" ret;\n"); } static void -print_struct(struct type *typ) +print_stmt_block(struct ast_node *parent) { - struct struct_member *mem; - - printf("struct (%lu bytes) {\n", typ->size); - - for (size_t r = 0; r < typ->members.n_rows; r++) { - mem = (struct struct_member*)typ->members.rows[r].head; - while (mem != (struct struct_member*)&typ->members.rows[r]) { - printf(" %.*s ", (int)mem->typ->name_len, mem->typ->name); - print_ptrs(mem->n_ptrs); - printf("%.*s;\n", (int)mem->name_len, mem->name); - - mem = (struct struct_member*)mem->hashmap_entry.list_entry.next; + struct ast_node *node; + + node = (struct ast_node*)parent->children.head; + while (node != (struct ast_node*)&parent->children) { + switch (node->kind) { + case NK_RETURN: + print_ret(node); + break; + default: + printf(" /* Unknown */\n"); + break; } - } - - printf("}\n"); -} -static void -print_type(struct type *typ) -{ - printf("type %.*s: ", (int)typ->name_len, typ->name); - - switch (typ->kind) { - case TYK_ALIAS: - print_alias(typ); - break; - case TYK_ENUM: - print_enum(typ); - break; - case TYK_STRUCT: - print_struct(typ); - break; - default: - printf("unknown;\n"); - break; + node = (struct ast_node*)node->list_entry.next; } } @@ -281,26 +243,14 @@ print_proc(struct procedure *proc) print_ptrs(proc->ret_n_ptrs); } - printf(";\n"); -} - -static void -dump_types(struct hashmap *map) -{ - struct type *typ, *next; - - for (size_t r = 0; r < map->n_rows; r++) { - typ = (struct type*)map->rows[r].head; - while (typ != (struct type*)&map->rows[r]) { - print_type(typ); - - next = (struct type*)typ->hashmap_entry.list_entry.next; - free(typ); - typ = next; - } + if (list_is_empty(&proc->node->children)) { + printf(";\n"); + return; } - free(map->rows); + printf(" {\n"); + print_stmt_block(proc->node); + printf("}\n"); } static void @@ -362,7 +312,6 @@ main(int argc, char **argv) parser_init(&parser, input); parser_parse(&parser); - dump_types(parser.types); dump_procs(parser.procs); free(input); |