<commit_before>/*
 * This file is part of libFirm.
 * Copyright (C) 2017 University of Karlsruhe.
 */

#include "mips_cconv.h"

#include "betranshlp.h"
#include "gen_mips_regalloc_if.h"
#include "mips_bearch_t.h"
#include "util.h"

static unsigned const regs_param_gp[] = {
	REG_A0,
	REG_A1,
	REG_A2,
	REG_A3,
};

static unsigned const regs_result_gp[] = {
	REG_V0,
	REG_V1,
};

void mips_determine_calling_convention(mips_calling_convention_t *const cconv, ir_type *const fun_type)
{
	/* Handle parameters. */
	mips_reg_or_slot_t *params;
	size_t              gp_param = 0;
	size_t        const n_params = get_method_n_params(fun_type);
	if (n_params != 0) {
		params = XMALLOCNZ(mips_reg_or_slot_t, n_params);

		for (size_t i = 0; i != n_params; ++i) {
			ir_type *const param_type = get_method_param_type(fun_type, i);
			ir_mode *const param_mode = get_type_mode(param_type);
			if (!param_mode) {
				panic("TODO");
			} else if (mode_is_float(param_mode)) {
				panic("TODO");
			} else {
				if (param_type->flags & tf_lowered_dw && gp_param % 2 != 0)
					++gp_param;
				if (gp_param < ARRAY_SIZE(regs_param_gp))
					params[i].reg = &mips_registers[regs_param_gp[gp_param]];
				params[i].offset = gp_param * (MIPS_MACHINE_SIZE / 8);
				++gp_param;
			}
		}
	} else {
		params = 0;
	}
	cconv->param_stack_size = MAX(4, gp_param) * (MIPS_MACHINE_SIZE / 8);
	cconv->n_mem_param      = gp_param > 4 ? gp_param - 4 : 0;
	cconv->parameters       = params;
<commit_msg>mips: Replace magic number '4' by a symbolic constant (number of GP register parameters).<commit_after>/*
 * This file is part of libFirm.
 * Copyright (C) 2017 University of Karlsruhe.
 */

#include "mips_cconv.h"

#include "betranshlp.h"
#include "gen_mips_regalloc_if.h"
#include "mips_bearch_t.h"
#include "util.h"

static unsigned const regs_param_gp[] = {
	REG_A0,
	REG_A1,
	REG_A2,
	REG_A3,
};

static unsigned const regs_result_gp[] = {
	REG_V0,
	REG_V1,
};

void mips_determine_calling_convention(mips_calling_convention_t *const cconv, ir_type *const fun_type)
{
	/* Handle parameters. */
	mips_reg_or_slot_t *params;
	size_t              gp_param = 0;
	size_t        const n_params = get_method_n_params(fun_type);
	if (n_params != 0) {
		params = XMALLOCNZ(mips_reg_or_slot_t, n_params);

		for (size_t i = 0; i != n_params; ++i) {
			ir_type *const param_type = get_method_param_type(fun_type, i);
			ir_mode *const param_mode = get_type_mode(param_type);
			if (!param_mode) {
				panic("TODO");
			} else if (mode_is_float(param_mode)) {
				panic("TODO");
			} else {
				if (param_type->flags & tf_lowered_dw && gp_param % 2 != 0)
					++gp_param;
				if (gp_param < ARRAY_SIZE(regs_param_gp))
					params[i].reg = &mips_registers[regs_param_gp[gp_param]];
				params[i].offset = gp_param * (MIPS_MACHINE_SIZE / 8);
				++gp_param;
			}
		}
	} else {
		params = 0;
	}
	size_t const n_reg_params = ARRAY_SIZE(regs_param_gp);
	cconv->param_stack_size = MAX(n_reg_params, gp_param) * (MIPS_MACHINE_SIZE / 8);
	cconv->n_mem_param      = gp_param > n_reg_params ? gp_param - n_reg_params : 0;
	cconv->parameters       = params;

{'fraction_non_alphanumeric': 0.12712680577849117, 'fraction_numerical': 0.01348314606741573, 'mean_word_length': 3.9225908372827805, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7623820', 'n_tokens_mistral': 1417, 'n_tokens_neox': 1292, 'n_words': 253}