#include "config.h"
#include "system.h"
#include "cpplib.h"
#include "tree.h"
#include "c-pragma.h"
#include "c-tree.h"
#include "toplev.h"
#include "tm_p.h"
#define BAD(msgid) do { warning (msgid); return; } while (0)
#define BAD2(msgid, arg) do { warning (msgid, arg); return; } while (0)
static void directive_with_named_function (const char *, void (*sec_f)(void));
static void push_field_alignment PARAMS ((int, int, int));
static void pop_field_alignment PARAMS ((void));
typedef struct align_stack
{
int alignment;
unsigned long mac68k;
unsigned long natural;
struct align_stack * prev;
} align_stack;
static struct align_stack * field_align_stack = NULL;
static void
push_field_alignment (bit_alignment, mac68k_alignment, natural_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)
target_flags |= MASK_ALIGN_MAC68K;
else
target_flags &= ~MASK_ALIGN_MAC68K;
if (natural_alignment)
target_flags |= MASK_ALIGN_NATURAL;
else
target_flags &= ~MASK_ALIGN_NATURAL;
}
static void
pop_field_alignment ()
{
if (field_align_stack)
{
align_stack *entry = field_align_stack;
maximum_field_alignment = entry->alignment;
if (entry->mac68k)
target_flags |= MASK_ALIGN_MAC68K;
else
target_flags &= ~MASK_ALIGN_MAC68K;
if (entry->natural)
target_flags |= MASK_ALIGN_NATURAL;
else
target_flags &= ~MASK_ALIGN_NATURAL;
field_align_stack = entry->prev;
free (entry);
}
else
error ("too many #pragma options align=reset");
}
void
darwin_pragma_ignore (pfile)
cpp_reader *pfile ATTRIBUTE_UNUSED;
{
}
void
darwin_pragma_options (pfile)
cpp_reader *pfile ATTRIBUTE_UNUSED;
{
const char *arg;
tree t, x;
if (c_lex (&t) != CPP_NAME)
BAD ("malformed '#pragma options', ignoring");
arg = IDENTIFIER_POINTER (t);
if (strcmp (arg, "align"))
BAD ("malformed '#pragma options', ignoring");
if (c_lex (&t) != CPP_EQ)
BAD ("malformed '#pragma options', ignoring");
if (c_lex (&t) != CPP_NAME)
BAD ("malformed '#pragma options', ignoring");
if (c_lex (&x) != CPP_EOF)
warning ("junk at end of '#pragma options'");
arg = IDENTIFIER_POINTER (t);
if (!strcmp (arg, "mac68k"))
push_field_alignment (0, 1, 0);
else if (!strcmp (arg, "native"))
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, 0, 0);
else if (!strcmp (arg, "reset"))
pop_field_alignment ();
else
warning ("malformed '#pragma options align={mac68k|power|natural|reset}', ignoring");
}
void
darwin_pragma_pack (pfile)
cpp_reader *pfile ATTRIBUTE_UNUSED;
{
tree x, id = 0;
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;
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 if (token == CPP_NAME)
{
#define GCC_BAD_ACTION do { if (action == push) \
BAD ("malformed '#pragma pack(push[, id], <n>)' - ignored"); \
else \
BAD ("malformed '#pragma pack(pop[, id])' - ignored"); \
} while (0)
const char *op = IDENTIFIER_POINTER (x);
if (!strcmp (op, "push"))
action = push;
else if (!strcmp (op, "pop"))
action = pop;
else
BAD2 ("unknown action '%s' for '#pragma pack' - ignored", op);
token = c_lex (&x);
if (token != CPP_COMMA && action == push)
GCC_BAD_ACTION;
if (token == CPP_COMMA)
{
token = c_lex (&x);
if (token == CPP_NAME)
{
id = x;
if (action == push && c_lex (&x) != CPP_COMMA)
GCC_BAD_ACTION;
token = c_lex (&x);
}
if (action == push)
{
if (token == CPP_NUMBER)
{
align = TREE_INT_CST_LOW (x);
token = c_lex (&x);
}
else
GCC_BAD_ACTION;
}
}
if (token != CPP_CLOSE_PAREN)
GCC_BAD_ACTION;
#undef GCC_BAD_ACTION
}
else
BAD ("malformed '#pragma pack' - ignored");
if (c_lex (&x) != CPP_EOF)
warning ("junk at end of '#pragma pack'");
if (action != pop)
{
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;
}
}
void
darwin_pragma_unused (pfile)
cpp_reader *pfile ATTRIBUTE_UNUSED;
{
tree decl, x;
int tok;
if (c_lex (&x) != CPP_OPEN_PAREN)
BAD ("missing '(' after '#pragma unused', ignoring");
while (1)
{
tok = c_lex (&decl);
if (tok == CPP_NAME && decl)
{
tree local = IDENTIFIER_LOCAL_VALUE (decl);
if (local && (TREE_CODE (local) == PARM_DECL
|| TREE_CODE (local) == VAR_DECL))
TREE_USED (local) = 1;
tok = c_lex (&x);
if (tok != CPP_COMMA)
break;
}
}
if (tok != CPP_CLOSE_PAREN)
BAD ("missing ')' after '#pragma unused', ignoring");
if (c_lex (&x) != CPP_EOF)
warning ("junk at end of '#pragma unused'");
}
extern void mod_init_section (void), mod_term_section (void);
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 (pfile)
cpp_reader *pfile ATTRIBUTE_UNUSED;
{
directive_with_named_function ("CALL_ON_LOAD", mod_init_section);
}
void
darwin_pragma_call_on_unload (pfile)
cpp_reader *pfile ATTRIBUTE_UNUSED;
{
directive_with_named_function ("CALL_ON_UNLOAD", mod_term_section);
}
void
darwin_pragma_call_on_module_bind (pfile)
cpp_reader *pfile ATTRIBUTE_UNUSED;
{
warning ("#pragma CALL_ON_MODULE_BIND is no longer supported, ignoring. "
"Use CALL_ON_LOAD instead.");
}
void
darwin_pragma_cc_no_mach_text_sections (pfile)
cpp_reader *pfile ATTRIBUTE_UNUSED;
{
warning ("#pragma CC_NO_MACH_TEXT_SECTIONS is no longer supported, ignoring");
}
void
darwin_pragma_cc_opt_off (pfile)
cpp_reader *pfile ATTRIBUTE_UNUSED;
{
warning ("#pragma CC_OPT_OFF is no longer supported, ignoring");
}
void
darwin_pragma_cc_opt_on (pfile)
cpp_reader *pfile ATTRIBUTE_UNUSED;
{
warning ("#pragma CC_OPT_ON is no longer supported, ignoring");
}
void
darwin_pragma_cc_opt_restore (pfile)
cpp_reader *pfile ATTRIBUTE_UNUSED;
{
warning ("#pragma CC_OPT_RESTORE is no longer supported, ignoring");
}
void
darwin_pragma_cc_writable_strings (pfile)
cpp_reader *pfile ATTRIBUTE_UNUSED;
{
warning ("#pragma CC_WRITABLE_STRINGS is no longer supported, ignoring");
}
void
darwin_pragma_cc_non_writable_strings (pfile)
cpp_reader *pfile ATTRIBUTE_UNUSED;
{
warning ("#pragma CC_NON_WRITABLE_STRINGS is no longer supported, ignoring");
}