bearch_TEMPLATE.c 18.1 KB
Newer Older
Christian Würdig's avatar
Christian Würdig committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/*
 * Copyright (C) 1995-2007 University of Karlsruhe.  All right reserved.
 *
 * This file is part of libFirm.
 *
 * This file may be distributed and/or modified under the terms of the
 * GNU General Public License version 2 as published by the Free Software
 * Foundation and appearing in the file LICENSE.GPL included in the
 * packaging of this file.
 *
 * Licensees holding valid libFirm Professional Edition licenses may use
 * this file in accordance with the libFirm Commercial License.
 * Agreement provided with the Software.
 *
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE.
 */

Matthias Braun's avatar
Matthias Braun committed
20
21
22
23
24
/**
 * @file
 * @brief    The main TEMPLATE backend driver file.
 * @version  $Id$
 */
25
#ifdef HAVE_CONFIG_H
26
#include "config.h"
27
28
29
30
31
32
33
34
35
36
37
38
#endif

#include "pseudo_irg.h"
#include "irgwalk.h"
#include "irprog.h"
#include "irprintf.h"
#include "ircons.h"
#include "irgmod.h"

#include "bitset.h"
#include "debug.h"

39
#include "../bearch_t.h"
40
41
42
#include "../benode_t.h"
#include "../belower.h"
#include "../besched_t.h"
43
#include "be.h"
Christian Würdig's avatar
Christian Würdig committed
44
#include "../beabi.h"
45
#include "../bemodule.h"
Matthias Braun's avatar
Matthias Braun committed
46
#include "../begnuas.h"
Christian Würdig's avatar
Christian Würdig committed
47

48
49
#include "bearch_TEMPLATE_t.h"

50
51
#include "TEMPLATE_new_nodes.h"
#include "gen_TEMPLATE_regalloc_if.h"
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include "TEMPLATE_transform.h"
#include "TEMPLATE_emitter.h"
#include "TEMPLATE_map_regs.h"

/* TODO: ugly, but we need it to get access to the registers assigned to Phi nodes */
static set *cur_reg_set = NULL;

/**************************************************
 *                         _ _              _  __
 *                        | | |            (_)/ _|
 *  _ __ ___  __ _    __ _| | | ___   ___   _| |_
 * | '__/ _ \/ _` |  / _` | | |/ _ \ / __| | |  _|
 * | | |  __/ (_| | | (_| | | | (_) | (__  | | |
 * |_|  \___|\__, |  \__,_|_|_|\___/ \___| |_|_|
 *            __/ |
 *           |___/
 **************************************************/

/**
 * Return register requirements for a TEMPLATE node.
 * If the node returns a tuple (mode_T) then the proj's
 * will be asked for this information.
 */
Matthias Braun's avatar
Matthias Braun committed
75
76
77
static const
arch_register_req_t *TEMPLATE_get_irn_reg_req(const void *self,
                                              const ir_node *node, int pos) {
78
	long               node_pos = pos == -1 ? 0 : pos;
Matthias Braun's avatar
Matthias Braun committed
79
	ir_mode           *mode     = get_irn_mode(node);
Matthias Braun's avatar
Matthias Braun committed
80
	(void) self;
81
82

	if (mode == mode_T || mode == mode_M) {
Matthias Braun's avatar
Matthias Braun committed
83
		return arch_no_register_req;
84
85
	}

Matthias Braun's avatar
Matthias Braun committed
86
	if (is_Proj(node)) {
87
88
89
		/* in case of a proj, we need to get the correct OUT slot */
		/* of the node corresponding to the proj number */
		if (pos == -1) {
Matthias Braun's avatar
Matthias Braun committed
90
91
			node_pos = TEMPLATE_translate_proj_pos(node);
		} else {
92
93
94
			node_pos = pos;
		}

Matthias Braun's avatar
Matthias Braun committed
95
		node = skip_Proj_const(node);
96
97
98
	}

	/* get requirements for our own nodes */
Matthias Braun's avatar
Matthias Braun committed
99
100
	if (is_TEMPLATE_irn(node)) {
		const arch_register_req_t *req;
101
		if (pos >= 0) {
Matthias Braun's avatar
Matthias Braun committed
102
103
104
			req = get_TEMPLATE_in_req(node, pos);
		} else {
			req = get_TEMPLATE_out_req(node, node_pos);
105
106
		}

Matthias Braun's avatar
Matthias Braun committed
107
		assert(req != NULL);
108

Matthias Braun's avatar
Matthias Braun committed
109
		return req;
110
111
	}

Matthias Braun's avatar
Matthias Braun committed
112
113
114
115
	/* unknowns should be transformed already */
	assert(!is_Unknown(node));

	return arch_no_register_req;
116
117
}

