diff options
author | gsvelto <gsvelto@138bc75d-0d04-0410-961f-82ee72b054a4> | 2009-05-05 22:22:47 +0000 |
---|---|---|
committer | gsvelto <gsvelto@138bc75d-0d04-0410-961f-82ee72b054a4> | 2009-05-05 22:22:47 +0000 |
commit | 952ff5bdc90aaf5a2b6f1cb93e20390c8cd47c54 (patch) | |
tree | 4a66b0d554480a9176b22efa6fd8b5e605fe5c3e | |
parent | 81f01cb929d47185686099a8d834a3e11e4eb9c3 (diff) |
Honor the -fsyntax-only flag by not emitting any assembly code.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/st/cli-be@147140 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | gcc/config/cil32/cil-refs.c | 100 | ||||
-rw-r--r-- | gcc/config/cil32/cil-refs.h | 8 | ||||
-rw-r--r-- | gcc/config/cil32/cil32.c | 10 | ||||
-rw-r--r-- | gcc/config/cil32/emit-cil.c | 34 |
4 files changed, 137 insertions, 15 deletions
diff --git a/gcc/config/cil32/cil-refs.c b/gcc/config/cil32/cil-refs.c index caf77afa176..187f16dce90 100644 --- a/gcc/config/cil32/cil-refs.c +++ b/gcc/config/cil32/cil-refs.c @@ -39,6 +39,7 @@ Erven Rohou <erven.rohou@inria.fr> #include "errors.h" #include "toplev.h" #include "tree.h" +#include "tree-flow.h" #include "tree-gimple.h" #include "tree-pass.h" #include "function.h" @@ -52,6 +53,9 @@ Erven Rohou <erven.rohou@inria.fr> * Local function prototypes * ******************************************************************************/ +static hashval_t assembly_hash (const void *); +static int assembly_eq (const void *, const void *); + static char *append_string (char *, const char *, size_t *, size_t *); static char *append_coded_type (char *, tree, size_t *, size_t *); static char *get_compact_identifier (const char *, size_t, size_t *); @@ -79,6 +83,8 @@ static int statement_list_num_instr (tree); * Globals * ******************************************************************************/ +static GTY((param_is (union tree_node))) htab_t ref_assemblies = NULL; +static GTY((param_is (union tree_node))) htab_t pending_assemblies = NULL; static GTY((param_is (union tree_node))) htab_t ref_types = NULL; static GTY((param_is (struct str_ref_d))) htab_t ref_strings = NULL; static unsigned int string_id = 0; @@ -97,6 +103,9 @@ refs_init (void) { if (ref_types == NULL) { + ref_assemblies = htab_create_ggc (4, assembly_hash, assembly_eq, NULL); + pending_assemblies = htab_create_ggc (4, assembly_hash, assembly_eq, + NULL); ref_types = htab_create_ggc (32, ref_type_hash, ref_type_eq, NULL); ref_strings = htab_create_ggc (32, str_ref_hash, str_ref_eq, NULL); labels_map = htab_create_ggc (32, label_addr_hash, label_addr_eq, NULL); @@ -115,6 +124,90 @@ void refs_fini (void) } /****************************************************************************** + * Referenced assemblies * + ******************************************************************************/ + +/* Hash function for referenced assemblies. */ + +static hashval_t assembly_hash (const void *ptr) +{ + const_tree assembly = (const_tree) ptr; + const char *str = TREE_STRING_POINTER (assembly); + hashval_t hash = 0; + size_t len = TREE_STRING_LENGTH (assembly); + size_t i; + + for (i = 0; i < len; i++) + { + hash += str[i]; + hash += (hash << 10); + hash ^= (hash >> 6); + } + + hash += (hash << 3); + hash ^= (hash >> 11); + hash += (hash << 15); + + return hash; +} + +/* Equality function for referenced assemblies. */ + +static int assembly_eq (const void *ptr1, const void *ptr2) +{ + const char *str1 = TREE_STRING_POINTER ((const_tree) ptr1); + const char *str2 = TREE_STRING_POINTER ((const_tree) ptr2); + + return str1 == str2; +} + +/* Add a referenced assembly to the list of pending assemblies if it is not + already present among the referenced assemblies. NAME is the name of the + referenced assembly. */ + +void add_referenced_assembly (const char *name) +{ + void **slot; + tree str = build_string (strlen (name), name); + + slot = htab_find_slot (ref_assemblies, str, NO_INSERT); + + if (slot != NULL) + return; /* We have already emitted this assembly's name. */ + + /* Add the assembly to the pending list if it has not been added yet. */ + slot = htab_find_slot (pending_assemblies, str, INSERT); + + if (*slot == NULL) + *slot = str; +} + +/* Return a pointer to the hash-table holding the referenced assemblies which + have not been emitted yet. */ + +htab_t pending_assemblies_htab ( void ) +{ + return pending_assemblies; +} + +/* Move the pending assemblies to the referenced assemblies hash table. */ + +void mark_pending_assemblies ( void ) +{ + htab_iterator hti; + void **slot; + tree name; + + FOR_EACH_HTAB_ELEMENT (pending_assemblies, name, tree, hti) + { + slot = htab_find_slot (ref_assemblies, name, INSERT); + *slot = name; + } + + htab_empty (pending_assemblies); +} + +/****************************************************************************** * Referenced types * ******************************************************************************/ @@ -858,13 +951,6 @@ referenced_strings_htab ( void ) * Functions * ******************************************************************************/ -static void -init_pinvokes ( void ) -{ - if (ref_pinvokes == NULL) - ref_pinvokes = htab_create_ggc (32, pinvoke_hash, pinvoke_eq, NULL); -} - /* Hash function for pinvokes */ static hashval_t diff --git a/gcc/config/cil32/cil-refs.h b/gcc/config/cil32/cil-refs.h index bc79de7d645..2e37e557ece 100644 --- a/gcc/config/cil32/cil-refs.h +++ b/gcc/config/cil32/cil-refs.h @@ -67,6 +67,14 @@ extern void refs_init (void); extern void refs_fini (void); /***************************************************************************** + * Referenced assemblies * + *****************************************************************************/ + +extern void add_referenced_assembly (const char *); +extern htab_t pending_assemblies_htab ( void ); +extern void mark_pending_assemblies ( void ); + +/***************************************************************************** * Types * *****************************************************************************/ diff --git a/gcc/config/cil32/cil32.c b/gcc/config/cil32/cil32.c index 4781d749f2d..892d6326276 100644 --- a/gcc/config/cil32/cil32.c +++ b/gcc/config/cil32/cil32.c @@ -154,8 +154,7 @@ cil_basic_block_eq (const void *ptr1, const void *ptr2) } static tree -cil32_handle_function_attribute (tree *node, tree name, - tree args ATTRIBUTE_UNUSED, +cil32_handle_function_attribute (tree *node, tree name, tree args, int flags ATTRIBUTE_UNUSED, bool *no_add_attrs) { @@ -168,7 +167,12 @@ cil32_handle_function_attribute (tree *node, tree name, } if (strcmp (IDENTIFIER_POINTER (name), "pinvoke") == 0) - add_pinvoke (*node); + { + add_pinvoke (*node); + add_referenced_assembly (TREE_STRING_POINTER (TREE_VALUE (args))); + } + else if (strcmp (IDENTIFIER_POINTER (name), "assembly_name") == 0) + add_referenced_assembly (TREE_STRING_POINTER (TREE_VALUE (args))); return NULL_TREE; } diff --git a/gcc/config/cil32/emit-cil.c b/gcc/config/cil32/emit-cil.c index 618bea4c951..a71e611760c 100644 --- a/gcc/config/cil32/emit-cil.c +++ b/gcc/config/cil32/emit-cil.c @@ -118,6 +118,7 @@ static void emit_string_custom_attr (FILE *, const char *); static bool emit_builtin_call (FILE *, const_cil_stmt); static void emit_call (FILE *, const_cil_stmt); static void emit_cil_stmt (FILE *, const_cil_stmt); +static void emit_referenced_assemblies (FILE *); static void emit_start_function (FILE *); static void rename_var (tree, const char *, unsigned long); static void emit_static_vars (FILE *); @@ -144,9 +145,15 @@ emit_cil_init (void) if (TARGET_GCC4NET_LINKER) { - fputs (".assembly extern mscorlib {}\n" - ".assembly extern gcc4net {}\n" - ".assembly extern ExternalAssembly {}\n", file); + add_referenced_assembly ("gcc4net"); + add_referenced_assembly ("mscorlib"); + add_referenced_assembly ("ExternalAssembly"); + } + + emit_referenced_assemblies (file); + + if (TARGET_GCC4NET_LINKER) + { fprintf (file, ".assembly '%s' {\n", aux_base_name); fputs ("\t.custom instance " "void [gcc4net]gcc4net.C_Attributes.CObjectFile::.ctor() " @@ -156,8 +163,7 @@ emit_cil_init (void) } else if (TARGET_OPENSYSTEMC) { - fputs (".assembly extern gcc4net {}\n" - ".module '<Module>'\n" + fputs (".module '<Module>'\n" ".custom instance " "void ['OpenSystem.C']'OpenSystem.C'.ModuleAttribute::.ctor() " "= (01 00 00 00)\n", file); @@ -2264,6 +2270,23 @@ emit_local_vars (FILE *file) fprintf (file, ")\n"); } +/* Emit the external assembly references which might have been added during + the previous phases. */ + +static void +emit_referenced_assemblies (FILE *file) +{ + htab_iterator hti; + tree name; + + FOR_EACH_HTAB_ELEMENT (pending_assemblies_htab (), name, tree, hti) + { + fprintf(file, ".assembly extern %s {}\n", TREE_STRING_POINTER (name)); + } + + mark_pending_assemblies (); +} + /* Emit the prototype of the current function, it's attributes, etc... */ static void @@ -2403,6 +2426,7 @@ emit_cil_1 (FILE *file) tree_block_label (bb); } + emit_referenced_assemblies (file); emit_function_header (file); FOR_EACH_BB (bb) |