* src/mcs51/gen.c (movc): improved check for 0 and 1, see RFE 1582704
[fw/sdcc] / support / cpp2 / cpplib.c
index cb493105ae94e2461cd3dbe975e3bed40e0fee82..93621adb25554671a36eba1f6909bbe0f6ff7437 100644 (file)
@@ -93,15 +93,17 @@ static unsigned int read_flag       PARAMS ((cpp_reader *, unsigned int));
 static int  strtoul_for_line   PARAMS ((const U_CHAR *, unsigned int,
                                         unsigned long *));
 static void do_diagnostic      PARAMS ((cpp_reader *, enum error_type, int));
-static cpp_hashnode *lex_macro_node    PARAMS ((cpp_reader *));
+static cpp_hashnode *lex_macro_node PARAMS ((cpp_reader *));
 static void do_include_common  PARAMS ((cpp_reader *, enum include_type));
 static void do_pragma_once     PARAMS ((cpp_reader *));
 static void do_pragma_poison   PARAMS ((cpp_reader *));
-static void do_pragma_system_header    PARAMS ((cpp_reader *));
-static void do_pragma_dependency       PARAMS ((cpp_reader *));
+static void do_pragma_sdcc_hash PARAMS ((cpp_reader *));
+static void do_pragma_preproc_asm   PARAMS ((cpp_reader *));
+static void do_pragma_system_header PARAMS ((cpp_reader *));
+static void do_pragma_dependency    PARAMS ((cpp_reader *));
 static int get__Pragma_string  PARAMS ((cpp_reader *, cpp_token *));
-static unsigned char *destringize      PARAMS ((const cpp_string *,
-                                                unsigned int *));
+static unsigned char *destringize   PARAMS ((const cpp_string *,
+                                            unsigned int *));
 static int parse_answer PARAMS ((cpp_reader *, struct answer **, int));
 static cpp_hashnode *parse_assertion PARAMS ((cpp_reader *, struct answer **,
                                              int));
@@ -109,6 +111,8 @@ static struct answer ** find_answer PARAMS ((cpp_hashnode *,
                                             const struct answer *));
 static void handle_assertion   PARAMS ((cpp_reader *, const char *, int));
 
+extern cpp_output_string (const char *s);
+
 /* This is the table of directive handlers.  It is ordered by
    frequency of occurrence; the numbers at the end are directive
    counts from all the source code I have lying around (egcs and libc
@@ -1025,6 +1029,11 @@ _cpp_init_internal_pragmas (pfile)
   cpp_register_pragma (pfile, "GCC", "poison", do_pragma_poison);
   cpp_register_pragma (pfile, "GCC", "system_header", do_pragma_system_header);
   cpp_register_pragma (pfile, "GCC", "dependency", do_pragma_dependency);
+    
+  /* Kevin abuse for SDCC. */
+  cpp_register_pragma(pfile, 0, "sdcc_hash", do_pragma_sdcc_hash);
+  /* SDCC _asm specific */ 
+  cpp_register_pragma(pfile, 0, "preproc_asm", do_pragma_preproc_asm);
 }
 
 static void
@@ -1126,6 +1135,51 @@ do_pragma_poison (pfile)
 #endif
 }
 
+static void
+do_pragma_sdcc_hash (pfile)
+     cpp_reader *pfile;
+{
+    cpp_token tok;
+    /*cpp_hashnode *hp;*/
+
+    _cpp_lex_token (pfile, &tok);
+    if (tok.type == CPP_PLUS)
+    {
+       CPP_OPTION(pfile, allow_naked_hash)++;
+    }
+    else if (tok.type == CPP_MINUS)
+    {
+       CPP_OPTION(pfile, allow_naked_hash)--;  
+    }
+    else
+    {
+       cpp_error (pfile, "invalid #pragma sdcc_hash directive, need '+' or '-'");
+    }
+}
+
+/* SDCC _asm specific
+   switch _asm block preprocessing on / off */
+static void
+do_pragma_preproc_asm (pfile)
+     cpp_reader *pfile;
+{
+  cpp_token tok;
+
+  _cpp_lex_token (pfile, &tok);
+  if (tok.type == CPP_PLUS)
+    {
+      CPP_OPTION(pfile, preproc_asm) = 1;
+    }
+  else if (tok.type == CPP_MINUS)
+    {
+      CPP_OPTION(pfile, preproc_asm)= 0;       
+    }
+  else
+    {
+      cpp_error (pfile, "invalid #pragma preproc_asm directive, need '+' or '-'");
+    }
+}
+
 /* Mark the current header as a system header.  This will suppress
    some categories of warnings (notably those from -pedantic).  It is
    intended for use in system libraries that cannot be implemented in
@@ -1233,7 +1287,9 @@ _cpp_do__Pragma (pfile)
     }
 
   buffer = destringize (&string.val.str, &len);
-  run_directive (pfile, T_PRAGMA, BUF_PRAGMA, (char *) buffer, len);
+  buffer[len] = 0;
+  cpp_output_string ("\n#pragma "); cpp_output_string (buffer); cpp_output_string ("\n");
+  //run_directive (pfile, T_PRAGMA, BUF_PRAGMA, (char *) buffer, len);
   free ((PTR) buffer);
 }