This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[lto] PATCH: more bones inside of lto_read_function_body.


Mark and Sandra,

I cleaned up the writing of the function header and added code inside
lto_read_function_body to read this.  This code will read the header and
call back into lto symbol table code to resolve all of the global
references and types used in the function but will not do much else. 
This code has not been tested awaiting an implementation of
lto_elf_map_function_body.  Of course, even with that, there is no code
yet to actually read the real body. But this will give you a poor man's
round trip of your code when that gets done.

There were other minor cleanups with regard to building the section name
and changing the implementation of a section in various of the
structures to be int64_t (all of this as per private conversations with
Mark.)

Kenny


2006-09-11  Kenneth Zadeck <zadeck@naturalbridge.com>
    * gcc/lto-function-out.c (output_block.field_decl_hash_table,
    output_block.fn_decl_hash_table, output_block.var_decl_hash_table,
    output_block.next_field_decl_index,
    noutput_block.next_fn_decl_index,
    output_block.next_var_decl_index,
    output_block.field_decls, output_block.fn_decls,
        output_block.var_decls):  New fields.
    (output_block.name_hash_table_index,
    output_block.name_next_index, output_block.local_decls):
    Deleted fields.
    (output_block.global_types): Renamed to types.
    (output_decl_ref): Deleted.
    (output_expr_operand): Reworked cases for *_DECL.
    (produce_asm): Reworked to use lto_function_header structure.
    Fixed computation of section_name.
    (output_data): Changed to match output_block structure.
    * gcc/dwarf2out.h (lto_out_ref.section) Changed to be int64_t.
    * gcc/lto/lto.h (lto_ref.section): Ditto.
    * gcc/lto-tags.h (LTO_minor_version): Upped.
    (struct lto_function_header): New structure.
    * gcc/lto/Make-lang.in (lto-read.o): More dependencies.
    * gcc/lto/lto-elf.c (lto_elf_map_fn_body): Fixed comment.
    * gcc/lto/lto-read.c (fun_in): New structure.
    * (load_globals): New function.
    * (lto_read_function_body): Added code to decode function header and
    load all of the global vars and types.

Index: gcc/lto-function-out.c
===================================================================
--- gcc/lto-function-out.c	(revision 116845)
+++ gcc/lto-function-out.c	(working copy)
@@ -207,42 +207,50 @@ struct output_block
   struct output_stream *string_stream;
 
   /* The hash table that contains the set of labels we have seen so
-     far and the indexs assigned to them.  */
+     far and the indexes assigned to them.  */
   htab_t label_hash_table;
   unsigned int next_label_index;
 
-  /* The hash table that contains the set of strings we have seen so
-     far and the indexs assigned to them.  */
+  /* The hash table that contains the set of local parm and var decls
+     we have seen so far and the indexes assigned to them.  */
   htab_t local_decl_hash_table;
   unsigned int next_local_decl_index;
+  VEC(tree,heap) *local_decls;
 
-  /* The hash table that contains the set of variable names we have
-     seen so far and the indexs assigned to them.  */
-  htab_t name_hash_table;
-  unsigned int next_name_index;
+  /* The hash table that contains the set of field_decls we have
+     seen so far and the indexes assigned to them.  */
+  htab_t field_decl_hash_table;
+  unsigned int next_field_decl_index;
+  VEC(tree,heap) *field_decls;
+
+  /* The hash table that contains the set of function_decls we have
+     seen so far and the indexes assigned to them.  */
+  htab_t fn_decl_hash_table;
+  unsigned int next_fn_decl_index;
+  VEC(tree,heap) *fn_decls;
+
+  /* The hash table that contains the set of var_decls we have
+     seen so far and the indexes assigned to them.  */
+  htab_t var_decl_hash_table;
+  unsigned int next_var_decl_index;
+  VEC(tree,heap) *var_decls;
 
   /* The hash table that contains the set of strings we have seen so
-     far and the indexs assigned to them.  */
+     far and the indexes assigned to them.  */
   htab_t string_hash_table;
   unsigned int next_string_index;
 
   /* The hash table that contains the set of type we have seen so far
-     and the indexs assigned to them.  */
+     and the indexes assigned to them.  */
   htab_t type_hash_table;
   unsigned int next_type_index;
