aboutsummaryrefslogtreecommitdiff
path: root/gcc/config/darwin-c.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/config/darwin-c.c')
-rw-r--r--gcc/config/darwin-c.c243
1 files changed, 231 insertions, 12 deletions
diff --git a/gcc/config/darwin-c.c b/gcc/config/darwin-c.c
index a4c6d8bd1da..51cc2ffc49c 100644
--- a/gcc/config/darwin-c.c
+++ b/gcc/config/darwin-c.c
@@ -34,37 +34,75 @@ Boston, MA 02111-1307, USA. */
/* Pragmas. */
#define BAD(msgid) do { warning (msgid); return; } while (0)
+#define BAD2(msgid, arg) do { warning (msgid, arg); return; } while (0)
static bool using_frameworks = false;
+/* APPLE LOCAL CALL_ON_LOAD/CALL_ON_UNLOAD pragmas 20020202 turly */
+static void directive_with_named_function (const char *, void (*sec_f)(void));
+
/* Maintain a small stack of alignments. This is similar to pragma
pack's stack, but simpler. */
-static void push_field_alignment (int);
+/* APPLE LOCAL begin Macintosh alignment 2001-12-17 ff */
+static void push_field_alignment (int, int, int);
+/* APPLE LOCAL end Macintosh alignment 2001-12-17 ff */
static void pop_field_alignment (void);
static const char *find_subframework_file (const char *, const char *);
static void add_system_framework_path (char *);
-static const char *find_subframework_header (cpp_reader *pfile, const char *header);
-
+static const char *find_subframework_header (cpp_reader *pfile, const char *header,
+ cpp_dir **dirp);
+
+/* APPLE LOCAL begin Macintosh alignment 2002-1-22 ff */
+/* There are four alignment modes supported on the Apple Macintosh
+ platform: power, mac68k, natural, and packed. These modes are
+ identified as follows:
+ if maximum_field_alignment != 0
+ mode = packed
+ else if TARGET_ALIGN_NATURAL
+ mode = natural
+ else if TARGET_ALIGN_MAC68K
+ mode
+ else
+ mode = power
+ These modes are saved on the alignment stack by saving the values
+ of maximum_field_alignment, TARGET_ALIGN_MAC68K, and
+ TARGET_ALIGN_NATURAL. */
typedef struct align_stack
{
int alignment;
+ unsigned long mac68k;
+ unsigned long natural;
struct align_stack * prev;
} align_stack;
+/* APPLE LOCAL end Macintosh alignment 2002-1-22 ff */
static struct align_stack * field_align_stack = NULL;
+/* APPLE LOCAL begin Macintosh alignment 2001-12-17 ff */
static void
-push_field_alignment (int bit_alignment)
+push_field_alignment (int bit_alignment,
+ int mac68k_alignment, int natural_alignment)
{
align_stack *entry = (align_stack *) xmalloc (sizeof (align_stack));
entry->alignment = maximum_field_alignment;
+ entry->mac68k = TARGET_ALIGN_MAC68K;
+ entry->natural = TARGET_ALIGN_NATURAL;
entry->prev = field_align_stack;
field_align_stack = entry;
maximum_field_alignment = bit_alignment;
+ if (mac68k_alignment)
+ rs6000_alignment_flags |= MASK_ALIGN_MAC68K;
+ else
+ rs6000_alignment_flags &= ~MASK_ALIGN_MAC68K;
+ if (natural_alignment)
+ rs6000_alignment_flags |= MASK_ALIGN_NATURAL;
+ else
+ rs6000_alignment_flags &= ~MASK_ALIGN_NATURAL;
}
+/* APPLE LOCAL end Macintosh alignment 2001-12-17 ff */
static void
pop_field_alignment (void)
@@ -74,6 +112,16 @@ pop_field_alignment (void)
align_stack *entry = field_align_stack;
maximum_field_alignment = entry->alignment;
+/* APPLE LOCAL begin Macintosh alignment 2001-12-17 ff */
+ if (entry->mac68k)
+ rs6000_alignment_flags |= MASK_ALIGN_MAC68K;
+ else
+ rs6000_alignment_flags &= ~MASK_ALIGN_MAC68K;
+ if (entry->natural)
+ rs6000_alignment_flags |= MASK_ALIGN_NATURAL;
+ else
+ rs6000_alignment_flags &= ~MASK_ALIGN_NATURAL;
+/* APPLE LOCAL end Macintosh alignment 2001-12-17 ff */
field_align_stack = entry->prev;
free (entry);
}
@@ -111,16 +159,85 @@ darwin_pragma_options (cpp_reader *pfile ATTRIBUTE_UNUSED)
warning ("junk at end of '#pragma options'");
arg = IDENTIFIER_POINTER (t);
+/* APPLE LOCAL begin Macintosh alignment 2002-1-22 ff */
if (!strcmp (arg, "mac68k"))
- push_field_alignment (16);
+ push_field_alignment (0, 1, 0);
+ else if (!strcmp (arg, "native")) /* equivalent to power on PowerPC */
+ push_field_alignment (0, 0, 0);
+ else if (!strcmp (arg, "natural"))
+ push_field_alignment (0, 0, 1);
+ else if (!strcmp (arg, "packed"))
+ push_field_alignment (8, 0, 0);
else if (!strcmp (arg, "power"))
- push_field_alignment (0);
+ push_field_alignment (0, 0, 0);
else if (!strcmp (arg, "reset"))
pop_field_alignment ();
else
- warning ("malformed '#pragma options align={mac68k|power|reset}', ignoring");
+ warning ("malformed '#pragma options align={mac68k|power|natural|reset}', ignoring");
+/* APPLE LOCAL end Macintosh alignment 2002-1-22 ff */
}
+/* APPLE LOCAL begin Macintosh alignment 2002-1-22 ff */
+/* #pragma pack ()
+ #pragma pack (N)
+
+ We have a problem handling the semantics of these directives since,
+ to play well with the Macintosh alignment directives, we want the
+ usual pack(N) form to do a push of the previous alignment state.
+ Do we want pack() to do another push or a pop? */
+
+void
+darwin_pragma_pack (cpp_reader *pfile ATTRIBUTE_UNUSED)
+{
+ tree x;
+ int align = -1;
+ enum cpp_ttype token;
+ enum { set, push, pop } action;
+
+ if (c_lex (&x) != CPP_OPEN_PAREN)
+ BAD ("missing '(' after '#pragma pack' - ignored");
+ token = c_lex (&x);
+ if (token == CPP_CLOSE_PAREN)
+ {
+ action = pop; /* or "set" ??? */
+ align = 0;
+ }
+ else if (token == CPP_NUMBER)
+ {
+ align = TREE_INT_CST_LOW (x);
+ action = push;
+ if (c_lex (&x) != CPP_CLOSE_PAREN)
+ BAD ("malformed '#pragma pack' - ignored");
+ }
+ else
+ BAD ("malformed '#pragma pack' - ignored");
+
+ if (c_lex (&x) != CPP_EOF)
+ warning ("junk at end of '#pragma pack'");
+
+ switch (align)
+ {
+ case 0:
+ case 1:
+ case 2:
+ case 4:
+ case 8:
+ case 16:
+ align *= BITS_PER_UNIT;
+ break;
+ default:
+ BAD2 ("alignment must be a small power of two, not %d", align);
+ }
+
+ switch (action)
+ {
+ case pop: pop_field_alignment (); break;
+ case push: push_field_alignment (align, 0, 0); break;
+ case set: break;
+ }
+}
+/* APPLE LOCAL end Macintosh alignment 2002-1-22 ff */
+
/* #pragma unused ([var {, var}*]) */
void
@@ -166,11 +283,13 @@ static int max_frameworks = 0;
/* Remember which frameworks have been seen, so that we can ensure
that all uses of that framework come from the same framework. DIR
is the place where the named framework NAME, which is of length
- LEN, was found. */
+ LEN, was found. We copy the directory name from NAME, as it will be
+ freed by others. */
static void
add_framework (const char *name, size_t len, cpp_dir *dir)
{
+ char *dir_name;
int i;
for (i = 0; i < num_frameworks; ++i)
{
@@ -183,10 +302,14 @@ add_framework (const char *name, size_t len, cpp_dir *dir)
if (i >= max_frameworks)
{
max_frameworks = i*2;
+ max_frameworks += i == 0;
frameworks_in_use = xrealloc (frameworks_in_use,
max_frameworks*sizeof(*frameworks_in_use));
}
- frameworks_in_use[num_frameworks].name = name;
+ dir_name = xmalloc (len + 1);
+ memcpy (dir_name, name, len);
+ dir_name[len] = '\0';
+ frameworks_in_use[num_frameworks].name = dir_name;
frameworks_in_use[num_frameworks].len = len;
frameworks_in_use[num_frameworks].dir = dir;
++num_frameworks;
@@ -272,7 +395,8 @@ framework_construct_pathname (const char *fname, cpp_dir *dir)
if (stat (frname, &st) == 0)
{
- add_framework (fname, fname_len, dir);
+ if (fast_dir == 0)
+ add_framework (fname, fname_len, dir);
return frname;
}
}
@@ -445,7 +569,7 @@ darwin_register_frameworks (int stdinc)
returns non-zero. */
static const char*
-find_subframework_header (cpp_reader *pfile, const char *header)
+find_subframework_header (cpp_reader *pfile, const char *header, cpp_dir **dirp)
{
const char *fname = header;
struct cpp_buffer *b;
@@ -457,10 +581,105 @@ find_subframework_header (cpp_reader *pfile, const char *header)
{
n = find_subframework_file (fname, cpp_get_path (cpp_get_file (b)));
if (n)
- return n;
+ {
+ /* Logically, the place where we found the subframework is
+ the place where we found the Framework that contains the
+ subframework. This is useful for tracking wether or not
+ we are in a system header. */
+ *dirp = cpp_get_dir (cpp_get_file (b));
+ return n;
+ }
}
return 0;
}
struct target_c_incpath_s target_c_incpath = C_INCPATH_INIT;
+
+/* APPLE LOCAL begin CALL_ON_LOAD/CALL_ON_UNLOAD pragmas 20020202 turly */
+extern void mod_init_section (void), mod_term_section (void);
+/* Grab the function name from the pragma line and output it to the
+ assembly output file with the parameter DIRECTIVE. Called by the
+ pragma CALL_ON_LOAD and CALL_ON_UNLOAD handlers below.
+ So: "#pragma CALL_ON_LOAD foo" will output ".mod_init_func _foo". */
+
+static void directive_with_named_function (const char *pragma_name,
+ void (*section_function) (void))
+{
+ tree decl;
+ int tok;
+
+ tok = c_lex (&decl);
+ if (tok == CPP_NAME && decl)
+ {
+ extern FILE *asm_out_file;
+
+ section_function ();
+ fprintf (asm_out_file, "\t.long _%s\n", IDENTIFIER_POINTER (decl));
+
+ if (c_lex (&decl) != CPP_EOF)
+ warning ("junk at end of #pragma %s <function_name>\n", pragma_name);
+ }
+ else
+ warning ("function name expected after #pragma %s\n", pragma_name);
+}
+void
+darwin_pragma_call_on_load (cpp_reader *pfile ATTRIBUTE_UNUSED)
+{
+ directive_with_named_function ("CALL_ON_LOAD", mod_init_section);
+}
+void
+darwin_pragma_call_on_unload (cpp_reader *pfile ATTRIBUTE_UNUSED)
+{
+ directive_with_named_function ("CALL_ON_UNLOAD", mod_term_section);
+}
+/* APPLE LOCAL end CALL_ON_LOAD/CALL_ON_UNLOAD pragmas 20020202 turly */
+
+/* APPLE LOCAL begin CALL_ON_MODULE_BIND deprecated 2002-4-10 ff */
+void
+darwin_pragma_call_on_module_bind (cpp_reader *pfile ATTRIBUTE_UNUSED)
+{
+ warning ("#pragma CALL_ON_MODULE_BIND is no longer supported, ignoring. "
+ "Use CALL_ON_LOAD instead.");
+}
+/* APPLE LOCAL end CALL_ON_MODULE_BIND deprecated 2002-4-10 ff */
+
+/* APPLE LOCAL begin temporary pragmas 2001-07-05 sts */
+/* These need to live only long enough to get their uses flushed out
+ of the system. */
+void
+darwin_pragma_cc_no_mach_text_sections (cpp_reader *pfile ATTRIBUTE_UNUSED)
+{
+ warning ("#pragma CC_NO_MACH_TEXT_SECTIONS is no longer supported, ignoring");
+}
+
+void
+darwin_pragma_cc_opt_off (cpp_reader *pfile ATTRIBUTE_UNUSED)
+{
+ warning ("#pragma CC_OPT_OFF is no longer supported, ignoring");
+}
+
+void
+darwin_pragma_cc_opt_on (cpp_reader *pfile ATTRIBUTE_UNUSED)
+{
+ warning ("#pragma CC_OPT_ON is no longer supported, ignoring");
+}
+
+void
+darwin_pragma_cc_opt_restore (cpp_reader *pfile ATTRIBUTE_UNUSED)
+{
+ warning ("#pragma CC_OPT_RESTORE is no longer supported, ignoring");
+}
+
+void
+darwin_pragma_cc_writable_strings (cpp_reader *pfile ATTRIBUTE_UNUSED)
+{
+ warning ("#pragma CC_WRITABLE_STRINGS is no longer supported, ignoring");
+}
+
+void
+darwin_pragma_cc_non_writable_strings (cpp_reader *pfile ATTRIBUTE_UNUSED)
+{
+ warning ("#pragma CC_NON_WRITABLE_STRINGS is no longer supported, ignoring");
+}
+/* APPLE LOCAL end temporary pragmas 2001-07-05 sts */