[hackers] [scc] [cc2-z80] Use _ to mark global scoped symbols || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Mon, 25 Jan 2016 11:00:39 +0100 (CET)

commit 5c6838058bf80ec9c14b72e9817bc0b80c539f1d
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Mon Jan 25 09:48:13 2016 +0100
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Mon Jan 25 09:48:13 2016 +0100

    [cc2-z80] Use _ to mark global scoped symbols
    
    In the case of z80 we can play a bit with the ABI,
    and in this case is funny to use the old convention
    about names with global scope.

diff --git a/cc2/arch/z80/code.c b/cc2/arch/z80/code.c
index cfe2228..eae5b1a 100644
--- a/cc2/arch/z80/code.c
+++ b/cc2/arch/z80/code.c
_AT_@ -4,6 +4,7 @@
 
 #include "arch.h"
 #include "../../cc2.h"
+#include "../../../inc/sizes.h"
 
 enum segment {
         CODESEG,
_AT_@ -29,6 +30,33 @@ segment(int seg)
         curseg = seg;
 }
 
+static char *
+symname(Symbol *sym)
+{
+ static char name[IDENTSIZ+1];
+ static unsigned short id;
+ int k = sym->kind;
+
+ if (sym->name) {
+ switch (sym->kind) {
+ case GLOB:
+ case EXTRN:
+ snprintf(name, sizeof(name), "_%s", sym->name);
+ return name;;
+ case PRIVAT:
+ return sym->name;
+ }
+ }
+
+ if (sym->numid == 0) {
+ if ((sym->numid = ++id) == 0)
+ error(EIDOVER);
+ }
+ sprintf(name, ".%d", sym->numid);
+
+ return name;
+}
+
 void
 code(int op, Node *to, Node *from)
 {
diff --git a/cc2/cc2.h b/cc2/cc2.h
index b59e402..6f02d59 100644
--- a/cc2/cc2.h
+++ b/cc2/cc2.h
_AT_@ -167,4 +167,3 @@ extern Symbol *getsym(int id);
 extern void popctx(void);
 extern void pushctx(void);
 extern void freesym(Symbol *sym);
-extern char *symname(Symbol *sym);
diff --git a/cc2/symbol.c b/cc2/symbol.c
index 16fe8ce..f5984df 100644
--- a/cc2/symbol.c
+++ b/cc2/symbol.c
_AT_@ -65,20 +65,3 @@ getsym(int id)
         }
         return sym;
 }
-
-char *
-symname(Symbol *sym)
-{
- static char name[20];
- static unsigned short id;
-
- if (sym->name)
- return sym->name;
- if (sym->numid == 0) {
- if ((sym->numid = ++id) == 0)
- error(EIDOVER);
- }
- sprintf(name, ".%d", sym->numid);
-
- return name;
-}
Received on Mon Jan 25 2016 - 11:00:39 CET

This archive was generated by hypermail 2.3.0 : Mon Jan 25 2016 - 11:12:33 CET