home *** CD-ROM | disk | FTP | other *** search
/ OpenStep (Enterprise) / OpenStepENTCD.toast / OEDEV / GNUSRC.Z / nextstep.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-16  |  6.1 KB  |  227 lines

  1. /* Functions for generic NeXT as target machine for GNU C compiler.
  2.    Copyright (C) 1989, 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU CC.
  5.  
  6. GNU CC is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10.  
  11. GNU CC is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU CC; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. /* Make everything that used to go in the text section really go there.  */
  21.  
  22. int flag_no_mach_text_sections = 0;
  23.  
  24. #define OPT_STRCMP(opt) ((!strncmp (opt, p, sizeof (opt)-1)) \
  25.              || (!strncmp ((opt)+1, p, sizeof (opt)-2)))
  26.  
  27. /* 1 if handle_pragma has been called yet.  */
  28.  
  29. static int pragma_initialized;
  30.  
  31. /* Initial setting of `optimize'.  */
  32.  
  33. static int initial_optimize_flag;
  34. static int initial_flag_expensive_optimizations;
  35.  
  36. extern char *get_directive_line ();
  37.  
  38. /* Called from check_newline via the macro HANDLE_PRAGMA.
  39.    FINPUT is the source file input stream.  */
  40.  
  41. void
  42. handle_pragma (finput, get_line_function)
  43.      FILE *finput;
  44.      char *(*get_line_function) ();
  45. {
  46.   register char *p = (*get_line_function) (finput);
  47.  
  48.   /* Record initial setting of optimize flag, so we can restore it.  */
  49.   if (!pragma_initialized)
  50.     {
  51.       pragma_initialized = 1;
  52.       initial_optimize_flag = optimize;
  53.       initial_flag_expensive_optimizations = flag_expensive_optimizations;
  54.     }
  55.  
  56.   if (OPT_STRCMP ("CC_OPT_ON"))
  57.     {
  58.       optimize = 1, obey_regdecls = 0;
  59.       flag_expensive_optimizations = initial_flag_expensive_optimizations;
  60.       warning ("optimization turned on");
  61.     }
  62.   else if (OPT_STRCMP ("CC_OPT_OFF"))
  63.     {
  64.       optimize = 0, obey_regdecls = 1;
  65.       flag_expensive_optimizations = 0;
  66.       warning ("optimization turned off");
  67.     }
  68.   else if (OPT_STRCMP ("CC_OPT_RESTORE"))
  69.     {
  70.       if (optimize != initial_optimize_flag)
  71.     {
  72.       if (initial_optimize_flag)
  73.         obey_regdecls = 0;
  74.       else
  75.         obey_regdecls = 1;
  76.       optimize = initial_optimize_flag;
  77.       flag_expensive_optimizations = initial_flag_expensive_optimizations;
  78.     }
  79.       warning ("optimization level restored");
  80.     }
  81.   else if (OPT_STRCMP ("CC_WRITABLE_STRINGS"))
  82.     flag_writable_strings = 1;
  83.   else if (OPT_STRCMP ("CC_NON_WRITABLE_STRINGS"))
  84.     flag_writable_strings = 0;
  85.   else if (OPT_STRCMP ("CC_NO_MACH_TEXT_SECTIONS"))
  86.     flag_no_mach_text_sections = 1;
  87.   else if (OPT_STRCMP ("SECTION"))
  88.     {
  89.       char name[1024];
  90.       char *q = &(name[0]);
  91.  
  92.       while (isalpha (*p)) p++;
  93.       while (*p && (isspace (*p) || (*p == '.'))) p++;
  94.       while (*p && !isspace (*p)) *q++ = *p++;
  95.       *q = 0;
  96.  
  97.       while (*p && isspace (*p)) p++;
  98.       if (*p == 0)
  99.         alias_section (name, 0);
  100.       else if (*p == '"')
  101.         {
  102.           char *start = ++p;
  103.           while (*p && *p != '"')
  104.             {
  105.               if (*p == '\\') p++;
  106.               p++;
  107.             }
  108.           *p = 0;
  109.           alias_section (name, start);
  110.         }
  111.       else
  112.         {
  113.           alias_section (name, p);
  114.         }
  115.     }
  116.   else if (OPT_STRCMP ("CALL_ON_MODULE_BIND"))
  117.     {
  118.       extern FILE *asm_out_file;
  119.       while (isalpha (*p) || *p == '_') p++;
  120.       while (*p && isspace (*p)) p++;
  121.  
  122.       if (*p)
  123.         {
  124.           mod_init_section ();
  125.           fprintf (asm_out_file, "\t.long _%s\n", p);
  126.         }
  127.     }
  128. }
  129.  
  130. static int
  131. name_needs_quotes(name)
  132.      const char *name;
  133. {
  134.   int c;
  135.   while ((c = *name++) != '\0')
  136.     if (!isalnum(c) && c != '_')
  137.       return 1;
  138.   return 0;
  139. }
  140.  
  141. #if defined (I386) || defined (MACHOPIC_M68K)
  142. /* Go through all the insns looking for a double constant.  Return nonzero
  143.    if one is found.  */
  144.  
  145. const_double_used ()
  146. {
  147.   rtx insn;
  148.   for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
  149.     {
  150.       enum rtx_code code;
  151.       rtx set = single_set (insn);
  152.       if (set)
  153.     if ((code = GET_CODE (SET_SRC (set))) == CONST_DOUBLE)
  154.       return 1;
  155. #ifdef MACHOPIC_M68K
  156.         else
  157.       /* Hopefully this catches all the cases we're interested in.  */
  158.       switch (GET_RTX_CLASS (code))
  159.         {
  160.           int i;
  161.         case '<':
  162.         case '1':
  163.         case 'c':
  164.         case '2':
  165.           for (i = 0; i < GET_RTX_LENGTH (code); i++)
  166.         if (GET_CODE (XEXP (SET_SRC (set), i)) == CONST_DOUBLE)
  167.           return 1;
  168.         }
  169. #endif
  170.     }
  171.   return 0;
  172. }
  173. #endif /* I386 || MACHOPIC_M68K */
  174.  
  175. #define GEN_BINDER_NAME_FOR_STUB(BUF,STUB,STUB_LENGTH)        \
  176.   do {                                \
  177.     const char *stub_ = (STUB);                    \
  178.     char *buffer_ = (BUF);                    \
  179.     strcpy(buffer_, stub_);                    \
  180.     if (stub_[0] == '"')                    \
  181.       {                                \
  182.     strcpy(buffer_ + (STUB_LENGTH) - 1, "_binder\"");    \
  183.       }                                \
  184.     else                            \
  185.       {                                \
  186.     strcpy(buffer_ + (STUB_LENGTH), "_binder");        \
  187.       }                                \
  188.   } while (0)
  189.  
  190. #define GEN_SYMBOL_NAME_FOR_SYMBOL(BUF,SYMBOL,SYMBOL_LENGTH)    \
  191.   do {                                \
  192.     const char *symbol_ = (SYMBOL);                \
  193.     char *buffer_ = (BUF);                    \
  194.     if (name_needs_quotes(symbol_) && symbol_[0] != '"')    \
  195.       {                                \
  196.       sprintf(buffer_, "\"%s\"", symbol_);            \
  197.       }                                \
  198.     else                            \
  199.       {                                \
  200.     strcpy(buffer_, symbol_);                \
  201.       }                                \
  202.   } while (0)
  203.  
  204. #define GEN_LAZY_PTR_NAME_FOR_SYMBOL(BUF,SYMBOL,SYMBOL_LENGTH)    \
  205.   do {                                \
  206.     const char *symbol_ = (SYMBOL);                \
  207.     char *buffer_ = (BUF);                    \
  208.     if (symbol_[0] == '"')                    \
  209.       {                                \
  210.         strcpy(buffer_, "\"L");                    \
  211.         strcpy(buffer_ + 2, symbol_ + 1);            \
  212.     strcpy(buffer_ + (SYMBOL_LENGTH), "$lazy_ptr\"");    \
  213.       }                                \
  214.     else if (name_needs_quotes(symbol_))            \
  215.       {                                \
  216.         strcpy(buffer_, "\"L");                    \
  217.         strcpy(buffer_ + 2, symbol_);                \
  218.     strcpy(buffer_ + (SYMBOL_LENGTH) + 2, "$lazy_ptr\"");    \
  219.       }                                \
  220.     else                            \
  221.       {                                \
  222.         strcpy(buffer_, "L");                    \
  223.         strcpy(buffer_ + 1, symbol_);                \
  224.     strcpy(buffer_ + (SYMBOL_LENGTH) + 1, "$lazy_ptr");    \
  225.       }                                \
  226.   } while (0)
  227.