+  VEC(tree,heap) *types;
 
   /* These are the last file and line that were seen in the stream.
      If the current node differs from these, it needs to insert
      something into the stream and fix these up.  */
   const char *last_file;
   int last_line;
-
-  /* The set of local, global decls and global types that have been
-     seen.  These will be generated last after the full set is
-     found.  */
-  VEC(tree,heap) *local_decls;
-  VEC(tree,heap) *global_decls;
-  VEC(tree,heap) *global_types;
 };
 
 /* The output stream that contains the abbrev table for all of the
@@ -638,19 +646,7 @@ output_type_ref (struct output_block *ob
   bool new = output_decl_index (ob->main_stream, ob->type_hash_table,
 				&ob->next_type_index, node);
   if (new)
-    VEC_safe_push (tree, heap, ob->global_types, node);
-}
-
-
-/* Look up NAME in the type table and write the uleb128 index for it.  */
-
-static void
-output_decl_ref (struct output_block *ob, tree name)
-{
-  bool new = output_decl_index (ob->main_stream, ob->name_hash_table,
-				&ob->next_name_index, name);
-  if (new)
-    VEC_safe_push (tree, heap, ob->global_decls, name);
+    VEC_safe_push (tree, heap, ob->types, node);
 }
 
 
@@ -1038,17 +1034,43 @@ output_expr_operand (struct output_block
       break;
 
     case CONST_DECL:
+      /* Just ignore these, Mark will make them disappear.  */
+      break;
+
     case FIELD_DECL:
+      {
+	bool new;
+	output_record_start (ob, NULL, NULL, tag);
+	
+	output_decl_index (ob->main_stream, ob->field_decl_hash_table,
+			   &ob->next_field_decl_index, expr);
+	if (new)
+	  VEC_safe_push (tree, heap, ob->field_decls, expr);
+      }
+      break;
+
     case FUNCTION_DECL:
-      output_record_start (ob, NULL, NULL, tag);
-      output_decl_ref (ob, expr);
+      {
+	bool new;
+	output_record_start (ob, NULL, NULL, tag);
+	
+	output_decl_index (ob->main_stream, ob->fn_decl_hash_table,
+			   &ob->next_fn_decl_index, expr);
+	if (new)
+	  VEC_safe_push (tree, heap, ob->fn_decls, expr);
+      }
       break;
 
     case VAR_DECL:
       if (TREE_STATIC (expr) || DECL_EXTERNAL (expr))
 	{
+	  bool new;
 	  output_record_start (ob, NULL, NULL, tag);
-	  output_decl_ref (ob, expr);
+
+	  output_decl_index (ob->main_stream, ob->var_decl_hash_table,
+			     &ob->next_var_decl_index, expr);
+	  if (new)
+	    VEC_safe_push (tree, heap, ob->var_decls, expr);
 	}
       else
 	{
@@ -1407,118 +1429,88 @@ output_bb (struct output_block *ob, basi
     }
 }
 
-#define SECTION_NAME_SIZE 1024
 
 /* Create the header in the file.  */
 
 static void
 produce_asm (struct output_block *ob, tree function)
 {
-  const int bit_size = HOST_BITS_PER_WIDE_INT;
-  const int byte_size = bit_size / 8;
   int index;
   tree decl;
   tree type;
-  tree fn = DECL_ASSEMBLER_NAME (function);
-  char * section_name = xmalloc (SECTION_NAME_SIZE + 1);
-  const char * function_name;
-
-  /* The entire header is stream computed here.  */
-  unsigned int header_size = 8 + (7 * byte_size);
+  const char *fn = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (function));
+  const char *section_name = concat (LTO_SECTION_NAME_PREFIX, fn, NULL);
+  struct lto_function_header function_header;
   lto_out_ref out_ref = {0, NULL, NULL};
 
-  gcc_assert (fn);
-  function_name = IDENTIFIER_POINTER (fn);
-  sprintf (section_name, "%s%s", LTO_SECTION_NAME_PREFIX, function_name);
+  /* The entire header is stream computed here.  */
   switch_to_section (get_section (section_name, SECTION_DEBUG, function));
-
+  
   /* Write the header which says how to decode the pieces of the
      function.  */
-  dw2_asm_output_data (2, LTO_major_version, "major version");
-  dw2_asm_output_data (2, LTO_minor_version, "minor version");
-  dw2_asm_output_data (2, bit_size, "bitsize");
-  dw2_asm_output_data (2, 0, "padding");
-
-  dw2_asm_output_data (byte_size, VEC_length (tree, ob->global_decls), "#decls");
-  dw2_asm_output_data (byte_size, VEC_length (tree, ob->global_types), "#types");
-
-  header_size += 2 * byte_size *
-    (VEC_length (tree, ob->global_decls)
-     + VEC_length (tree, ob->global_types));
-  dw2_asm_output_data (byte_size, header_size, "start of gimple");
-  dw2_asm_output_data (byte_size, 0, "compressed data size");
-
-  dw2_asm_output_data (byte_size, ob->local_decl_stream->total_size,
-		       "local decl size");
-  dw2_asm_output_data (byte_size, ob->main_stream->total_size,
-		       "gimple size");
-  dw2_asm_output_data (byte_size, ob->string_stream->total_size,
-		       "string size");
-
-  /* Write the global decl references.  */
-  for (index = 0; VEC_iterate(tree, ob->global_decls, index, decl); index++)
-    {
-      const char * name;
-      tree tree_name;
-      switch (TREE_CODE (decl))
-	{
-	case CONST_DECL:
-#ifdef GIMPLE_SYMBOL_TABLE_WORKS
-	  lto_const_ref (decl, out_ref);
-#else
-	  out_ref.section = 0;
-	  out_ref.base_label = "0";
-	  out_ref.label = "0";
-#endif
-	  break;
+  function_header.major_version = LTO_major_version;
+  function_header.minor_version = LTO_minor_version;
+  
+  function_header.num_field_decls = VEC_length (tree, ob->field_decls);
+  function_header.num_fn_decls = VEC_length (tree, ob->fn_decls);
+  function_header.num_var_decls = VEC_length (tree, ob->var_decls);
+  function_header.num_types = VEC_length (tree, ob->types);
+
+  function_header.compressed_size = 0;
+  function_header.local_decls_size = ob->local_decl_stream->total_size;
+  function_header.main_size = ob->main_stream->total_size;
+  function_header.string_size = ob->string_stream->total_size;
 
-	case FIELD_DECL:
+  assemble_string ((const char *)&function_header, 
+		   sizeof (struct lto_function_header));
+
+  /* Write the global type references.  */
+  for (index = 0; VEC_iterate(tree, ob->field_decls, index, decl); index++)
+    {
 #ifdef GIMPLE_SYMBOL_TABLE_WORKS
-	  lto_field_ref (decl, out_ref);
+      lto_field_ref (decl, out_ref);
 #else
-	  out_ref.section = 0;
-	  out_ref.base_label = "0";
-	  out_ref.label = "0";
+      out_ref.section = 0;
+      out_ref.base_label = "0";
+      out_ref.label = "0";
 #endif
-	  break;
+      dw2_asm_output_data (8, out_ref.section, " ");
+      dw2_asm_output_delta (8, out_ref.label,
+			    out_ref.base_label, " ");
+    }
 
-	case FUNCTION_DECL:
+  /* Write the global type references.  */
+  for (index = 0; VEC_iterate(tree, ob->fn_decls, index, decl); index++)
+    {
 #ifdef GIMPLE_SYMBOL_TABLE_WORKS
-	  lto_fn_ref (decl, &out_ref);
+      lto_fn_ref (delc, &out_ref);
 #else
-	  out_ref.section = 0;
-	  out_ref.base_label = "0";
-	  out_ref.label = "0";
+      out_ref.section = 0;
+      out_ref.base_label = "0";
+      out_ref.label = "0";
 #endif
-	  break;
+      dw2_asm_output_data (8, out_ref.section, " ");
+      dw2_asm_output_delta (8, out_ref.label,
+			    out_ref.base_label, " ");
+    }
 
-	case VAR_DECL:
+  /* Write the global type references.  */
+  for (index = 0; VEC_iterate(tree, ob->var_decls, index, decl); index++)
+    {
 #ifdef GIMPLE_SYMBOL_TABLE_WORKS
-	  lto_var_ref (decl, &out_ref);
+      lto_var_ref (decl, &out_ref);
 #else
-	  out_ref.section = 0;
-	  out_ref.base_label = "0";
-	  out_ref.label = "0";
+      out_ref.section = 0;
+      out_ref.base_label = "0";
+      out_ref.label = "0";
 #endif
-	  break;
-
-	default:
-	  gcc_unreachable ();
-	  break;
-	}
-      tree_name = DECL_NAME (decl);
-      if (tree_name == NULL_TREE)
-	name = " ";
-      else
-	name = IDENTIFIER_POINTER (tree_name);
-
-      dw2_asm_output_data (byte_size, out_ref.section, name);
-      dw2_asm_output_delta (byte_size, out_ref.label,
+      dw2_asm_output_data (8, out_ref.section, " ");
+      dw2_asm_output_delta (8, out_ref.label,
 			    out_ref.base_label, " ");
     }
 
   /* Write the global type references.  */
-  for (index = 0; VEC_iterate(tree, ob->global_types, index, type); index++)
+  for (index = 0; VEC_iterate(tree, ob->types, index, type); index++)
     {
 #ifdef GIMPLE_SYMBOL_TABLE_WORKS
       lto_type_ref (type, &out_ref);
@@ -1527,8 +1519,8 @@ produce_asm (struct output_block *ob, tr
       out_ref.base_label = "0";
       out_ref.label = "0";
 #endif
-      dw2_asm_output_data (byte_size, out_ref.section, " ");
-      dw2_asm_output_delta (byte_size, out_ref.label,
+      dw2_asm_output_data (8, out_ref.section, " ");
+      dw2_asm_output_delta (8, out_ref.label,
 			    out_ref.base_label, " ");
     }
 
@@ -1639,7 +1631,11 @@ output_function (tree function)
     = htab_create (37, hash_label_slot_node, eq_label_slot_node, free);
   ob->local_decl_hash_table
     = htab_create (37, hash_decl_slot_node, eq_decl_slot_node, free);
-  ob->name_hash_table
+  ob->field_decl_hash_table
+    = htab_create (37, hash_decl_slot_node, eq_decl_slot_node, free);
+  ob->fn_decl_hash_table
+    = htab_create (37, hash_decl_slot_node, eq_decl_slot_node, free);
+  ob->var_decl_hash_table
     = htab_create (37, hash_decl_slot_node, eq_decl_slot_node, free);
   ob->string_hash_table
     = htab_create (37, hash_string_slot_node, eq_string_slot_node, free);
@@ -1688,12 +1684,16 @@ output_function (tree function)
 
   htab_delete (ob->label_hash_table);
   htab_delete (ob->local_decl_hash_table);
-  htab_delete (ob->name_hash_table);
+  htab_delete (ob->field_decl_hash_table);
+  htab_delete (ob->fn_decl_hash_table);
+  htab_delete (ob->var_decl_hash_table);
   htab_delete (ob->string_hash_table);
   htab_delete (ob->type_hash_table);
   VEC_free (tree, heap, ob->local_decls);
-  VEC_free (tree, heap, ob->global_decls);
-  VEC_free (tree, heap, ob->global_types);
+  VEC_free (tree, heap, ob->field_decls);
+  VEC_free (tree, heap, ob->fn_decls);
+  VEC_free (tree, heap, ob->var_decls);
+  VEC_free (tree, heap, ob->types);
   free (ob);
 }
 
Index: gcc/dwarf2out.h
===================================================================
--- gcc/dwarf2out.h	(revision 116845)
+++ gcc/dwarf2out.h	(working copy)
@@ -46,7 +46,7 @@ extern void dwarf2out_set_demangle_name_
 /* A reference to a global entity.  */
 typedef struct lto_out_ref {
   /* The index of the compilation unit containing the entity.  */
-  unsigned section;
+  int64_t section;
   /* The label corresponding to the base of the DWARF 2 section
      containing this entity.  This string must not be freed by the
      caller.  */
Index: gcc/lto-tags.h
===================================================================
--- gcc/lto-tags.h	(revision 116845)
+++ gcc/lto-tags.h	(working copy)
@@ -27,7 +27,7 @@
 #include "sbitmap.h"
 
 #define LTO_major_version 0
-#define LTO_minor_version 1
+#define LTO_minor_version 2
 
 /* This file is one header in a collection of files that write the
    gimple intermediate code for a function into the assembly stream
@@ -36,41 +36,43 @@
    This comment describes, in rough terms the methods used to encode
    that gimple stream.  This does not describe gimple itself.
 
-   The encoding for a function consists of 6 (7 in debugging mode),
+   The encoding for a function consists of 8 (9 in debugging mode),
    sections of information.
 
    1) The header.
-   2) Global decl refs.
-   3) Type refs.
-   4) Gimple for local decls.
-   5) Gimple for the function.
-   6) Strings.
-   7) Redundant information to aid in debugging the stream.
+   2) FIELD_DECLS.
+   3) FUNCTION_DECLS.
+   4) global VAR_DECLS.
+   5) types.
+   6) Gimple for local decls.
+   7) Gimple for the function.
+   8) Strings.
+   9) Redundant information to aid in debugging the stream.
       This is only present if the compiler is built with
       LTO_STREAM_DEBUGGING defined.
 
-   Sections 1-3 are in plain text that can easily be read in the
-   assembly file.  Sections 4-6 will be zlib encoded in the future.
+   Sections 1-5 are in plain text that can easily be read in the
+   assembly file.  Sections 6-8 will be zlib encoded in the future.
 
    1) THE HEADER.
+*/
 
-     4 - 16 bit fields:
-       LTO_major_version.
-       LTO_minor_version.
-       word size with (in bits).
-       reserverd.
-
-     7 (or 9 if LTO_STREAM_DEBUGGING) word size fields:
-       # of global decl refs.
-       # of type refs.
-       Offset to start of (4).
-       Size of (4)
-       Size of (5)
-       Size of (6)
-       Offset to start of (7) if LTO_STREAM_DEBUGGING
-       Size of (7) if LTO_STREAM_DEBUGGING
+/* The is the first part of the record for a function in the .o file.  */
+struct lto_function_header
+{
+  int16_t major_version;     /* LTO_major_version. */
+  int16_t minor_version;     /* LTO_minor_version. */
+  int32_t num_field_decls;   /* Number of FIELD_DECLS.  */
+  int32_t num_fn_decls;      /* Number of FUNCTION_DECLS.  */
+  int32_t num_var_decls;     /* Number of non local VAR_DECLS.  */
+  int32_t num_types;         /* Number of types.  */
+  int32_t compressed_size;   /* Size compressed or 0 if not compressed.  */
+  int32_t local_decls_size;  /* Size of local par and var decl region. */
+  int32_t main_size;         /* Size of main gimple body of function.  */
+  int32_t string_size;       /* Size of the string table.  */
+}; 
 
-   2-3) THE GLOBAL DECLS AND TYPES.
+/* 2-5) THE GLOBAL DECLS AND TYPES.
 
      The global decls and types are encoded in the same way.  For each
      entry, there is a pair of words.  The first is the debugging
@@ -81,7 +83,7 @@
      a label for the debugging section.  This will cause more work for
      the linker but will make ln -r work properly.
 
-   4-5) GIMPLE FOR THE LOCAL DECLS AND THE FUNCTION BODY.
+   6-7) GIMPLE FOR THE LOCAL DECLS AND THE FUNCTION BODY.
 
      The gimple consists of a set of records.
 
@@ -97,7 +99,7 @@
 	 type         - If the tree code has a bit set in
                         lto_types_needed_for, a reference to the type
 			is generated.  This reference is an index into
-                        (3).  The index is encoded in uleb128 form.
+                        (6).  The index is encoded in uleb128 form.
 
 	 flags        - The set of flags defined for this tree code
 		        packed into a word where the low order 2 bits
@@ -138,7 +140,7 @@
 
      THE FUNCTION
 	
-     At the top level of (5) is the function. It consists of five
+     At the top level of (7) is the function. It consists of five
      pieces:
 
      LTO_function     - The tag.
@@ -192,12 +194,12 @@
 			  to terminate the statements and exception
 			  regions within this block.
 
-   6) STRINGS
+   8) STRINGS
 
      String are represented in the table as pairs, a length in ULEB128
      form followed by the data for the string.
 
-   7) STREAM DEBUGGING
+   9) STREAM DEBUGGING
 
      tbd
 */
@@ -395,7 +397,11 @@
    section name for the function.  */
 #define LTO_SECTION_NAME_PREFIX         ".lto_"
 
+/* This bitmap is indexed by gimple type codes and contains a 1 if the 
+   tree type needs to have the type written.  */
 extern sbitmap lto_types_needed_for;
 
+
+
 void lto_static_init (void);
 #endif /* lto-tags.h */
Index: gcc/lto/Make-lang.in
===================================================================
--- gcc/lto/Make-lang.in	(revision 116845)
+++ gcc/lto/Make-lang.in	(working copy)
@@ -83,7 +83,12 @@ lto/lto.o: lto/lto.c $(CONFIG_H) $(CGRAP
 	$(GGC_H) opts.h $(SYSTEM_H) toplev.h $(TM_H) $(LTO_H)
 lto/lto-elf.o: lto/lto-elf.c $(CONFIG_H) coretypes.h $(SYSTEM_H) \
 	toplev.h $(LTO_H) 
-lto/lto-read.o: lto/lto-read.c $(CONFIG_H) coretypes.h $(SYSTEM_H) \
-	$(LTO_H) $(TREE_GIMPLE_H)
 lto/lto-symtab.o: lto/lto-symtab.c $(CONFIG_H) coretypes.h \
-	$(SYSTEM_H) toplev.h $(LTO_H) lto/lto-tree.h
+	$(SYSTEM_H) toplev.h $(TREE_H) $(LTO_H) lto/lto-tree.h
+lto-read.o : lto-read.c $(CONFIG_H) $(SYSTEM_H) \
+	coretypes.h $(TM_H) toplev.h $(TREE_H) $(EXPR_H) $(FLAGS_H) \
+	$(PARAMS_H) input.h $(VARRAY_H) $(HASHTAB_H) langhooks.h \
+	$(BASIC_BLOCK_H) tree-iterator.h tree-pass.h tree-flow.h \
+	$(CGRAPH_H) $(FUNCTION_H) $(GGC_H) $(DIAGNOSTIC_H) \
+	except.h debug.h $(TIMEVAR_H) $(LTO_TAGS_H) lto-tree-flags.def \
+	lto-tree-tags.def output.h dwarf2asm.h dwarf2out.h 
Index: gcc/lto/lto-elf.c
===================================================================
--- gcc/lto/lto-elf.c	(revision 116845)
+++ gcc/lto/lto-elf.c	(working copy)
@@ -265,7 +265,7 @@ lto_elf_map_fn_body (lto_file *file ATTR
 		     const char *fn ATTRIBUTE_UNUSED)
 {
   /* ??? Look in the ELF file to find the actual data, which should be
-     in the section named ".lto_FN".  */
+     in the section named LTO_SECTION_NAME_PREFIX || "the function name".  */
   return (void *)0x1;
 }
 
Index: gcc/lto/lto.h
===================================================================
--- gcc/lto/lto.h	(revision 116845)
+++ gcc/lto/lto.h	(working copy)
@@ -108,7 +108,7 @@ struct lto_file
 typedef struct lto_ref
 {
   /* The DWARF compilation unit containing the entity.  */
-  unsigned section;
+  uint64_t section;
   /* The offset of the DIE corresponding to the entity.  */
   uint64_t offset;
 } lto_ref;
Index: gcc/lto/lto-read.c
===================================================================
--- gcc/lto/lto-read.c	(revision 116845)
+++ gcc/lto/lto-read.c	(working copy)
@@ -1,5 +1,8 @@
-/* LTO function reader.
+/* Read the gimple representation of a function and it's local
+   variables from the memory mapped representation of a a .o file.
+
    Copyright 2006 Free Software Foundation, Inc.
+   Contributed by Kenneth Zadeck <zadeck@naturalbridge.com>
 
 This file is part of GCC.
 
@@ -21,11 +24,137 @@ Boston, MA 02110-1301, USA.  */
 #include "config.h"
 #include "system.h"
 #include "coretypes.h"
+#include "tm.h"
+#include "toplev.h"
 #include "tree.h"
-#include "tree-gimple.h"
+#include "expr.h"
+#include "flags.h"
+#include "params.h"
+#include "input.h"
+#include "varray.h"
+#include "hashtab.h"
+#include "langhooks.h"
+#include "basic-block.h"
 #include "tree-iterator.h"
+#include "tree-pass.h"
+#include "tree-flow.h"
+#include "cgraph.h"
+#include "function.h"
+#include "ggc.h"
+#include "diagnostic.h"
+#include "except.h"
+#include "debug.h"
+#include "vec.h"
+#include "timevar.h"
+#include "dwarf2asm.h"
+#include "dwarf2out.h"
+#include "output.h"
+#include "lto-tags.h"
 #include "lto.h"
+#include <ctype.h>
+
+struct fun_in
+{
+  tree *field_decls;
+  tree *fn_decls;
+  tree *var_decls;
+  tree *types;
+};
+
+
+/* Load in the global vars and all of the types from the main symbol
+   table.  */
+static void
+load_globals (struct lto_function_header * header,
+	      lto_info_fd *fd,
+	      lto_context *context,	
+	      struct fun_in *fun_in, 
+	      lto_ref in_field_decls[] ATTRIBUTE_UNUSED,
+	      lto_ref in_fn_decls[],
+	      lto_ref in_var_decls[],
+	      lto_ref in_types[])
+{
+  int i;
+  fun_in->field_decls = xcalloc (header->num_field_decls, sizeof (tree*));
+  fun_in->fn_decls    = xcalloc (header->num_fn_decls, sizeof (tree*));
+  fun_in->var_decls   = xcalloc (header->num_var_decls, sizeof (tree*));
+  fun_in->types       = xcalloc (header->num_types, sizeof (tree*));
+
+  /* FIXME: The test for zero section can go away when everything gets
+     working.  */
+  /*
+  for (i=0; i<header->num_field_decls; i++)
+    if (in_field_decls[i].section)
+      fun_in->field_decls[i] 
+        = lto_resolve_field_ref (fd, context, in_field_decls[i]);
+  */
+
+  for (i=0; i<header->num_fn_decls; i++)
+    if (in_fn_decls[i].section)
+      fun_in->fn_decls[i] 
+	= lto_resolve_fn_ref (fd, context, &in_fn_decls[i]);
+
+  for (i=0; i<header->num_var_decls; i++)
+    if (in_var_decls[i].section)
+      fun_in->var_decls[i] 
+	= lto_resolve_var_ref (fd, context, &in_var_decls[i]);
+
+  for (i=0; i<header->num_types; i++)
+    if (in_types[i].section)
+      fun_in->types[i]
+	= lto_resolve_type_ref (fd, context, &in_types[i]);
+}
+
+
+void 
+lto_read_function_body (lto_info_fd *fd,
+			lto_context *context,
+			tree fn ATTRIBUTE_UNUSED,
+			const void *data)
+{
+  struct lto_function_header * header 
+    = (struct lto_function_header *) data;
+  struct fun_in fun_in;
+  int32_t fields_offset = sizeof (struct lto_function_header); 
+  int32_t fns_offset 
+    = fields_offset + 
+    (header->num_field_decls * sizeof (lto_ref));
+  int32_t vars_offset 
+    = fns_offset + 
+    (header->num_fn_decls * sizeof (lto_ref));
+  int32_t types_offset 
+    = vars_offset + 
+    (header->num_var_decls * sizeof (lto_ref));
+
+#if 0
+  int32_t locals_offset 
+    = types_offset + 
+    (header->num_types * sizeof (lto_ref));
+  int32_t main_offset = locals_offset + header->local_decls_size;
+  int32_t string_offset = main_offset + header->main_size;
+#endif
+
+  lto_ref *in_field_decls = (lto_ref*)(data + fields_offset);
+  lto_ref *in_fn_decls    = (lto_ref*)(data + fns_offset);
+  lto_ref *in_var_decls   = (lto_ref*)(data + vars_offset);
+  lto_ref *in_types       = (lto_ref*)(data + types_offset);
+
+#if 0
+  const char * local_decls = data + locals_offset;
+  const char * main_gimple = data + main_offset;
+  const char * strings     = data + string_offset;
+#endif
+
+  /* No upward compatibility here.  */
+  gcc_assert (header->major_version == LTO_major_version);
+  gcc_assert (header->minor_version == LTO_minor_version);
+
+  load_globals (header, fd, context, &fun_in, 
+		in_field_decls, in_fn_decls, 
+		in_var_decls, in_types);
+}
 
+#if 0
 void
 lto_read_function_body (lto_info_fd *fd ATTRIBUTE_UNUSED,
 			lto_context *context ATTRIBUTE_UNUSED,
@@ -48,3 +177,4 @@ lto_read_function_body (lto_info_fd *fd 
 
   return;
 }
+#endif

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]