aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorpacien2018-06-05 23:05:40 +0200
committerpacien2018-06-05 23:05:40 +0200
commit9a661bc8e79398cb842a64fcd3169c3895d48a54 (patch)
tree3f560b6b47c26b7c29969978cae9761ded447d69 /src
parent1c1ba0e8cd1f7cb17b04626b7ef3cf9fcbe520ab (diff)
downloadtpc-compiler-9a661bc8e79398cb842a64fcd3169c3895d48a54.tar.gz
attempt for const fetching
Diffstat (limited to 'src')
-rw-r--r--src/generator.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/src/generator.c b/src/generator.c
index 60a2b89..c6140f1 100644
--- a/src/generator.c
+++ b/src/generator.c
@@ -397,21 +397,22 @@ int gen_negate_expr(int type) {
397 397
398int gen_value(const char ident[], Scope scope) { 398int gen_value(const char ident[], Scope scope) {
399 int l_addr = loc_get_addr(ident); 399 int l_addr = loc_get_addr(ident);
400 int g_addr = glo_get_addr(ident); 400
401 switch (scope) { 401 switch (scope) {
402 case GLOBAL:
403 fprintf(output, "push QWORD [globals + %d] ;%s\n", g_addr,
404 ident);
405 return glo_lookup(ident);
406 case LOCAL: 402 case LOCAL:
407 if (l_addr != -1) { 403 if (l_addr != -1) {
408 fprintf(output, "push QWORD [rbp - %d] ;%s\n", l_addr, 404 fprintf(output, "push QWORD [rbp - %d] ;%s\n", l_addr, ident);
409 ident);
410 return loc_lookup(ident); 405 return loc_lookup(ident);
411 } else {
412 fprintf(output, "push QWORD [globals + %d] ;%s\n", g_addr, ident);
413 return glo_lookup(ident);
414 } 406 }
407
408 case GLOBAL:
409 if (is_read_only(ident, scope))
410 fprintf(output, "push QWORD %s\n", ident);
411 else
412 fprintf(output, "push QWORD [globals + %d] ;%s\n", glo_get_addr(ident), ident);
413
414 return glo_lookup(ident);
415
415 default: 416 default:
416 exit(1); 417 exit(1);
417 } 418 }