aboutsummaryrefslogtreecommitdiff
path: root/src/generator.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/generator.c')
-rw-r--r--src/generator.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/generator.c b/src/generator.c
new file mode 100644
index 0000000..a7a7c72
--- /dev/null
+++ b/src/generator.c
@@ -0,0 +1,53 @@
1/**
2 * UPEM / Compilation / Projet
3 * Pacien TRAN-GIRARD, Adam NAILI
4 */
5
6#include "generator.h"
7#include <stdio.h>
8#include "symbol_table.h"
9
10void prologue() {
11 printf("extern printf\n");
12 printf("section .data\n");
13 printf("format_int db \"%%d\",10,0\n\n");
14 printf("section .bss\nsection .text\n\nglobal _start\n");
15 printf("print: ;print needs an argument in rax\n");
16 printf("push rbp\n");
17 printf("mov rbp, rsp\n");
18 printf("push rsi\n");
19 printf("mov rsi, rax\n");
20 printf("mov rdi, format_int\n");
21 printf("mov rax, 0\n");
22 printf("call printf WRT ..plt\n");
23 printf("pop rsi\n");
24 printf("pop rbp\n");
25 printf("ret\n");
26 printf("\n_start:\n");
27 printf("push rbp\nmov rbp, rsp\n\n");
28}
29
30void const_declaration() {
31 printf("mov rax,60 \n");
32 printf("mov rdi,0 \n");
33 printf("syscall \n");
34 printf(";global table\n");
35 glo_display_table();
36 printf(";local table\n");
37 loc_display_table();
38}
39
40void declaration(const char name[], int type, Scope scope) {
41 switch (scope) {
42 case GLOBAL:
43 glo_addVar(name, type);
44 break;
45 case LOCAL:
46 loc_addVar(name, type);
47 break;
48 }
49
50 printf("push 0\n");
51}
52
53