aboutsummaryrefslogtreecommitdiff
path: root/src/generator.c
diff options
context:
space:
mode:
authorAdam NAILI2018-06-05 23:03:29 +0200
committerAdam NAILI2018-06-05 23:03:29 +0200
commita037a641ca537f012865b2655917207af683ea1f (patch)
tree2cc15c0e2df751e635fe766cb89c534592944ec3 /src/generator.c
parent4cc53658a9503191f41945914e6223ccc5a95717 (diff)
parent1c1ba0e8cd1f7cb17b04626b7ef3cf9fcbe520ab (diff)
downloadtpc-compiler-a037a641ca537f012865b2655917207af683ea1f.tar.gz
Merge branch 'master' of https://github.com/pacien/upem-compil-tpc
Diffstat (limited to 'src/generator.c')
-rw-r--r--src/generator.c22
1 files changed, 19 insertions, 3 deletions
diff --git a/src/generator.c b/src/generator.c
index dc85517..1965ab9 100644
--- a/src/generator.c
+++ b/src/generator.c
@@ -102,7 +102,7 @@ void gen_const(const char name[], int value, Scope scope) {
102 102
103 case GLOBAL: 103 case GLOBAL:
104 glo_addConst(name); 104 glo_addConst(name);
105 fprintf(output, "%s: db QWORD %d\n", name, value); 105 fprintf(output, "%s dq %d\n", name, value);
106 return; 106 return;
107 } 107 }
108} 108}
@@ -159,7 +159,12 @@ void gen_check(const char name[], Scope scope) {
159} 159}
160 160
161// ----- READ AND PRINT FUNCTIONS ----- 161// ----- READ AND PRINT FUNCTIONS -----
162void gen_reade(const char name[]) { 162void gen_reade(const char name[], Scope scope) {
163 if (is_read_only(name, scope)) {
164 fprintf(stderr, "Symbol \"%s\" at line %d is read only.\n", name, lineno);
165 exit(1);
166 }
167
163 if (loc_lookup(name) != INT) { 168 if (loc_lookup(name) != INT) {
164 fprintf(stderr, "Need to be a INT in the reade() function\n"); 169 fprintf(stderr, "Need to be a INT in the reade() function\n");
165 return; 170 return;
@@ -174,7 +179,12 @@ void gen_reade(const char name[]) {
174 fprintf(output, "mov rax,globals\nadd rax,%d\ncall reade\n", g_addr); 179 fprintf(output, "mov rax,globals\nadd rax,%d\ncall reade\n", g_addr);
175} 180}
176 181
177void gen_readc(const char name[]) { 182void gen_readc(const char name[], Scope scope) {
183 if (is_read_only(name, scope)) {
184 fprintf(stderr, "Symbol \"%s\" at line %d is read only.\n", name, lineno);
185 exit(1);
186 }
187
178 if (loc_lookup(name) != CHAR) { 188 if (loc_lookup(name) != CHAR) {
179 fprintf(stderr, "Need to be a CHAR in the readc() function\n"); 189 fprintf(stderr, "Need to be a CHAR in the readc() function\n");
180 return; 190 return;
@@ -233,6 +243,12 @@ void gen_ifelse_end(int idx) {
233int gen_assign(const char ident[], Scope scope) { 243int gen_assign(const char ident[], Scope scope) {
234 int l_addr = loc_get_addr(ident); 244 int l_addr = loc_get_addr(ident);
235 int g_addr = glo_get_addr(ident); 245 int g_addr = glo_get_addr(ident);
246
247 if (is_read_only(ident, scope)) {
248 fprintf(stderr, "Symbol \"%s\" at line %d is read only.\n", ident, lineno);
249 exit(1);
250 }
251
236 switch (scope) { 252 switch (scope) {
237 case GLOBAL: 253 case GLOBAL:
238 fprintf(output, "pop QWORD [globals + %d] ;%s\n", g_addr, 254 fprintf(output, "pop QWORD [globals + %d] ;%s\n", g_addr,