Matthias Braun's avatar
Matthias Braun committed
118
119
static void TEMPLATE_set_irn_reg(const void *self, ir_node *irn, const arch_register_t *reg)
{
120
	int pos = 0;
Matthias Braun's avatar
Matthias Braun committed
121
	(void) self;
122

Christian Würdig's avatar
Christian Würdig committed
123
	if (is_Proj(irn)) {
124
		pos = TEMPLATE_translate_proj_pos(irn);
Matthias Braun's avatar
Matthias Braun committed
125
		irn = skip_Proj(irn);
126
127
128
129
130
131
132
133
134
135
136
137
138
139
	}

	if (is_TEMPLATE_irn(irn)) {
		const arch_register_t **slots;

		slots      = get_TEMPLATE_slots(irn);
		slots[pos] = reg;
	}
	else {
		/* here we set the registers for the Phi nodes */
		TEMPLATE_set_firm_reg(irn, reg, cur_reg_set);
	}
}

Matthias Braun's avatar
Matthias Braun committed
140
141
static
const arch_register_t *TEMPLATE_get_irn_reg(const void *self,
Matthias Braun's avatar
Matthias Braun committed
142
143
                                            const ir_node *irn)
{
144
145
	int pos = 0;
	const arch_register_t *reg = NULL;
Matthias Braun's avatar
Matthias Braun committed
146
	(void) self;
147

Christian Würdig's avatar
Christian Würdig committed
148
	if (is_Proj(irn)) {
149
		pos = TEMPLATE_translate_proj_pos(irn);
Matthias Braun's avatar
Matthias Braun committed
150
		irn = skip_Proj_const(irn);
151
152
153
	}

	if (is_TEMPLATE_irn(irn)) {
Matthias Braun's avatar
Matthias Braun committed
154
155
		const arch_register_t * const *slots;
		slots = get_TEMPLATE_slots_const(irn);
156
157
158
159
160
161
162
163
164
165
		reg   = slots[pos];
	}
	else {
		reg = TEMPLATE_get_firm_reg(irn, cur_reg_set);
	}

	return reg;
}

static arch_irn_class_t TEMPLATE_classify(const void *self, const ir_node *irn) {
Matthias Braun's avatar
Matthias Braun committed
166
	irn = skip_Proj_const(irn);
Matthias Braun's avatar
Matthias Braun committed
167
	(void) self;
168
169
170
171
172
173
174
175
176
177
178
179

	if (is_cfop(irn)) {
		return arch_irn_class_branch;
	}
	else if (is_TEMPLATE_irn(irn)) {
		return arch_irn_class_normal;
	}

	return 0;
}

static arch_irn_flags_t TEMPLATE_get_flags(const void *self, const ir_node *irn) {
Matthias Braun's avatar
Matthias Braun committed
180
	irn = skip_Proj_const(irn);
Matthias Braun's avatar
Matthias Braun committed
181
	(void) self;
182
183
184
185
186
187
188
189
190
191
192

	if (is_TEMPLATE_irn(irn)) {
		return get_TEMPLATE_flags(irn);
	}
	else if (is_Unknown(irn)) {
		return arch_irn_flags_ignore;
	}

	return 0;
}

