From 67fc7933df394848eeb86a45f37e35ded032e5e9 Mon Sep 17 00:00:00 2001 From: Adam NAILI Date: Mon, 14 May 2018 15:48:01 +0200 Subject: Not working properly: Beginning of the implementation of globals -> need to modify if(global) else --- src/generator.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/generator.c') diff --git a/src/generator.c b/src/generator.c index e547a23..88f32d7 100644 --- a/src/generator.c +++ b/src/generator.c @@ -13,7 +13,11 @@ void gen_prologue() { printf("extern printf\n"); printf("section .data\n"); printf("format_int db \"%%d\",10,0\n\n"); - printf("section .bss\nsection .text\n\nglobal _start\n"); + printf("section .bss\n"); +} +void gen_prologue_continue(){ + printf("globals: resq %d\n", nb_globals); + printf("section .text\n\nglobal _start\n"); printf("print: ;print needs an argument in rax\n"); printf("push rbp\n"); printf("mov rbp, rsp\n"); @@ -28,7 +32,6 @@ void gen_prologue() { printf("\n_start:\n"); printf("push rbp\nmov rbp, rsp\n\n"); } - void gen_const_declaration() { printf("mov rax,60 \n"); printf("mov rdi,0 \n"); @@ -43,13 +46,14 @@ void gen_declaration(const char name[], int type, Scope scope) { switch (scope) { case GLOBAL: glo_addVar(name, type); + nb_globals++; break; case LOCAL: loc_addVar(name, type); + printf("push 0\n"); break; } - printf("push 0\n"); } // ----- READ AND PRINT FUNCTIONS ----- -- cgit v1.2.3