summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2022-02-17 21:33:21 -0500
committerpommicket <pommicket@gmail.com>2022-02-17 21:33:21 -0500
commitc42c5d94b8944e19cd17a5b540e4c70013c62b92 (patch)
tree284829db6fc30945f7a011db0e9f6df51d26c793
parente94266df3dba36f2998fd85c6aa269f3e6351225 (diff)
fixed += bug with non-char pointers
tcc 0.9.25 can't compile musl (or any libc, probably). will probably need to write libc for tcc, then compile gcc or a later version of tcc with it
-rw-r--r--05/codegen.b9
-rw-r--r--05/main.c12
-rw-r--r--05/stdc_common.h1
-rw-r--r--05/tcc-0.9.25/stdc_common.h1
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)
diff --git a/05/main.c b/05/main.c
index 0eee651..3c989d9 100644
--- a/05/main.c
+++ b/05/main.c
@@ -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);
}