diff options
author | pacien | 2018-06-05 23:05:46 +0200 |
---|---|---|
committer | pacien | 2018-06-05 23:05:46 +0200 |
commit | 12c6e05e4c341e3db89e4551299b3f10e7623542 (patch) | |
tree | 73051e24d0c4e0ca8ee47b56cb83453177bedbb8 /src | |
parent | 9a661bc8e79398cb842a64fcd3169c3895d48a54 (diff) | |
parent | a037a641ca537f012865b2655917207af683ea1f (diff) | |
download | tpc-compiler-12c6e05e4c341e3db89e4551299b3f10e7623542.tar.gz |
Merge branch 'master' of https://github.com/pacien/upem-compil-tpc
Diffstat (limited to 'src')
-rw-r--r-- | src/generator.c | 8 | ||||
-rw-r--r-- | src/tpc.y | 2 |
2 files changed, 5 insertions, 5 deletions
diff --git a/src/generator.c b/src/generator.c index c6140f1..ab3777c 100644 --- a/src/generator.c +++ b/src/generator.c | |||
@@ -282,7 +282,7 @@ void gen_or(int left, int right, int idx) { | |||
282 | fprintf(output, "jmp .false%d\n", idx); | 282 | fprintf(output, "jmp .false%d\n", idx); |
283 | fprintf(output, ".true%d:\n", idx); | 283 | fprintf(output, ".true%d:\n", idx); |
284 | fprintf(output, "push 1\n"); | 284 | fprintf(output, "push 1\n"); |
285 | fprintf(output, ".false%d:", idx); | 285 | fprintf(output, ".false%d:\n", idx); |
286 | } | 286 | } |
287 | 287 | ||
288 | void gen_and(int left, int right, int idx) { | 288 | void gen_and(int left, int right, int idx) { |
@@ -300,7 +300,7 @@ void gen_and(int left, int right, int idx) { | |||
300 | fprintf(output, "jmp .true%d\n", idx); | 300 | fprintf(output, "jmp .true%d\n", idx); |
301 | fprintf(output, ".false%d:\n", idx); | 301 | fprintf(output, ".false%d:\n", idx); |
302 | fprintf(output, "push 0\n"); | 302 | fprintf(output, "push 0\n"); |
303 | fprintf(output, ".true%d:", idx); | 303 | fprintf(output, ".true%d:\n", idx); |
304 | } | 304 | } |
305 | 305 | ||
306 | void gen_eq(const char op[], int left, int right, int idx) { | 306 | void gen_eq(const char op[], int left, int right, int idx) { |
@@ -316,7 +316,7 @@ void gen_eq(const char op[], int left, int right, int idx) { | |||
316 | else | 316 | else |
317 | exit(1); // TODO: error on unexpected op | 317 | exit(1); // TODO: error on unexpected op |
318 | 318 | ||
319 | fprintf(output, "push 0\njmp .false%d\n.true%d:\npush 1\n.false%d:", idx, idx, | 319 | fprintf(output, "push 0\njmp .false%d\n.true%d:\npush 1\n.false%d:\n", idx, idx, |
320 | idx); | 320 | idx); |
321 | } | 321 | } |
322 | 322 | ||
@@ -337,7 +337,7 @@ void gen_order(const char op[], int left, int right, int idx) { | |||
337 | else | 337 | else |
338 | exit(1); // TODO: error on unexpected op | 338 | exit(1); // TODO: error on unexpected op |
339 | 339 | ||
340 | fprintf(output, "push 0\njmp .false%d\n.true%d:\npush 1\n.false%d:", idx, idx, | 340 | fprintf(output, "push 0\njmp .false%d\n.true%d:\npush 1\n.false%d:\n", idx, idx, |
341 | idx); | 341 | idx); |
342 | } | 342 | } |
343 | 343 | ||
@@ -126,7 +126,7 @@ Instr: | |||
126 | | PRINT '(' Exp ')' ';' { gen_print($<type>3);} | 126 | | PRINT '(' Exp ')' ';' { gen_print($<type>3);} |
127 | | IF '(' Exp IfHandling')' Instr { gen_if_label($<num>4); } | 127 | | IF '(' Exp IfHandling')' Instr { gen_if_label($<num>4); } |
128 | | IF '(' Exp IfHandling')' Instr ELSE IfEndHandling Instr IfElseEndHandling | 128 | | IF '(' Exp IfHandling')' Instr ELSE IfEndHandling Instr IfElseEndHandling |
129 | | WHILE '(' Exp ')' Instr | 129 | | WHILE {fprintf(output,".upwhile%d:\n",num_while);}'(' Exp {fprintf(output,"pop rax\ncmp rax,0\njz .downwhile%d\n",num_while);}')' Instr {fprintf(output,"jmp .upwhile%d\n.downwhile%d:\n",num_while,num_while);num_while++;} |
130 | | '{' SuiteInstr '}' | 130 | | '{' SuiteInstr '}' |
131 | ; | 131 | ; |
132 | IfHandling: { gen_if_start($<num>$ = num_if++); }; | 132 | IfHandling: { gen_if_start($<num>$ = num_if++); }; |