+/**
+ * Returns the register for parameter nr.
+ *
+ * @param n The number of parameters
+ * @param modes The list of the parameter modes
+ * @param nr The number of the parameter to return the requirements for
+ * @param cc The calling convention
+ * @return The register
+ */
+const arch_register_t *ia32_get_RegParam_reg(int n, ir_mode **modes, long nr, unsigned cc) {
+ const arch_register_t **current_gpreg_param_reg;
+ const arch_register_t **current_fpreg_param_reg;
+ const arch_register_t *param_reg = NULL;
+ int n_gpregparam = 0;
+ int n_fpregparam = 0;
+ int i, done = 0;
+ int cur_gp_idx = 0;
+ int cur_fp_idx = 0;
+ int biggest_n = ia32_get_n_regparam_class(n, modes, &n_gpregparam, &n_fpregparam);
+
+ /* Check if parameter #nr is in range for passing in register */
+ if (nr <= biggest_n) {
+ current_gpreg_param_reg = gpreg_param_reg_std;
+ current_fpreg_param_reg = fpreg_param_reg_std;
+
+ if (cc & cc_this_call) {
+ current_gpreg_param_reg = gpreg_param_reg_this;
+ current_fpreg_param_reg = fpreg_param_reg_this;
+ }
+
+ /* loop over all parameters and determine whether its a int or float register parameter */
+ for (i = 0; i < nr && !done && (cc & cc_reg_param); i++) {
+ if ((mode_is_int(modes[i]) || mode_is_reference(modes[i])) && cur_gp_idx < maxnum_gpreg_args) {
+ /* param can be passed in general purpose register and we have some registers left */
+ cur_gp_idx++;
+ }
+ else if (mode_is_float(modes[i]) && cur_fp_idx < maxnum_fpreg_args) {
+ /* param can be passed in floating point register and we have some registers left */
+ assert(current_gpreg_param_reg[cur_fp_idx] && "'this' pointer cannot be passed as float");
+ cur_fp_idx++;
+ }
+ }
+
+ /* now: i == nr, that's the parameter requirement we want */
+ if ((mode_is_int(modes[i]) || mode_is_reference(modes[i])) && cur_gp_idx < maxnum_gpreg_args) {
+ /* parameter #nr can be passed in general purpose register */
+ param_reg = current_gpreg_param_reg[i];
+ }
+ else if (mode_is_float(modes[i]) && cur_fp_idx < maxnum_fpreg_args) {
+ /* parameter #nr can be passed in floating point register */
+ param_reg = current_fpreg_param_reg[i];
+ }
+ else {
+ assert(0 && "This should not happen!");
+ }