Matthias Braun's avatar
Matthias Braun committed
193
static ir_entity *TEMPLATE_get_frame_entity(const void *self, const ir_node *node) {
Matthias Braun's avatar
Matthias Braun committed
194
195
	(void) self;
	(void) node;
196
	/* TODO: return the ir_entity assigned to the frame */
Christian Würdig's avatar
Christian Würdig committed
197
198
199
	return NULL;
}

Matthias Braun's avatar
Matthias Braun committed
200
static void TEMPLATE_set_frame_entity(const void *self, ir_node *node, ir_entity *ent) {
Matthias Braun's avatar
Matthias Braun committed
201
202
203
	(void) self;
	(void) node;
	(void) ent;
204
	/* TODO: set the ir_entity assigned to the frame */
205
206
}

Christian Würdig's avatar
Christian Würdig committed
207
208
209
210
/**
 * This function is called by the generic backend to correct offsets for
 * nodes accessing the stack.
 */
211
static void TEMPLATE_set_frame_offset(const void *self, ir_node *irn, int offset) {
Matthias Braun's avatar
Matthias Braun committed
212
213
214
	(void) self;
	(void) irn;
	(void) offset;
Christian Würdig's avatar
Christian Würdig committed
215
216
217
	/* TODO: correct offset if irn accesses the stack */
}

218
static int TEMPLATE_get_sp_bias(const void *self, const ir_node *irn) {
Matthias Braun's avatar
Matthias Braun committed
219
220
	(void) self;
	(void) irn;
221
222
223
	return 0;
}

224
225
226
227
228
229
230
/* fill register allocator interface */

static const arch_irn_ops_if_t TEMPLATE_irn_ops_if = {
	TEMPLATE_get_irn_reg_req,
	TEMPLATE_set_irn_reg,
	TEMPLATE_get_irn_reg,
	TEMPLATE_classify,
Christian Würdig's avatar
Christian Würdig committed
231
232
	TEMPLATE_get_flags,
	TEMPLATE_get_frame_entity,
233
	TEMPLATE_set_frame_entity,
234
235
	TEMPLATE_set_frame_offset,
	TEMPLATE_get_sp_bias,
236
237
238
239
	NULL,    /* get_inverse             */
	NULL,    /* get_op_estimated_cost   */
	NULL,    /* possible_memory_operand */
	NULL,    /* perform_memory_operand  */
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
};

TEMPLATE_irn_ops_t TEMPLATE_irn_ops = {
	&TEMPLATE_irn_ops_if,
	NULL
};



/**************************************************
 *                _                         _  __
 *               | |                       (_)/ _|
 *   ___ ___   __| | ___  __ _  ___ _ __    _| |_
 *  / __/ _ \ / _` |/ _ \/ _` |/ _ \ '_ \  | |  _|
 * | (_| (_) | (_| |  __/ (_| |  __/ | | | | | |
 *  \___\___/ \__,_|\___|\__, |\___|_| |_| |_|_|
 *                        __/ |
 *                       |___/
 **************************************************/

/**
 * Transforms the standard firm graph into
 * a TEMLPATE firm graph
 */
static void TEMPLATE_prepare_graph(void *self) {
	TEMPLATE_code_gen_t *cg = self;

Christian Würdig's avatar
Christian Würdig committed
267
	irg_walk_blkwise_graph(cg->irg, NULL, TEMPLATE_transform_node, cg);
268
269
270
271
272
}



/**
Christian Würdig's avatar
Christian Würdig committed
273
 * Called immediatly before emit phase.
274
 */
275
276
277
278
279
static void TEMPLATE_finish_irg(void *self) {
	TEMPLATE_code_gen_t *cg = self;
	ir_graph            *irg = cg->irg;

	dump_ir_block_graph_sched(irg, "-TEMPLATE-finished");
280
281
282
}


Christian Würdig's avatar
Christian Würdig committed
283
284
285
/**
 * These are some hooks which must be filled but are probably not needed.
 */
286
static void TEMPLATE_before_sched(void *self) {
Matthias Braun's avatar
Matthias Braun committed
287
	(void) self;
Christian Würdig's avatar
Christian Würdig committed
288
	/* Some stuff you need to do after scheduling but before register allocation */
289
290
}

