00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "config.h"
00023 #include "system.h"
00024 #include "coretypes.h"
00025 #include "tm.h"
00026 #include "rtl.h"
00027 #include "regs.h"
00028 #include "hard-reg-set.h"
00029 #include "output.h"
00030 #include "tree.h"
00031 #include "flags.h"
00032 #include "tm_p.h"
00033 #include "toplev.h"
00034 #include "ggc.h"
00035
00036
00037
00038
00039
00040
00041 static tree
00042 gen_stdcall_or_fastcall_decoration (tree decl, char prefix)
00043 {
00044 unsigned total = 0;
00045
00046
00047 const char *asmname = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
00048 char *newsym;
00049 tree formal_type = TYPE_ARG_TYPES (TREE_TYPE (decl));
00050
00051 if (formal_type != NULL_TREE)
00052 {
00053
00054
00055
00056 if (TREE_VALUE (tree_last (formal_type)) != void_type_node)
00057 return NULL_TREE;
00058
00059
00060
00061 while (TREE_VALUE (formal_type) != void_type_node
00062 && COMPLETE_TYPE_P (TREE_VALUE (formal_type)))
00063 {
00064 unsigned parm_size
00065 = TREE_INT_CST_LOW (TYPE_SIZE (TREE_VALUE (formal_type)));
00066
00067
00068
00069 parm_size = ((parm_size + PARM_BOUNDARY - 1)
00070 / PARM_BOUNDARY * PARM_BOUNDARY);
00071 total += parm_size;
00072 formal_type = TREE_CHAIN (formal_type);
00073 }
00074 }
00075
00076 newsym = alloca (1 + strlen (asmname) + 1 + 10 + 1);
00077 return get_identifier_with_length (newsym,
00078 sprintf (newsym,
00079 "%c%s@%u",
00080 prefix,
00081 asmname,
00082 total / BITS_PER_UNIT));
00083 }
00084
00085
00086
00087
00088
00089 static tree
00090 gen_regparm_prefix (tree decl, unsigned nregs)
00091 {
00092 unsigned total = 0;
00093
00094
00095 const char *asmname = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
00096 char *newsym;
00097 tree formal_type = TYPE_ARG_TYPES (TREE_TYPE (decl));
00098
00099 if (formal_type != NULL_TREE)
00100 {
00101
00102 if (TREE_VALUE (tree_last (formal_type)) != void_type_node)
00103 return NULL_TREE;
00104
00105
00106
00107 while (TREE_VALUE (formal_type) != void_type_node
00108 && COMPLETE_TYPE_P (TREE_VALUE (formal_type)))
00109 {
00110 unsigned parm_size
00111 = TREE_INT_CST_LOW (TYPE_SIZE (TREE_VALUE (formal_type)));
00112
00113
00114
00115 parm_size = ((parm_size + PARM_BOUNDARY - 1)
00116 / PARM_BOUNDARY * PARM_BOUNDARY);
00117 total += parm_size;
00118 formal_type = TREE_CHAIN (formal_type);
00119 }
00120 }
00121
00122 if (nregs > total / BITS_PER_WORD)
00123 nregs = total / BITS_PER_WORD;
00124 if (nregs > 9) abort();
00125 newsym = alloca (3 + strlen (asmname) + 1);
00126 return get_identifier_with_length (newsym,
00127 sprintf (newsym,
00128 "_%u@%s",
00129 nregs,
00130 asmname));
00131 }
00132
00133 void
00134 i386_nlm_encode_section_info (tree decl, rtx rtl, int first)
00135 {
00136 default_encode_section_info (decl, rtl, first);
00137
00138 if (first
00139 && TREE_CODE (decl) == FUNCTION_DECL
00140 && *IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)) != '*'
00141 && !strchr (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), '@'))
00142 {
00143 tree type_attributes = TYPE_ATTRIBUTES (TREE_TYPE (decl));
00144 tree newid;
00145
00146 if (lookup_attribute ("stdcall", type_attributes))
00147 newid = gen_stdcall_or_fastcall_decoration (decl, '_');
00148 else if (lookup_attribute ("fastcall", type_attributes))
00149 newid = gen_stdcall_or_fastcall_decoration (decl, FASTCALL_PREFIX);
00150 else if ((newid = lookup_attribute ("regparm", type_attributes)) != NULL_TREE)
00151 newid = gen_regparm_prefix (decl,
00152 TREE_INT_CST_LOW (TREE_VALUE (TREE_VALUE (newid))));
00153 if (newid != NULL_TREE)
00154 {
00155 rtx rtlname = XEXP (rtl, 0);
00156
00157 if (GET_CODE (rtlname) == MEM)
00158 rtlname = XEXP (rtlname, 0);
00159 XSTR (rtlname, 0) = IDENTIFIER_POINTER (newid);
00160
00161
00162
00163
00164 change_decl_assembler_name (decl, newid);
00165 }
00166 }
00167 }
00168
00169
00170
00171 const char *
00172 i386_nlm_strip_name_encoding (const char *str)
00173 {
00174 const char *name = default_strip_name_encoding (str);
00175
00176 if (*str != '*' && (*name == '_' || *name == '@'))
00177 {
00178 const char *p = strchr (name + 1, '@');
00179
00180 if (p)
00181 {
00182 ++name;
00183 if (ISDIGIT (p[1]))
00184 name = ggc_alloc_string (name, p - name);
00185 else if (!ISDIGIT (*name) || ++name != p)
00186 abort();
00187 }
00188 }
00189 return name;
00190 }