aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib.s14
-rw-r--r--mips.c1
-rw-r--r--semantics.c3
3 files changed, 18 insertions, 0 deletions
diff --git a/lib.s b/lib.s
index 7c025b5..c8c4b2e 100644
--- a/lib.s
+++ b/lib.s
@@ -153,3 +153,17 @@ _func_malloc:
li $2, 9
syscall
jr $31
+_func_memcpy: # the copied mem must be 4-aligned
+ lw $8, 0($sp) # dest addr
+ lw $9, 4($sp) # src addr
+ lw $10, 8($sp) # size
+ j __COND
+__LOOP:
+ lw $2, 0($9)
+ sw $2, 0($8)
+ addiu $8, $8, 4
+ addiu $9, $9, 4
+ addiu $10, $10, -4
+__COND:
+ bnez $10, __LOOP
+ jr $31
diff --git a/mips.c b/mips.c
index 5fa5831..eeada74 100644
--- a/mips.c
+++ b/mips.c
@@ -54,6 +54,7 @@ void mips_prologue() {
else
printf("\t.space %d\n", calc_size(var->type));
}
+ printf("\t.align 2\n");
for (s = cstrs; s; s = s->next)
{
printf("_str_%d:\n", s->id);
diff --git a/semantics.c b/semantics.c
index bbed137..77d4b54 100644
--- a/semantics.c
+++ b/semantics.c
@@ -59,6 +59,7 @@ static CType_t basic_type_void;
static CType_t builtin_printf;
static CType_t builtin_scanf;
static CType_t builtin_malloc;
+static CType_t builtin_memcpy;
static CType_t builtin_print_int;
static CType_t builtin_print_char;
static CType_t builtin_print_string;
@@ -1874,6 +1875,7 @@ void semantics_check(CNode *p) {
builtin_print_int = make_builtin_func("__print_int", basic_type_int);
builtin_print_char = make_builtin_func("__print_char", basic_type_int);
builtin_print_string = make_builtin_func("__print_string", basic_type_int);
+ builtin_memcpy = make_builtin_func("memcpy", basic_type_void);
{
CType_t vstar = ctype_create("", CPTR, NULL);
vstar->rec.ref = basic_type_void;
@@ -1886,6 +1888,7 @@ void semantics_check(CNode *p) {
cscope_push_type(scope, builtin_printf, NS_ID);
cscope_push_type(scope, builtin_scanf, NS_ID);
cscope_push_type(scope, builtin_malloc, NS_ID);
+ cscope_push_type(scope, builtin_memcpy, NS_ID);
cscope_push_type(scope, builtin_print_int, NS_ID);
cscope_push_type(scope, builtin_print_char, NS_ID);
cscope_push_type(scope, builtin_print_string, NS_ID);