Matthias Braun's avatar
Matthias Braun committed
291
static void TEMPLATE_before_ra(void *self) {
Matthias Braun's avatar
Matthias Braun committed
292
	(void) self;
293
	/* Some stuff you need to do after scheduling but before register allocation */
294
295
}

296
static void TEMPLATE_after_ra(void *self) {
Matthias Braun's avatar
Matthias Braun committed
297
	(void) self;
298
	/* Some stuff you need to do immediatly after register allocation */
299
300
301
302
303
304
305
306
}



/**
 * Emits the code, closes the output file and frees
 * the code generator interface.
 */
Christian Würdig's avatar
Christian Würdig committed
307
static void TEMPLATE_emit_and_done(void *self) {
308
309
310
	TEMPLATE_code_gen_t *cg = self;
	ir_graph           *irg = cg->irg;

Matthias Braun's avatar
Matthias Braun committed
311
	TEMPLATE_gen_routine(cg, irg);
312
313
314
315
316

	cur_reg_set = NULL;

	/* de-allocate code generator */
	del_set(cg->reg_set);
317
	free(cg);
318
319
}

Matthias Braun's avatar
Matthias Braun committed
320
static void *TEMPLATE_cg_init(be_irg_t *birg);
321
322
323

static const arch_code_generator_if_t TEMPLATE_code_gen_if = {
	TEMPLATE_cg_init,
Matthias Braun's avatar
Matthias Braun committed
324
	NULL,                    /* before abi introduce hook */
325
	TEMPLATE_prepare_graph,
Matthias Braun's avatar
Matthias Braun committed
326
	NULL,                    /* spill hook */
327
328
	TEMPLATE_before_sched,   /* before scheduling hook */
	TEMPLATE_before_ra,      /* before register allocation hook */
329
	TEMPLATE_after_ra,       /* after register allocation hook */
330
	TEMPLATE_finish_irg,
Christian Würdig's avatar
Christian Würdig committed
331
	TEMPLATE_emit_and_done
332
333
334
335
336
};

/**
 * Initializes the code generator.
 */
Matthias Braun's avatar
Matthias Braun committed
337
static void *TEMPLATE_cg_init(be_irg_t *birg) {
338
339
340
	const arch_env_t    *arch_env = be_get_birg_arch_env(birg);
	TEMPLATE_isa_t      *isa      = (TEMPLATE_isa_t *) arch_env->isa;
	TEMPLATE_code_gen_t *cg       = xmalloc(sizeof(*cg));
341

Christian Würdig's avatar
Christian Würdig committed
342
	cg->impl     = &TEMPLATE_code_gen_if;
343
	cg->irg      = be_get_birg_irg(birg);
Christian Würdig's avatar
Christian Würdig committed
344
	cg->reg_set  = new_set(TEMPLATE_cmp_irn_reg_assoc, 1024);
345
	cg->arch_env = arch_env;
346
	cg->isa      = isa;
Christian Würdig's avatar
Christian Würdig committed
347
	cg->birg     = birg;
348
	FIRM_DBG_REGISTER(cg->mod, "firm.be.TEMPLATE.cg");
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368

	cur_reg_set = cg->reg_set;

	TEMPLATE_irn_ops.cg = cg;

	return (arch_code_generator_t *)cg;
}



/*****************************************************************
 *  ____             _                  _   _____  _____
 * |  _ \           | |                | | |_   _|/ ____|  /\
 * | |_) | __ _  ___| | _____ _ __   __| |   | | | (___   /  \
 * |  _ < / _` |/ __| |/ / _ \ '_ \ / _` |   | |  \___ \ / /\ \
 * | |_) | (_| | (__|   <  __/ | | | (_| |  _| |_ ____) / ____ \
 * |____/ \__,_|\___|_|\_\___|_| |_|\__,_| |_____|_____/_/    \_\
 *
 *****************************************************************/

