#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "tm.h"
#include "tree.h"
#include "real.h"
#include "flags.h"
#include "toplev.h"
#include "rtl.h"
#include "expr.h"
#include "ggc.h"
#include "function.h"
#include "except.h"
#include "debug.h"
#include "output.h"
#include "tree-gimple.h"
#include "ada.h"
#include "types.h"
#include "atree.h"
#include "elists.h"
#include "namet.h"
#include "nlists.h"
#include "snames.h"
#include "stringt.h"
#include "uintp.h"
#include "urealp.h"
#include "fe.h"
#include "sinfo.h"
#include "einfo.h"
#include "ada-tree.h"
#include "gigi.h"
int max_gnat_nodes;
int number_names;
struct Node *Nodes_Ptr;
Node_Id *Next_Node_Ptr;
Node_Id *Prev_Node_Ptr;
struct Elist_Header *Elists_Ptr;
struct Elmt_Item *Elmts_Ptr;
struct String_Entry *Strings_Ptr;
Char_Code *String_Chars_Ptr;
struct List_Header *List_Headers_Ptr;
const char *ref_filename;
bool type_annotate_only;
struct stmt_group GTY((chain_next ("%h.previous"))) {
struct stmt_group *previous;
tree stmt_list;
tree block;
tree cleanups;
};
static GTY(()) struct stmt_group *current_stmt_group;
static GTY((deletable)) struct stmt_group *stmt_group_free_list;
struct elab_info GTY((chain_next ("%h.next"))) {
struct elab_info *next;
tree elab_proc;
int gnat_node;
};
static GTY(()) struct elab_info *elab_info_list;
static GTY((deletable)) tree gnu_stack_free_list;
static GTY(()) tree gnu_except_ptr_stack;
static GTY(()) tree gnu_elab_proc_stack;
static GTY(()) tree gnu_return_label_stack;
static GTY(()) tree gnu_loop_label_stack;
static GTY(()) tree gnu_switch_label_stack;
static enum tree_code gnu_codes[Number_Node_Kinds];
Node_Id error_gnat_node;
static void Compilation_Unit_to_gnu (Node_Id);
static void record_code_position (Node_Id);
static void insert_code_for (Node_Id);
static void start_stmt_group (void);
static void add_cleanup (tree);
static tree mark_visited (tree *, int *, void *);
static tree mark_unvisited (tree *, int *, void *);
static tree end_stmt_group (void);
static void add_stmt_list (List_Id);
static tree build_stmt_group (List_Id, bool);
static void push_stack (tree *, tree, tree);
static void pop_stack (tree *);
static enum gimplify_status gnat_gimplify_stmt (tree *);
static void elaborate_all_entities (Node_Id);
static void process_freeze_entity (Node_Id);
static void process_inlined_subprograms (Node_Id);
static void process_decls (List_Id, List_Id, Node_Id, bool, bool);
static tree emit_range_check (tree, Node_Id);
static tree emit_index_check (tree, tree, tree, tree);
static tree emit_check (tree, tree, int);
static tree convert_with_check (Entity_Id, tree, bool, bool, bool);
static bool addressable_p (tree);
static tree assoc_to_constructor (Node_Id, tree);
static tree extract_values (tree, tree);
static tree pos_to_constructor (Node_Id, tree, Entity_Id);
static tree maybe_implicit_deref (tree);
static tree gnat_stabilize_reference_1 (tree, bool);
static void annotate_with_node (tree, Node_Id);
void
gigi (Node_Id gnat_root, int max_gnat_node, int number_name,
struct Node *nodes_ptr, Node_Id *next_node_ptr, Node_Id *prev_node_ptr,
struct Elist_Header *elists_ptr, struct Elmt_Item *elmts_ptr,
struct String_Entry *strings_ptr, Char_Code *string_chars_ptr,
struct List_Header *list_headers_ptr, Int number_units ATTRIBUTE_UNUSED,
char *file_info_ptr ATTRIBUTE_UNUSED, Entity_Id standard_integer,
Entity_Id standard_long_long_float, Entity_Id standard_exception_type,
Int gigi_operating_mode)
{
tree gnu_standard_long_long_float;
tree gnu_standard_exception_type;
struct elab_info *info;
max_gnat_nodes = max_gnat_node;
number_names = number_name;
Nodes_Ptr = nodes_ptr;
Next_Node_Ptr = next_node_ptr;
Prev_Node_Ptr = prev_node_ptr;
Elists_Ptr = elists_ptr;
Elmts_Ptr = elmts_ptr;
Strings_Ptr = strings_ptr;
String_Chars_Ptr = string_chars_ptr;
List_Headers_Ptr = list_headers_ptr;
type_annotate_only = (gigi_operating_mode == 1);
init_gnat_to_gnu ();
gnat_compute_largest_alignment ();
init_dummy_type ();
if (type_annotate_only)
{
TYPE_SIZE (void_type_node) = bitsize_zero_node;
TYPE_SIZE_UNIT (void_type_node) = size_zero_node;
}
save_gnu_tree (Base_Type (standard_integer), TYPE_NAME (integer_type_node),
false);
gnu_except_ptr_stack = tree_cons (NULL_TREE, NULL_TREE, NULL_TREE);
gnu_standard_long_long_float
= gnat_to_gnu_entity (Base_Type (standard_long_long_float), NULL_TREE, 0);
gnu_standard_exception_type
= gnat_to_gnu_entity (Base_Type (standard_exception_type), NULL_TREE, 0);
init_gigi_decls (gnu_standard_long_long_float, gnu_standard_exception_type);
#ifdef ASM_OUTPUT_IDENT
if (Present (Ident_String (Main_Unit)))
ASM_OUTPUT_IDENT
(asm_out_file,
TREE_STRING_POINTER (gnat_to_gnu (Ident_String (Main_Unit))));
#endif
if (Exception_Mechanism == GCC_ZCX)
gnat_init_gcc_eh ();
gcc_assert (Nkind (gnat_root) == N_Compilation_Unit);
Compilation_Unit_to_gnu (gnat_root);
for (info = elab_info_list; info; info = info->next)
{
tree gnu_body = DECL_SAVED_TREE (info->elab_proc);
tree gnu_stmts;
walk_tree_without_duplicates (&gnu_body, mark_unvisited, NULL);
current_function_decl = info->elab_proc;
gimplify_body (&gnu_body, info->elab_proc, true);
gnu_stmts = gnu_body;
if (TREE_CODE (gnu_stmts) == BIND_EXPR)
gnu_stmts = BIND_EXPR_BODY (gnu_stmts);
if (!gnu_stmts || !STATEMENT_LIST_HEAD (gnu_stmts))
Set_Has_No_Elaboration_Code (info->gnat_node, 1);
else
{
begin_subprog_body (info->elab_proc);
end_subprog_body (gnu_body);
}
}
}
void
gnat_init_stmt_group ()
{
init_code_table ();
start_stmt_group ();
if (!Stack_Check_Probes_On_Target)
set_stack_check_libfunc (gen_rtx_SYMBOL_REF (Pmode, "_gnat_stack_check"));
gcc_assert (Exception_Mechanism != Front_End_ZCX);
}
static tree
Identifier_to_gnu (Node_Id gnat_node, tree *gnu_result_type_p)
{
tree gnu_result_type;
tree gnu_result;
Node_Id gnat_temp, gnat_temp_type;
gnat_temp = (Nkind (gnat_node) == N_Defining_Identifier
? gnat_node : Entity (gnat_node));
gnat_temp_type = Etype (gnat_temp);
gcc_assert (Etype (gnat_node) == gnat_temp_type
|| (Is_Packed (gnat_temp_type)
&& Etype (gnat_node) == Packed_Array_Type (gnat_temp_type))
|| (Is_Class_Wide_Type (Etype (gnat_node)))
|| (IN (Ekind (gnat_temp_type), Private_Kind)
&& Present (Full_View (gnat_temp_type))
&& ((Etype (gnat_node) == Full_View (gnat_temp_type))
|| (Is_Packed (Full_View (gnat_temp_type))
&& (Etype (gnat_node)
== Packed_Array_Type (Full_View
(gnat_temp_type))))))
|| (Is_Itype (Etype (gnat_node)) && Is_Itype (gnat_temp_type))
|| !(Ekind (gnat_temp) == E_Variable
|| Ekind (gnat_temp) == E_Component
|| Ekind (gnat_temp) == E_Constant
|| Ekind (gnat_temp) == E_Loop_Parameter
|| IN (Ekind (gnat_temp), Formal_Kind)));
if (Is_Private_Type (gnat_temp_type)
&& Has_Unknown_Discriminants (gnat_temp_type)
&& Present (Full_View (gnat_temp))
&& !Is_Type (gnat_temp))
{
gnat_temp = Full_View (gnat_temp);
gnat_temp_type = Etype (gnat_temp);
gnu_result_type = get_unpadded_type (gnat_temp_type);
}
else
{
if ((Ekind (gnat_temp) == E_Constant
|| Ekind (gnat_temp) == E_Variable || Is_Formal (gnat_temp))
&& !(Is_Array_Type (Etype (gnat_temp))
&& Present (Packed_Array_Type (Etype (gnat_temp))))
&& Present (Actual_Subtype (gnat_temp))
&& present_gnu_tree (Actual_Subtype (gnat_temp)))
gnat_temp_type = Actual_Subtype (gnat_temp);
else
gnat_temp_type = Etype (gnat_node);
gnu_result_type = get_unpadded_type (gnat_temp_type);
}
gnu_result = gnat_to_gnu_entity (gnat_temp, NULL_TREE, 0);
if (TREE_VALUE (gnu_except_ptr_stack)
&& TREE_CODE (gnu_result) == VAR_DECL)
TREE_THIS_VOLATILE (gnu_result) = TREE_SIDE_EFFECTS (gnu_result) = 1;
if (DECL_P (gnu_result)
&& (DECL_BY_REF_P (gnu_result)
|| (TREE_CODE (gnu_result) == PARM_DECL
&& DECL_BY_COMPONENT_PTR_P (gnu_result))))
{
bool ro = DECL_POINTS_TO_READONLY_P (gnu_result);
tree initial;
if (TREE_CODE (gnu_result) == PARM_DECL
&& DECL_BY_COMPONENT_PTR_P (gnu_result))
gnu_result
= build_unary_op (INDIRECT_REF, NULL_TREE,
convert (build_pointer_type (gnu_result_type),
gnu_result));
else if (TREE_READONLY (gnu_result)
&& DECL_INITIAL (gnu_result)
&& ((initial = TREE_CODE (DECL_INITIAL (gnu_result))
== NOP_EXPR
? TREE_OPERAND (DECL_INITIAL (gnu_result), 0)
: DECL_INITIAL (gnu_result), 1))
&& TREE_CODE (initial) == ADDR_EXPR
&& (TREE_CODE (TREE_OPERAND (initial, 0)) == ARRAY_REF
|| (TREE_CODE (TREE_OPERAND (initial, 0))
== COMPONENT_REF)))
gnu_result = TREE_OPERAND (initial, 0);
else
gnu_result = build_unary_op (INDIRECT_REF, NULL_TREE,
fold (gnu_result));
TREE_READONLY (gnu_result) = TREE_STATIC (gnu_result) = ro;
}
if (TREE_CODE (TREE_TYPE (gnu_result)) == FUNCTION_TYPE
|| Is_Constr_Subt_For_UN_Aliased (gnat_temp_type))
{
gnu_result_type = TREE_TYPE (gnu_result);
if (TREE_CODE (gnu_result_type) == RECORD_TYPE
&& TYPE_IS_PADDING_P (gnu_result_type))
gnu_result_type = TREE_TYPE (TYPE_FIELDS (gnu_result_type));
}
if (TREE_CODE (gnu_result) == CONST_DECL)
{
gnat_temp = Parent (gnat_node);
if (!DECL_CONST_CORRESPONDING_VAR (gnu_result)
|| (Nkind (gnat_temp) != N_Reference
&& !(Nkind (gnat_temp) == N_Attribute_Reference
&& ((Get_Attribute_Id (Attribute_Name (gnat_temp))
== Attr_Address)
|| (Get_Attribute_Id (Attribute_Name (gnat_temp))
== Attr_Access)
|| (Get_Attribute_Id (Attribute_Name (gnat_temp))
== Attr_Unchecked_Access)
|| (Get_Attribute_Id (Attribute_Name (gnat_temp))
== Attr_Unrestricted_Access)))))
gnu_result = DECL_INITIAL (gnu_result);
}
*gnu_result_type_p = gnu_result_type;
return gnu_result;
}
static tree
Pragma_to_gnu (Node_Id gnat_node)
{
Node_Id gnat_temp;
tree gnu_result = alloc_stmt_list ();
if (type_annotate_only || !Is_Pragma_Name (Chars (gnat_node)))
return gnu_result;
switch (Get_Pragma_Id (Chars (gnat_node)))
{
case Pragma_Inspection_Point:
if (global_bindings_p ())
break;
for (gnat_temp = First (Pragma_Argument_Associations (gnat_node));
Present (gnat_temp);
gnat_temp = Next (gnat_temp))
{
tree gnu_expr = gnat_to_gnu (Expression (gnat_temp));
if (TREE_CODE (gnu_expr) == UNCONSTRAINED_ARRAY_REF)
gnu_expr = TREE_OPERAND (gnu_expr, 0);
gnu_expr = build1 (USE_STMT, void_type_node, gnu_expr);
annotate_with_node (gnu_expr, gnat_node);
append_to_statement_list (gnu_expr, &gnu_result);
}
break;
case Pragma_Optimize:
switch (Chars (Expression
(First (Pragma_Argument_Associations (gnat_node)))))
{
case Name_Time: case Name_Space:
if (optimize == 0)
post_error ("insufficient -O value?", gnat_node);
break;
case Name_Off:
if (optimize != 0)
post_error ("must specify -O0?", gnat_node);
break;
default:
gcc_unreachable ();
}
break;
case Pragma_Reviewable:
if (write_symbols == NO_DEBUG)
post_error ("must specify -g?", gnat_node);
break;
}
return gnu_result;
}
static tree
Attribute_to_gnu (Node_Id gnat_node, tree *gnu_result_type_p, int attribute)
{
tree gnu_result = error_mark_node;
tree gnu_result_type;
tree gnu_expr;
bool prefix_unused = false;
tree gnu_prefix = gnat_to_gnu (Prefix (gnat_node));
tree gnu_type = TREE_TYPE (gnu_prefix);
if (TREE_CODE (gnu_prefix) == NULL_EXPR)
{
*gnu_result_type_p = get_unpadded_type (Etype (gnat_node));
return build1 (NULL_EXPR, *gnu_result_type_p,
TREE_OPERAND (gnu_prefix, 0));
}
switch (attribute)
{
case Attr_Pos:
case Attr_Val:
{
bool checkp = Do_Range_Check (First (Expressions (gnat_node)));
gnu_result = gnat_to_gnu (First (Expressions (gnat_node)));
gnu_result_type = get_unpadded_type (Etype (gnat_node));
gnu_result = convert_with_check (Etype (gnat_node), gnu_result,
checkp, checkp, true);
}
break;
case Attr_Pred:
case Attr_Succ:
gnu_expr = gnat_to_gnu (First (Expressions (gnat_node)));
gnu_result_type = get_unpadded_type (Etype (gnat_node));
if (Do_Range_Check (First (Expressions (gnat_node))))
{
gnu_expr = protect_multiple_eval (gnu_expr);
gnu_expr
= emit_check
(build_binary_op (EQ_EXPR, integer_type_node,
gnu_expr,
attribute == Attr_Pred
? TYPE_MIN_VALUE (gnu_result_type)
: TYPE_MAX_VALUE (gnu_result_type)),
gnu_expr, CE_Range_Check_Failed);
}
gnu_result
= build_binary_op (attribute == Attr_Pred
? MINUS_EXPR : PLUS_EXPR,
gnu_result_type, gnu_expr,
convert (gnu_result_type, integer_one_node));
break;
case Attr_Address:
case Attr_Unrestricted_Access:
gnu_prefix = remove_conversions (gnu_prefix,
!Must_Be_Byte_Aligned (gnat_node));
gnu_prefix = maybe_unconstrained_array (gnu_prefix);
case Attr_Access:
case Attr_Unchecked_Access:
case Attr_Code_Address:
gnu_result_type = get_unpadded_type (Etype (gnat_node));
gnu_result
= build_unary_op (((attribute == Attr_Address
|| attribute == Attr_Unrestricted_Access)
&& !Must_Be_Byte_Aligned (gnat_node))
? ATTR_ADDR_EXPR : ADDR_EXPR,
gnu_result_type, gnu_prefix);
if (attribute == Attr_Code_Address)
{
for (gnu_expr = gnu_result;
TREE_CODE (gnu_expr) == NOP_EXPR
|| TREE_CODE (gnu_expr) == CONVERT_EXPR;
gnu_expr = TREE_OPERAND (gnu_expr, 0))
TREE_CONSTANT (gnu_expr) = 1;
if (TREE_CODE (gnu_expr) == ADDR_EXPR)
TREE_STATIC (gnu_expr) = TREE_CONSTANT (gnu_expr) = 1;
}
break;
case Attr_Pool_Address:
{
tree gnu_obj_type;
tree gnu_ptr = gnu_prefix;
gnu_result_type = get_unpadded_type (Etype (gnat_node));
if (TYPE_FAT_POINTER_P (TREE_TYPE (gnu_ptr)))
gnu_ptr
= convert (build_pointer_type
(TYPE_OBJECT_RECORD_TYPE
(TYPE_UNCONSTRAINED_ARRAY (TREE_TYPE (gnu_ptr)))),
gnu_ptr);
gnu_obj_type = TREE_TYPE (TREE_TYPE (gnu_ptr));
if (TREE_CODE (gnu_obj_type) == RECORD_TYPE
&& TYPE_CONTAINS_TEMPLATE_P (gnu_obj_type))
{
tree gnu_char_ptr_type = build_pointer_type (char_type_node);
tree gnu_pos = byte_position (TYPE_FIELDS (gnu_obj_type));
tree gnu_byte_offset
= convert (gnu_char_ptr_type,
size_diffop (size_zero_node, gnu_pos));
gnu_ptr = convert (gnu_char_ptr_type, gnu_ptr);
gnu_ptr = build_binary_op (MINUS_EXPR, gnu_char_ptr_type,
gnu_ptr, gnu_byte_offset);
}
gnu_result = convert (gnu_result_type, gnu_ptr);
}
break;
case Attr_Size:
case Attr_Object_Size:
case Attr_Value_Size:
case Attr_Max_Size_In_Storage_Elements:
gnu_expr = gnu_prefix;
while (TREE_CODE (gnu_expr) == NOP_EXPR)
gnu_expr = TREE_OPERAND (gnu_expr, 0)
;
gnu_prefix = remove_conversions (gnu_prefix, true);
prefix_unused = true;
gnu_type = TREE_TYPE (gnu_prefix);
if (TREE_CODE (gnu_type) == UNCONSTRAINED_ARRAY_TYPE)
{
gnu_type = TYPE_OBJECT_RECORD_TYPE (gnu_type);
if (attribute != Attr_Max_Size_In_Storage_Elements)
gnu_type = TREE_TYPE (TREE_CHAIN (TYPE_FIELDS (gnu_type)));
}
if (TREE_CODE (gnu_prefix) == COMPONENT_REF)
gnu_result = DECL_SIZE (TREE_OPERAND (gnu_prefix, 1));
else if (TREE_CODE (gnu_prefix) != TYPE_DECL
|| attribute == Attr_Object_Size
|| attribute == Attr_Max_Size_In_Storage_Elements)
{
if (TREE_CODE (gnu_type) == RECORD_TYPE
&& TYPE_IS_PADDING_P (gnu_type)
&& TREE_CODE (gnu_expr) == COMPONENT_REF)
{
gnu_result = rm_size (gnu_type);
if (!(CONTAINS_PLACEHOLDER_P
(DECL_SIZE (TREE_OPERAND (gnu_expr, 1)))))
gnu_result
= size_binop (MAX_EXPR, gnu_result,
DECL_SIZE (TREE_OPERAND (gnu_expr, 1)));
}
else
gnu_result = TYPE_SIZE (gnu_type);
}
else
gnu_result = rm_size (gnu_type);
gcc_assert (gnu_result);
if (CONTAINS_PLACEHOLDER_P (gnu_result))
{
if (TREE_CODE (gnu_prefix) != TYPE_DECL)
gnu_result = substitute_placeholder_in_expr (gnu_result,
gnu_expr);
else
gnu_result = max_size (gnu_result, true);
}
if (TREE_CODE (gnu_type) == RECORD_TYPE
&& TYPE_CONTAINS_TEMPLATE_P (gnu_type))
gnu_result = size_binop (MINUS_EXPR, gnu_result,
DECL_SIZE (TYPE_FIELDS (gnu_type)));
gnu_result_type = get_unpadded_type (Etype (gnat_node));
if (attribute == Attr_Max_Size_In_Storage_Elements)
gnu_result = convert (sizetype,
fold (build2 (CEIL_DIV_EXPR, bitsizetype,
gnu_result, bitsize_unit_node)));
break;
case Attr_Alignment:
if (TREE_CODE (gnu_prefix) == COMPONENT_REF
&& (TREE_CODE (TREE_TYPE (TREE_OPERAND (gnu_prefix, 0)))
== RECORD_TYPE)
&& (TYPE_IS_PADDING_P (TREE_TYPE (TREE_OPERAND (gnu_prefix, 0)))))
gnu_prefix = TREE_OPERAND (gnu_prefix, 0);
gnu_type = TREE_TYPE (gnu_prefix);
gnu_result_type = get_unpadded_type (Etype (gnat_node));
prefix_unused = true;
if (TREE_CODE (gnu_prefix) == COMPONENT_REF)
gnu_result = size_int (DECL_ALIGN (TREE_OPERAND (gnu_prefix, 1)));
else
gnu_result = size_int (TYPE_ALIGN (gnu_type) / BITS_PER_UNIT);
break;
case Attr_First:
case Attr_Last:
case Attr_Range_Length:
prefix_unused = true;
if (INTEGRAL_TYPE_P (gnu_type) || TREE_CODE (gnu_type) == REAL_TYPE)
{
gnu_result_type = get_unpadded_type (Etype (gnat_node));
if (attribute == Attr_First)
gnu_result = TYPE_MIN_VALUE (gnu_type);
else if (attribute == Attr_Last)
gnu_result = TYPE_MAX_VALUE (gnu_type);
else
gnu_result
= build_binary_op
(MAX_EXPR, get_base_type (gnu_result_type),
build_binary_op
(PLUS_EXPR, get_base_type (gnu_result_type),
build_binary_op (MINUS_EXPR,
get_base_type (gnu_result_type),
convert (gnu_result_type,
TYPE_MAX_VALUE (gnu_type)),
convert (gnu_result_type,
TYPE_MIN_VALUE (gnu_type))),
convert (gnu_result_type, integer_one_node)),
convert (gnu_result_type, integer_zero_node));
break;
}
case Attr_Length:
{
int Dimension = (Present (Expressions (gnat_node))
? UI_To_Int (Intval (First (Expressions (gnat_node))))
: 1);
gnu_prefix = maybe_implicit_deref (gnu_prefix);
gnu_prefix = maybe_unconstrained_array (gnu_prefix);
gnu_type = TREE_TYPE (gnu_prefix);
prefix_unused = true;
gnu_result_type = get_unpadded_type (Etype (gnat_node));
if (TYPE_CONVENTION_FORTRAN_P (gnu_type))
{
int ndim;
tree gnu_type_temp;
for (ndim = 1, gnu_type_temp = gnu_type;
TREE_CODE (TREE_TYPE (gnu_type_temp)) == ARRAY_TYPE
&& TYPE_MULTI_ARRAY_P (TREE_TYPE (gnu_type_temp));
ndim++, gnu_type_temp = TREE_TYPE (gnu_type_temp))
;
Dimension = ndim + 1 - Dimension;
}
for (; Dimension > 1; Dimension--)
gnu_type = TREE_TYPE (gnu_type);
gcc_assert (TREE_CODE (gnu_type) == ARRAY_TYPE);
if (attribute == Attr_First)
gnu_result
= TYPE_MIN_VALUE (TYPE_INDEX_TYPE (TYPE_DOMAIN (gnu_type)));
else if (attribute == Attr_Last)
gnu_result
= TYPE_MAX_VALUE (TYPE_INDEX_TYPE (TYPE_DOMAIN (gnu_type)));
else
{
tree gnu_compute_type
= gnat_signed_or_unsigned_type (0,
get_base_type (gnu_result_type));
gnu_result
= build_binary_op
(MAX_EXPR, gnu_compute_type,
build_binary_op
(PLUS_EXPR, gnu_compute_type,
build_binary_op
(MINUS_EXPR, gnu_compute_type,
convert (gnu_compute_type,
TYPE_MAX_VALUE
(TYPE_INDEX_TYPE (TYPE_DOMAIN (gnu_type)))),
convert (gnu_compute_type,
TYPE_MIN_VALUE
(TYPE_INDEX_TYPE (TYPE_DOMAIN (gnu_type))))),
convert (gnu_compute_type, integer_one_node)),
convert (gnu_compute_type, integer_zero_node));
}
gnu_result = SUBSTITUTE_PLACEHOLDER_IN_EXPR (gnu_result,
gnu_prefix);
break;
}
case Attr_Bit_Position:
case Attr_Position:
case Attr_First_Bit:
case Attr_Last_Bit:
case Attr_Bit:
{
HOST_WIDE_INT bitsize;
HOST_WIDE_INT bitpos;
tree gnu_offset;
tree gnu_field_bitpos;
tree gnu_field_offset;
tree gnu_inner;
enum machine_mode mode;
int unsignedp, volatilep;
gnu_result_type = get_unpadded_type (Etype (gnat_node));
gnu_prefix = remove_conversions (gnu_prefix, true);
prefix_unused = true;
if (attribute == Attr_Bit
&& TREE_CODE (gnu_prefix) != COMPONENT_REF
&& TREE_CODE (gnu_prefix) != FIELD_DECL)
{
gnu_result = integer_zero_node;
break;
}
else
gcc_assert (TREE_CODE (gnu_prefix) == COMPONENT_REF
|| (attribute == Attr_Bit_Position
&& TREE_CODE (gnu_prefix) == FIELD_DECL));
get_inner_reference (gnu_prefix, &bitsize, &bitpos, &gnu_offset,
&mode, &unsignedp, &volatilep, false);
if (TREE_CODE (gnu_prefix) == COMPONENT_REF)
{
gnu_field_bitpos = bit_position (TREE_OPERAND (gnu_prefix, 1));
gnu_field_offset = byte_position (TREE_OPERAND (gnu_prefix, 1));
for (gnu_inner = TREE_OPERAND (gnu_prefix, 0);
TREE_CODE (gnu_inner) == COMPONENT_REF
&& DECL_INTERNAL_P (TREE_OPERAND (gnu_inner, 1));
gnu_inner = TREE_OPERAND (gnu_inner, 0))
{
gnu_field_bitpos
= size_binop (PLUS_EXPR, gnu_field_bitpos,
bit_position (TREE_OPERAND (gnu_inner, 1)));
gnu_field_offset
= size_binop (PLUS_EXPR, gnu_field_offset,
byte_position (TREE_OPERAND (gnu_inner, 1)));
}
}
else if (TREE_CODE (gnu_prefix) == FIELD_DECL)
{
gnu_field_bitpos = bit_position (gnu_prefix);
gnu_field_offset = byte_position (gnu_prefix);
}
else
{
gnu_field_bitpos = bitsize_zero_node;
gnu_field_offset = size_zero_node;
}
switch (attribute)
{
case Attr_Position:
gnu_result = gnu_field_offset;
break;
case Attr_First_Bit:
case Attr_Bit:
gnu_result = size_int (bitpos % BITS_PER_UNIT);
break;
case Attr_Last_Bit:
gnu_result = bitsize_int (bitpos % BITS_PER_UNIT);
gnu_result = size_binop (PLUS_EXPR, gnu_result,
TYPE_SIZE (TREE_TYPE (gnu_prefix)));
gnu_result = size_binop (MINUS_EXPR, gnu_result,
bitsize_one_node);
break;
case Attr_Bit_Position:
gnu_result = gnu_field_bitpos;
break;
}
gnu_result = SUBSTITUTE_PLACEHOLDER_IN_EXPR (gnu_result, gnu_prefix);
break;
}
case Attr_Min:
case Attr_Max:
{
tree gnu_lhs = gnat_to_gnu (First (Expressions (gnat_node)));
tree gnu_rhs = gnat_to_gnu (Next (First (Expressions (gnat_node))));
gnu_result_type = get_unpadded_type (Etype (gnat_node));
gnu_result = build_binary_op (attribute == Attr_Min
? MIN_EXPR : MAX_EXPR,
gnu_result_type, gnu_lhs, gnu_rhs);
}
break;
case Attr_Passed_By_Reference:
gnu_result = size_int (default_pass_by_ref (gnu_type)
|| must_pass_by_ref (gnu_type));
gnu_result_type = get_unpadded_type (Etype (gnat_node));
break;
case Attr_Component_Size:
if (TREE_CODE (gnu_prefix) == COMPONENT_REF
&& (TREE_CODE (TREE_TYPE (TREE_OPERAND (gnu_prefix, 0)))
== RECORD_TYPE)
&& (TYPE_IS_PADDING_P (TREE_TYPE (TREE_OPERAND (gnu_prefix, 0)))))
gnu_prefix = TREE_OPERAND (gnu_prefix, 0);
gnu_prefix = maybe_implicit_deref (gnu_prefix);
gnu_type = TREE_TYPE (gnu_prefix);
if (TREE_CODE (gnu_type) == UNCONSTRAINED_ARRAY_TYPE)
gnu_type = TREE_TYPE (TREE_TYPE (TYPE_FIELDS (TREE_TYPE (gnu_type))));
while (TREE_CODE (TREE_TYPE (gnu_type)) == ARRAY_TYPE
&& TYPE_MULTI_ARRAY_P (TREE_TYPE (gnu_type)))
gnu_type = TREE_TYPE (gnu_type);
gcc_assert (TREE_CODE (gnu_type) == ARRAY_TYPE);
gnu_result = TYPE_SIZE (TREE_TYPE (gnu_type));
gnu_result_type = get_unpadded_type (Etype (gnat_node));
prefix_unused = true;
break;
case Attr_Null_Parameter:
gnu_result_type = get_unpadded_type (Etype (gnat_node));
gnu_result
= build_unary_op (INDIRECT_REF, NULL_TREE,
convert (build_pointer_type (gnu_result_type),
integer_zero_node));
TREE_PRIVATE (gnu_result) = 1;
break;
case Attr_Mechanism_Code:
{
int code;
Entity_Id gnat_obj = Entity (Prefix (gnat_node));
prefix_unused = true;
gnu_result_type = get_unpadded_type (Etype (gnat_node));
if (Present (Expressions (gnat_node)))
{
int i = UI_To_Int (Intval (First (Expressions (gnat_node))));
for (gnat_obj = First_Formal (gnat_obj); i > 1;
i--, gnat_obj = Next_Formal (gnat_obj))
;
}
code = Mechanism (gnat_obj);
if (code == Default)
code = ((present_gnu_tree (gnat_obj)
&& (DECL_BY_REF_P (get_gnu_tree (gnat_obj))
|| ((TREE_CODE (get_gnu_tree (gnat_obj))
== PARM_DECL)
&& (DECL_BY_COMPONENT_PTR_P
(get_gnu_tree (gnat_obj))))))
? By_Reference : By_Copy);
gnu_result = convert (gnu_result_type, size_int (- code));
}
break;
default:
post_error ("unimplemented attribute", gnat_node);
gnu_result_type = get_unpadded_type (Etype (gnat_node));
gnu_result = integer_zero_node;
break;
}
if (prefix_unused && TREE_SIDE_EFFECTS (gnu_prefix)
&& !Is_Entity_Name (Prefix (gnat_node)))
gnu_result = fold (build2 (COMPOUND_EXPR, TREE_TYPE (gnu_result),
gnu_prefix, gnu_result));
*gnu_result_type_p = gnu_result_type;
return gnu_result;
}
static tree
Case_Statement_to_gnu (Node_Id gnat_node)
{
tree gnu_result;
tree gnu_expr;
Node_Id gnat_when;
gnu_expr = gnat_to_gnu (Expression (gnat_node));
gnu_expr = convert (get_base_type (TREE_TYPE (gnu_expr)), gnu_expr);
if (Paren_Count (Expression (gnat_node)) != 0
|| !Is_OK_Static_Subtype (Underlying_Type
(Etype (Expression (gnat_node)))))
gnu_expr = convert (get_base_type (TREE_TYPE (gnu_expr)), gnu_expr);
push_stack (&gnu_switch_label_stack, NULL_TREE, create_artificial_label ());
start_stmt_group ();
for (gnat_when = First_Non_Pragma (Alternatives (gnat_node));
Present (gnat_when);
gnat_when = Next_Non_Pragma (gnat_when))
{
Node_Id gnat_choice;
for (gnat_choice = First (Discrete_Choices (gnat_when));
Present (gnat_choice); gnat_choice = Next (gnat_choice))
{
tree gnu_low = NULL_TREE, gnu_high = NULL_TREE;
switch (Nkind (gnat_choice))
{
case N_Range:
gnu_low = gnat_to_gnu (Low_Bound (gnat_choice));
gnu_high = gnat_to_gnu (High_Bound (gnat_choice));
break;
case N_Subtype_Indication:
gnu_low = gnat_to_gnu (Low_Bound (Range_Expression
(Constraint (gnat_choice))));
gnu_high = gnat_to_gnu (High_Bound (Range_Expression
(Constraint (gnat_choice))));
break;
case N_Identifier:
case N_Expanded_Name:
if (IN (Ekind (Entity (gnat_choice)), Type_Kind))
{
tree gnu_type = get_unpadded_type (Entity (gnat_choice));
gnu_low = fold (TYPE_MIN_VALUE (gnu_type));
gnu_high = fold (TYPE_MAX_VALUE (gnu_type));
break;
}
case N_Character_Literal:
case N_Integer_Literal:
gnu_low = gnat_to_gnu (gnat_choice);
break;
case N_Others_Choice:
break;
default:
gcc_unreachable ();
}
add_stmt_with_node (build3 (CASE_LABEL_EXPR, void_type_node,
gnu_low, gnu_high,
create_artificial_label ()),
gnat_choice);
}
add_stmt (build_stmt_group (Statements (gnat_when), true));
add_stmt (build1 (GOTO_EXPR, void_type_node,
TREE_VALUE (gnu_switch_label_stack)));
}
add_stmt (build1 (LABEL_EXPR, void_type_node,
TREE_VALUE (gnu_switch_label_stack)));
gnu_result = build3 (SWITCH_EXPR, TREE_TYPE (gnu_expr), gnu_expr,
end_stmt_group (), NULL_TREE);
pop_stack (&gnu_switch_label_stack);
return gnu_result;
}
static tree
Loop_Statement_to_gnu (Node_Id gnat_node)
{
tree gnu_loop_stmt = build_nt (LOOP_STMT, NULL_TREE, NULL_TREE,
NULL_TREE, NULL_TREE, NULL_TREE);
tree gnu_loop_var = NULL_TREE;
Node_Id gnat_iter_scheme = Iteration_Scheme (gnat_node);
tree gnu_cond_expr = NULL_TREE;
tree gnu_result;
TREE_TYPE (gnu_loop_stmt) = void_type_node;
TREE_SIDE_EFFECTS (gnu_loop_stmt) = 1;
LOOP_STMT_LABEL (gnu_loop_stmt) = create_artificial_label ();
annotate_with_node (gnu_loop_stmt, gnat_node);
push_stack (&gnu_loop_label_stack, NULL_TREE,
LOOP_STMT_LABEL (gnu_loop_stmt));
if (No (gnat_iter_scheme))
;
else if (Present (Condition (gnat_iter_scheme)))
LOOP_STMT_TOP_COND (gnu_loop_stmt)
= gnat_to_gnu (Condition (gnat_iter_scheme));
else
{
Node_Id gnat_loop_spec = Loop_Parameter_Specification (gnat_iter_scheme);
Entity_Id gnat_loop_var = Defining_Entity (gnat_loop_spec);
Entity_Id gnat_type = Etype (gnat_loop_var);
tree gnu_type = get_unpadded_type (gnat_type);
tree gnu_low = TYPE_MIN_VALUE (gnu_type);
tree gnu_high = TYPE_MAX_VALUE (gnu_type);
bool reversep = Reverse_Present (gnat_loop_spec);
tree gnu_first = reversep ? gnu_high : gnu_low;
tree gnu_last = reversep ? gnu_low : gnu_high;
enum tree_code end_code = reversep ? GE_EXPR : LE_EXPR;
tree gnu_base_type = get_base_type (gnu_type);
tree gnu_limit = (reversep ? TYPE_MIN_VALUE (gnu_base_type)
: TYPE_MAX_VALUE (gnu_base_type));
if (TREE_CODE (gnu_last) != INTEGER_CST
|| TREE_CODE (gnu_limit) != INTEGER_CST
|| tree_int_cst_equal (gnu_last, gnu_limit))
{
gnu_cond_expr
= build3 (COND_EXPR, void_type_node,
build_binary_op (LE_EXPR, integer_type_node,
gnu_low, gnu_high),
NULL_TREE, alloc_stmt_list ());
annotate_with_node (gnu_cond_expr, gnat_loop_spec);
}
start_stmt_group ();
gnat_pushlevel ();
gnu_loop_var = gnat_to_gnu_entity (gnat_loop_var, gnu_first, 1);
if (DECL_BY_REF_P (gnu_loop_var))
gnu_loop_var = build_unary_op (INDIRECT_REF, NULL_TREE, gnu_loop_var);
gnu_loop_var = convert (get_base_type (gnu_type), gnu_loop_var);
if (gnu_cond_expr)
LOOP_STMT_BOT_COND (gnu_loop_stmt)
= build_binary_op (NE_EXPR, integer_type_node,
gnu_loop_var, gnu_last);
else
LOOP_STMT_TOP_COND (gnu_loop_stmt)
= build_binary_op (end_code, integer_type_node,
gnu_loop_var, gnu_last);
LOOP_STMT_UPDATE (gnu_loop_stmt)
= build_binary_op (reversep ? PREDECREMENT_EXPR
: PREINCREMENT_EXPR,
TREE_TYPE (gnu_loop_var),
gnu_loop_var,
convert (TREE_TYPE (gnu_loop_var),
integer_one_node));
annotate_with_node (LOOP_STMT_UPDATE (gnu_loop_stmt),
gnat_iter_scheme);
}
if (Present (Identifier (gnat_node)))
save_gnu_tree (Entity (Identifier (gnat_node)),
LOOP_STMT_LABEL (gnu_loop_stmt), true);
LOOP_STMT_BODY (gnu_loop_stmt)
= build_stmt_group (Statements (gnat_node), true);
if (gnu_loop_var)
{
add_stmt (gnu_loop_stmt);
gnat_poplevel ();
gnu_loop_stmt = end_stmt_group ();
}
if (gnu_cond_expr)
{
COND_EXPR_THEN (gnu_cond_expr) = gnu_loop_stmt;
gnu_result = gnu_cond_expr;
recalculate_side_effects (gnu_cond_expr);
}
else
gnu_result = gnu_loop_stmt;
pop_stack (&gnu_loop_label_stack);
return gnu_result;
}
static void
Subprogram_Body_to_gnu (Node_Id gnat_node)
{
enum debug_info_type save_write_symbols = write_symbols;
const struct gcc_debug_hooks *const save_debug_hooks = debug_hooks;
Entity_Id gnat_param;
Entity_Id gnat_subprog_id
= (Present (Corresponding_Spec (gnat_node))
? Corresponding_Spec (gnat_node) : Defining_Entity (gnat_node));
tree gnu_subprog_decl;
tree gnu_subprog_type;
tree gnu_cico_list;
tree gnu_result;
if (Ekind (gnat_subprog_id) == E_Generic_Procedure
|| Ekind (gnat_subprog_id) == E_Generic_Function
|| Is_Eliminated (gnat_subprog_id))
return;
if (!Needs_Debug_Info (gnat_subprog_id))
{
write_symbols = NO_DEBUG;
debug_hooks = &do_nothing_debug_hooks;
}
gnu_subprog_decl
= gnat_to_gnu_entity (gnat_subprog_id, NULL_TREE,
Acts_As_Spec (gnat_node)
&& !present_gnu_tree (gnat_subprog_id));
gnu_subprog_type = TREE_TYPE (gnu_subprog_decl);
Sloc_to_locus (Sloc (gnat_node), &DECL_SOURCE_LOCATION (gnu_subprog_decl));
begin_subprog_body (gnu_subprog_decl);
gnu_cico_list = TYPE_CI_CO_LIST (gnu_subprog_type);
push_stack (&gnu_return_label_stack, NULL_TREE,
gnu_cico_list ? create_artificial_label () : NULL_TREE);
start_stmt_group ();
gnat_pushlevel ();
for (gnat_param = First_Formal (gnat_subprog_id);
Present (gnat_param);
gnat_param = Next_Formal_With_Extras (gnat_param))
if (!present_gnu_tree (gnat_param))
{
for (; gnu_cico_list && TREE_VALUE (gnu_cico_list);
gnu_cico_list = TREE_CHAIN (gnu_cico_list))
;
TREE_VALUE (gnu_cico_list)
= convert (TREE_TYPE (TREE_PURPOSE (gnu_cico_list)),
gnat_to_gnu_entity (gnat_param, NULL_TREE, 1));
}
process_decls (Declarations (gnat_node), Empty, Empty, true, true);
add_stmt (gnat_to_gnu (Handled_Statement_Sequence (gnat_node)));
gnat_poplevel ();
gnu_result = end_stmt_group ();
if (TREE_VALUE (gnu_return_label_stack))
{
tree gnu_retval;
start_stmt_group ();
gnat_pushlevel ();
add_stmt (gnu_result);
add_stmt (build1 (LABEL_EXPR, void_type_node,
TREE_VALUE (gnu_return_label_stack)));
gnu_cico_list = TYPE_CI_CO_LIST (gnu_subprog_type);
if (list_length (gnu_cico_list) == 1)
gnu_retval = TREE_VALUE (gnu_cico_list);
else
gnu_retval = gnat_build_constructor (TREE_TYPE (gnu_subprog_type),
gnu_cico_list);
if (DECL_P (gnu_retval) && DECL_BY_REF_P (gnu_retval))
gnu_retval = build_unary_op (INDIRECT_REF, NULL_TREE, gnu_retval);
add_stmt_with_node
(build1 (RETURN_EXPR, void_type_node,
build2 (MODIFY_EXPR, TREE_TYPE (gnu_retval),
DECL_RESULT (current_function_decl), gnu_retval)),
gnat_node);
gnat_poplevel ();
gnu_result = end_stmt_group ();
}
pop_stack (&gnu_return_label_stack);
allocate_struct_function (current_function_decl);
Sloc_to_locus
((Present (End_Label (Handled_Statement_Sequence (gnat_node)))
? Sloc (End_Label (Handled_Statement_Sequence (gnat_node)))
: Sloc (gnat_node)),
&cfun->function_end_locus);
end_subprog_body (gnu_result);
for (gnat_param = First_Formal (gnat_subprog_id);
Present (gnat_param);
gnat_param = Next_Formal_With_Extras (gnat_param))
if (TREE_CODE (get_gnu_tree (gnat_param)) == VAR_DECL)
save_gnu_tree (gnat_param, NULL_TREE, false);
mark_out_of_scope (Defining_Unit_Name (Specification (gnat_node)));
write_symbols = save_write_symbols;
debug_hooks = save_debug_hooks;
}
static tree
call_to_gnu (Node_Id gnat_node, tree *gnu_result_type_p, tree gnu_target)
{
tree gnu_result;
tree gnu_subprog_node = gnat_to_gnu (Name (gnat_node));
tree gnu_subprog_type = TREE_TYPE (gnu_subprog_node);
tree gnu_subprog_addr = build_unary_op (ADDR_EXPR, NULL_TREE,
gnu_subprog_node);
Entity_Id gnat_formal;
Node_Id gnat_actual;
tree gnu_actual_list = NULL_TREE;
tree gnu_name_list = NULL_TREE;
tree gnu_before_list = NULL_TREE;
tree gnu_after_list = NULL_TREE;
tree gnu_subprog_call;
switch (Nkind (Name (gnat_node)))
{
case N_Identifier:
case N_Operator_Symbol:
case N_Expanded_Name:
case N_Attribute_Reference:
if (Is_Eliminated (Entity (Name (gnat_node))))
Eliminate_Error_Msg (gnat_node, Entity (Name (gnat_node)));
}
gcc_assert (TREE_CODE (gnu_subprog_type) == FUNCTION_TYPE);
if (TREE_CODE (gnu_subprog_node) == FUNCTION_DECL
&& DECL_STUBBED_P (gnu_subprog_node))
{
for (gnat_actual = First_Actual (gnat_node);
Present (gnat_actual);
gnat_actual = Next_Actual (gnat_actual))
add_stmt (gnat_to_gnu (gnat_actual));
if (Nkind (gnat_node) == N_Function_Call && !gnu_target)
{
*gnu_result_type_p = TREE_TYPE (gnu_subprog_type);
return build1 (NULL_EXPR, *gnu_result_type_p,
build_call_raise (PE_Stubbed_Subprogram_Called));
}
else
return build_call_raise (PE_Stubbed_Subprogram_Called);
}
if (TYPE_RETURNS_BY_TARGET_PTR_P (gnu_subprog_type))
{
tree gnu_real_ret_type
= TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (gnu_subprog_type)));
if (!gnu_target)
{
tree gnu_obj_type
= maybe_pad_type (gnu_real_ret_type,
max_size (TYPE_SIZE (gnu_real_ret_type), true),
0, Etype (Name (gnat_node)), "PAD", false,
false, false);
gnu_target = create_tmp_var_raw (gnu_obj_type, "LR");
gnat_pushdecl (gnu_target, gnat_node);
}
gnu_actual_list
= tree_cons (NULL_TREE,
build_unary_op (ADDR_EXPR, NULL_TREE,
unchecked_convert (gnu_real_ret_type,
gnu_target,
false)),
NULL_TREE);
}
if (Nkind (Name (gnat_node)) == N_Explicit_Dereference)
gnat_formal = First_Formal (Etype (Name (gnat_node)));
else if (Nkind (Name (gnat_node)) == N_Attribute_Reference)
gnat_formal = 0;
else
gnat_formal = First_Formal (Entity (Name (gnat_node)));
for (gnat_actual = First_Actual (gnat_node);
Present (gnat_actual);
gnat_formal = Next_Formal_With_Extras (gnat_formal),
gnat_actual = Next_Actual (gnat_actual))
{
tree gnu_formal
= (present_gnu_tree (gnat_formal)
? get_gnu_tree (gnat_formal) : NULL_TREE);
bool unchecked_convert_p
= (Nkind (gnat_actual) == N_Unchecked_Type_Conversion
|| (Nkind (gnat_actual) == N_Type_Conversion
&& Is_Composite_Type (Underlying_Type (Etype (gnat_formal)))));
Node_Id gnat_name = (unchecked_convert_p
? Expression (gnat_actual) : gnat_actual);
tree gnu_name = gnat_to_gnu (gnat_name);
tree gnu_name_type = gnat_to_gnu_type (Etype (gnat_name));
tree gnu_actual;
tree gnu_formal_type;
if (Ekind (gnat_formal) != E_In_Parameter)
{
gnu_name = gnat_stabilize_reference (gnu_name, true);
if (!addressable_p (gnu_name)
&& gnu_formal
&& (DECL_BY_REF_P (gnu_formal)
|| (TREE_CODE (gnu_formal) == PARM_DECL
&& (DECL_BY_COMPONENT_PTR_P (gnu_formal)
|| (DECL_BY_DESCRIPTOR_P (gnu_formal))))))
{
tree gnu_copy = gnu_name;
tree gnu_temp;
if (TREE_CODE (gnu_name) == COMPONENT_REF
&& ((TREE_CODE (TREE_TYPE (TREE_OPERAND (gnu_name, 0)))
== RECORD_TYPE)
&& (TYPE_IS_PADDING_P
(TREE_TYPE (TREE_OPERAND (gnu_name, 0))))))
gnu_name = gnu_copy = TREE_OPERAND (gnu_name, 0);
else if (TREE_CODE (gnu_name_type) == RECORD_TYPE
&& (TYPE_JUSTIFIED_MODULAR_P (gnu_name_type)))
gnu_name = convert (gnu_name_type, gnu_name);
gnu_actual = save_expr (gnu_name);
gnu_temp = skip_simple_arithmetic (gnu_actual);
if (TREE_CODE (gnu_temp) == SAVE_EXPR)
{
TREE_ADDRESSABLE (gnu_temp) = 1;
TREE_READONLY (gnu_temp) = 0;
}
gnu_temp = build2 (MODIFY_EXPR, TREE_TYPE (gnu_copy),
gnu_copy, gnu_actual);
annotate_with_node (gnu_temp, gnat_actual);
append_to_statement_list (gnu_temp, &gnu_after_list);
}
}
gnu_actual = gnu_name;
if (Ekind (gnat_formal) != E_Out_Parameter
&& TREE_CODE (TREE_TYPE (gnu_actual)) == RECORD_TYPE
&& TYPE_IS_PADDING_P (TREE_TYPE (gnu_actual)))
gnu_actual = convert (get_unpadded_type (Etype (gnat_actual)),
gnu_actual);
if (Ekind (gnat_formal) != E_In_Parameter
&& TREE_CODE (gnu_name) == CONSTRUCTOR
&& TREE_CODE (TREE_TYPE (gnu_name)) == RECORD_TYPE
&& TYPE_JUSTIFIED_MODULAR_P (TREE_TYPE (gnu_name)))
gnu_name = convert (TREE_TYPE (TYPE_FIELDS (TREE_TYPE (gnu_name))),
gnu_name);
if (Ekind (gnat_formal) != E_Out_Parameter
&& !unchecked_convert_p
&& Do_Range_Check (gnat_actual))
gnu_actual = emit_range_check (gnu_actual, Etype (gnat_formal));
if (unchecked_convert_p)
{
gnu_actual
= unchecked_convert (gnat_to_gnu_type (Etype (gnat_actual)),
gnu_actual,
(Nkind (gnat_actual)
== N_Unchecked_Type_Conversion)
&& No_Truncation (gnat_actual));
if (Ekind (gnat_formal) != E_Out_Parameter
&& Do_Range_Check (gnat_actual))
gnu_actual = emit_range_check (gnu_actual,
Etype (gnat_formal));
}
else if (TREE_CODE (gnu_actual) != SAVE_EXPR)
gnu_actual = convert (gnat_to_gnu_type (Etype (gnat_actual)),
gnu_actual);
if (gnu_formal
&& TREE_CODE (gnu_formal) == PARM_DECL && DECL_BY_REF_P (gnu_formal))
{
if (Ekind (gnat_formal) != E_In_Parameter)
{
gnu_actual = gnu_name;
if (TREE_CODE (TREE_TYPE (gnu_actual)) == RECORD_TYPE
&& TYPE_IS_PADDING_P (TREE_TYPE (gnu_actual))
&& TREE_CODE (gnu_actual) != SAVE_EXPR)
gnu_actual = convert (get_unpadded_type (Etype (gnat_actual)),
gnu_actual);
if (TREE_CODE (TREE_TYPE (gnu_actual)) == RECORD_TYPE
&& TYPE_CONTAINS_TEMPLATE_P (TREE_TYPE (gnu_actual))
&& TREE_CODE (gnu_actual) != SAVE_EXPR
&& Is_Constr_Subt_For_UN_Aliased (Etype (gnat_actual))
&& Is_Array_Type (Etype (gnat_actual)))
gnu_actual = convert (gnat_to_gnu_type (Etype (gnat_actual)),
gnu_actual);
}
if (TREE_CODE (gnu_actual) == COMPONENT_REF
&& !TREE_CONSTANT (TYPE_SIZE (TREE_TYPE (gnu_actual)))
&& (TREE_CODE (TREE_TYPE (TREE_OPERAND (gnu_actual, 0)))
== RECORD_TYPE)
&& TYPE_IS_PADDING_P (TREE_TYPE
(TREE_OPERAND (gnu_actual, 0)))
&& !addressable_p (gnu_actual))
gnu_actual = TREE_OPERAND (gnu_actual, 0);
gnu_formal_type = TREE_TYPE (get_gnu_tree (gnat_formal));
gnu_actual = build_unary_op (ADDR_EXPR, gnu_formal_type, gnu_actual);
}
else if (gnu_formal && TREE_CODE (gnu_formal) == PARM_DECL
&& DECL_BY_COMPONENT_PTR_P (gnu_formal))
{
gnu_formal_type = TREE_TYPE (get_gnu_tree (gnat_formal));
gnu_actual = maybe_implicit_deref (gnu_actual);
gnu_actual = maybe_unconstrained_array (gnu_actual);
if (TREE_CODE (gnu_formal_type) == RECORD_TYPE
&& TYPE_IS_PADDING_P (gnu_formal_type))
{
gnu_formal_type = TREE_TYPE (TYPE_FIELDS (gnu_formal_type));
gnu_actual = convert (gnu_formal_type, gnu_actual);
}
gnu_actual = convert (gnu_formal_type,
build_unary_op (ADDR_EXPR, NULL_TREE,
gnu_actual));
}
else if (gnu_formal && TREE_CODE (gnu_formal) == PARM_DECL
&& DECL_BY_DESCRIPTOR_P (gnu_formal))
{
if ((TREE_CODE (gnu_actual) == INDIRECT_REF
|| TREE_CODE (gnu_actual) == UNCONSTRAINED_ARRAY_REF)
&& TREE_PRIVATE (gnu_actual))
gnu_actual = convert (DECL_ARG_TYPE (get_gnu_tree (gnat_formal)),
integer_zero_node);
else
gnu_actual = build_unary_op (ADDR_EXPR, NULL_TREE,
fill_vms_descriptor (gnu_actual,
gnat_formal));
}
else
{
tree gnu_actual_size = TYPE_SIZE (TREE_TYPE (gnu_actual));
if (Ekind (gnat_formal) != E_In_Parameter)
gnu_name_list = tree_cons (NULL_TREE, gnu_name, gnu_name_list);
if (!gnu_formal || TREE_CODE (gnu_formal) != PARM_DECL)
continue;
else if (TREE_CODE (gnu_actual) == INDIRECT_REF
&& TREE_PRIVATE (gnu_actual)
&& host_integerp (gnu_actual_size, 1)
&& 0 >= compare_tree_int (gnu_actual_size,
BITS_PER_WORD))
gnu_actual
= unchecked_convert (DECL_ARG_TYPE (gnu_formal),
convert (gnat_type_for_size
(tree_low_cst (gnu_actual_size, 1),
1),
integer_zero_node),
false);
else
gnu_actual = convert (DECL_ARG_TYPE (gnu_formal), gnu_actual);
}
gnu_actual_list = tree_cons (NULL_TREE, gnu_actual, gnu_actual_list);
}
gnu_subprog_call = build3 (CALL_EXPR, TREE_TYPE (gnu_subprog_type),
gnu_subprog_addr, nreverse (gnu_actual_list),
NULL_TREE);
if (TYPE_RETURNS_BY_TARGET_PTR_P (gnu_subprog_type))
{
add_stmt_with_node (gnu_subprog_call, gnat_node);
*gnu_result_type_p
= TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (gnu_subprog_type)));
return unchecked_convert (*gnu_result_type_p, gnu_target, false);
}
else if (Nkind (gnat_node) == N_Function_Call)
{
gnu_result = gnu_subprog_call;
if (TYPE_RETURNS_UNCONSTRAINED_P (gnu_subprog_type)
|| TYPE_RETURNS_BY_REF_P (gnu_subprog_type))
gnu_result = build_unary_op (INDIRECT_REF, NULL_TREE, gnu_result);
if (gnu_target)
gnu_result = build_binary_op (MODIFY_EXPR, NULL_TREE,
gnu_target, gnu_result);
else
*gnu_result_type_p = get_unpadded_type (Etype (gnat_node));
return gnu_result;
}
else if (TYPE_CI_CO_LIST (gnu_subprog_type) != NULL_TREE)
{
tree scalar_return_list = TYPE_CI_CO_LIST (gnu_subprog_type);
int length = list_length (scalar_return_list);
if (length > 1)
{
tree gnu_name;
gnu_subprog_call = save_expr (gnu_subprog_call);
gnu_name_list = nreverse (gnu_name_list);
for (gnu_name = gnu_name_list; gnu_name;
gnu_name = TREE_CHAIN (gnu_name))
if (TREE_SIDE_EFFECTS (TREE_VALUE (gnu_name)))
append_to_statement_list (TREE_VALUE (gnu_name),
&gnu_before_list);
}
if (Nkind (Name (gnat_node)) == N_Explicit_Dereference)
gnat_formal = First_Formal (Etype (Name (gnat_node)));
else
gnat_formal = First_Formal (Entity (Name (gnat_node)));
for (gnat_actual = First_Actual (gnat_node);
Present (gnat_actual);
gnat_formal = Next_Formal_With_Extras (gnat_formal),
gnat_actual = Next_Actual (gnat_actual))
if (!(present_gnu_tree (gnat_formal)
&& TREE_CODE (get_gnu_tree (gnat_formal)) == PARM_DECL
&& (DECL_BY_REF_P (get_gnu_tree (gnat_formal))
|| (TREE_CODE (get_gnu_tree (gnat_formal)) == PARM_DECL
&& ((DECL_BY_COMPONENT_PTR_P (get_gnu_tree (gnat_formal))
|| (DECL_BY_DESCRIPTOR_P
(get_gnu_tree (gnat_formal))))))))
&& Ekind (gnat_formal) != E_In_Parameter)
{
tree gnu_result
= length == 1 ? gnu_subprog_call
: build_component_ref (gnu_subprog_call, NULL_TREE,
TREE_PURPOSE (scalar_return_list),
false);
bool unchecked_conversion = (Nkind (gnat_actual)
== N_Unchecked_Type_Conversion);
tree gnu_actual
= maybe_unconstrained_array (TREE_VALUE (gnu_name_list));
if (TREE_CODE (TREE_TYPE (gnu_result)) == RECORD_TYPE
&& TYPE_IS_PADDING_P (TREE_TYPE (gnu_result)))
gnu_result = convert (TREE_TYPE (TYPE_FIELDS
(TREE_TYPE (gnu_result))),
gnu_result);
if (Nkind (gnat_actual) == N_Type_Conversion)
gnu_result
= convert_with_check
(Etype (Expression (gnat_actual)), gnu_result,
Do_Overflow_Check (gnat_actual),
Do_Range_Check (Expression (gnat_actual)),
Float_Truncate (gnat_actual));
else if (unchecked_conversion)
gnu_result = unchecked_convert (TREE_TYPE (gnu_actual),
gnu_result,
No_Truncation (gnat_actual));
else
{
if (Do_Range_Check (gnat_actual))
gnu_result = emit_range_check (gnu_result,
Etype (gnat_actual));
if (!(!TREE_CONSTANT (TYPE_SIZE (TREE_TYPE (gnu_actual)))
&& TREE_CONSTANT (TYPE_SIZE (TREE_TYPE (gnu_result)))))
gnu_result = convert (TREE_TYPE (gnu_actual), gnu_result);
}
gnu_result = build_binary_op (MODIFY_EXPR, NULL_TREE,
gnu_actual, gnu_result);
annotate_with_node (gnu_result, gnat_actual);
append_to_statement_list (gnu_result, &gnu_before_list);
scalar_return_list = TREE_CHAIN (scalar_return_list);
gnu_name_list = TREE_CHAIN (gnu_name_list);
}
}
else
{
annotate_with_node (gnu_subprog_call, gnat_node);
append_to_statement_list (gnu_subprog_call, &gnu_before_list);
}
append_to_statement_list (gnu_after_list, &gnu_before_list);
return gnu_before_list;
}
static tree
Handled_Sequence_Of_Statements_to_gnu (Node_Id gnat_node)
{
tree gnu_jmpsave_decl = NULL_TREE;
tree gnu_jmpbuf_decl = NULL_TREE;
bool gcc_zcx = (!type_annotate_only
&& Present (Exception_Handlers (gnat_node))
&& Exception_Mechanism == GCC_ZCX);
bool setjmp_longjmp
= (!type_annotate_only && Present (Exception_Handlers (gnat_node))
&& Exception_Mechanism == Setjmp_Longjmp);
bool at_end = !type_annotate_only && Present (At_End_Proc (gnat_node));
bool binding_for_block = (at_end || gcc_zcx || setjmp_longjmp);
tree gnu_inner_block;
tree gnu_result;
tree gnu_expr;
Node_Id gnat_temp;
if (binding_for_block)
{
start_stmt_group ();
gnat_pushlevel ();
}
if (at_end)
add_cleanup (build_call_0_expr (gnat_to_gnu (At_End_Proc (gnat_node))));
if (setjmp_longjmp)
{
gnu_jmpsave_decl = create_var_decl (get_identifier ("JMPBUF_SAVE"),
NULL_TREE, jmpbuf_ptr_type,
build_call_0_expr (get_jmpbuf_decl),
false, false, false, false, NULL,
gnat_node);
gnu_jmpbuf_decl = create_var_decl (get_identifier ("JMP_BUF"),
NULL_TREE, jmpbuf_type,
NULL_TREE, false, false, false, false,
NULL, gnat_node);
set_block_jmpbuf_decl (gnu_jmpbuf_decl);
add_cleanup (build_call_1_expr (set_jmpbuf_decl, gnu_jmpsave_decl));
}
start_stmt_group ();
if (setjmp_longjmp)
add_stmt (build_call_1_expr (set_jmpbuf_decl,
build_unary_op (ADDR_EXPR, NULL_TREE,
gnu_jmpbuf_decl)));
if (Present (First_Real_Statement (gnat_node)))
process_decls (Statements (gnat_node), Empty,
First_Real_Statement (gnat_node), true, true);
for (gnat_temp = (Present (First_Real_Statement (gnat_node))
? First_Real_Statement (gnat_node)
: First (Statements (gnat_node)));
Present (gnat_temp); gnat_temp = Next (gnat_temp))
add_stmt (gnat_to_gnu (gnat_temp));
gnu_inner_block = end_stmt_group ();
if (setjmp_longjmp)
{
tree *gnu_else_ptr = 0;
tree gnu_handler;
start_stmt_group ();
gnat_pushlevel ();
push_stack (&gnu_except_ptr_stack, NULL_TREE,
create_var_decl (get_identifier ("EXCEPT_PTR"),
NULL_TREE,
build_pointer_type (except_type_node),
build_call_0_expr (get_excptr_decl), false,
false, false, false, NULL, gnat_node));
for (gnat_temp = First_Non_Pragma (Exception_Handlers (gnat_node));
Present (gnat_temp); gnat_temp = Next_Non_Pragma (gnat_temp))
{
gnu_expr = gnat_to_gnu (gnat_temp);
if (!gnu_else_ptr)
add_stmt (gnu_expr);
else
*gnu_else_ptr = gnu_expr;
gnu_else_ptr = &COND_EXPR_ELSE (gnu_expr);
}
gnu_expr = build_call_1_expr (raise_nodefer_decl,
TREE_VALUE (gnu_except_ptr_stack));
annotate_with_node (gnu_expr, gnat_node);
if (gnu_else_ptr)
*gnu_else_ptr = gnu_expr;
else
add_stmt (gnu_expr);
pop_stack (&gnu_except_ptr_stack);
gnat_poplevel ();
gnu_handler = end_stmt_group ();
start_stmt_group ();
add_stmt_with_node (build_call_1_expr (set_jmpbuf_decl,
gnu_jmpsave_decl),
gnat_node);
add_stmt (gnu_handler);
gnu_handler = end_stmt_group ();
gnu_result = build3 (COND_EXPR, void_type_node,
(build_call_1_expr
(setjmp_decl,
build_unary_op (ADDR_EXPR, NULL_TREE,
gnu_jmpbuf_decl))),
gnu_handler, gnu_inner_block);
}
else if (gcc_zcx)
{
tree gnu_handlers;
start_stmt_group ();
for (gnat_temp = First_Non_Pragma (Exception_Handlers (gnat_node));
Present (gnat_temp);
gnat_temp = Next_Non_Pragma (gnat_temp))
add_stmt (gnat_to_gnu (gnat_temp));
gnu_handlers = end_stmt_group ();
gnu_result = build2 (TRY_CATCH_EXPR, void_type_node,
gnu_inner_block, gnu_handlers);
}
else
gnu_result = gnu_inner_block;
if (binding_for_block)
{
add_stmt (gnu_result);
gnat_poplevel ();
gnu_result = end_stmt_group ();
}
return gnu_result;
}
static tree
Exception_Handler_to_gnu_sjlj (Node_Id gnat_node)
{
tree gnu_choice = integer_zero_node;
tree gnu_body = build_stmt_group (Statements (gnat_node), false);
Node_Id gnat_temp;
for (gnat_temp = First (Exception_Choices (gnat_node));
gnat_temp; gnat_temp = Next (gnat_temp))
{
tree this_choice;
if (Nkind (gnat_temp) == N_Others_Choice)
{
if (All_Others (gnat_temp))
this_choice = integer_one_node;
else
this_choice
= build_binary_op
(EQ_EXPR, integer_type_node,
convert
(integer_type_node,
build_component_ref
(build_unary_op
(INDIRECT_REF, NULL_TREE,
TREE_VALUE (gnu_except_ptr_stack)),
get_identifier ("not_handled_by_others"), NULL_TREE,
false)),
integer_zero_node);
}
else if (Nkind (gnat_temp) == N_Identifier
|| Nkind (gnat_temp) == N_Expanded_Name)
{
Entity_Id gnat_ex_id = Entity (gnat_temp);
tree gnu_expr;
if (Present (Renamed_Object (gnat_ex_id)))
gnat_ex_id = Renamed_Object (gnat_ex_id);
gnu_expr = gnat_to_gnu_entity (gnat_ex_id, NULL_TREE, 0);
this_choice
= build_binary_op
(EQ_EXPR, integer_type_node, TREE_VALUE (gnu_except_ptr_stack),
convert (TREE_TYPE (TREE_VALUE (gnu_except_ptr_stack)),
build_unary_op (ADDR_EXPR, NULL_TREE, gnu_expr)));
if (Is_Non_Ada_Error (Entity (gnat_temp)))
{
tree gnu_comp
= build_component_ref
(build_unary_op (INDIRECT_REF, NULL_TREE,
TREE_VALUE (gnu_except_ptr_stack)),
get_identifier ("lang"), NULL_TREE, false);
this_choice
= build_binary_op
(TRUTH_ORIF_EXPR, integer_type_node,
build_binary_op (EQ_EXPR, integer_type_node, gnu_comp,
build_int_cst (TREE_TYPE (gnu_comp), 'V')),
this_choice);
}
}
else
gcc_unreachable ();
gnu_choice = build_binary_op (TRUTH_ORIF_EXPR, integer_type_node,
gnu_choice, this_choice);
}
return build3 (COND_EXPR, void_type_node, gnu_choice, gnu_body, NULL_TREE);
}
static tree
Exception_Handler_to_gnu_zcx (Node_Id gnat_node)
{
tree gnu_etypes_list = NULL_TREE;
tree gnu_expr;
tree gnu_etype;
tree gnu_current_exc_ptr;
tree gnu_incoming_exc_ptr;
Node_Id gnat_temp;
for (gnat_temp = First (Exception_Choices (gnat_node));
gnat_temp; gnat_temp = Next (gnat_temp))
{
if (Nkind (gnat_temp) == N_Others_Choice)
{
tree gnu_expr
= All_Others (gnat_temp) ? all_others_decl : others_decl;
gnu_etype
= build_unary_op (ADDR_EXPR, NULL_TREE, gnu_expr);
}
else if (Nkind (gnat_temp) == N_Identifier
|| Nkind (gnat_temp) == N_Expanded_Name)
{
Entity_Id gnat_ex_id = Entity (gnat_temp);
if (Present (Renamed_Object (gnat_ex_id)))
gnat_ex_id = Renamed_Object (gnat_ex_id);
gnu_expr = gnat_to_gnu_entity (gnat_ex_id, NULL_TREE, 0);
gnu_etype = build_unary_op (ADDR_EXPR, NULL_TREE, gnu_expr);
}
else
gcc_unreachable ();
gnu_etypes_list = tree_cons (NULL_TREE, gnu_etype, gnu_etypes_list);
}
start_stmt_group ();
gnat_pushlevel ();
gnu_current_exc_ptr = build0 (EXC_PTR_EXPR, ptr_type_node);
gnu_incoming_exc_ptr = create_var_decl (get_identifier ("EXPTR"), NULL_TREE,
ptr_type_node, gnu_current_exc_ptr,
false, false, false, false, NULL,
gnat_node);
add_stmt_with_node (build_call_1_expr (begin_handler_decl,
gnu_incoming_exc_ptr),
gnat_node);
add_cleanup (build_call_1_expr (end_handler_decl, gnu_incoming_exc_ptr));
add_stmt_list (Statements (gnat_node));
gnat_poplevel ();
return build2 (CATCH_EXPR, void_type_node, gnu_etypes_list,
end_stmt_group ());
}
static void
Compilation_Unit_to_gnu (Node_Id gnat_node)
{
bool body_p = (Defining_Entity (Unit (gnat_node)),
Nkind (Unit (gnat_node)) == N_Package_Body
|| Nkind (Unit (gnat_node)) == N_Subprogram_Body);
Entity_Id gnat_unit_entity = Defining_Entity (Unit (gnat_node));
tree gnu_elab_proc_decl
= create_subprog_decl
(create_concat_name (gnat_unit_entity,
body_p ? "elabb" : "elabs"),
NULL_TREE, void_ftype, NULL_TREE, false, true, false, NULL,
gnat_unit_entity);
struct elab_info *info;
push_stack (&gnu_elab_proc_stack, NULL_TREE, gnu_elab_proc_decl);
DECL_ELABORATION_PROC_P (gnu_elab_proc_decl) = 1;
allocate_struct_function (gnu_elab_proc_decl);
Sloc_to_locus (Sloc (gnat_unit_entity), &cfun->function_end_locus);
cfun = 0;
if (Nkind (Unit (gnat_node)) == N_Package_Body
|| (Nkind (Unit (gnat_node)) == N_Subprogram_Body
&& !Acts_As_Spec (gnat_node)))
add_stmt (gnat_to_gnu (Library_Unit (gnat_node)));
process_inlined_subprograms (gnat_node);
if (type_annotate_only)
{
elaborate_all_entities (gnat_node);
if (Nkind (Unit (gnat_node)) == N_Subprogram_Declaration
|| Nkind (Unit (gnat_node)) == N_Generic_Package_Declaration
|| Nkind (Unit (gnat_node)) == N_Generic_Subprogram_Declaration)
return;
}
process_decls (Declarations (Aux_Decls_Node (gnat_node)), Empty, Empty,
true, true);
add_stmt (gnat_to_gnu (Unit (gnat_node)));
add_stmt_list (Pragmas_After (Aux_Decls_Node (gnat_node)));
add_stmt_list (Actions (Aux_Decls_Node (gnat_node)));
info = (struct elab_info *) ggc_alloc (sizeof (struct elab_info));
set_current_block_context (gnu_elab_proc_decl);
gnat_poplevel ();
DECL_SAVED_TREE (gnu_elab_proc_decl) = end_stmt_group ();
info->next = elab_info_list;
info->elab_proc = gnu_elab_proc_decl;
info->gnat_node = gnat_node;
elab_info_list = info;
pop_stack (&gnu_elab_proc_stack);
}
tree
gnat_to_gnu (Node_Id gnat_node)
{
bool went_into_elab_proc = false;
tree gnu_result = error_mark_node;
tree gnu_result_type = void_type_node;
tree gnu_expr;
tree gnu_lhs, gnu_rhs;
Node_Id gnat_temp;
error_gnat_node = gnat_node;
Sloc_to_locus (Sloc (gnat_node), &input_location);
if (type_annotate_only
&& IN (Nkind (gnat_node), N_Statement_Other_Than_Procedure_Call))
return alloc_stmt_list ();
if (type_annotate_only
&& IN (Nkind (gnat_node), N_Subexpr)
&& Nkind (gnat_node) != N_Identifier
&& !Compile_Time_Known_Value (gnat_node))
return build1 (NULL_EXPR, get_unpadded_type (Etype (gnat_node)),
build_call_raise (CE_Range_Check_Failed));
if (!current_function_decl
&& ((IN (Nkind (gnat_node), N_Statement_Other_Than_Procedure_Call)
&& Nkind (gnat_node) != N_Null_Statement)
|| Nkind (gnat_node) == N_Procedure_Call_Statement
|| Nkind (gnat_node) == N_Label
|| Nkind (gnat_node) == N_Implicit_Label_Declaration
|| Nkind (gnat_node) == N_Handled_Sequence_Of_Statements
|| ((Nkind (gnat_node) == N_Raise_Constraint_Error
|| Nkind (gnat_node) == N_Raise_Storage_Error
|| Nkind (gnat_node) == N_Raise_Program_Error)
&& (Ekind (Etype (gnat_node)) == E_Void))))
{
current_function_decl = TREE_VALUE (gnu_elab_proc_stack);
start_stmt_group ();
gnat_pushlevel ();
went_into_elab_proc = true;
}
switch (Nkind (gnat_node))
{
case N_Identifier:
case N_Expanded_Name:
case N_Operator_Symbol:
case N_Defining_Identifier:
gnu_result = Identifier_to_gnu (gnat_node, &gnu_result_type);
break;
case N_Integer_Literal:
{
tree gnu_type;
gnu_type = gnu_result_type = get_unpadded_type (Etype (gnat_node));
if (TREE_CODE (gnu_type) == RECORD_TYPE
&& TYPE_JUSTIFIED_MODULAR_P (gnu_type))
gnu_type = TREE_TYPE (TYPE_FIELDS (gnu_type));
gnu_result = UI_To_gnu (Intval (gnat_node), gnu_type);
gcc_assert (!TREE_CONSTANT_OVERFLOW (gnu_result));
}
break;
case N_Character_Literal:
gnu_result_type = get_unpadded_type (Etype (gnat_node));
if (Present (Entity (gnat_node)))
gnu_result = DECL_INITIAL (get_gnu_tree (Entity (gnat_node)));
else
gnu_result
= force_fit_type
(build_int_cst
(gnu_result_type, UI_To_CC (Char_Literal_Value (gnat_node))),
false, false, false);
break;
case N_Real_Literal:
if (IN (Ekind (Underlying_Type (Etype (gnat_node))), Fixed_Point_Kind))
{
gnu_result_type = get_unpadded_type (Etype (gnat_node));
gnu_result = UI_To_gnu (Corresponding_Integer_Value (gnat_node),
gnu_result_type);
gcc_assert (!TREE_CONSTANT_OVERFLOW (gnu_result));
}
else if (Vax_Float (Underlying_Type (Etype (gnat_node))))
gcc_unreachable ();
else
{
Ureal ur_realval = Realval (gnat_node);
gnu_result_type = get_unpadded_type (Etype (gnat_node));
if (UR_Is_Zero (ur_realval))
gnu_result = convert (gnu_result_type, integer_zero_node);
else
{
if (!Is_Machine_Number (gnat_node))
ur_realval
= Machine (Base_Type (Underlying_Type (Etype (gnat_node))),
ur_realval, Round_Even, gnat_node);
gnu_result
= UI_To_gnu (Numerator (ur_realval), gnu_result_type);
if (No (Rbase (ur_realval)))
gnu_result
= build_binary_op (RDIV_EXPR,
get_base_type (gnu_result_type),
gnu_result,
UI_To_gnu (Denominator (ur_realval),
gnu_result_type));
else
{
REAL_VALUE_TYPE tmp;
gcc_assert (Rbase (ur_realval) == 2);
real_ldexp (&tmp, &TREE_REAL_CST (gnu_result),
- UI_To_Int (Denominator (ur_realval)));
gnu_result = build_real (gnu_result_type, tmp);
}
}
if (UR_Is_Negative (Realval (gnat_node)))
gnu_result
= build_unary_op (NEGATE_EXPR, get_base_type (gnu_result_type),
gnu_result);
}
break;
case N_String_Literal:
gnu_result_type = get_unpadded_type (Etype (gnat_node));
if (TYPE_PRECISION (TREE_TYPE (gnu_result_type)) == HOST_BITS_PER_CHAR)
{
String_Id gnat_string = Strval (gnat_node);
int length = String_Length (gnat_string);
char *string = (char *) alloca (length + 1);
int i;
for (i = 0; i < length; i++)
string[i] = Get_String_Char (gnat_string, i + 1);
string[i] = 0;
gnu_result = build_string (length, string);
TREE_TYPE (gnu_result) = gnu_result_type;
}
else
{
String_Id gnat_string = Strval (gnat_node);
int length = String_Length (gnat_string);
int i;
tree gnu_list = NULL_TREE;
tree gnu_idx = TYPE_MIN_VALUE (TYPE_DOMAIN (gnu_result_type));
for (i = 0; i < length; i++)
{
gnu_list
= tree_cons (gnu_idx,
build_int_cst (TREE_TYPE (gnu_result_type),
Get_String_Char (gnat_string,
i + 1)),
gnu_list);
gnu_idx = int_const_binop (PLUS_EXPR, gnu_idx, integer_one_node,
0);
}
gnu_result
= gnat_build_constructor (gnu_result_type, nreverse (gnu_list));
}
break;
case N_Pragma:
gnu_result = Pragma_to_gnu (gnat_node);
break;
case N_Subtype_Declaration:
case N_Full_Type_Declaration:
case N_Incomplete_Type_Declaration:
case N_Private_Type_Declaration:
case N_Private_Extension_Declaration:
case N_Task_Type_Declaration:
process_type (Defining_Entity (gnat_node));
gnu_result = alloc_stmt_list ();
break;
case N_Object_Declaration:
case N_Exception_Declaration:
gnat_temp = Defining_Entity (gnat_node);
gnu_result = alloc_stmt_list ();
if (type_annotate_only
&& (((Is_Array_Type (Etype (gnat_temp))
|| Is_Record_Type (Etype (gnat_temp)))
&& !Is_Constrained (Etype (gnat_temp)))
|| Is_Concurrent_Type (Etype (gnat_temp))))
break;
if (Present (Expression (gnat_node))
&& !(Nkind (gnat_node) == N_Object_Declaration
&& No_Initialization (gnat_node))
&& (!type_annotate_only
|| Compile_Time_Known_Value (Expression (gnat_node))))
{
gnu_expr = gnat_to_gnu (Expression (gnat_node));
if (Do_Range_Check (Expression (gnat_node)))
gnu_expr = emit_range_check (gnu_expr, Etype (gnat_temp));
if (Present (Freeze_Node (gnat_temp)))
{
if ((Is_Public (gnat_temp) || global_bindings_p ())
&& !TREE_CONSTANT (gnu_expr))
gnu_expr
= create_var_decl (create_concat_name (gnat_temp, "init"),
NULL_TREE, TREE_TYPE (gnu_expr),
gnu_expr, false, Is_Public (gnat_temp),
false, false, NULL, gnat_temp);
else
gnu_expr = maybe_variable (gnu_expr);
save_gnu_tree (gnat_node, gnu_expr, true);
}
}
else
gnu_expr = NULL_TREE;
if (type_annotate_only && gnu_expr && TREE_CODE (gnu_expr) == ERROR_MARK)
gnu_expr = NULL_TREE;
if (No (Freeze_Node (gnat_temp)))
gnat_to_gnu_entity (gnat_temp, gnu_expr, 1);
break;
case N_Object_Renaming_Declaration:
gnat_temp = Defining_Entity (gnat_node);
if (!Is_Renaming_Of_Object (gnat_temp)
&& ! (type_annotate_only
&& (Is_Array_Type (Etype (gnat_temp))
|| Is_Record_Type (Etype (gnat_temp))
|| Is_Concurrent_Type (Etype (gnat_temp)))))
gnu_result
= gnat_to_gnu_entity (gnat_temp,
gnat_to_gnu (Renamed_Object (gnat_temp)), 1);
else
gnu_result = alloc_stmt_list ();
break;
case N_Implicit_Label_Declaration:
gnat_to_gnu_entity (Defining_Entity (gnat_node), NULL_TREE, 1);
gnu_result = alloc_stmt_list ();
break;
case N_Exception_Renaming_Declaration:
case N_Number_Declaration:
case N_Package_Renaming_Declaration:
case N_Subprogram_Renaming_Declaration:
gnu_result = alloc_stmt_list ();
break;
case N_Explicit_Dereference:
gnu_result = gnat_to_gnu (Prefix (gnat_node));
gnu_result_type = get_unpadded_type (Etype (gnat_node));
gnu_result = build_unary_op (INDIRECT_REF, NULL_TREE, gnu_result);
break;
case N_Indexed_Component:
{
tree gnu_array_object = gnat_to_gnu (Prefix (gnat_node));
tree gnu_type;
int ndim;
int i;
Node_Id *gnat_expr_array;
gnu_array_object = maybe_implicit_deref (gnu_array_object);
gnu_array_object = maybe_unconstrained_array (gnu_array_object);
if (TREE_CODE (TREE_TYPE (gnu_array_object)) == RECORD_TYPE
&& TYPE_IS_PADDING_P (TREE_TYPE (gnu_array_object)))
gnu_array_object
= convert (TREE_TYPE (TYPE_FIELDS (TREE_TYPE (gnu_array_object))),
gnu_array_object);
gnu_result = gnu_array_object;
for (ndim = 1, gnu_type = TREE_TYPE (gnu_array_object);
TREE_CODE (TREE_TYPE (gnu_type)) == ARRAY_TYPE
&& TYPE_MULTI_ARRAY_P (TREE_TYPE (gnu_type));
ndim++, gnu_type = TREE_TYPE (gnu_type))
;
gnat_expr_array = (Node_Id *) alloca (ndim * sizeof (Node_Id));
if (TYPE_CONVENTION_FORTRAN_P (TREE_TYPE (gnu_array_object)))
for (i = ndim - 1, gnat_temp = First (Expressions (gnat_node));
i >= 0;
i--, gnat_temp = Next (gnat_temp))
gnat_expr_array[i] = gnat_temp;
else
for (i = 0, gnat_temp = First (Expressions (gnat_node));
i < ndim;
i++, gnat_temp = Next (gnat_temp))
gnat_expr_array[i] = gnat_temp;
for (i = 0, gnu_type = TREE_TYPE (gnu_array_object);
i < ndim; i++, gnu_type = TREE_TYPE (gnu_type))
{
gcc_assert (TREE_CODE (gnu_type) == ARRAY_TYPE);
gnat_temp = gnat_expr_array[i];
gnu_expr = gnat_to_gnu (gnat_temp);
if (Do_Range_Check (gnat_temp))
gnu_expr
= emit_index_check
(gnu_array_object, gnu_expr,
TYPE_MIN_VALUE (TYPE_INDEX_TYPE (TYPE_DOMAIN (gnu_type))),
TYPE_MAX_VALUE (TYPE_INDEX_TYPE (TYPE_DOMAIN (gnu_type))));
gnu_result = build_binary_op (ARRAY_REF, NULL_TREE,
gnu_result, gnu_expr);
}
}
gnu_result_type = get_unpadded_type (Etype (gnat_node));
break;
case N_Slice:
{
tree gnu_type;
Node_Id gnat_range_node = Discrete_Range (gnat_node);
gnu_result = gnat_to_gnu (Prefix (gnat_node));
gnu_result_type = get_unpadded_type (Etype (gnat_node));
gnu_result = maybe_implicit_deref (gnu_result);
gnu_result = maybe_unconstrained_array (gnu_result);
gnu_type = TREE_TYPE (gnu_result);
if (Do_Range_Check (gnat_range_node))
{
tree gnu_index_type
= TYPE_INDEX_TYPE (TYPE_DOMAIN (gnu_result_type));
tree gnu_min_expr = TYPE_MIN_VALUE (gnu_index_type);
tree gnu_max_expr = TYPE_MAX_VALUE (gnu_index_type);
tree gnu_expr_l, gnu_expr_h, gnu_expr_type;
gnu_expr_l
= emit_index_check
(gnu_result, gnu_min_expr,
TYPE_MIN_VALUE (TYPE_INDEX_TYPE (TYPE_DOMAIN (gnu_type))),
TYPE_MAX_VALUE (TYPE_INDEX_TYPE (TYPE_DOMAIN (gnu_type))));
gnu_expr_h
= emit_index_check
(gnu_result, gnu_max_expr,
TYPE_MIN_VALUE (TYPE_INDEX_TYPE (TYPE_DOMAIN (gnu_type))),
TYPE_MAX_VALUE (TYPE_INDEX_TYPE (TYPE_DOMAIN (gnu_type))));
gnu_expr_type = get_base_type (TREE_TYPE (gnu_expr_l));
gnu_expr
= build_binary_op (COMPOUND_EXPR, gnu_expr_type,
convert (gnu_expr_type, gnu_expr_h),
convert (gnu_expr_type, gnu_expr_l));
gnu_expr
= fold (build3 (COND_EXPR, gnu_expr_type,
build_binary_op (GE_EXPR, gnu_expr_type,
convert (gnu_expr_type,
gnu_max_expr),
convert (gnu_expr_type,
gnu_min_expr)),
gnu_expr, gnu_min_expr));
}
else
gnu_expr = TYPE_MIN_VALUE (TYPE_DOMAIN (gnu_result_type));
gnu_result = build_binary_op (ARRAY_RANGE_REF, gnu_result_type,
gnu_result, gnu_expr);
}
break;
case N_Selected_Component:
{
tree gnu_prefix = gnat_to_gnu (Prefix (gnat_node));
Entity_Id gnat_field = Entity (Selector_Name (gnat_node));
Entity_Id gnat_pref_type = Etype (Prefix (gnat_node));
tree gnu_field;
while (IN (Ekind (gnat_pref_type), Incomplete_Or_Private_Kind)
|| IN (Ekind (gnat_pref_type), Access_Kind))
{
if (IN (Ekind (gnat_pref_type), Incomplete_Or_Private_Kind))
gnat_pref_type = Underlying_Type (gnat_pref_type);
else if (IN (Ekind (gnat_pref_type), Access_Kind))
gnat_pref_type = Designated_Type (gnat_pref_type);
}
gnu_prefix = maybe_implicit_deref (gnu_prefix);
if (Is_Tagged_Type (gnat_pref_type))
while (Present (Corresponding_Discriminant (gnat_field)))
gnat_field = Corresponding_Discriminant (gnat_field);
else if (Present (Corresponding_Discriminant (gnat_field)))
gnat_field = Original_Record_Component (gnat_field);
if (TREE_CODE (TREE_TYPE (gnu_prefix)) == COMPLEX_TYPE)
gnu_result = build_unary_op (Present (Next_Entity (gnat_field))
? REALPART_EXPR : IMAGPART_EXPR,
NULL_TREE, gnu_prefix);
else
{
gnu_field = gnat_to_gnu_field_decl (gnat_field);
if (Has_Discriminants (Is_Access_Type (Etype (Prefix (gnat_node)))
? Designated_Type (Etype
(Prefix (gnat_node)))
: Etype (Prefix (gnat_node))))
gnu_prefix = gnat_stabilize_reference (gnu_prefix, 0);
gnu_result
= build_component_ref (gnu_prefix, NULL_TREE, gnu_field,
(Nkind (Parent (gnat_node))
== N_Attribute_Reference));
}
gcc_assert (gnu_result);
gnu_result_type = get_unpadded_type (Etype (gnat_node));
}
break;
case N_Attribute_Reference:
{
int attribute = Get_Attribute_Id (Attribute_Name (gnat_node));
if (attribute == Attr_Elab_Body || attribute == Attr_Elab_Spec)
return (create_subprog_decl
(create_concat_name (Entity (Prefix (gnat_node)),
attribute == Attr_Elab_Body
? "elabb" : "elabs"),
NULL_TREE, void_ftype, NULL_TREE, false, true, true, NULL,
gnat_node));
gnu_result = Attribute_to_gnu (gnat_node, &gnu_result_type, attribute);
}
break;
case N_Reference:
gnu_result = gnat_to_gnu (Prefix (gnat_node));
gnu_result = build_unary_op (ADDR_EXPR, NULL_TREE, gnu_result);
gnu_result_type = get_unpadded_type (Etype (gnat_node));
break;
case N_Aggregate:
case N_Extension_Aggregate:
{
tree gnu_aggr_type;
gcc_assert (!Expansion_Delayed (gnat_node));
gnu_aggr_type = gnu_result_type
= get_unpadded_type (Etype (gnat_node));
if (TREE_CODE (gnu_result_type) == RECORD_TYPE
&& TYPE_CONTAINS_TEMPLATE_P (gnu_result_type))
gnu_aggr_type
= TREE_TYPE (TREE_CHAIN (TYPE_FIELDS (gnu_result_type)));
if (Null_Record_Present (gnat_node))
gnu_result = gnat_build_constructor (gnu_aggr_type, NULL_TREE);
else if (TREE_CODE (gnu_aggr_type) == UNION_TYPE
&& TYPE_UNCHECKED_UNION_P (gnu_aggr_type))
{
Node_Id gnat_assoc
= Next (First (Component_Associations (gnat_node)));
Entity_Id gnat_field = Entity (First (Choices (gnat_assoc)));
tree gnu_field_type
= TREE_TYPE (gnat_to_gnu_entity (gnat_field, NULL_TREE, 0));
gnu_result = convert (gnu_field_type,
gnat_to_gnu (Expression (gnat_assoc)));
}
else if (TREE_CODE (gnu_aggr_type) == RECORD_TYPE
|| TREE_CODE (gnu_aggr_type) == UNION_TYPE)
gnu_result
= assoc_to_constructor (First (Component_Associations (gnat_node)),
gnu_aggr_type);
else if (TREE_CODE (gnu_aggr_type) == ARRAY_TYPE)
gnu_result = pos_to_constructor (First (Expressions (gnat_node)),
gnu_aggr_type,
Component_Type (Etype (gnat_node)));
else if (TREE_CODE (gnu_aggr_type) == COMPLEX_TYPE)
gnu_result
= build_binary_op
(COMPLEX_EXPR, gnu_aggr_type,
gnat_to_gnu (Expression (First
(Component_Associations (gnat_node)))),
gnat_to_gnu (Expression
(Next
(First (Component_Associations (gnat_node))))));
else
gcc_unreachable ();
gnu_result = convert (gnu_result_type, gnu_result);
}
break;
case N_Null:
gnu_result = null_pointer_node;
gnu_result_type = get_unpadded_type (Etype (gnat_node));
break;
case N_Type_Conversion:
case N_Qualified_Expression:
gnu_result = gnat_to_gnu (Expression (gnat_node));
gnu_result_type = get_unpadded_type (Etype (gnat_node));
gnu_result
= convert_with_check (Etype (gnat_node), gnu_result,
Do_Overflow_Check (gnat_node),
Do_Range_Check (Expression (gnat_node)),
Nkind (gnat_node) == N_Type_Conversion
&& Float_Truncate (gnat_node));
break;
case N_Unchecked_Type_Conversion:
gnu_result = gnat_to_gnu (Expression (gnat_node));
gnu_result_type = get_unpadded_type (Etype (gnat_node));
if (STRICT_ALIGNMENT && POINTER_TYPE_P (gnu_result_type)
&& IN (Ekind (Etype (gnat_node)), Access_Kind))
{
unsigned int align = known_alignment (gnu_result);
tree gnu_obj_type = TREE_TYPE (gnu_result_type);
unsigned int oalign = TYPE_ALIGN (gnu_obj_type);
if (align != 0 && align < oalign && !TYPE_ALIGN_OK (gnu_obj_type))
post_error_ne_tree_2
("?source alignment (^) < alignment of & (^)",
gnat_node, Designated_Type (Etype (gnat_node)),
size_int (align / BITS_PER_UNIT), oalign / BITS_PER_UNIT);
}
gnu_result = unchecked_convert (gnu_result_type, gnu_result,
No_Truncation (gnat_node));
break;
case N_In:
case N_Not_In:
{
tree gnu_object = gnat_to_gnu (Left_Opnd (gnat_node));
Node_Id gnat_range = Right_Opnd (gnat_node);
tree gnu_low;
tree gnu_high;
if (Nkind (gnat_range) == N_Range)
{
gnu_low = gnat_to_gnu (Low_Bound (gnat_range));
gnu_high = gnat_to_gnu (High_Bound (gnat_range));
}
else if (Nkind (gnat_range) == N_Identifier
|| Nkind (gnat_range) == N_Expanded_Name)
{
tree gnu_range_type = get_unpadded_type (Entity (gnat_range));
gnu_low = TYPE_MIN_VALUE (gnu_range_type);
gnu_high = TYPE_MAX_VALUE (gnu_range_type);
}
else
gcc_unreachable ();
gnu_result_type = get_unpadded_type (Etype (gnat_node));
if (operand_equal_p (gnu_low, gnu_high, 0))
gnu_result = build_binary_op (EQ_EXPR, gnu_result_type,
gnu_object, gnu_low);
else
{
gnu_object = protect_multiple_eval (gnu_object);
gnu_result
= build_binary_op (TRUTH_ANDIF_EXPR, gnu_result_type,
build_binary_op (GE_EXPR, gnu_result_type,
gnu_object, gnu_low),
build_binary_op (LE_EXPR, gnu_result_type,
gnu_object, gnu_high));
}
if (Nkind (gnat_node) == N_Not_In)
gnu_result = invert_truthvalue (gnu_result);
}
break;
case N_Op_Divide:
gnu_lhs = gnat_to_gnu (Left_Opnd (gnat_node));
gnu_rhs = gnat_to_gnu (Right_Opnd (gnat_node));
gnu_result_type = get_unpadded_type (Etype (gnat_node));
gnu_result = build_binary_op (FLOAT_TYPE_P (gnu_result_type)
? RDIV_EXPR
: (Rounded_Result (gnat_node)
? ROUND_DIV_EXPR : TRUNC_DIV_EXPR),
gnu_result_type, gnu_lhs, gnu_rhs);
break;
case N_Op_Or: case N_Op_And: case N_Op_Xor:
if (IN (Ekind (Underlying_Type (Etype (gnat_node))),
Modular_Integer_Kind))
{
enum tree_code code
= (Nkind (gnat_node) == N_Op_Or ? BIT_IOR_EXPR
: Nkind (gnat_node) == N_Op_And ? BIT_AND_EXPR
: BIT_XOR_EXPR);
gnu_lhs = gnat_to_gnu (Left_Opnd (gnat_node));
gnu_rhs = gnat_to_gnu (Right_Opnd (gnat_node));
gnu_result_type = get_unpadded_type (Etype (gnat_node));
gnu_result = build_binary_op (code, gnu_result_type,
gnu_lhs, gnu_rhs);
break;
}
case N_Op_Eq: case N_Op_Ne: case N_Op_Lt:
case N_Op_Le: case N_Op_Gt: case N_Op_Ge:
case N_Op_Add: case N_Op_Subtract: case N_Op_Multiply:
case N_Op_Mod: case N_Op_Rem:
case N_Op_Rotate_Left:
case N_Op_Rotate_Right:
case N_Op_Shift_Left:
case N_Op_Shift_Right:
case N_Op_Shift_Right_Arithmetic:
case N_And_Then: case N_Or_Else:
{
enum tree_code code = gnu_codes[Nkind (gnat_node)];
tree gnu_type;
gnu_lhs = gnat_to_gnu (Left_Opnd (gnat_node));
gnu_rhs = gnat_to_gnu (Right_Opnd (gnat_node));
gnu_type = gnu_result_type = get_unpadded_type (Etype (gnat_node));
if (TREE_CODE_CLASS (code) == tcc_comparison)
{
gnu_lhs = maybe_unconstrained_array (gnu_lhs);
gnu_rhs = maybe_unconstrained_array (gnu_rhs);
}
else if (Is_Private_Type (Etype (gnat_node)))
gnu_type = gnu_result_type
= get_unpadded_type (Base_Type (Full_View (Etype (gnat_node))));
if (IN (Nkind (gnat_node), N_Op_Shift)
&& !Shift_Count_OK (gnat_node))
{
tree gnu_count_type = get_base_type (TREE_TYPE (gnu_rhs));
tree gnu_max_shift
= convert (gnu_count_type, TYPE_SIZE (gnu_type));
if (Nkind (gnat_node) == N_Op_Rotate_Left
|| Nkind (gnat_node) == N_Op_Rotate_Right)
gnu_rhs = build_binary_op (TRUNC_MOD_EXPR, gnu_count_type,
gnu_rhs, gnu_max_shift);
else if (Nkind (gnat_node) == N_Op_Shift_Right_Arithmetic)
gnu_rhs
= build_binary_op
(MIN_EXPR, gnu_count_type,
build_binary_op (MINUS_EXPR,
gnu_count_type,
gnu_max_shift,
convert (gnu_count_type,
integer_one_node)),
gnu_rhs);
}
if (Nkind (gnat_node) == N_Op_Shift_Right
&& !TYPE_UNSIGNED (gnu_type))
gnu_type = gnat_unsigned_type (gnu_type);
else if (Nkind (gnat_node) == N_Op_Shift_Right_Arithmetic
&& TYPE_UNSIGNED (gnu_type))
gnu_type = gnat_signed_type (gnu_type);
if (gnu_type != gnu_result_type)
{
gnu_lhs = convert (gnu_type, gnu_lhs);
gnu_rhs = convert (gnu_type, gnu_rhs);
}
gnu_result = build_binary_op (code, gnu_type, gnu_lhs, gnu_rhs);
if ((Nkind (gnat_node) == N_Op_Shift_Left
|| Nkind (gnat_node) == N_Op_Shift_Right)
&& !Shift_Count_OK (gnat_node))
gnu_result
= build_cond_expr
(gnu_type,
build_binary_op (GE_EXPR, integer_type_node,
gnu_rhs,
convert (TREE_TYPE (gnu_rhs),
TYPE_SIZE (gnu_type))),
convert (gnu_type, integer_zero_node),
gnu_result);
}
break;
case N_Conditional_Expression:
{
tree gnu_cond = gnat_to_gnu (First (Expressions (gnat_node)));
tree gnu_true = gnat_to_gnu (Next (First (Expressions (gnat_node))));
tree gnu_false
= gnat_to_gnu (Next (Next (First (Expressions (gnat_node)))));
gnu_result_type = get_unpadded_type (Etype (gnat_node));
gnu_result = build_cond_expr (gnu_result_type,
gnat_truthvalue_conversion (gnu_cond),
gnu_true, gnu_false);
}
break;
case N_Op_Plus:
gnu_result = gnat_to_gnu (Right_Opnd (gnat_node));
gnu_result_type = get_unpadded_type (Etype (gnat_node));
break;
case N_Op_Not:
if (IN (Ekind (Etype (gnat_node)), Modular_Integer_Kind))
{
gnu_expr = gnat_to_gnu (Right_Opnd (gnat_node));
gnu_result_type = get_unpadded_type (Etype (gnat_node));
gnu_result = build_unary_op (BIT_NOT_EXPR, gnu_result_type,
gnu_expr);
break;
}
case N_Op_Minus: case N_Op_Abs:
gnu_expr = gnat_to_gnu (Right_Opnd (gnat_node));
if (Ekind (Etype (gnat_node)) != E_Private_Type)
gnu_result_type = get_unpadded_type (Etype (gnat_node));
else
gnu_result_type = get_unpadded_type (Base_Type
(Full_View (Etype (gnat_node))));
gnu_result = build_unary_op (gnu_codes[Nkind (gnat_node)],
gnu_result_type, gnu_expr);
break;
case N_Allocator:
{
tree gnu_init = 0;
tree gnu_type;
gnat_temp = Expression (gnat_node);
if (Nkind (gnat_temp) == N_Identifier
|| Nkind (gnat_temp) == N_Expanded_Name)
gnu_type = gnat_to_gnu_type (Entity (gnat_temp));
else if (Nkind (gnat_temp) == N_Qualified_Expression)
{
Entity_Id gnat_desig_type
= Designated_Type (Underlying_Type (Etype (gnat_node)));
gnu_init = gnat_to_gnu (Expression (gnat_temp));
gnu_init = maybe_unconstrained_array (gnu_init);
if (Do_Range_Check (Expression (gnat_temp)))
gnu_init = emit_range_check (gnu_init, gnat_desig_type);
if (Is_Elementary_Type (gnat_desig_type)
|| Is_Constrained (gnat_desig_type))
{
gnu_type = gnat_to_gnu_type (gnat_desig_type);
gnu_init = convert (gnu_type, gnu_init);
}
else
{
gnu_type = gnat_to_gnu_type (Etype (Expression (gnat_temp)));
if (TREE_CODE (gnu_type) == UNCONSTRAINED_ARRAY_TYPE)
gnu_type = TREE_TYPE (gnu_init);
gnu_init = convert (gnu_type, gnu_init);
}
}
else
gcc_unreachable ();
gnu_result_type = get_unpadded_type (Etype (gnat_node));
return build_allocator (gnu_type, gnu_init, gnu_result_type,
Procedure_To_Call (gnat_node),
Storage_Pool (gnat_node), gnat_node);
}
break;
case N_Label:
gnu_result = build1 (LABEL_EXPR, void_type_node,
gnat_to_gnu (Identifier (gnat_node)));
break;
case N_Null_Statement:
gnu_result = alloc_stmt_list ();
break;
case N_Assignment_Statement:
gnu_lhs = maybe_unconstrained_array (gnat_to_gnu (Name (gnat_node)));
if (TREE_CODE (TYPE_SIZE (TREE_TYPE (gnu_lhs))) == INTEGER_CST
&& TREE_OVERFLOW (TYPE_SIZE (TREE_TYPE (gnu_lhs))))
gnu_result = build_call_raise (SE_Object_Too_Large);
else if (Nkind (Expression (gnat_node)) == N_Function_Call
&& !Do_Range_Check (Expression (gnat_node)))
gnu_result = call_to_gnu (Expression (gnat_node),
&gnu_result_type, gnu_lhs);
else
{
gnu_rhs
= maybe_unconstrained_array (gnat_to_gnu (Expression (gnat_node)));
if (Do_Range_Check (Expression (gnat_node)))
gnu_rhs = emit_range_check (gnu_rhs, Etype (Name (gnat_node)));
gnu_result
= build_binary_op (MODIFY_EXPR, NULL_TREE, gnu_lhs, gnu_rhs);
}
break;
case N_If_Statement:
{
tree *gnu_else_ptr;
gnu_result = build3 (COND_EXPR, void_type_node,
gnat_to_gnu (Condition (gnat_node)),
NULL_TREE, NULL_TREE);
COND_EXPR_THEN (gnu_result)
= build_stmt_group (Then_Statements (gnat_node), false);
TREE_SIDE_EFFECTS (gnu_result) = 1;
gnu_else_ptr = &COND_EXPR_ELSE (gnu_result);
if (Present (Elsif_Parts (gnat_node)))
for (gnat_temp = First (Elsif_Parts (gnat_node));
Present (gnat_temp); gnat_temp = Next (gnat_temp))
{
gnu_expr = build3 (COND_EXPR, void_type_node,
gnat_to_gnu (Condition (gnat_temp)),
NULL_TREE, NULL_TREE);
COND_EXPR_THEN (gnu_expr)
= build_stmt_group (Then_Statements (gnat_temp), false);
TREE_SIDE_EFFECTS (gnu_expr) = 1;
annotate_with_node (gnu_expr, gnat_temp);
*gnu_else_ptr = gnu_expr;
gnu_else_ptr = &COND_EXPR_ELSE (gnu_expr);
}
*gnu_else_ptr = build_stmt_group (Else_Statements (gnat_node), false);
}
break;
case N_Case_Statement:
gnu_result = Case_Statement_to_gnu (gnat_node);
break;
case N_Loop_Statement:
gnu_result = Loop_Statement_to_gnu (gnat_node);
break;
case N_Block_Statement:
start_stmt_group ();
gnat_pushlevel ();
process_decls (Declarations (gnat_node), Empty, Empty, true, true);
add_stmt (gnat_to_gnu (Handled_Statement_Sequence (gnat_node)));
gnat_poplevel ();
gnu_result = end_stmt_group ();
if (Present (Identifier (gnat_node)))
mark_out_of_scope (Entity (Identifier (gnat_node)));
break;
case N_Exit_Statement:
gnu_result
= build2 (EXIT_STMT, void_type_node,
(Present (Condition (gnat_node))
? gnat_to_gnu (Condition (gnat_node)) : NULL_TREE),
(Present (Name (gnat_node))
? get_gnu_tree (Entity (Name (gnat_node)))
: TREE_VALUE (gnu_loop_label_stack)));
break;
case N_Return_Statement:
{
tree gnu_subprog_type = TREE_TYPE (current_function_decl);
tree gnu_ret_val = NULL_TREE;
tree gnu_lhs;
gnu_result = NULL_TREE;
if (TREE_VALUE (gnu_return_label_stack))
{
gnu_result = build1 (GOTO_EXPR, void_type_node,
TREE_VALUE (gnu_return_label_stack));
break;
}
else if (TYPE_CI_CO_LIST (gnu_subprog_type))
{
gnu_lhs = DECL_RESULT (current_function_decl);
if (list_length (TYPE_CI_CO_LIST (gnu_subprog_type)) == 1)
gnu_ret_val = TREE_VALUE (TYPE_CI_CO_LIST (gnu_subprog_type));
else
gnu_ret_val
= gnat_build_constructor (TREE_TYPE (gnu_subprog_type),
TYPE_CI_CO_LIST (gnu_subprog_type));
}
else if (Present (Expression (gnat_node)))
{
if (TYPE_RETURNS_BY_TARGET_PTR_P (gnu_subprog_type)
&& Nkind (Expression (gnat_node)) == N_Function_Call)
{
gnu_lhs
= build_unary_op (INDIRECT_REF, NULL_TREE,
DECL_ARGUMENTS (current_function_decl));
gnu_result = call_to_gnu (Expression (gnat_node),
&gnu_result_type, gnu_lhs);
}
else
{
gnu_ret_val = gnat_to_gnu (Expression (gnat_node));
if (TYPE_RETURNS_BY_TARGET_PTR_P (gnu_subprog_type))
gnu_lhs
= build_unary_op (INDIRECT_REF, TREE_TYPE (gnu_ret_val),
DECL_ARGUMENTS (current_function_decl));
else
gnu_lhs = DECL_RESULT (current_function_decl);
if (TREE_CODE (gnu_ret_val) == COMPONENT_REF
&& (TREE_CODE (TREE_TYPE (TREE_OPERAND (gnu_ret_val, 0)))
== RECORD_TYPE)
&& (TYPE_IS_PADDING_P
(TREE_TYPE (TREE_OPERAND (gnu_ret_val, 0))))
&& (CONTAINS_PLACEHOLDER_P
(TYPE_SIZE (TREE_TYPE (gnu_ret_val)))))
gnu_ret_val = TREE_OPERAND (gnu_ret_val, 0);
if (TYPE_RETURNS_BY_REF_P (gnu_subprog_type)
|| By_Ref (gnat_node))
gnu_ret_val
= build_unary_op (ADDR_EXPR, NULL_TREE, gnu_ret_val);
else if (TYPE_RETURNS_UNCONSTRAINED_P (gnu_subprog_type))
{
gnu_ret_val = maybe_unconstrained_array (gnu_ret_val);
if (TYPE_RETURNS_STACK_DEPRESSED (gnu_subprog_type))
gnu_ret_val
= build_allocator (TREE_TYPE (gnu_ret_val),
gnu_ret_val,
TREE_TYPE (gnu_subprog_type),
0, -1, gnat_node);
else
gnu_ret_val
= build_allocator (TREE_TYPE (gnu_ret_val),
gnu_ret_val,
TREE_TYPE (gnu_subprog_type),
Procedure_To_Call (gnat_node),
Storage_Pool (gnat_node),
gnat_node);
}
}
}
if (gnu_ret_val)
gnu_result = build2 (MODIFY_EXPR, TREE_TYPE (gnu_ret_val),
gnu_lhs, gnu_ret_val);
if (TYPE_RETURNS_BY_TARGET_PTR_P (gnu_subprog_type))
{
add_stmt_with_node (gnu_result, gnat_node);
gnu_result = NULL_TREE;
}
gnu_result = build1 (RETURN_EXPR, void_type_node, gnu_result);
}
break;
case N_Goto_Statement:
gnu_result = build1 (GOTO_EXPR, void_type_node,
gnat_to_gnu (Name (gnat_node)));
break;
case N_Subprogram_Declaration:
if (No (Freeze_Node (Defining_Entity (Specification (gnat_node)))))
gnat_to_gnu_entity (Defining_Entity (Specification (gnat_node)),
NULL_TREE, 1);
gnu_result = alloc_stmt_list ();
break;
case N_Abstract_Subprogram_Declaration:
for (gnat_temp
= First_Formal (Defining_Entity (Specification (gnat_node)));
Present (gnat_temp);
gnat_temp = Next_Formal_With_Extras (gnat_temp))
if (Is_Itype (Etype (gnat_temp))
&& !From_With_Type (Etype (gnat_temp)))
gnat_to_gnu_entity (Etype (gnat_temp), NULL_TREE, 0);
gnu_result = alloc_stmt_list ();
break;
case N_Defining_Program_Unit_Name:
gnu_result = gnat_to_gnu (Parent (gnat_node));
break;
case N_Subprogram_Body:
Subprogram_Body_to_gnu (gnat_node);
gnu_result = alloc_stmt_list ();
break;
case N_Function_Call:
case N_Procedure_Call_Statement:
gnu_result = call_to_gnu (gnat_node, &gnu_result_type, NULL_TREE);
break;
case N_Package_Declaration:
gnu_result = gnat_to_gnu (Specification (gnat_node));
break;
case N_Package_Specification:
start_stmt_group ();
process_decls (Visible_Declarations (gnat_node),
Private_Declarations (gnat_node), Empty, true, true);
gnu_result = end_stmt_group ();
break;
case N_Package_Body:
if (Ekind (Corresponding_Spec (gnat_node)) == E_Generic_Package)
{
gnu_result = alloc_stmt_list ();
break;
}
start_stmt_group ();
process_decls (Declarations (gnat_node), Empty, Empty, true, true);
if (Present (Handled_Statement_Sequence (gnat_node)))
add_stmt (gnat_to_gnu (Handled_Statement_Sequence (gnat_node)));
gnu_result = end_stmt_group ();
break;
case N_Use_Package_Clause:
case N_Use_Type_Clause:
gnu_result = alloc_stmt_list ();
break;
case N_Protected_Type_Declaration:
gnu_result = alloc_stmt_list ();
break;
case N_Single_Task_Declaration:
gnat_to_gnu_entity (Defining_Entity (gnat_node), NULL_TREE, 1);
gnu_result = alloc_stmt_list ();
break;
case N_Compilation_Unit:
start_stmt_group ();
gnat_pushlevel ();
Compilation_Unit_to_gnu (gnat_node);
gnu_result = alloc_stmt_list ();
break;
case N_Subprogram_Body_Stub:
case N_Package_Body_Stub:
case N_Protected_Body_Stub:
case N_Task_Body_Stub:
gnu_result = gnat_to_gnu (Unit (Library_Unit (gnat_node)));
break;
case N_Subunit:
gnu_result = gnat_to_gnu (Proper_Body (gnat_node));
break;
case N_Handled_Sequence_Of_Statements:
gcc_assert (type_annotate_only
|| Exception_Mechanism != Setjmp_Longjmp
|| No (At_End_Proc (gnat_node))
|| Present (Exception_Handlers (gnat_node))
|| No_Exception_Handlers_Set ());
gnu_result = Handled_Sequence_Of_Statements_to_gnu (gnat_node);
break;
case N_Exception_Handler:
if (Exception_Mechanism == Setjmp_Longjmp)
gnu_result = Exception_Handler_to_gnu_sjlj (gnat_node);
else if (Exception_Mechanism == GCC_ZCX)
gnu_result = Exception_Handler_to_gnu_zcx (gnat_node);
else
gcc_unreachable ();
break;
case N_Generic_Function_Renaming_Declaration:
case N_Generic_Package_Renaming_Declaration:
case N_Generic_Procedure_Renaming_Declaration:
case N_Generic_Package_Declaration:
case N_Generic_Subprogram_Declaration:
case N_Package_Instantiation:
case N_Procedure_Instantiation:
case N_Function_Instantiation:
gnu_result = alloc_stmt_list ();
break;
case N_Attribute_Definition_Clause:
gnu_result = alloc_stmt_list ();
if (Get_Attribute_Id (Chars (gnat_node)) != Attr_Address
|| No (Freeze_Node (Entity (Name (gnat_node)))))
break;
save_gnu_tree (Entity (Name (gnat_node)),
gnat_to_gnu (Expression (gnat_node)), true);
break;
case N_Enumeration_Representation_Clause:
case N_Record_Representation_Clause:
case N_At_Clause:
gnu_result = alloc_stmt_list ();
break;
case N_Code_Statement:
if (!type_annotate_only)
{
tree gnu_template = gnat_to_gnu (Asm_Template (gnat_node));
tree gnu_input_list = NULL_TREE, gnu_output_list = NULL_TREE;
tree gnu_clobber_list = NULL_TREE;
char *clobber;
Setup_Asm_Inputs (gnat_node);
while (Present (gnat_temp = Asm_Input_Value ()))
{
tree gnu_value = gnat_to_gnu (gnat_temp);
tree gnu_constr = build_tree_list (NULL_TREE, gnat_to_gnu
(Asm_Input_Constraint ()));
gnu_input_list
= tree_cons (gnu_constr, gnu_value, gnu_input_list);
Next_Asm_Input ();
}
Setup_Asm_Outputs (gnat_node);
while (Present (gnat_temp = Asm_Output_Variable ()))
{
tree gnu_value = gnat_to_gnu (gnat_temp);
tree gnu_constr = build_tree_list (NULL_TREE, gnat_to_gnu
(Asm_Output_Constraint ()));
gnu_output_list
= tree_cons (gnu_constr, gnu_value, gnu_output_list);
Next_Asm_Output ();
}
Clobber_Setup (gnat_node);
while ((clobber = Clobber_Get_Next ()))
gnu_clobber_list
= tree_cons (NULL_TREE,
build_string (strlen (clobber) + 1, clobber),
gnu_clobber_list);
gnu_input_list = nreverse (gnu_input_list);
gnu_output_list = nreverse (gnu_output_list);
gnu_result = build4 (ASM_EXPR, void_type_node,
gnu_template, gnu_output_list,
gnu_input_list, gnu_clobber_list);
ASM_VOLATILE_P (gnu_result) = Is_Asm_Volatile (gnat_node);
}
else
gnu_result = alloc_stmt_list ();
break;
case N_Freeze_Entity:
start_stmt_group ();
process_freeze_entity (gnat_node);
process_decls (Actions (gnat_node), Empty, Empty, true, true);
gnu_result = end_stmt_group ();
break;
case N_Itype_Reference:
if (!present_gnu_tree (Itype (gnat_node)))
process_type (Itype (gnat_node));
gnu_result = alloc_stmt_list ();
break;
case N_Free_Statement:
if (!type_annotate_only)
{
tree gnu_ptr = gnat_to_gnu (Expression (gnat_node));
tree gnu_obj_type;
tree gnu_obj_size;
int align;
if (TYPE_THIN_POINTER_P (TREE_TYPE (gnu_ptr)))
gnu_ptr = build_unary_op (ADDR_EXPR, NULL_TREE,
build_unary_op (INDIRECT_REF, NULL_TREE,
gnu_ptr));
if (TYPE_FAT_POINTER_P (TREE_TYPE (gnu_ptr)))
gnu_ptr
= convert (build_pointer_type
(TYPE_OBJECT_RECORD_TYPE
(TYPE_UNCONSTRAINED_ARRAY (TREE_TYPE (gnu_ptr)))),
gnu_ptr);
gnu_obj_type = TREE_TYPE (TREE_TYPE (gnu_ptr));
gnu_obj_size = TYPE_SIZE_UNIT (gnu_obj_type);
align = TYPE_ALIGN (gnu_obj_type);
if (TREE_CODE (gnu_obj_type) == RECORD_TYPE
&& TYPE_CONTAINS_TEMPLATE_P (gnu_obj_type))
{
tree gnu_char_ptr_type = build_pointer_type (char_type_node);
tree gnu_pos = byte_position (TYPE_FIELDS (gnu_obj_type));
tree gnu_byte_offset
= convert (gnu_char_ptr_type,
size_diffop (size_zero_node, gnu_pos));
gnu_ptr = convert (gnu_char_ptr_type, gnu_ptr);
gnu_ptr = build_binary_op (MINUS_EXPR, gnu_char_ptr_type,
gnu_ptr, gnu_byte_offset);
}
gnu_result = build_call_alloc_dealloc (gnu_ptr, gnu_obj_size, align,
Procedure_To_Call (gnat_node),
Storage_Pool (gnat_node),
gnat_node);
}
break;
case N_Raise_Constraint_Error:
case N_Raise_Program_Error:
case N_Raise_Storage_Error:
if (type_annotate_only)
{
gnu_result = alloc_stmt_list ();
break;
}
gnu_result_type = get_unpadded_type (Etype (gnat_node));
gnu_result = build_call_raise (UI_To_Int (Reason (gnat_node)));
if (TREE_CODE (gnu_result_type) == VOID_TYPE)
{
annotate_with_node (gnu_result, gnat_node);
if (Present (Condition (gnat_node)))
gnu_result = build3 (COND_EXPR, void_type_node,
gnat_to_gnu (Condition (gnat_node)),
gnu_result, alloc_stmt_list ());
}
else
gnu_result = build1 (NULL_EXPR, gnu_result_type, gnu_result);
break;
case N_Validate_Unchecked_Conversion:
{
tree gnu_source_type = gnat_to_gnu_type (Source_Type (gnat_node));
tree gnu_target_type = gnat_to_gnu_type (Target_Type (gnat_node));
if (POINTER_TYPE_P (gnu_target_type)
&& !In_Same_Source_Unit (Target_Type (gnat_node), gnat_node)
&& get_alias_set (TREE_TYPE (gnu_target_type)) != 0
&& !No_Strict_Aliasing (Underlying_Type (Target_Type (gnat_node)))
&& (!POINTER_TYPE_P (gnu_source_type)
|| (get_alias_set (TREE_TYPE (gnu_source_type))
!= get_alias_set (TREE_TYPE (gnu_target_type)))))
{
post_error_ne
("?possible aliasing problem for type&",
gnat_node, Target_Type (gnat_node));
post_error
("\\?use -fno-strict-aliasing switch for references",
gnat_node);
post_error_ne
("\\?or use `pragma No_Strict_Aliasing (&);`",
gnat_node, Target_Type (gnat_node));
}
}
gnu_result = alloc_stmt_list ();
break;
case N_Raise_Statement:
case N_Function_Specification:
case N_Procedure_Specification:
case N_Op_Concat:
case N_Component_Association:
case N_Task_Body:
default:
gcc_assert (type_annotate_only);
gnu_result = alloc_stmt_list ();
}
if (went_into_elab_proc)
{
add_stmt (gnu_result);
gnat_poplevel ();
gnu_result = end_stmt_group ();
current_function_decl = NULL_TREE;
}
if (gnu_result && EXPR_P (gnu_result))
annotate_with_node (gnu_result, gnat_node);
if (TREE_CODE (gnu_result_type) == VOID_TYPE)
return gnu_result;
else if (TREE_CODE (gnu_result) == INTEGER_CST
&& TREE_CONSTANT_OVERFLOW (gnu_result))
{
post_error ("Constraint_Error will be raised at run-time?", gnat_node);
gnu_result
= build1 (NULL_EXPR, gnu_result_type,
build_call_raise (CE_Overflow_Check_Failed));
}
if (TREE_SIDE_EFFECTS (gnu_result)
&& (TREE_CODE (gnu_result_type) == UNCONSTRAINED_ARRAY_TYPE
|| CONTAINS_PLACEHOLDER_P (TYPE_SIZE (gnu_result_type))))
gnu_result = gnat_stabilize_reference (gnu_result, 0);
if (Present (Parent (gnat_node))
&& ((Nkind (Parent (gnat_node)) == N_Assignment_Statement
&& Name (Parent (gnat_node)) == gnat_node)
|| (Nkind (Parent (gnat_node)) == N_Procedure_Call_Statement
&& Name (Parent (gnat_node)) != gnat_node)
|| (Nkind (Parent (gnat_node)) == N_Unchecked_Type_Conversion
&& !AGGREGATE_TYPE_P (gnu_result_type)
&& !AGGREGATE_TYPE_P (TREE_TYPE (gnu_result)))
|| Nkind (Parent (gnat_node)) == N_Parameter_Association)
&& !(TYPE_SIZE (gnu_result_type)
&& TYPE_SIZE (TREE_TYPE (gnu_result))
&& (AGGREGATE_TYPE_P (gnu_result_type)
== AGGREGATE_TYPE_P (TREE_TYPE (gnu_result)))
&& ((TREE_CODE (TYPE_SIZE (gnu_result_type)) == INTEGER_CST
&& (TREE_CODE (TYPE_SIZE (TREE_TYPE (gnu_result)))
!= INTEGER_CST))
|| (TREE_CODE (TYPE_SIZE (gnu_result_type)) != INTEGER_CST
&& !CONTAINS_PLACEHOLDER_P (TYPE_SIZE (gnu_result_type))
&& (CONTAINS_PLACEHOLDER_P
(TYPE_SIZE (TREE_TYPE (gnu_result))))))
&& !(TREE_CODE (gnu_result_type) == RECORD_TYPE
&& TYPE_JUSTIFIED_MODULAR_P (gnu_result_type))))
{
if (TREE_CODE (TREE_TYPE (gnu_result)) == RECORD_TYPE
&& TYPE_IS_PADDING_P (TREE_TYPE (gnu_result))
&& CONTAINS_PLACEHOLDER_P (TYPE_SIZE
(TREE_TYPE (TYPE_FIELDS
(TREE_TYPE (gnu_result))))))
gnu_result = convert (TREE_TYPE (TYPE_FIELDS (TREE_TYPE (gnu_result))),
gnu_result);
}
else if (TREE_CODE (gnu_result) == LABEL_DECL
|| TREE_CODE (gnu_result) == FIELD_DECL
|| TREE_CODE (gnu_result) == ERROR_MARK
|| (TYPE_SIZE (gnu_result_type)
&& TREE_CODE (TYPE_SIZE (gnu_result_type)) != INTEGER_CST
&& TREE_CODE (gnu_result) != INDIRECT_REF
&& CONTAINS_PLACEHOLDER_P (TYPE_SIZE (gnu_result_type)))
|| ((TYPE_NAME (gnu_result_type)
== TYPE_NAME (TREE_TYPE (gnu_result)))
&& TREE_CODE (gnu_result_type) == RECORD_TYPE
&& TREE_CODE (TREE_TYPE (gnu_result)) == RECORD_TYPE
&& TYPE_MODE (gnu_result_type) == BLKmode
&& (GET_MODE_CLASS (TYPE_MODE (TREE_TYPE (gnu_result)))
== MODE_INT)))
{
if (TREE_CODE (TREE_TYPE (gnu_result)) == RECORD_TYPE
&& TYPE_IS_PADDING_P (TREE_TYPE (gnu_result)))
gnu_result = convert (TREE_TYPE (TYPE_FIELDS (TREE_TYPE (gnu_result))),
gnu_result);
}
else if (gnu_result == error_mark_node
|| gnu_result_type == void_type_node)
gnu_result = error_mark_node;
else if (gnu_result_type != TREE_TYPE (gnu_result))
gnu_result = convert (gnu_result_type, gnu_result);
while ((TREE_CODE (gnu_result) == NOP_EXPR
|| TREE_CODE (gnu_result) == NON_LVALUE_EXPR)
&& TREE_TYPE (TREE_OPERAND (gnu_result, 0)) == TREE_TYPE (gnu_result))
gnu_result = TREE_OPERAND (gnu_result, 0);
return gnu_result;
}
static void
record_code_position (Node_Id gnat_node)
{
tree stmt_stmt = build1 (STMT_STMT, void_type_node, NULL_TREE);
add_stmt_with_node (stmt_stmt, gnat_node);
save_gnu_tree (gnat_node, stmt_stmt, true);
}
static void
insert_code_for (Node_Id gnat_node)
{
STMT_STMT_STMT (get_gnu_tree (gnat_node)) = gnat_to_gnu (gnat_node);
save_gnu_tree (gnat_node, NULL_TREE, true);
}
static void
start_stmt_group ()
{
struct stmt_group *group = stmt_group_free_list;
if (group)
stmt_group_free_list = group->previous;
else
group = (struct stmt_group *) ggc_alloc (sizeof (struct stmt_group));
group->previous = current_stmt_group;
group->stmt_list = group->block = group->cleanups = NULL_TREE;
current_stmt_group = group;
}
void
add_stmt (tree gnu_stmt)
{
append_to_statement_list (gnu_stmt, ¤t_stmt_group->stmt_list);
if (global_bindings_p ())
walk_tree (&gnu_stmt, mark_visited, NULL, NULL);
}
void
add_stmt_with_node (tree gnu_stmt, Node_Id gnat_node)
{
if (Present (gnat_node))
annotate_with_node (gnu_stmt, gnat_node);
add_stmt (gnu_stmt);
}
void
add_decl_expr (tree gnu_decl, Entity_Id gnat_entity)
{
tree gnu_stmt;
if (!DECL_P (gnu_decl)
|| (TREE_CODE (gnu_decl) == TYPE_DECL
&& TREE_CODE (TREE_TYPE (gnu_decl)) == UNCONSTRAINED_ARRAY_TYPE))
return;
gnu_stmt = build1 (DECL_EXPR, void_type_node, gnu_decl);
if (!global_bindings_p ())
add_stmt_with_node (gnu_stmt, gnat_entity);
else
{
walk_tree (&gnu_stmt, mark_visited, NULL, NULL);
if (TREE_CODE (gnu_decl) == VAR_DECL
|| TREE_CODE (gnu_decl) == CONST_DECL)
{
walk_tree (&DECL_SIZE (gnu_decl), mark_visited, NULL, NULL);
walk_tree (&DECL_SIZE_UNIT (gnu_decl), mark_visited, NULL, NULL);
walk_tree (&DECL_INITIAL (gnu_decl), mark_visited, NULL, NULL);
}
}
if (TREE_CODE (gnu_decl) == VAR_DECL && DECL_INITIAL (gnu_decl))
{
tree gnu_init = DECL_INITIAL (gnu_decl);
tree gnu_lhs = NULL_TREE;
if (TREE_CODE (TREE_TYPE (gnu_decl)) == RECORD_TYPE
&& TYPE_IS_PADDING_P (TREE_TYPE (gnu_decl)))
gnu_lhs
= convert (TREE_TYPE (TYPE_FIELDS (TREE_TYPE (gnu_decl))), gnu_decl);
else if (TREE_STATIC (gnu_decl)
&& !initializer_constant_valid_p (gnu_init,
TREE_TYPE (gnu_decl)))
gnu_lhs = gnu_decl;
if (gnu_lhs)
{
tree gnu_assign_stmt
= build_binary_op (MODIFY_EXPR, NULL_TREE,
gnu_lhs, DECL_INITIAL (gnu_decl));
DECL_INITIAL (gnu_decl) = 0;
TREE_READONLY (gnu_decl) = 0;
annotate_with_locus (gnu_assign_stmt,
DECL_SOURCE_LOCATION (gnu_decl));
add_stmt (gnu_assign_stmt);
}
}
}
static tree
mark_visited (tree *tp, int *walk_subtrees, void *data ATTRIBUTE_UNUSED)
{
if (TREE_VISITED (*tp))
*walk_subtrees = 0;
else if (!TYPE_IS_DUMMY_P (*tp))
TREE_VISITED (*tp) = 1;
if (TYPE_P (*tp))
TYPE_SIZES_GIMPLIFIED (*tp) = 1;
return NULL_TREE;
}
static tree
mark_unvisited (tree *tp, int *walk_subtrees ATTRIBUTE_UNUSED,
void *data ATTRIBUTE_UNUSED)
{
TREE_VISITED (*tp) = 0;
return NULL_TREE;
}
static void
add_cleanup (tree gnu_cleanup)
{
append_to_statement_list (gnu_cleanup, ¤t_stmt_group->cleanups);
}
void
set_block_for_group (tree gnu_block)
{
gcc_assert (!current_stmt_group->block);
current_stmt_group->block = gnu_block;
}
static tree
end_stmt_group ()
{
struct stmt_group *group = current_stmt_group;
tree gnu_retval = group->stmt_list;
if (gnu_retval == NULL_TREE)
gnu_retval = alloc_stmt_list ();
if (group->cleanups)
gnu_retval = build2 (TRY_FINALLY_EXPR, void_type_node, gnu_retval,
group->cleanups);
if (current_stmt_group->block)
gnu_retval = build3 (BIND_EXPR, void_type_node, BLOCK_VARS (group->block),
gnu_retval, group->block);
current_stmt_group = group->previous;
group->previous = stmt_group_free_list;
stmt_group_free_list = group;
return gnu_retval;
}
static void
add_stmt_list (List_Id gnat_list)
{
Node_Id gnat_node;
if (Present (gnat_list))
for (gnat_node = First (gnat_list); Present (gnat_node);
gnat_node = Next (gnat_node))
add_stmt (gnat_to_gnu (gnat_node));
}
static tree
build_stmt_group (List_Id gnat_list, bool binding_p)
{
start_stmt_group ();
if (binding_p)
gnat_pushlevel ();
add_stmt_list (gnat_list);
if (binding_p)
gnat_poplevel ();
return end_stmt_group ();
}
static void
push_stack (tree *gnu_stack_ptr, tree gnu_purpose, tree gnu_value)
{
tree gnu_node = gnu_stack_free_list;
if (gnu_node)
{
gnu_stack_free_list = TREE_CHAIN (gnu_node);
TREE_CHAIN (gnu_node) = *gnu_stack_ptr;
TREE_PURPOSE (gnu_node) = gnu_purpose;
TREE_VALUE (gnu_node) = gnu_value;
}
else
gnu_node = tree_cons (gnu_purpose, gnu_value, *gnu_stack_ptr);
*gnu_stack_ptr = gnu_node;
}
static void
pop_stack (tree *gnu_stack_ptr)
{
tree gnu_node = *gnu_stack_ptr;
*gnu_stack_ptr = TREE_CHAIN (gnu_node);
TREE_CHAIN (gnu_node) = gnu_stack_free_list;
gnu_stack_free_list = gnu_node;
}
void
gnat_expand_stmt (tree gnu_stmt)
{
#if 0
tree gnu_elmt, gnu_elmt_2;
#endif
switch (TREE_CODE (gnu_stmt))
{
#if 0
case USE_STMT:
gnu_elmt = gen_rtx_ASM_INPUT (VOIDmode, "");
MEM_VOLATILE_P (gnu_elmt) = 1;
emit_insn (gnu_elmt);
gnu_elmt = expand_expr (TREE_OPERAND (gnu_stmt, 0), NULL_RTX, VOIDmode,
modifier);
emit_insn (gen_rtx_USE (VOIDmode, ));
return target;
#endif
default:
gcc_unreachable ();
}
}
int
gnat_gimplify_expr (tree *expr_p, tree *pre_p, tree *post_p ATTRIBUTE_UNUSED)
{
tree expr = *expr_p;
if (IS_ADA_STMT (expr))
return gnat_gimplify_stmt (expr_p);
switch (TREE_CODE (expr))
{
case NULL_EXPR:
if (AGGREGATE_TYPE_P (TREE_TYPE (expr)))
*expr_p = build1 (INDIRECT_REF, TREE_TYPE (expr),
convert (build_pointer_type (TREE_TYPE (expr)),
integer_zero_node));
else
{
*expr_p = create_tmp_var (TREE_TYPE (expr), NULL);
TREE_NO_WARNING (*expr_p) = 1;
}
append_to_statement_list (TREE_OPERAND (expr, 0), pre_p);
return GS_OK;
case UNCONSTRAINED_ARRAY_REF:
*expr_p = TREE_OPERAND (*expr_p, 0);
return GS_OK;
case ADDR_EXPR:
if (TREE_CODE (TREE_OPERAND (expr, 0)) == CONSTRUCTOR
&& TREE_CONSTANT (TREE_OPERAND (expr, 0)))
{
tree new_var
= create_tmp_var (TREE_TYPE (TREE_OPERAND (expr, 0)), "C");
TREE_READONLY (new_var) = 1;
TREE_STATIC (new_var) = 1;
TREE_ADDRESSABLE (new_var) = 1;
DECL_INITIAL (new_var) = TREE_OPERAND (expr, 0);
TREE_OPERAND (expr, 0) = new_var;
return GS_ALL_DONE;
}
return GS_UNHANDLED;
case COMPONENT_REF:
if (TYPE_FAT_POINTER_P (TREE_TYPE (TREE_OPERAND (*expr_p, 0)))
&& DECL_ORIGINAL_FIELD (TREE_OPERAND (*expr_p, 1)))
{
TREE_OPERAND (*expr_p, 1)
= DECL_ORIGINAL_FIELD (TREE_OPERAND (*expr_p, 1));
return GS_OK;
}
default:
return GS_UNHANDLED;
}
}
static enum gimplify_status
gnat_gimplify_stmt (tree *stmt_p)
{
tree stmt = *stmt_p;
switch (TREE_CODE (stmt))
{
case STMT_STMT:
*stmt_p = STMT_STMT_STMT (stmt);
return GS_OK;
case USE_STMT:
*stmt_p = NULL_TREE;
return GS_ALL_DONE;
case LOOP_STMT:
{
tree gnu_start_label = create_artificial_label ();
tree gnu_end_label = LOOP_STMT_LABEL (stmt);
*stmt_p = NULL_TREE;
append_to_statement_list (build1 (LABEL_EXPR, void_type_node,
gnu_start_label),
stmt_p);
if (LOOP_STMT_TOP_COND (stmt))
append_to_statement_list (build3 (COND_EXPR, void_type_node,
LOOP_STMT_TOP_COND (stmt),
alloc_stmt_list (),
build1 (GOTO_EXPR,
void_type_node,
gnu_end_label)),
stmt_p);
append_to_statement_list (LOOP_STMT_BODY (stmt), stmt_p);
if (LOOP_STMT_BOT_COND (stmt))
append_to_statement_list (build3 (COND_EXPR, void_type_node,
LOOP_STMT_BOT_COND (stmt),
alloc_stmt_list (),
build1 (GOTO_EXPR,
void_type_node,
gnu_end_label)),
stmt_p);
if (LOOP_STMT_UPDATE (stmt))
append_to_statement_list (LOOP_STMT_UPDATE (stmt), stmt_p);
append_to_statement_list (build1 (GOTO_EXPR, void_type_node,
gnu_start_label),
stmt_p);
append_to_statement_list (build1 (LABEL_EXPR, void_type_node,
gnu_end_label),
stmt_p);
return GS_OK;
}
case EXIT_STMT:
*stmt_p = build1 (GOTO_EXPR, void_type_node, EXIT_STMT_LABEL (stmt));
if (EXIT_STMT_COND (stmt))
*stmt_p = build3 (COND_EXPR, void_type_node,
EXIT_STMT_COND (stmt), *stmt_p, alloc_stmt_list ());
return GS_OK;
default:
gcc_unreachable ();
}
}
static void
elaborate_all_entities (Node_Id gnat_node)
{
Entity_Id gnat_with_clause, gnat_entity;
if (!present_gnu_tree (gnat_node))
save_gnu_tree (gnat_node, integer_zero_node, true);
for (gnat_with_clause = First (Context_Items (gnat_node));
Present (gnat_with_clause);
gnat_with_clause = Next (gnat_with_clause))
if (Nkind (gnat_with_clause) == N_With_Clause
&& !present_gnu_tree (Library_Unit (gnat_with_clause))
&& Library_Unit (gnat_with_clause) != Library_Unit (Cunit (Main_Unit)))
{
elaborate_all_entities (Library_Unit (gnat_with_clause));
if (Ekind (Entity (Name (gnat_with_clause))) == E_Package)
{
for (gnat_entity = First_Entity (Entity (Name (gnat_with_clause)));
Present (gnat_entity);
gnat_entity = Next_Entity (gnat_entity))
if (Is_Public (gnat_entity)
&& Convention (gnat_entity) != Convention_Intrinsic
&& Ekind (gnat_entity) != E_Package
&& Ekind (gnat_entity) != E_Package_Body
&& Ekind (gnat_entity) != E_Operator
&& !(IN (Ekind (gnat_entity), Type_Kind)
&& !Is_Frozen (gnat_entity))
&& !((Ekind (gnat_entity) == E_Procedure
|| Ekind (gnat_entity) == E_Function)
&& Is_Intrinsic_Subprogram (gnat_entity))
&& !IN (Ekind (gnat_entity), Named_Kind)
&& !IN (Ekind (gnat_entity), Generic_Unit_Kind))
gnat_to_gnu_entity (gnat_entity, NULL_TREE, 0);
}
else if (Ekind (Entity (Name (gnat_with_clause))) == E_Generic_Package)
{
Node_Id gnat_body
= Corresponding_Body (Unit (Library_Unit (gnat_with_clause)));
while (Present (gnat_body)
&& Nkind (gnat_body) != N_Compilation_Unit)
gnat_body = Parent (gnat_body);
if (Present (gnat_body))
elaborate_all_entities (gnat_body);
}
}
if (Nkind (Unit (gnat_node)) == N_Package_Body && type_annotate_only)
elaborate_all_entities (Library_Unit (gnat_node));
}
static void
process_freeze_entity (Node_Id gnat_node)
{
Entity_Id gnat_entity = Entity (gnat_node);
tree gnu_old;
tree gnu_new;
tree gnu_init
= (Nkind (Declaration_Node (gnat_entity)) == N_Object_Declaration
&& present_gnu_tree (Declaration_Node (gnat_entity)))
? get_gnu_tree (Declaration_Node (gnat_entity)) : NULL_TREE;
if (Ekind (gnat_entity) == E_Package)
{
insert_code_for
(Parent (Corresponding_Body
(Parent (Declaration_Node (gnat_entity)))));
return;
}
gnu_old
= present_gnu_tree (gnat_entity) ? get_gnu_tree (gnat_entity) : 0;
if (Present (Address_Clause (gnat_entity)))
gnu_old = 0;
if (Ekind (gnat_entity) == E_Class_Wide_Type
|| (Ekind (gnat_entity) == E_Class_Wide_Subtype
&& Present (Equivalent_Type (gnat_entity))))
return;
if (gnu_old
&& TREE_CODE (gnu_old) == FUNCTION_DECL
&& (Ekind (gnat_entity) == E_Function
|| Ekind (gnat_entity) == E_Procedure))
return;
if (gnu_old
&& !(TREE_CODE (gnu_old) == TYPE_DECL
&& TYPE_IS_DUMMY_P (TREE_TYPE (gnu_old))))
{
gcc_assert ((IN (Ekind (gnat_entity), Incomplete_Or_Private_Kind)
&& Present (Full_View (gnat_entity))
&& No (Freeze_Node (Full_View (gnat_entity))))
|| Is_Concurrent_Type (gnat_entity));
return;
}
if (gnu_old)
{
save_gnu_tree (gnat_entity, NULL_TREE, false);
if (IN (Ekind (gnat_entity), Incomplete_Or_Private_Kind)
&& Present (Full_View (gnat_entity))
&& present_gnu_tree (Full_View (gnat_entity)))
save_gnu_tree (Full_View (gnat_entity), NULL_TREE, false);
if (Present (Class_Wide_Type (gnat_entity))
&& Class_Wide_Type (gnat_entity) != gnat_entity)
save_gnu_tree (Class_Wide_Type (gnat_entity), NULL_TREE, false);
}
if (IN (Ekind (gnat_entity), Incomplete_Or_Private_Kind)
&& Present (Full_View (gnat_entity)))
{
gnu_new = gnat_to_gnu_entity (Full_View (gnat_entity), NULL_TREE, 1);
if (!present_gnu_tree (gnat_entity))
save_gnu_tree (gnat_entity, gnu_new, false);
if (Present (Class_Wide_Type (gnat_entity))
&& Class_Wide_Type (gnat_entity) != gnat_entity)
save_gnu_tree (Class_Wide_Type (gnat_entity), gnu_new, false);
}
else
gnu_new = gnat_to_gnu_entity (gnat_entity, gnu_init, 1);
if (gnu_old)
update_pointer_to (TYPE_MAIN_VARIANT (TREE_TYPE (gnu_old)),
TREE_TYPE (gnu_new));
}
static void
process_inlined_subprograms (Node_Id gnat_node)
{
Entity_Id gnat_entity;
Node_Id gnat_body;
if (optimize > 0 && !flag_no_inline)
for (gnat_entity = First_Inlined_Subprogram (gnat_node);
Present (gnat_entity);
gnat_entity = Next_Inlined_Subprogram (gnat_entity))
{
gnat_body = Parent (Declaration_Node (gnat_entity));
if (Nkind (gnat_body) != N_Subprogram_Body)
{
if (No (Corresponding_Body (gnat_body)))
continue;
gnat_body
= Parent (Declaration_Node (Corresponding_Body (gnat_body)));
}
if (Present (gnat_body))
{
gnat_to_gnu_entity (gnat_entity, NULL_TREE, 0);
add_stmt (gnat_to_gnu (gnat_body));
}
}
}
static void
process_decls (List_Id gnat_decls, List_Id gnat_decls2,
Node_Id gnat_end_list, bool pass1p, bool pass2p)
{
List_Id gnat_decl_array[2];
Node_Id gnat_decl;
int i;
gnat_decl_array[0] = gnat_decls, gnat_decl_array[1] = gnat_decls2;
if (pass1p)
for (i = 0; i <= 1; i++)
if (Present (gnat_decl_array[i]))
for (gnat_decl = First (gnat_decl_array[i]);
gnat_decl != gnat_end_list; gnat_decl = Next (gnat_decl))
{
if (Nkind (gnat_decl) == N_Package_Declaration
&& (Nkind (Specification (gnat_decl)
== N_Package_Specification)))
process_decls (Visible_Declarations (Specification (gnat_decl)),
Private_Declarations (Specification (gnat_decl)),
Empty, true, false);
else if (Nkind (gnat_decl) == N_Freeze_Entity)
{
process_freeze_entity (gnat_decl);
process_decls (Actions (gnat_decl), Empty, Empty, true, false);
}
else if (Nkind (gnat_decl) == N_Package_Body
&& Present (Freeze_Node (Corresponding_Spec (gnat_decl))))
record_code_position (gnat_decl);
else if (Nkind (gnat_decl) == N_Package_Body_Stub
&& Present (Library_Unit (gnat_decl))
&& Present (Freeze_Node
(Corresponding_Spec
(Proper_Body (Unit
(Library_Unit (gnat_decl)))))))
record_code_position
(Proper_Body (Unit (Library_Unit (gnat_decl))));
else if (Nkind (gnat_decl) == N_Subprogram_Body)
{
if (Acts_As_Spec (gnat_decl))
{
Node_Id gnat_subprog_id = Defining_Entity (gnat_decl);
if (Ekind (gnat_subprog_id) != E_Generic_Procedure
&& Ekind (gnat_subprog_id) != E_Generic_Function)
gnat_to_gnu_entity (gnat_subprog_id, NULL_TREE, 1);
}
}
else if (Nkind (gnat_decl) == N_Subprogram_Body_Stub)
{
Node_Id gnat_subprog_id =
Defining_Entity (Specification (gnat_decl));
if (Ekind (gnat_subprog_id) != E_Subprogram_Body
&& Ekind (gnat_subprog_id) != E_Generic_Procedure
&& Ekind (gnat_subprog_id) != E_Generic_Function)
gnat_to_gnu_entity (gnat_subprog_id, NULL_TREE, 1);
}
else if (Nkind (gnat_decl) == N_Task_Body_Stub
|| Nkind (gnat_decl) == N_Protected_Body_Stub)
;
else
add_stmt (gnat_to_gnu (gnat_decl));
}
if (pass2p)
for (i = 0; i <= 1; i++)
if (Present (gnat_decl_array[i]))
for (gnat_decl = First (gnat_decl_array[i]);
gnat_decl != gnat_end_list; gnat_decl = Next (gnat_decl))
{
if (Nkind (gnat_decl) == N_Subprogram_Body
|| Nkind (gnat_decl) == N_Subprogram_Body_Stub
|| Nkind (gnat_decl) == N_Task_Body_Stub
|| Nkind (gnat_decl) == N_Protected_Body_Stub)
add_stmt (gnat_to_gnu (gnat_decl));
else if (Nkind (gnat_decl) == N_Package_Declaration
&& (Nkind (Specification (gnat_decl)
== N_Package_Specification)))
process_decls (Visible_Declarations (Specification (gnat_decl)),
Private_Declarations (Specification (gnat_decl)),
Empty, false, true);
else if (Nkind (gnat_decl) == N_Freeze_Entity)
process_decls (Actions (gnat_decl), Empty, Empty, false, true);
}
}
static tree
emit_range_check (tree gnu_expr, Entity_Id gnat_range_type)
{
tree gnu_range_type = get_unpadded_type (gnat_range_type);
tree gnu_low = TYPE_MIN_VALUE (gnu_range_type);
tree gnu_high = TYPE_MAX_VALUE (gnu_range_type);
tree gnu_compare_type = get_base_type (TREE_TYPE (gnu_expr));
if (INTEGRAL_TYPE_P (TREE_TYPE (gnu_expr))
&& (TYPE_PRECISION (gnu_compare_type)
< TYPE_PRECISION (get_base_type (gnu_range_type))))
return gnu_expr;
gnu_expr = protect_multiple_eval (gnu_expr);
return emit_check
(build_binary_op (TRUTH_ORIF_EXPR, integer_type_node,
invert_truthvalue
(build_binary_op (GE_EXPR, integer_type_node,
convert (gnu_compare_type, gnu_expr),
convert (gnu_compare_type, gnu_low))),
invert_truthvalue
(build_binary_op (LE_EXPR, integer_type_node,
convert (gnu_compare_type, gnu_expr),
convert (gnu_compare_type,
gnu_high)))),
gnu_expr, CE_Range_Check_Failed);
}
static tree
emit_index_check (tree gnu_array_object,
tree gnu_expr,
tree gnu_low,
tree gnu_high)
{
tree gnu_expr_check;
gnu_expr = protect_multiple_eval (gnu_expr);
gnu_expr_check = convert (get_base_type (TREE_TYPE (gnu_expr)), gnu_expr);
gnu_low = SUBSTITUTE_PLACEHOLDER_IN_EXPR (gnu_low, gnu_array_object);
gnu_high = SUBSTITUTE_PLACEHOLDER_IN_EXPR (gnu_high, gnu_array_object);
return emit_check
(build_binary_op (TRUTH_ORIF_EXPR, integer_type_node,
build_binary_op (LT_EXPR, integer_type_node,
gnu_expr_check,
convert (TREE_TYPE (gnu_expr_check),
gnu_low)),
build_binary_op (GT_EXPR, integer_type_node,
gnu_expr_check,
convert (TREE_TYPE (gnu_expr_check),
gnu_high))),
gnu_expr, CE_Index_Check_Failed);
}
static tree
emit_check (tree gnu_cond, tree gnu_expr, int reason)
{
tree gnu_call;
tree gnu_result;
gnu_call = build_call_raise (reason);
gnu_result = fold (build3 (COND_EXPR, TREE_TYPE (gnu_expr), gnu_cond,
build2 (COMPOUND_EXPR, TREE_TYPE (gnu_expr),
gnu_call, gnu_expr),
gnu_expr));
if (TREE_SIDE_EFFECTS (gnu_expr))
gnu_result
= build2 (COMPOUND_EXPR, TREE_TYPE (gnu_expr), gnu_expr, gnu_result);
else
TREE_SIDE_EFFECTS (gnu_result) = 0;
return save_expr (gnu_result);
}
static tree
convert_with_check (Entity_Id gnat_type, tree gnu_expr, bool overflowp,
bool rangep, bool truncatep)
{
tree gnu_type = get_unpadded_type (gnat_type);
tree gnu_in_type = TREE_TYPE (gnu_expr);
tree gnu_in_basetype = get_base_type (gnu_in_type);
tree gnu_base_type = get_base_type (gnu_type);
tree gnu_ada_base_type = get_ada_base_type (gnu_type);
tree gnu_result = gnu_expr;
if (!rangep && !overflowp && INTEGRAL_TYPE_P (gnu_base_type)
&& !FLOAT_TYPE_P (gnu_in_type))
return convert (gnu_type, gnu_expr);
if (TREE_CODE (gnu_type) != UNCONSTRAINED_ARRAY_TYPE)
gnu_result = convert (gnu_in_basetype, gnu_result);
if (overflowp
&& !(FLOAT_TYPE_P (gnu_base_type) && INTEGRAL_TYPE_P (gnu_in_basetype)))
{
tree gnu_input = protect_multiple_eval (gnu_result);
tree gnu_cond = integer_zero_node;
tree gnu_in_lb = TYPE_MIN_VALUE (gnu_in_basetype);
tree gnu_in_ub = TYPE_MAX_VALUE (gnu_in_basetype);
tree gnu_out_lb = TYPE_MIN_VALUE (gnu_base_type);
tree gnu_out_ub = TYPE_MAX_VALUE (gnu_base_type);
if (INTEGRAL_TYPE_P (gnu_in_basetype) && TYPE_UNSIGNED (gnu_in_basetype))
gnu_in_lb = convert (gnat_signed_type (gnu_in_basetype), gnu_in_lb);
if (INTEGRAL_TYPE_P (gnu_in_basetype)
&& !TYPE_UNSIGNED (gnu_in_basetype))
gnu_in_ub = convert (gnat_unsigned_type (gnu_in_basetype), gnu_in_ub);
if (INTEGRAL_TYPE_P (gnu_base_type) && TYPE_UNSIGNED (gnu_base_type))
gnu_out_lb = convert (gnat_signed_type (gnu_base_type), gnu_out_lb);
if (INTEGRAL_TYPE_P (gnu_base_type) && !TYPE_UNSIGNED (gnu_base_type))
gnu_out_ub = convert (gnat_unsigned_type (gnu_base_type), gnu_out_ub);
if (INTEGRAL_TYPE_P (gnu_in_basetype)
? tree_int_cst_lt (gnu_in_lb, gnu_out_lb)
: (FLOAT_TYPE_P (gnu_base_type)
? REAL_VALUES_LESS (TREE_REAL_CST (gnu_in_lb),
TREE_REAL_CST (gnu_out_lb))
: 1))
gnu_cond
= invert_truthvalue
(build_binary_op (GE_EXPR, integer_type_node,
gnu_input, convert (gnu_in_basetype,
gnu_out_lb)));
if (INTEGRAL_TYPE_P (gnu_in_basetype)
? tree_int_cst_lt (gnu_out_ub, gnu_in_ub)
: (FLOAT_TYPE_P (gnu_base_type)
? REAL_VALUES_LESS (TREE_REAL_CST (gnu_out_ub),
TREE_REAL_CST (gnu_in_lb))
: 1))
gnu_cond
= build_binary_op (TRUTH_ORIF_EXPR, integer_type_node, gnu_cond,
invert_truthvalue
(build_binary_op (LE_EXPR, integer_type_node,
gnu_input,
convert (gnu_in_basetype,
gnu_out_ub))));
if (!integer_zerop (gnu_cond))
gnu_result = emit_check (gnu_cond, gnu_input,
CE_Overflow_Check_Failed);
}
if (INTEGRAL_TYPE_P (gnu_ada_base_type) && FLOAT_TYPE_P (gnu_in_basetype)
&& !truncatep)
{
REAL_VALUE_TYPE half_minus_pred_half, pred_half;
tree gnu_conv, gnu_zero, gnu_comp, gnu_saved_result, calc_type;
tree gnu_pred_half, gnu_add_pred_half, gnu_subtract_pred_half;
const struct real_format *fmt;
calc_type = longest_float_type_node;
if (TREE_CODE (calc_type) == RECORD_TYPE
&& TYPE_IS_PADDING_P (calc_type))
calc_type = TREE_TYPE (TYPE_FIELDS (calc_type));
fmt = REAL_MODE_FORMAT (TYPE_MODE (calc_type));
real_2expN (&half_minus_pred_half, -(fmt->p) - 1);
REAL_ARITHMETIC (pred_half, MINUS_EXPR, dconsthalf,
half_minus_pred_half);
gnu_pred_half = build_real (calc_type, pred_half);
gnu_zero = convert (gnu_in_basetype, integer_zero_node);
gnu_saved_result = save_expr (gnu_result);
gnu_conv = convert (calc_type, gnu_saved_result);
gnu_comp = build2 (GE_EXPR, integer_type_node,
gnu_saved_result, gnu_zero);
gnu_add_pred_half
= build2 (PLUS_EXPR, calc_type, gnu_conv, gnu_pred_half);
gnu_subtract_pred_half
= build2 (MINUS_EXPR, calc_type, gnu_conv, gnu_pred_half);
gnu_result = build3 (COND_EXPR, calc_type, gnu_comp,
gnu_add_pred_half, gnu_subtract_pred_half);
}
if (TREE_CODE (gnu_ada_base_type) == INTEGER_TYPE
&& TYPE_HAS_ACTUAL_BOUNDS_P (gnu_ada_base_type)
&& TREE_CODE (gnu_result) == UNCONSTRAINED_ARRAY_REF)
gnu_result = unchecked_convert (gnu_ada_base_type, gnu_result, false);
else
gnu_result = convert (gnu_ada_base_type, gnu_result);
if (rangep
|| (TREE_CODE (gnu_base_type) == INTEGER_TYPE
&& TYPE_MODULAR_P (gnu_base_type) && overflowp))
gnu_result = emit_range_check (gnu_result, gnat_type);
return convert (gnu_type, gnu_result);
}
static bool
addressable_p (tree gnu_expr)
{
switch (TREE_CODE (gnu_expr))
{
case VAR_DECL:
case PARM_DECL:
case FUNCTION_DECL:
case RESULT_DECL:
return true;
case UNCONSTRAINED_ARRAY_REF:
case INDIRECT_REF:
case CONSTRUCTOR:
case NULL_EXPR:
case SAVE_EXPR:
return true;
case COMPONENT_REF:
return (!DECL_BIT_FIELD (TREE_OPERAND (gnu_expr, 1))
&& (!DECL_NONADDRESSABLE_P (TREE_OPERAND (gnu_expr, 1))
|| !flag_strict_aliasing)
&& addressable_p (TREE_OPERAND (gnu_expr, 0)));
case ARRAY_REF: case ARRAY_RANGE_REF:
case REALPART_EXPR: case IMAGPART_EXPR:
case NOP_EXPR:
return addressable_p (TREE_OPERAND (gnu_expr, 0));
case CONVERT_EXPR:
return (AGGREGATE_TYPE_P (TREE_TYPE (gnu_expr))
&& addressable_p (TREE_OPERAND (gnu_expr, 0)));
case VIEW_CONVERT_EXPR:
{
tree type = TREE_TYPE (gnu_expr);
tree inner_type = TREE_TYPE (TREE_OPERAND (gnu_expr, 0));
return (((TYPE_MODE (type) == TYPE_MODE (inner_type)
&& (TYPE_ALIGN (type) <= TYPE_ALIGN (inner_type)
|| TYPE_ALIGN (inner_type) >= BIGGEST_ALIGNMENT))
|| ((TYPE_MODE (type) == BLKmode
|| TYPE_MODE (inner_type) == BLKmode)
&& (TYPE_ALIGN (type) <= TYPE_ALIGN (inner_type)
|| TYPE_ALIGN (inner_type) >= BIGGEST_ALIGNMENT
|| TYPE_ALIGN_OK (type)
|| TYPE_ALIGN_OK (inner_type))))
&& addressable_p (TREE_OPERAND (gnu_expr, 0)));
}
default:
return false;
}
}
void
process_type (Entity_Id gnat_entity)
{
tree gnu_old
= present_gnu_tree (gnat_entity) ? get_gnu_tree (gnat_entity) : 0;
tree gnu_new;
if (Present (Freeze_Node (gnat_entity))
|| (IN (Ekind (gnat_entity), Incomplete_Or_Private_Kind)
&& Present (Full_View (gnat_entity))
&& Freeze_Node (Full_View (gnat_entity))
&& !present_gnu_tree (Full_View (gnat_entity))))
{
elaborate_entity (gnat_entity);
if (!gnu_old)
{
tree gnu_decl = create_type_decl (get_entity_name (gnat_entity),
make_dummy_type (gnat_entity),
NULL, false, false, gnat_entity);
save_gnu_tree (gnat_entity, gnu_decl, false);
if (IN (Ekind (gnat_entity), Incomplete_Or_Private_Kind)
&& Present (Full_View (gnat_entity)))
save_gnu_tree (Full_View (gnat_entity), gnu_decl, false);
}
return;
}
if (gnu_old)
{
if (TREE_CODE (gnu_old) != TYPE_DECL
|| !TYPE_IS_DUMMY_P (TREE_TYPE (gnu_old)))
{
gcc_assert (Is_Type (gnat_entity) && From_With_Type (gnat_entity));
return;
}
save_gnu_tree (gnat_entity, NULL_TREE, false);
}
gnu_new = gnat_to_gnu_entity (gnat_entity, NULL_TREE, 1);
gcc_assert (TREE_CODE (gnu_new) == TYPE_DECL);
if (gnu_old)
update_pointer_to (TYPE_MAIN_VARIANT (TREE_TYPE (gnu_old)),
TREE_TYPE (gnu_new));
if (IN (Ekind (gnat_entity), Record_Kind)
&& Is_Concurrent_Record_Type (gnat_entity)
&& present_gnu_tree (Corresponding_Concurrent_Type (gnat_entity)))
{
tree gnu_task_old
= get_gnu_tree (Corresponding_Concurrent_Type (gnat_entity));
save_gnu_tree (Corresponding_Concurrent_Type (gnat_entity),
NULL_TREE, false);
save_gnu_tree (Corresponding_Concurrent_Type (gnat_entity),
gnu_new, false);
update_pointer_to (TYPE_MAIN_VARIANT (TREE_TYPE (gnu_task_old)),
TREE_TYPE (gnu_new));
}
}
static tree
assoc_to_constructor (Node_Id gnat_assoc, tree gnu_type)
{
tree gnu_list, gnu_result;
for (gnu_list = NULL_TREE; Present (gnat_assoc);
gnat_assoc = Next (gnat_assoc))
{
Node_Id gnat_field = First (Choices (gnat_assoc));
tree gnu_field = gnat_to_gnu_field_decl (Entity (gnat_field));
tree gnu_expr = gnat_to_gnu (Expression (gnat_assoc));
gcc_assert (No (Next (gnat_field)));
if (Present (Corresponding_Discriminant (Entity (gnat_field)))
&& Is_Tagged_Type (Scope (Entity (gnat_field))))
continue;
if (Do_Range_Check (Expression (gnat_assoc)))
gnu_expr = emit_range_check (gnu_expr, Etype (gnat_field));
gnu_expr = convert (TREE_TYPE (gnu_field), gnu_expr);
gnu_list = tree_cons (gnu_field, gnu_expr, gnu_list);
}
gnu_result = extract_values (gnu_list, gnu_type);
#ifdef ENABLE_CHECKING
{
tree gnu_field;
for (gnu_field = gnu_list; gnu_field; gnu_field = TREE_CHAIN (gnu_field))
gcc_assert (TREE_ADDRESSABLE (gnu_field));
}
#endif
return gnu_result;
}
static tree
pos_to_constructor (Node_Id gnat_expr, tree gnu_array_type,
Entity_Id gnat_component_type)
{
tree gnu_expr_list = NULL_TREE;
tree gnu_index = TYPE_MIN_VALUE (TYPE_DOMAIN (gnu_array_type));
tree gnu_expr;
for ( ; Present (gnat_expr); gnat_expr = Next (gnat_expr))
{
if (Nkind (gnat_expr) == N_Aggregate
&& TREE_CODE (TREE_TYPE (gnu_array_type)) == ARRAY_TYPE
&& TYPE_MULTI_ARRAY_P (TREE_TYPE (gnu_array_type)))
gnu_expr = pos_to_constructor (First (Expressions (gnat_expr)),
TREE_TYPE (gnu_array_type),
gnat_component_type);
else
{
gnu_expr = gnat_to_gnu (gnat_expr);
if (Do_Range_Check (gnat_expr))
gnu_expr = emit_range_check (gnu_expr, gnat_component_type);
}
gnu_expr_list
= tree_cons (gnu_index, convert (TREE_TYPE (gnu_array_type), gnu_expr),
gnu_expr_list);
gnu_index = int_const_binop (PLUS_EXPR, gnu_index, integer_one_node, 0);
}
return gnat_build_constructor (gnu_array_type, nreverse (gnu_expr_list));
}
static tree
extract_values (tree values, tree record_type)
{
tree result = NULL_TREE;
tree field, tem;
for (field = TYPE_FIELDS (record_type); field; field = TREE_CHAIN (field))
{
tree value = 0;
if ((tem = purpose_member (field, values)))
{
value = TREE_VALUE (tem);
TREE_ADDRESSABLE (tem) = 1;
}
else if (DECL_INTERNAL_P (field))
{
value = extract_values (values, TREE_TYPE (field));
if (TREE_CODE (value) == CONSTRUCTOR && !CONSTRUCTOR_ELTS (value))
value = 0;
}
else
for (tem = values; tem; tem = TREE_CHAIN (tem))
if (DECL_NAME (TREE_PURPOSE (tem)) == DECL_NAME (field))
{
value = convert (TREE_TYPE (field), TREE_VALUE (tem));
TREE_ADDRESSABLE (tem) = 1;
}
if (!value)
continue;
result = tree_cons (field, value, result);
}
return gnat_build_constructor (record_type, nreverse (result));
}
static tree
maybe_implicit_deref (tree exp)
{
if (POINTER_TYPE_P (TREE_TYPE (exp)) || TYPE_FAT_POINTER_P (TREE_TYPE (exp)))
exp = build_unary_op (INDIRECT_REF, NULL_TREE, exp);
if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE
&& TYPE_IS_PADDING_P (TREE_TYPE (exp)))
exp = convert (TREE_TYPE (TYPE_FIELDS (TREE_TYPE (exp))), exp);
return exp;
}
tree
protect_multiple_eval (tree exp)
{
tree type = TREE_TYPE (exp);
if (!TREE_SIDE_EFFECTS (exp))
return exp;
else if (TREE_CODE (exp) == NON_LVALUE_EXPR
|| TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR
|| TREE_CODE (exp) == VIEW_CONVERT_EXPR
|| TREE_CODE (exp) == INDIRECT_REF
|| TREE_CODE (exp) == UNCONSTRAINED_ARRAY_REF)
return build1 (TREE_CODE (exp), type,
protect_multiple_eval (TREE_OPERAND (exp, 0)));
if (TYPE_FAT_POINTER_P (type) || TYPE_MODE (type) != BLKmode)
return save_expr (exp);
else
return
build_unary_op (INDIRECT_REF, type,
save_expr (build_unary_op (ADDR_EXPR,
build_reference_type (type),
exp)));
}
tree
gnat_stabilize_reference (tree ref, bool force)
{
tree type = TREE_TYPE (ref);
enum tree_code code = TREE_CODE (ref);
tree result;
switch (code)
{
case VAR_DECL:
case PARM_DECL:
case RESULT_DECL:
return ref;
case NOP_EXPR:
case CONVERT_EXPR:
case FLOAT_EXPR:
case FIX_TRUNC_EXPR:
case FIX_FLOOR_EXPR:
case FIX_ROUND_EXPR:
case FIX_CEIL_EXPR:
case VIEW_CONVERT_EXPR:
case ADDR_EXPR:
result
= build1 (code, type,
gnat_stabilize_reference (TREE_OPERAND (ref, 0), force));
break;
case INDIRECT_REF:
case UNCONSTRAINED_ARRAY_REF:
result = build1 (code, type,
gnat_stabilize_reference_1 (TREE_OPERAND (ref, 0),
force));
break;
case COMPONENT_REF:
result = build3 (COMPONENT_REF, type,
gnat_stabilize_reference (TREE_OPERAND (ref, 0),
force),
TREE_OPERAND (ref, 1), NULL_TREE);
break;
case BIT_FIELD_REF:
result = build3 (BIT_FIELD_REF, type,
gnat_stabilize_reference (TREE_OPERAND (ref, 0), force),
gnat_stabilize_reference_1 (TREE_OPERAND (ref, 1),
force),
gnat_stabilize_reference_1 (TREE_OPERAND (ref, 2),
force));
break;
case ARRAY_REF:
case ARRAY_RANGE_REF:
result = build4 (code, type,
gnat_stabilize_reference (TREE_OPERAND (ref, 0), force),
gnat_stabilize_reference_1 (TREE_OPERAND (ref, 1),
force),
NULL_TREE, NULL_TREE);
break;
case COMPOUND_EXPR:
result = build2 (COMPOUND_EXPR, type,
gnat_stabilize_reference_1 (TREE_OPERAND (ref, 0),
force),
gnat_stabilize_reference (TREE_OPERAND (ref, 1),
force));
break;
default:
return ref;
case ERROR_MARK:
return error_mark_node;
}
TREE_READONLY (result) = TREE_READONLY (ref);
TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (ref);
TREE_SIDE_EFFECTS (result) |= TREE_SIDE_EFFECTS (ref);
return result;
}
static tree
gnat_stabilize_reference_1 (tree e, bool force)
{
enum tree_code code = TREE_CODE (e);
tree type = TREE_TYPE (e);
tree result;
if (TREE_CONSTANT (e) || code == SAVE_EXPR)
return e;
switch (TREE_CODE_CLASS (code))
{
case tcc_exceptional:
case tcc_type:
case tcc_declaration:
case tcc_comparison:
case tcc_statement:
case tcc_expression:
case tcc_reference:
if (code == COMPONENT_REF
&& TYPE_FAT_POINTER_P (TREE_TYPE (TREE_OPERAND (e, 0))))
result = build3 (COMPONENT_REF, type,
gnat_stabilize_reference_1 (TREE_OPERAND (e, 0),
force),
TREE_OPERAND (e, 1), TREE_OPERAND (e, 2));
else if (TREE_SIDE_EFFECTS (e) || force)
return save_expr (e);
else
return e;
break;
case tcc_constant:
return e;
case tcc_binary:
result = build2 (code, type,
gnat_stabilize_reference_1 (TREE_OPERAND (e, 0), force),
gnat_stabilize_reference_1 (TREE_OPERAND (e, 1),
force));
break;
case tcc_unary:
result = build1 (code, type,
gnat_stabilize_reference_1 (TREE_OPERAND (e, 0),
force));
break;
default:
gcc_unreachable ();
}
TREE_READONLY (result) = TREE_READONLY (e);
TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (e);
TREE_SIDE_EFFECTS (result) |= TREE_SIDE_EFFECTS (e);
return result;
}
extern char *__gnat_to_canonical_file_spec (char *);
bool
Sloc_to_locus (Source_Ptr Sloc, location_t *locus)
{
if (Sloc < 0)
return false;
locus->file
= IDENTIFIER_POINTER
(get_identifier
(__gnat_to_canonical_file_spec
(Get_Name_String (Full_Debug_Name (Get_Source_File_Index (Sloc))))));
locus->line = Get_Logical_Line_Number (Sloc);
ref_filename
= IDENTIFIER_POINTER
(get_identifier
(Get_Name_String (Debug_Source_Name (Get_Source_File_Index (Sloc)))));;
return true;
}
static void
annotate_with_node (tree node, Node_Id gnat_node)
{
location_t locus;
if (!Sloc_to_locus (Sloc (gnat_node), &locus))
return;
annotate_with_locus (node, locus);
}
void
post_error (const char *msg, Node_Id node)
{
String_Template temp;
Fat_Pointer fp;
temp.Low_Bound = 1, temp.High_Bound = strlen (msg);
fp.Array = msg, fp.Bounds = &temp;
if (Present (node))
Error_Msg_N (fp, node);
}
void
post_error_ne (const char *msg, Node_Id node, Entity_Id ent)
{
String_Template temp;
Fat_Pointer fp;
temp.Low_Bound = 1, temp.High_Bound = strlen (msg);
fp.Array = msg, fp.Bounds = &temp;
if (Present (node))
Error_Msg_NE (fp, node, ent);
}
void
post_error_ne_num (const char *msg, Node_Id node, Entity_Id ent, int n)
{
String_Template temp;
Fat_Pointer fp;
temp.Low_Bound = 1, temp.High_Bound = strlen (msg);
fp.Array = msg, fp.Bounds = &temp;
Error_Msg_Uint_1 = UI_From_Int (n);
if (Present (node))
Error_Msg_NE (fp, node, ent);
}
void
post_error_ne_tree (const char *msg, Node_Id node, Entity_Id ent, tree t)
{
char *newmsg = alloca (strlen (msg) + 1);
String_Template temp = {1, 0};
Fat_Pointer fp;
char start_yes, end_yes, start_no, end_no;
const char *p;
char *q;
fp.Array = newmsg, fp.Bounds = &temp;
if (host_integerp (t, 1)
#if HOST_BITS_PER_WIDE_INT > HOST_BITS_PER_INT
&&
compare_tree_int
(t, (((unsigned HOST_WIDE_INT) 1 << (HOST_BITS_PER_INT - 1)) - 1)) < 0
#endif
)
{
Error_Msg_Uint_1 = UI_From_Int (tree_low_cst (t, 1));
start_yes = '{', end_yes = '}', start_no = '[', end_no = ']';
}
else
start_yes = '[', end_yes = ']', start_no = '{', end_no = '}';
for (p = msg, q = newmsg; *p; p++)
{
if (*p == start_yes)
for (p++; *p != end_yes; p++)
*q++ = *p;
else if (*p == start_no)
for (p++; *p != end_no; p++)
;
else
*q++ = *p;
}
*q = 0;
temp.High_Bound = strlen (newmsg);
if (Present (node))
Error_Msg_NE (fp, node, ent);
}
void
post_error_ne_tree_2 (const char *msg,
Node_Id node,
Entity_Id ent,
tree t,
int num)
{
Error_Msg_Uint_2 = UI_From_Int (num);
post_error_ne_tree (msg, node, ent, t);
}
void
set_second_error_entity (Entity_Id e)
{
Error_Msg_Node_2 = e;
}
void
init_code_table (void)
{
gnu_codes[N_And_Then] = TRUTH_ANDIF_EXPR;
gnu_codes[N_Or_Else] = TRUTH_ORIF_EXPR;
gnu_codes[N_Op_And] = TRUTH_AND_EXPR;
gnu_codes[N_Op_Or] = TRUTH_OR_EXPR;
gnu_codes[N_Op_Xor] = TRUTH_XOR_EXPR;
gnu_codes[N_Op_Eq] = EQ_EXPR;
gnu_codes[N_Op_Ne] = NE_EXPR;
gnu_codes[N_Op_Lt] = LT_EXPR;
gnu_codes[N_Op_Le] = LE_EXPR;
gnu_codes[N_Op_Gt] = GT_EXPR;
gnu_codes[N_Op_Ge] = GE_EXPR;
gnu_codes[N_Op_Add] = PLUS_EXPR;
gnu_codes[N_Op_Subtract] = MINUS_EXPR;
gnu_codes[N_Op_Multiply] = MULT_EXPR;
gnu_codes[N_Op_Mod] = FLOOR_MOD_EXPR;
gnu_codes[N_Op_Rem] = TRUNC_MOD_EXPR;
gnu_codes[N_Op_Minus] = NEGATE_EXPR;
gnu_codes[N_Op_Abs] = ABS_EXPR;
gnu_codes[N_Op_Not] = TRUTH_NOT_EXPR;
gnu_codes[N_Op_Rotate_Left] = LROTATE_EXPR;
gnu_codes[N_Op_Rotate_Right] = RROTATE_EXPR;
gnu_codes[N_Op_Shift_Left] = LSHIFT_EXPR;
gnu_codes[N_Op_Shift_Right] = RSHIFT_EXPR;
gnu_codes[N_Op_Shift_Right_Arithmetic] = RSHIFT_EXPR;
}
#include "gt-ada-trans.h"