commit 394f3485b1f97dc88cdc8d130f9a693d624c5d58
parent 975dc3570759c0609e8532e9dce4127d9216ac7b
Author: Roberto E. Vargas Caballero <Roberto E. Vargas Caballero>
Date: Tue, 26 Apr 2016 19:54:01 +0200
[cc2] Move generation of numid to getsym()
This change frees to the target of doing this operation, and it also allows
that some opimizations can use the numid field. It also has the drawback
of gerating numids that will be not used, and it means that temporary
labels are not going to be consecutive.
Diffstat:
5 files changed, 3 insertions(+), 9 deletions(-)
diff --git a/cc2/arch/amd64-sysv/code.c b/cc2/arch/amd64-sysv/code.c
@@ -45,8 +45,6 @@ symname(Symbol *sym)
}
}
- if (sym->numid == 0 && (sym->numid = ++id) == 0)
- error(EIDOVER);
sprintf(name, ".L%d", sym->numid);
return name;
diff --git a/cc2/arch/i386-sysv/code.c b/cc2/arch/i386-sysv/code.c
@@ -45,8 +45,6 @@ symname(Symbol *sym)
}
}
- if (sym->numid == 0 && (sym->numid = ++id) == 0)
- error(EIDOVER);
sprintf(name, ".L%d", sym->numid);
return name;
diff --git a/cc2/arch/qbe/code.c b/cc2/arch/qbe/code.c
@@ -171,9 +171,6 @@ symname(Symbol *sym)
abort();
}
}
-
- if (sym->numid == 0 && (sym->numid = ++id) == 0)
- error(EIDOVER);
sprintf(buff, "%c.%u", c, sym->numid);
return buff;
diff --git a/cc2/arch/z80/code.c b/cc2/arch/z80/code.c
@@ -48,8 +48,6 @@ symname(Symbol *sym)
}
}
- if (sym->numid == 0 && (sym->numid = ++id) == 0)
- error(EIDOVER);
sprintf(name, ".%d", sym->numid);
return name;
diff --git a/cc2/symbol.c b/cc2/symbol.c
@@ -48,6 +48,7 @@ Symbol *
getsym(unsigned id)
{
Symbol **htab, *sym;
+ static unsigned short num;
if (id > USHRT_MAX)
error(EBADID);
@@ -60,6 +61,8 @@ getsym(unsigned id)
if (!sym) {
sym = xcalloc(1, sizeof(*sym));
sym->id = id;
+ if ((sym->numid = ++num) == 0)
+ error(EIDOVER);
if (infunction) {
if (!locals)
locals = sym;