scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit 5c6838058bf80ec9c14b72e9817bc0b80c539f1d
parent b1ed9087223b78b86fdbb90ffc858c2c99b02833
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Mon, 25 Jan 2016 09:48:13 +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.

Diffstat:
Mcc2/arch/z80/code.c | 28++++++++++++++++++++++++++++
Mcc2/cc2.h | 1-
Mcc2/symbol.c | 17-----------------
3 files changed, 28 insertions(+), 18 deletions(-)

diff --git 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, @@ -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 @@ -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 @@ -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; -}