Christian Würdig's avatar
Christian Würdig committed
369
static TEMPLATE_isa_t TEMPLATE_isa_template = {
Matthias Braun's avatar
Matthias Braun committed
370
371
372
373
374
375
	{
		&TEMPLATE_isa_if,             /* isa interface implementation */
		&TEMPLATE_general_purpose_regs[REG_SP],  /* stack pointer register */
		&TEMPLATE_general_purpose_regs[REG_BP],  /* base pointer register */
		-1,                          /* stack direction */
		NULL,                        /* main environment */
376
377
		7,                           /* costs for a spill instruction */
		5,                           /* costs for a reload instruction */
Matthias Braun's avatar
Matthias Braun committed
378
	},
Christian Würdig's avatar
Christian Würdig committed
379
380
};

381
382
383
/**
 * Initializes the backend ISA and opens the output file.
 */
384
static void *TEMPLATE_init(FILE *outfile) {
Matthias Braun's avatar
Matthias Braun committed
385
	static int run_once = 0;
Christian Würdig's avatar
Christian Würdig committed
386
	TEMPLATE_isa_t *isa;
387

Matthias Braun's avatar
Matthias Braun committed
388
	if(run_once)
389
		return NULL;
Matthias Braun's avatar
Matthias Braun committed
390
	run_once = 1;
391

Christian Würdig's avatar
Christian Würdig committed
392
393
	isa = xcalloc(1, sizeof(*isa));
	memcpy(isa, &TEMPLATE_isa_template, sizeof(*isa));
394

395
	be_emit_init(outfile);
396

Matthias Braun's avatar
Matthias Braun committed
397
	TEMPLATE_register_init();
398
399
400
401
402
403
404
405
406
407
408
	TEMPLATE_create_opcodes();

	return isa;
}



/**
 * Closes the output file and frees the ISA structure.
 */
static void TEMPLATE_done(void *self) {
Matthias Braun's avatar
Matthias Braun committed
409
410
411
	TEMPLATE_isa_t *isa = self;

	/* emit now all global declarations */
412
	be_gas_emit_decls(isa->arch_isa.main_env, 0);
Matthias Braun's avatar
Matthias Braun committed
413

414
	be_emit_exit();
415
416
417
418
419
	free(self);
}



420
static unsigned TEMPLATE_get_n_reg_class(const void *self)
Matthias Braun's avatar
Matthias Braun committed
421
422
{
	(void) self;
423
424
425
	return N_CLASSES;
}

Matthias Braun's avatar
Matthias Braun committed
426
static const arch_register_class_t *TEMPLATE_get_reg_class(const void *self,
427
                                                           unsigned i)
Matthias Braun's avatar
Matthias Braun committed
428
429
{
	(void) self;
430
	assert(i < N_CLASSES);
431
432
433
	return &TEMPLATE_reg_classes[i];
}

Christian Würdig's avatar
Christian Würdig committed
434
435
436
437
438
439
440
441


/**
 * Get the register class which shall be used to store a value of a given mode.
 * @param self The this pointer.
 * @param mode The mode in question.
 * @return A register class which can hold values of the given mode.
 */
Matthias Braun's avatar
Matthias Braun committed
442
443
444
445
const arch_register_class_t *TEMPLATE_get_reg_class_for_mode(const void *self,
		const ir_mode *mode)
{
	(void) self;
Christian Würdig's avatar
Christian Würdig committed
446
447
448
449
450
451
452
453
	if (mode_is_float(mode))
		return &TEMPLATE_reg_classes[CLASS_TEMPLATE_floating_point];
	else
		return &TEMPLATE_reg_classes[CLASS_TEMPLATE_general_purpose];
}



Michael Beck's avatar
Michael Beck committed
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
typedef struct {
	be_abi_call_flags_bits_t flags;
	const arch_env_t *arch_env;
	const arch_isa_t *isa;
	ir_graph *irg;
} TEMPLATE_abi_env_t;

static void *TEMPLATE_abi_init(const be_abi_call_t *call, const arch_env_t *arch_env, ir_graph *irg)
{
	TEMPLATE_abi_env_t *env = xmalloc(sizeof(env[0]));
	be_abi_call_flags_t fl = be_abi_call_get_flags(call);
	env->flags    = fl.bits;
	env->irg      = irg;
	env->arch_env = arch_env;
	env->isa      = arch_env->isa;
	return env;
}

Christian Würdig's avatar
Christian Würdig committed
472
/**
Michael Beck's avatar
Michael Beck committed
473
474
475
 * Get the between type for that call.
 * @param self The callback object.
 * @return The between type of for that call.
Christian Würdig's avatar
Christian Würdig committed
476
 */
Matthias Braun's avatar
Matthias Braun committed
477
478
static ir_type *TEMPLATE_get_between_type(void *self)
{
Christian Würdig's avatar
Christian Würdig committed
479
	static ir_type *between_type = NULL;
Matthias Braun's avatar
Matthias Braun committed
480
481
	static ir_entity *old_bp_ent = NULL;
	(void) self;
Christian Würdig's avatar
Christian Würdig committed
482
483

	if(!between_type) {
484
		ir_entity *ret_addr_ent;
Christian Würdig's avatar
Christian Würdig committed
485
486
487
488
489
490
491
		ir_type *ret_addr_type = new_type_primitive(new_id_from_str("return_addr"), mode_P);
		ir_type *old_bp_type   = new_type_primitive(new_id_from_str("bp"), mode_P);

		between_type           = new_type_class(new_id_from_str("TEMPLATE_between_type"));
		old_bp_ent             = new_entity(between_type, new_id_from_str("old_bp"), old_bp_type);
		ret_addr_ent           = new_entity(between_type, new_id_from_str("old_bp"), ret_addr_type);

Michael Beck's avatar
Michael Beck committed
492
493
		set_entity_offset(old_bp_ent, 0);
		set_entity_offset(ret_addr_ent, get_type_size_bytes(old_bp_type));
Christian Würdig's avatar
Christian Würdig committed
494
495
496
497
498
499
		set_type_size_bytes(between_type, get_type_size_bytes(old_bp_type) + get_type_size_bytes(ret_addr_type));
	}

	return between_type;
}

Michael Beck's avatar
Michael Beck committed
500
501
502
503
504
505
506
507
508
509
510
511
static void TEMPLATE_abi_dont_save_regs(void *self, pset *s)
{
	TEMPLATE_abi_env_t *env = self;
	if (env->flags.try_omit_fp) {
		/* insert the BP register into the ignore set */
		pset_insert_ptr(s, env->isa->bp);
	}
}

/**
 * Build the prolog, return the BASE POINTER register
 */
Matthias Braun's avatar
Matthias Braun committed
512
513
514
static const arch_register_t *TEMPLATE_abi_prologue(void *self, ir_node **mem,
                                                    pmap *reg_map)
{
Michael Beck's avatar
Michael Beck committed
515
	TEMPLATE_abi_env_t *env = self;
Matthias Braun's avatar
Matthias Braun committed
516
517
	(void) reg_map;
	(void) mem;
Michael Beck's avatar
Michael Beck committed
518
519
520
521
522
523
524

	if(env->flags.try_omit_fp)
		return env->isa->sp;
	return env->isa->bp;
}

/* Build the epilog */
Matthias Braun's avatar
Matthias Braun committed
525
526
527
528
529
530
531
static void TEMPLATE_abi_epilogue(void *self, ir_node *bl, ir_node **mem,
                                  pmap *reg_map)
{
	(void) self;
	(void) bl;
	(void) mem;
	(void) reg_map;
Michael Beck's avatar
Michael Beck committed
532
533
534
535
536
537
538
539
}

static const be_abi_callbacks_t TEMPLATE_abi_callbacks = {
	TEMPLATE_abi_init,
	free,
	TEMPLATE_get_between_type,
	TEMPLATE_abi_dont_save_regs,
	TEMPLATE_abi_prologue,
540
	TEMPLATE_abi_epilogue,
Michael Beck's avatar
Michael Beck committed
541
542
};

