ref: 5c6838058bf80ec9c14b72e9817bc0b80c539f1d
parent: b1ed9087223b78b86fdbb90ffc858c2c99b02833
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Mon Jan 25 04:48:13 EST 2016
[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.
--- a/cc2/arch/z80/code.c
+++ b/cc2/arch/z80/code.c
@@ -4,6 +4,7 @@
#include "arch.h"
#include "../../cc2.h"
+#include "../../../inc/sizes.h"
enum segment {
CODESEG,
@@ -27,6 +28,33 @@
return;
fputs(txt[seg], stdout);
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
--- a/cc2/cc2.h
+++ b/cc2/cc2.h
@@ -167,4 +167,3 @@
extern void popctx(void);
extern void pushctx(void);
extern void freesym(Symbol *sym);
-extern char *symname(Symbol *sym);
--- a/cc2/symbol.c
+++ b/cc2/symbol.c
@@ -65,20 +65,3 @@
}
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;
-}