ref: bb963053b66e9f3f8a62bbba26deb6028b174ba3
parent: 200e2387df6fa8f874a4504437b3787df5327368
author: Roberto E. Vargas Caballero <[email protected]>
date: Tue Apr 26 15:54:01 EDT 2016
[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.
--- a/cc2/arch/amd64-sysv/code.c
+++ b/cc2/arch/amd64-sysv/code.c
@@ -45,8 +45,6 @@
}
}
- if (sym->numid == 0 && (sym->numid = ++id) == 0)
- error(EIDOVER);
sprintf(name, ".L%d", sym->numid);
return name;
--- a/cc2/arch/i386-sysv/code.c
+++ b/cc2/arch/i386-sysv/code.c
@@ -45,8 +45,6 @@
}
}
- if (sym->numid == 0 && (sym->numid = ++id) == 0)
- error(EIDOVER);
sprintf(name, ".L%d", sym->numid);
return name;
--- a/cc2/arch/qbe/code.c
+++ b/cc2/arch/qbe/code.c
@@ -171,9 +171,6 @@
abort();
}
}
-
- if (sym->numid == 0 && (sym->numid = ++id) == 0)
- error(EIDOVER);
sprintf(buff, "%c.%u", c, sym->numid);
return buff;
--- a/cc2/arch/z80/code.c
+++ b/cc2/arch/z80/code.c
@@ -48,8 +48,6 @@
}
}
- if (sym->numid == 0 && (sym->numid = ++id) == 0)
- error(EIDOVER);
sprintf(name, ".%d", sym->numid);
return name;
--- a/cc2/symbol.c
+++ b/cc2/symbol.c
@@ -48,6 +48,7 @@
getsym(unsigned id)
{
Symbol **htab, *sym;
+ static unsigned short num;
if (id > USHRT_MAX)
error(EBADID);
@@ -60,6 +61,8 @@
if (!sym) {
sym = xcalloc(1, sizeof(*sym));
sym->id = id;
+ if ((sym->numid = ++num) == 0)
+ error(EIDOVER);
if (infunction) {
if (!locals)
locals = sym;