Patchwork [-,vms] : Add support of pragma __extern_prefix

login
register
mail settings
Submitter Tristan Gingold
Date Nov. 7, 2011, 11:33 a.m.
Message ID <C14D5F35-64FA-4523-BFD0-24CC7F5B9AA4@adacore.com>
Download mbox | patch
Permalink /patch/124065/
State New
Headers show

Comments

Tristan Gingold - Nov. 7, 2011, 11:33 a.m.
Hi,

DEC-C for vms has '#pragma __extern_prefix' which is not unlike '#pragma extern_prefix' supported by DEC-C for Tru64.

This patch adds supports for the VMS version (which can save and restore the current prefix).  It reuses most of the current infrastructure, but to do so c-pragma.c:pragma_extern_prefix had to be public.

Manually tested by cross-building for ia64-vms and alpha-vms.

Ok for trunk ?

(I could have added __extern_prefix in c-pragma.c, but I think the design of save/restore is inferior to the push/pop functionality used in some other pragma).

Tristan.

2011-11-07  Tristan Gingold  <gingold@adacore.com>

	* c-family/c-pragma.h (pragma_extern_prefix): Declare.
	* c-family/c-pragma.c (pragma_extern_prefix): Make it public.
	* config/vms/vms-c.c (saved_extern_prefix): New variable.
	(vms_pragma_extern_prefix): New function.
	(vms_c_register_pragma): Register vms_pragma_extern_prefix.
Joseph S. Myers - Nov. 9, 2011, 5:45 p.m.
On Mon, 7 Nov 2011, Tristan Gingold wrote:

> Hi,
> 
> DEC-C for vms has '#pragma __extern_prefix' which is not unlike '#pragma 
> extern_prefix' supported by DEC-C for Tru64.
> 
> This patch adds supports for the VMS version (which can save and restore 
> the current prefix).  It reuses most of the current infrastructure, but 
> to do so c-pragma.c:pragma_extern_prefix had to be public.
> 
> Manually tested by cross-building for ia64-vms and alpha-vms.
> 
> Ok for trunk ?

The c-family changes are OK.

Patch

diff --git a/gcc/c-family/c-pragma.c b/gcc/c-family/c-pragma.c
index 7622f0b..930423b 100644
--- a/gcc/c-family/c-pragma.c
+++ b/gcc/c-family/c-pragma.c
@@ -494,7 +494,8 @@  add_to_renaming_pragma_list (tree oldname, tree newname)
   p->newname = newname;
 }
 
-static GTY(()) tree pragma_extern_prefix;
+/* The current prefix set by #pragma extern_prefix.  */
+GTY(()) tree pragma_extern_prefix;
 
 /* #pragma extern_prefix "prefix" */
 static void
diff --git a/gcc/c-family/c-pragma.h b/gcc/c-family/c-pragma.h
index 04af94f..86681ae 100644
--- a/gcc/c-family/c-pragma.h
+++ b/gcc/c-family/c-pragma.h
@@ -146,4 +146,6 @@  extern enum cpp_ttype c_lex_with_flags (tree *, location_t *, unsigned char *,
 
 extern void c_pp_lookup_pragma (unsigned int, const char **, const char **);
 
+extern GTY(()) tree pragma_extern_prefix;
+
 #endif /* GCC_C_PRAGMA_H */
diff --git a/gcc/config/vms/vms-c.c b/gcc/config/vms/vms-c.c
index eb4c635..19291b6 100644
--- a/gcc/config/vms/vms-c.c
+++ b/gcc/config/vms/vms-c.c
@@ -227,6 +227,42 @@  vms_pragma_message (cpp_reader *pfile ATTRIBUTE_UNUSED)
 #endif
 }
 
+/* Handle '#pragma __extern_prefix'  */
+
+static GTY(()) tree saved_extern_prefix;
+
+static void
+vms_pragma_extern_prefix (cpp_reader * ARG_UNUSED (dummy))
+{
+  enum cpp_ttype tok;
+  tree x;
+
+  tok = pragma_lex (&x);
+  if (tok == CPP_NAME)
+    {
+      const char *op = IDENTIFIER_POINTER (x);
+
+      if (!strcmp (op, "__save"))
+        saved_extern_prefix = pragma_extern_prefix;
+      else if (!strcmp (op, "__restore"))
+        pragma_extern_prefix = saved_extern_prefix;
+      else
+        warning (OPT_Wpragmas,
+                 "malformed '#pragma __extern_prefix', ignoring");
+      return;
+    }
+  else if (tok != CPP_STRING)
+    {
+      warning (OPT_Wpragmas,
+               "malformed '#pragma __extern_prefix', ignoring");
+    }
+  else
+    {
+      /* Note that the length includes the null terminator.  */
+      pragma_extern_prefix = (TREE_STRING_LENGTH (x) > 1 ? x : NULL);
+    }
+}
+
 /* Add vms-specific pragma.  */
 
 void
@@ -245,4 +281,5 @@  vms_c_register_pragma (void)
   c_register_pragma (NULL, "__extern_model", vms_pragma_extern_model);
   c_register_pragma (NULL, "extern_model", vms_pragma_extern_model);
   c_register_pragma (NULL, "__message", vms_pragma_message);
+  c_register_pragma (NULL, "__extern_prefix", vms_pragma_extern_prefix);
 }