On 06/18/13 16:37:04, Gary Funck wrote:
> The initialization function is currently generated in tree form in the
> usual way (it will be gimplified when the gimple pass is run).
> 
> The code that is being generated is roughly equivalent to:
> 
>     static void
>     __upc_init_decls (void)
>     {
>       /* Compiler generated:
>          Initialize data related to UPC shared variables.  */
>     }
> 
>     static void (*const __upc_init_addr) (void)
>       __attribute__ ((section ("upc_init_array"))) = __upc_init_decls;
> 

I tried building a variable declaration along the
lines of __upc_init_addr above, by defining this function:

/* Create a static variable of type 'type'.
   This routine mimics the behavior of 'objc_create_temporary_var'
   with the change that it creates a static (file scoped) variable.
   If we continue to need this function, the two implementations
   should be unified.  */
static tree
upc_create_static_var (tree type, const char *name)
{
  tree id = (name != NULL) ? get_identifier (name) : NULL;
  tree decl = build_decl (input_location, VAR_DECL, id, type);
  TREE_USED (decl) = 1;
  TREE_EXTERNAL (decl) = 0;
  TREE_STATIC (decl) = 1;
  TREE_READONLY (decl) = 1;
  TREE_THIS_VOLATILE (decl) = 0;
  TREE_ADDRESSABLE (decl) = 0;
  DECL_PRESERVE_P (decl) = 1;
  DECL_ARTIFICIAL (decl) = 1;
  DECL_IGNORED_P (decl) = 1;
  DECL_CONTEXT (decl) = NULL;
  return decl;
}

and then using it as follows:

  init_func_ptr_type = build_pointer_type (TREE_TYPE (init_func));
  init_func_addr = upc_create_static_var (init_func_ptr_type, NULL);
  DECL_INITIAL (init_func_addr) = build_unary_op (loc, ADDR_EXPR,
                                                  init_func, 0);
  DECL_SECTION_NAME (init_func_addr) = build_string (
                                    strlen (UPC_INIT_ARRAY_SECTION_NAME),
                                    UPC_INIT_ARRAY_SECTION_NAME);


The variable declaration tree node looks about right to me.
However, it never makes it into the output assembler file.

What is the recommended method for making sure that the
static variable created above is associated with the current
translation unit and that its initialization makes it into
the assembler output file?

Thanks,
- Gary

Reply via email to