+/*
+ * Allocate an area of size bytes aligned at alignment
+ * at a frame type.
+ */
+static ir_entity *alloc_trampoline(ir_type *frame_type, int size, unsigned alignment) {
+ static unsigned area_cnt = 0;
+ char buf[32];
+
+ snprintf(buf, sizeof(buf), "trampolin%u", area_cnt++);
+ ident *name = new_id_from_str(buf);
+
+ ir_type *tp = new_type_array(id_mangle_u(get_type_ident(frame_type), name), 1, ir_type_char);
+ set_array_bounds_int(tp, 0, 0, size);
+ set_type_alignment_bytes(tp, alignment);
+
+ ir_entity *area = new_entity(frame_type, name, tp);
+
+ /* mark this entity as compiler generated */
+ set_entity_compiler_generated(area, 1);
+ return area;
+}
+
+/**
+ * Return a node representing a trampoline reagion
+ * for a given entity.
+ *
+ * @param dbgi debug info
+ * @param entity the entity
+ */
+static ir_node *get_trampoline_region(dbg_info *dbgi, ir_entity *entity)
+{
+ ir_entity *region = NULL;
+ int i;
+
+ if (current_trampolines != NULL) {
+ for (i = ARR_LEN(current_trampolines) - 1; i >= 0; --i) {
+ if (current_trampolines[i].function == entity) {
+ region = current_trampolines[i].region;
+ break;
+ }
+ }
+ } else {
+ current_trampolines = NEW_ARR_F(trampoline_region, 0);
+ }
+ ir_graph *irg = current_ir_graph;
+ if (region == NULL) {
+ /* create a new region */
+ ir_type *frame_tp = get_irg_frame_type(irg);
+ trampoline_region reg;
+ reg.function = entity;
+
+ reg.region = alloc_trampoline(frame_tp,
+ be_params->trampoline_size,
+ be_params->trampoline_align);
+ ARR_APP1(trampoline_region, current_trampolines, reg);
+ region = reg.region;
+ }
+ return new_d_simpleSel(dbgi, get_irg_no_mem(irg), get_irg_frame(irg),
+ region);
+}
+
+