diff options
Diffstat (limited to 'codegen.c')
| -rw-r--r-- | codegen.c | 17 |
1 files changed, 10 insertions, 7 deletions
@@ -331,14 +331,11 @@ void codegen_lvar(CodeGen* g, AstNode* ast, GenMode gen_mode) { } void codegen_gvar(CodeGen* g, AstNode* ast, GenMode gen_mode) { - if (gen_mode == GenMode_lval) { - unimplemented(); - } - if (ast->ty->kind != TypeKind_ptr) { - unimplemented(); - } - printf(" mov rax, QWORD PTR %.*s[rip]\n", ast->name.len, ast->name.data); + printf(" lea rax, %.*s[rip]\n", ast->name.len, ast->name.data); printf(" push rax\n"); + if (gen_mode == GenMode_rval) { + codegen_lval2rval(ast->ty); + } } void codegen_composite_expr(CodeGen* g, AstNode* ast) { @@ -534,6 +531,12 @@ void codegen(Program* prog) { printf(" .string \"%s\"\n\n", prog->str_literals[i]); } + printf(".bss\n\n"); + for (i = 0; i < prog->vars->node_len; ++i) { + AstNode* var = prog->vars->node_items + i; + printf(" .lcomm %.*s, %d\n", var->name.len, var->name.data, type_sizeof(var->ty)); + } + printf(".globl main\n\n"); printf(".text\n\n"); |
