Skip to content
Snippets Groups Projects
Commit a359e28c authored by gyuri's avatar gyuri
Browse files

Implement initializer in declaration

parent b58eb1e8
No related branches found
No related tags found
No related merge requests found
...@@ -275,7 +275,14 @@ static void cg_gen_declaration(struct state *s, const struct ast_node *n) { ...@@ -275,7 +275,14 @@ static void cg_gen_declaration(struct state *s, const struct ast_node *n) {
// TODO: type. now we assume literally EVERY type is 64 bit... // TODO: type. now we assume literally EVERY type is 64 bit...
int size = 8; int size = 8;
s->sp -= size; s->sp -= size;
hashmap_put(&s->vars, dd->ident, &s->sp); int loc = s->sp;
hashmap_put(&s->vars, dd->ident, &loc);
if (ni->init_declarator.initializer) {
val val_init = cg_gen_expr(s, ni->init_declarator.initializer);
val_read(s, &val_init, "rax");
val_store(s, &(val){ .s = loc }, "rax");
}
} }
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment