2 * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved.
4 * This file is part of libFirm.
6 * This file may be distributed and/or modified under the terms of the
7 * GNU General Public License version 2 as published by the Free Software
8 * Foundation and appearing in the file LICENSE.GPL included in the
9 * packaging of this file.
11 * Licensees holding valid libFirm Professional Edition licenses may use
12 * this file in accordance with the libFirm Commercial License.
13 * Agreement provided with the Software.
15 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * @brief calling convention helpers
23 * @author Matthias Braun
28 #include "arm_cconv.h"
34 calling_convention_t *decide_calling_convention(ir_type *function_type)
37 reg_or_stackslot_t *params;
38 reg_or_stackslot_t *results;
40 = sizeof(param_regs)/sizeof(param_regs[0]);
42 = sizeof(result_regs)/sizeof(result_regs[0]);
47 calling_convention_t *cconv;
49 /* determine how parameters are passed */
50 n_params = get_method_n_params(function_type);
52 params = XMALLOCNZ(reg_or_stackslot_t, n_params);
54 for (i = 0; i < n_params; ++i) {
55 ir_type *param_type = get_method_param_type(function_type,i);
56 ir_mode *mode = get_type_mode(param_type);
57 int bits = get_mode_size_bits(mode);
58 reg_or_stackslot_t *param = ¶ms[i];
60 if (regnum < n_param_regs) {
61 const arch_register_t *reg = param_regs[regnum++];
64 param->type = param_type;
65 param->offset = stack_offset;
66 /* increase offset 4 bytes so everything is aligned */
71 /* we might need a 2nd 32bit component (for 64bit or double values) */
74 panic("only 32 and 64bit modes supported in arm backend");
76 if (regnum < n_param_regs) {
77 const arch_register_t *reg = param_regs[regnum++];
80 ir_mode *mode = param_regs[0]->reg_class->mode;
81 ir_type *type = get_type_for_mode(mode);
83 param->offset = stack_offset;
89 n_results = get_method_n_ress(function_type);
91 results = XMALLOCNZ(reg_or_stackslot_t, n_results);
92 for (i = 0; i < n_results; ++i) {
93 ir_type *result_type = get_method_res_type(function_type, i);
94 ir_mode *result_mode = get_type_mode(result_type);
95 reg_or_stackslot_t *result = &results[i];
97 if (get_mode_size_bits(result_mode) > 32) {
98 panic("Results with more than 32bits not supported by arm backend yet");
101 if (regnum >= n_result_regs) {
102 panic("Too many results for arm backend");
104 const arch_register_t *reg = result_regs[regnum++];
109 cconv = XMALLOCZ(calling_convention_t);
110 cconv->parameters = params;
111 cconv->param_stack_size = stack_offset;
112 cconv->results = results;
117 void free_calling_convention(calling_convention_t *cconv)
119 free(cconv->parameters);
120 free(cconv->results);