-/*
- _____ _ _ _ _ _
- | ___| __ __ _ _ __ ___ ___ | | | | __ _ _ __ __| | (_)_ __ __ _
- | |_ | '__/ _` | '_ ` _ \ / _ \ | |_| |/ _` | '_ \ / _` | | | '_ \ / _` |
- | _|| | | (_| | | | | | | __/ | _ | (_| | | | | (_| | | | | | | (_| |
- |_| |_| \__,_|_| |_| |_|\___| |_| |_|\__,_|_| |_|\__,_|_|_|_| |_|\__, |
- |___/
-
- Handling of the stack frame. It is composed of three types:
- 1) The type of the arguments which are pushed on the stack.
- 2) The "between type" which consists of stuff the call of the
- function pushes on the stack (like the return address and
- the old base pointer for ia32).
- 3) The Firm frame type which consists of all local variables
- and the spills.
-*/
-
-static int get_stack_entity_offset(be_stack_layout_t *frame, ir_entity *ent,
- int bias)
-{
- ir_type *t = get_entity_owner(ent);
- int ofs = get_entity_offset(ent);
-
- int index;
-
- /* Find the type the entity is contained in. */
- for (index = 0; index < N_FRAME_TYPES; ++index) {
- if (frame->order[index] == t)
- break;
- /* Add the size of all the types below the one of the entity to the entity's offset */
- ofs += get_type_size_bytes(frame->order[index]);
- }
-
- /* correct the offset by the initial position of the frame pointer */
- ofs -= frame->initial_offset;
-
- /* correct the offset with the current bias. */
- ofs += bias;
-
- return ofs;
-}
-
-/**
- * Retrieve the entity with given offset from a frame type.
- */
-static ir_entity *search_ent_with_offset(ir_type *t, int offset)
-{
- int i, n;
-
- for (i = 0, n = get_compound_n_members(t); i < n; ++i) {
- ir_entity *ent = get_compound_member(t, i);
- if (get_entity_offset(ent) == offset)
- return ent;
- }
-
- return NULL;
-}
-
-static int stack_frame_compute_initial_offset(be_stack_layout_t *frame)
-{
- ir_type *base = frame->stack_dir < 0 ? frame->between_type : frame->frame_type;
- ir_entity *ent = search_ent_with_offset(base, 0);
-
- if (ent == NULL) {
- frame->initial_offset
- = frame->stack_dir < 0 ? get_type_size_bytes(frame->frame_type) : get_type_size_bytes(frame->between_type);
- } else {
- frame->initial_offset = get_stack_entity_offset(frame, ent, 0);
- }
-
- return frame->initial_offset;
-}
-