gnupic: gpasm `extern' vs `global' (new feature patch)


Previous by date: 29 Oct 2005 18:07:49 +0100 Re: [gnupic] Switch, Scott Dattalo
Next by date: 29 Oct 2005 18:07:49 +0100 Re: [gnupic] picp 0.6.7 and data eeprom of 16f873, Nestor A. Marchesini
Previous in thread: 29 Oct 2005 18:07:49 +0100 Re: gpasm `extern' vs `global' (new feature patch), Craig Franklin
Next in thread:

Subject: Re: gpasm `extern' vs `global' (new feature patch)
From: Ian Jackson ####@####.####
Date: 29 Oct 2005 18:07:49 +0100
Message-Id: <17251.44121.536566.890436@davenant.relativity.greenend.org.uk>

In April, I wrote:
> I found it inconvenient that when defining a global symbol (one with
> `external linkage' in C parlance, although there is of course no C
> here) in gpasm I have to say `global', but when I'm referring to it I
> have to say `extern'.  That means I can't have one include file with a
> list of all of the global symbols.
> 
> So, I wrote the patch below which is supposed to allow the use of
> `extern' even for symbols defined in the same file, at least for
> labels.  (You have to say `extern' before the label.)  When the
> definition is encountered the symbol is converted from extern to
> global.  This appears to work for me.

I tried actually using my patch in anger and it doesn't work.  It
messes up the way the coff symbol table entry numbers are calculated.

So, after some head-scratching, I came up with an alternative - see
below.  With this new patch you have to say `extern' _after_ the
definition.  If you do, it treats the `extern' more or less as if it
was `global'.

This is a less friendly version of the patch than the previous one,
IMO, but the way the coff symbol number calculation is done makes it
impractical do it it another way.

The patch is against 0.13.3-1 from Debian; if applying to the
non-Debian version you can just ignore the attempt to edit
debian/changelog - and will probably want to make a change to
ChangeLog instead.

Regards,
Ian.

diff -ru orig/gputils-0.13.3/debian/changelog gputils-0.13.3/debian/changelog
--- orig/gputils-0.13.3/debian/changelog	2005-10-28 00:02:21.754919510 +0100
+++ gputils-0.13.3/debian/changelog	2005-10-29 17:24:17.498756153 +0100
@@ -1,3 +1,13 @@
+gputils (0.13.3-1.0iwj2) unstable; urgency=low
+
+  * extern/global feature for labels:
+    If we encounter `extern' for a label which is already defined
+    as gvt_static or gvt_address, we change it to gvt_global.
+    This means that `extern' after a label definition is much like
+    `global'.
+
+ -- Ian Jackson ####@####.####  Sat, 29 Oct 2005 17:24:12 +0100
+
 gputils (0.13.3-1) unstable; urgency=low
 
   * New upstream version. 
Only in gputils-0.13.3/debian: changelog~
diff -ru orig/gputils-0.13.3/gpasm/coff.c gputils-0.13.3/gpasm/coff.c
--- orig/gputils-0.13.3/gpasm/coff.c	2005-01-03 22:21:04.000000000 +0000
+++ gputils-0.13.3/gpasm/coff.c	2005-10-29 15:59:18.913415094 +0100
@@ -447,7 +447,7 @@
     if ((new->type != class) || 
         (new->section_number != section_number)) {
       snprintf(message, sizeof(message),
-               "Duplicate label or redefining symbol that cannot be redefined. (%s)",
+               "Duplicate extern label or redefining symbol that cannot be redefined. (%s)",
                name);    
       gperror(GPE_UNKNOWN, message);
     }
@@ -455,7 +455,7 @@
 
   if ((new != NULL) && (type != gvt_extern) && (type != gvt_debug))  {
     snprintf(message, sizeof(message),
-             "Duplicate label or redefining symbol that cannot be redefined. (%s)",
+             "Duplicate non-extern label or redefining symbol that cannot be redefined. (%s)",
              name);    
     gperror(GPE_DUPLAB, message);
   } else {
diff -ru orig/gputils-0.13.3/gpasm/directive.c gputils-0.13.3/gpasm/directive.c
--- orig/gputils-0.13.3/gpasm/directive.c	2005-07-02 18:10:13.000000000 +0100
+++ gputils-0.13.3/gpasm/directive.c	2005-10-29 17:06:08.431816728 +0100
@@ -1342,6 +1342,8 @@
 		          struct pnode *parms)
 {
   char *p;
+  struct symbol *s;
+  struct variable *var;
   state.lst.line.linetype = dir;
   
   if (state.mode == absolute) {
@@ -1350,7 +1352,15 @@
     for (; parms; parms = TAIL(parms)) {
       p = maybe_evaluate_concat(HEAD(parms));
       if (p) {
-        set_global(p, 0, PERMANENT, gvt_extern);
+	s = get_symbol(state.stTop, p);
+	var = s ? get_symbol_annotation(s) : NULL;
+	if (var &&
+	    (var->previous_type == gvt_static || 
+	     var->previous_type == gvt_address)) {
+	  var->type = gvt_global;
+	} else {
+	  set_global(p, 0, PERMANENT, gvt_extern);
+	}
       }
     }
   }

-- 
Ian Jackson, at home.           Local/personal: ####@####.####
####@####.####       http://www.chiark.greenend.org.uk/~ijackson/
Problems mailing me ?  Send postmaster@chiark the bounce (bypasses the blocks).

Previous by date: 29 Oct 2005 18:07:49 +0100 Re: [gnupic] Switch, Scott Dattalo
Next by date: 29 Oct 2005 18:07:49 +0100 Re: [gnupic] picp 0.6.7 and data eeprom of 16f873, Nestor A. Marchesini
Previous in thread: 29 Oct 2005 18:07:49 +0100 Re: gpasm `extern' vs `global' (new feature patch), Craig Franklin
Next in thread:


Powered by ezmlm-browse 0.20.