From 3f1eec11f94e074b775725f7aa6d19abcfe7ef73 Mon Sep 17 00:00:00 2001 From: Wolfgang Thaller Date: Wed, 24 Sep 2014 20:48:44 +0200 Subject: [PATCH] allow defining pascal functions --- gcc/gcc/function.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/gcc/gcc/function.c b/gcc/gcc/function.c index 1a8682bb7c..6e86da7c9c 100644 --- a/gcc/gcc/function.c +++ b/gcc/gcc/function.c @@ -2318,6 +2318,17 @@ assign_parms_augmented_arg_list (struct assign_parm_data_all *all) all->function_result_decl = decl; } + if (lookup_attribute ("pascal", TYPE_ATTRIBUTES (TREE_TYPE(current_function_decl)))) + { + // reverse argument order + unsigned n = fnargs.length(), n2 = fnargs.length() / 2; + for(unsigned i = 0; i < n2; i++) + { + tree tmp = fnargs[i]; + fnargs[i] = fnargs[n - 1 - i]; + fnargs[n - 1 - i] = tmp; + } + } /* If the target wants to split complex arguments into scalars, do so. */ if (targetm.calls.split_complex_arg) @@ -5042,10 +5053,25 @@ expand_function_end (void) communicate between __builtin_eh_return and the epilogue. */ expand_eh_return (); + + if (lookup_attribute ("pascal", TYPE_ATTRIBUTES (TREE_TYPE(current_function_decl)))) + { + printf("\n\npascal function\n\n"); + tree decl_result = DECL_RESULT (current_function_decl); + rtx decl_rtl = DECL_RTL (decl_result); + enum machine_mode mode = GET_MODE(decl_rtl);; + + rtx return_slot = GEN_INT(crtl->args.pops_args + 8); + return_slot = gen_rtx_PLUS(Pmode, arg_pointer_rtx, return_slot); + return_slot = gen_rtx_MEM(mode, return_slot); + MEM_VOLATILE_P(return_slot) = true; + emit_move_insn (return_slot, decl_rtl); + crtl->return_rtx = return_slot; + } /* If scalar return value was computed in a pseudo-reg, or was a named return value that got dumped to the stack, copy that to the hard return register. */ - if (DECL_RTL_SET_P (DECL_RESULT (current_function_decl))) + else if (DECL_RTL_SET_P (DECL_RESULT (current_function_decl))) { tree decl_result = DECL_RESULT (current_function_decl); rtx decl_rtl = DECL_RTL (decl_result);