summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTing-Wei Lan <lantw44@gmail.com>2016-01-21 16:53:22 +0800
committerTing-Wei Lan <lantw44@gmail.com>2016-01-21 17:54:31 +0800
commit067bbf1f8f007070777f82ca6aefd409d426ebdd (patch)
treea16eea32bd002e0943a7b8b7f490d719dc95bff7
parent17d17e0ee801ba40cd8f83d29422449001d19941 (diff)
downloadcompiler2015-067bbf1f8f007070777f82ca6aefd409d426ebdd.tar
compiler2015-067bbf1f8f007070777f82ca6aefd409d426ebdd.tar.gz
compiler2015-067bbf1f8f007070777f82ca6aefd409d426ebdd.tar.bz2
compiler2015-067bbf1f8f007070777f82ca6aefd409d426ebdd.tar.lz
compiler2015-067bbf1f8f007070777f82ca6aefd409d426ebdd.tar.xz
compiler2015-067bbf1f8f007070777f82ca6aefd409d426ebdd.tar.zst
compiler2015-067bbf1f8f007070777f82ca6aefd409d426ebdd.zip
Reverse the order of arguments on the stack
-rw-r--r--src/code-generation.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/code-generation.c b/src/code-generation.c
index a96aaf6..8dfc8ac 100644
--- a/src/code-generation.c
+++ b/src/code-generation.c
@@ -444,6 +444,10 @@ static void call_function(CcmmcAst *id, CcmmcState *state,
generate_expression(arg, state, dists[i], current_offset);
ccmmc_register_save_arguments(state->reg_pool, stored_param_count);
ccmmc_register_caller_save(state->reg_pool);
+ if (call_param_count > 8)
+ fprintf(state->asm_output,
+ "\tsub\tsp, sp, %zu\n",
+ (call_param_count - 8) * 8);
for (i = 0, arg = id->right_sibling->child; i < call_param_count;
i++, arg = arg->right_sibling) {
if (ccmmc_symbol_type_is_array(func_sym->type.param_list[i])) {
@@ -489,7 +493,8 @@ static void call_function(CcmmcAst *id, CcmmcState *state,
"\tmov\tx%zu, " REG_TMP "\n", i);
else
fprintf(state->asm_output,
- "\tstr\t" REG_TMP ", [sp, -8]!\n");
+ "\tstr\t" REG_TMP ", [sp, %zu]\n",
+ (i - 8) * 8);
#undef REG_TMP
ccmmc_register_unlock(state->reg_pool, offset);
ccmmc_register_free(state->reg_pool, offset, current_offset);
@@ -524,9 +529,9 @@ static void call_function(CcmmcAst *id, CcmmcState *state,
else
fprintf(state->asm_output,
"\tsxtw\t%s, %s\n"
- "\tstr\t%s, [sp, -8]!\n",
+ "\tstr\t%s, [sp, %zu]\n",
dist_extend, dist_reg,
- dist_reg);
+ dist_extend, (i - 8) * 8);
ccmmc_register_unlock(state->reg_pool, dists[i]);
}
}