diff options
Diffstat (limited to '05')
-rw-r--r-- | 05/codegen.b | 9 | ||||
-rw-r--r-- | 05/main.c | 12 | ||||
-rw-r--r-- | 05/stdc_common.h | 1 | ||||
-rw-r--r-- | 05/tcc-0.9.25/stdc_common.h | 1 |
4 files changed, 15 insertions, 8 deletions
diff --git a/05/codegen.b b/05/codegen.b index 4d2ca1b..4a22399 100644 --- a/05/codegen.b +++ b/05/codegen.b @@ -1566,6 +1566,7 @@ function generate_push_expression local addr1 local addr2 local type + local type2 type = expr + 4 type = *4type @@ -1721,6 +1722,8 @@ function generate_push_expression :generate_assign_add expr += 8 p = expression_get_end(expr) + type2 = p + 4 + type2 = *4type2 p = generate_push_expression_casted(statement, p, type) generate_push_address_of_expression(statement, expr) expr = p @@ -1729,7 +1732,7 @@ function generate_push_expression generate_stack_dereference(statement, type) emit_mov_rax_qword_rsp_plus_imm32(16) ; mov rax, [rsp+16] (addend) emit_push_rax() ; push rax - generate_stack_add(statement, type, type, type) + generate_stack_add(statement, type, type2, type) emit_mov_rax_qword_rsp_plus_imm32(8) ; mov rax, [rsp+8] (address) emit_push_rax() ; push rax generate_stack_assign(statement, type) @@ -1740,6 +1743,8 @@ function generate_push_expression :generate_assign_sub expr += 8 p = expression_get_end(expr) + type2 = p + 4 + type2 = *4type2 p = generate_push_expression_casted(statement, p, type) generate_push_address_of_expression(statement, expr) expr = p @@ -1748,7 +1753,7 @@ function generate_push_expression generate_stack_dereference(statement, type) emit_mov_rax_qword_rsp_plus_imm32(16) ; mov rax, [rsp+16] (2nd operand) emit_push_rax() ; push rax - generate_stack_sub(statement, type, type, type) + generate_stack_sub(statement, type, type2, type) emit_mov_rax_qword_rsp_plus_imm32(8) ; mov rax, [rsp+8] (address) emit_push_rax() ; push rax generate_stack_assign(statement, type) @@ -1,6 +1,6 @@ /* #define _STDLIB_DEBUG */ /* #include <math.h> */ -/* #include <stdio.h> */ +#include <stdio.h> /* #include <signal.h> */ /* #include <stdlib.h> */ /* #include <string.h> */ @@ -9,10 +9,10 @@ /* #include <setjmp.h> */ /* */ -char *p = "a"; -char s[] = "hello\0there"; - -int _main(int argc, char **argv) { - return s; +int main(int argc, char **argv) { + int *p = 0x100; + p += 1; + printf("%p\n",p); + return 0; } diff --git a/05/stdc_common.h b/05/stdc_common.h index 1540f19..b9ffd9d 100644 --- a/05/stdc_common.h +++ b/05/stdc_common.h @@ -264,6 +264,7 @@ int wait4(int pid, int *status, int options, struct rusage *rusage) { #define SIGSEGV 11 #define SIGTERM 15 #define SIGBUS 7 +#define SIGTRAP 5 void abort(void) { kill(getpid(), SIGABRT); } diff --git a/05/tcc-0.9.25/stdc_common.h b/05/tcc-0.9.25/stdc_common.h index 1540f19..b9ffd9d 100644 --- a/05/tcc-0.9.25/stdc_common.h +++ b/05/tcc-0.9.25/stdc_common.h @@ -264,6 +264,7 @@ int wait4(int pid, int *status, int options, struct rusage *rusage) { #define SIGSEGV 11 #define SIGTERM 15 #define SIGBUS 7 +#define SIGTRAP 5 void abort(void) { kill(getpid(), SIGABRT); } |