Christian Würdig's avatar
Christian Würdig committed
543
544
545
546
547
548
/**
 * Get the ABI restrictions for procedure calls.
 * @param self        The this pointer.
 * @param method_type The type of the method (procedure) in question.
 * @param abi         The abi object to be modified
 */
Matthias Braun's avatar
Matthias Braun committed
549
550
551
void TEMPLATE_get_call_abi(const void *self, ir_type *method_type,
                           be_abi_call_t *abi)
{
Christian Würdig's avatar
Christian Würdig committed
552
553
554
	ir_type  *tp;
	ir_mode  *mode;
	int       i, n = get_method_n_params(method_type);
555
	be_abi_call_flags_t call_flags;
Matthias Braun's avatar
Matthias Braun committed
556
	(void) self;
557
558
559
560
561
562
563

	/* set abi flags for calls */
	call_flags.bits.left_to_right         = 0;
	call_flags.bits.store_args_sequential = 1;
	call_flags.bits.try_omit_fp           = 1;
	call_flags.bits.fp_free               = 0;
	call_flags.bits.call_has_imm          = 1;
Christian Würdig's avatar
Christian Würdig committed
564
565

	/* set stack parameter passing style */
Michael Beck's avatar
Michael Beck committed
566
	be_abi_call_set_flags(abi, call_flags, &TEMPLATE_abi_callbacks);
Christian Würdig's avatar
Christian Würdig committed
567
568
569
570
571
572
573

	for (i = 0; i < n; i++) {
		/* TODO: implement register parameter: */
		/* reg = get reg for param i;          */
		/* be_abi_call_param_reg(abi, i, reg); */

		/* default: all parameters on stack */
574
575
576
		tp   = get_method_param_type(method_type, i);
		mode = get_type_mode(tp);
		be_abi_call_param_stack(abi, i, mode, 4, 0, 0);
Christian Würdig's avatar
Christian Würdig committed
577
578
579
580
581
582
583
584
585
586
587
588
589
	}

	/* TODO: set correct return register */
	/* default: return value is in R0 resp. F0 */
	if (get_method_n_ress(method_type) > 0) {
		tp   = get_method_res_type(method_type, 0);
		mode = get_type_mode(tp);

		be_abi_call_res_reg(abi, 0,
			mode_is_float(mode) ? &TEMPLATE_floating_point_regs[REG_F0] : &TEMPLATE_general_purpose_regs[REG_R0]);
	}
}

Matthias Braun's avatar
Matthias Braun committed
590
591
592
593
594
static const void *TEMPLATE_get_irn_ops(const arch_irn_handler_t *self,
                                        const ir_node *irn)
{
	(void) self;
	(void) irn;
595
596
597
598
599
600
601
	return &TEMPLATE_irn_ops;
}

const arch_irn_handler_t TEMPLATE_irn_handler = {
	TEMPLATE_get_irn_ops
};

Matthias Braun's avatar
Matthias Braun committed
602
603
604
const arch_irn_handler_t *TEMPLATE_get_irn_handler(const void *self)
{
	(void) self;
605
606
607
	return &TEMPLATE_irn_handler;
}

Matthias Braun's avatar
Matthias Braun committed
608
609
610
611
int TEMPLATE_to_appear_in_schedule(void *block_env, const ir_node *irn)
{
	(void) block_env;

612
613
614
615
	if(!is_TEMPLATE_irn(irn))
		return -1;

	return 1;
616
617
618
619
620
}

/**
 * Initializes the code generator interface.
 */
Matthias Braun's avatar
Matthias Braun committed
621
622
623
624
static const arch_code_generator_if_t *TEMPLATE_get_code_generator_if(
		void *self)
{
	(void) self;
625
626
627
628
629
630
631
632
	return &TEMPLATE_code_gen_if;
}

list_sched_selector_t TEMPLATE_sched_selector;

/**
 * Returns the reg_pressure scheduler with to_appear_in_schedule() overloaded
 */
Matthias Braun's avatar
Matthias Braun committed
633
634
635
636
static const list_sched_selector_t *TEMPLATE_get_list_sched_selector(
		const void *self, list_sched_selector_t *selector)
{
	(void) self;
Matthias Braun's avatar
Matthias Braun committed
637
638
	(void) selector;

639
	TEMPLATE_sched_selector = trivial_selector;
640
641
642
643
	TEMPLATE_sched_selector.to_appear_in_schedule = TEMPLATE_to_appear_in_schedule;
	return &TEMPLATE_sched_selector;
}

Matthias Braun's avatar
Matthias Braun committed
644
645
646
647
static const ilp_sched_selector_t *TEMPLATE_get_ilp_sched_selector(
		const void *self)
{
	(void) self;
Michael Beck's avatar
Michael Beck committed
648
649
650
	return NULL;
}

651
652
653
/**
 * Returns the necessary byte alignment for storing a register of given class.
 */
Matthias Braun's avatar
Matthias Braun committed
654
655
static int TEMPLATE_get_reg_class_alignment(const void *self,
                                            const arch_register_class_t *cls) {
656
	ir_mode *mode = arch_register_class_mode(cls);
Matthias Braun's avatar
Matthias Braun committed
657
	(void) self;
658
659
660
	return get_mode_size_bytes(mode);
}

661
662
663
/**
 * Returns the libFirm configuration parameter for this backend.
 */
664
static const backend_params *TEMPLATE_get_backend_params(void) {
665
	static backend_params p = {
666
667
		0,     /* no dword lowering */
		0,     /* no inline assembly */
668
669
670
671
		NULL,  /* no additional opcodes */
		NULL,  /* will be set later */
		NULL,  /* no creator function */
		NULL,  /* context for create_intrinsic_fkt */
Michael Beck's avatar
Michael Beck committed
672
		NULL,  /* parameter for if conversion */
673
674
675
676
	};
	return &p;
}

Matthias Braun's avatar
Matthias Braun committed
677
678
679
680
681
static const be_execution_unit_t ***TEMPLATE_get_allowed_execution_units(
		const void *self, const ir_node *irn)
{
	(void) self;
	(void) irn;
Michael Beck's avatar
Michael Beck committed
682
683
684
685
686
	/* TODO */
	assert(0);
	return NULL;
}

Matthias Braun's avatar
Matthias Braun committed
687
688
689
static const be_machine_t *TEMPLATE_get_machine(const void *self)
{
	(void) self;
Michael Beck's avatar
Michael Beck committed
690
691
692
693
694
	/* TODO */
	assert(0);
	return NULL;
}

Matthias Braun's avatar
Matthias Braun committed
695
696
697
698
699
static ir_graph **TEMPLATE_get_backend_irg_list(const void *self,
                                                ir_graph ***irgs)
{
	(void) self;
	(void) irgs;
700
701
702
	return NULL;
}

Michael Beck's avatar
Michael Beck committed
703

704
705
706
707
708
const arch_isa_if_t TEMPLATE_isa_if = {
	TEMPLATE_init,
	TEMPLATE_done,
	TEMPLATE_get_n_reg_class,
	TEMPLATE_get_reg_class,
Christian Würdig's avatar
Christian Würdig committed
709
710
	TEMPLATE_get_reg_class_for_mode,
	TEMPLATE_get_call_abi,
711
712
713
	TEMPLATE_get_irn_handler,
	TEMPLATE_get_code_generator_if,
	TEMPLATE_get_list_sched_selector,
Michael Beck's avatar
Michael Beck committed
714
	TEMPLATE_get_ilp_sched_selector,
715
	TEMPLATE_get_reg_class_alignment,
716
    TEMPLATE_get_backend_params,
Michael Beck's avatar
Michael Beck committed
717
	TEMPLATE_get_allowed_execution_units,
718
719
	TEMPLATE_get_machine,
	TEMPLATE_get_backend_irg_list
720
};
721
722
723
724
725
726
727

void be_init_arch_TEMPLATE(void)
{
	be_register_isa_if("TEMPLATE", &TEMPLATE_isa_if);
}

BE_REGISTER_MODULE_CONSTRUCTOR(be_init_arch_TEMPLATE);