scc

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

commit cfd05d23cb1e3716f9d59e1ad95bbb29c4da713b
parent dbd4a25ef1165b87b3848ad1d7e64beb663b6329
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Fri, 14 Aug 2015 22:02:23 +0200

Reserve always an identifier for labels

Labels are always emitted, so they must have an identifier
always. Before this patch temporal labels were not installed
because they don't have name, and it caused that all the
temporal labels hadn't an identifier, they were emitted
as L0.

Diffstat:
Mcc1/symbol.c | 3++-
Mcc1/tests/test004.c | 7+++----
Mcc1/tests/test005.c | 4++--
3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/cc1/symbol.c b/cc1/symbol.c @@ -166,6 +166,7 @@ newsym(unsigned ns) return sym; if (ns == NS_LABEL) { sym->next = labels; + sym->id = ++localcnt; return labels = sym; } @@ -260,7 +261,7 @@ install(unsigned ns, Symbol *sym) sym = linkhash(newsym(ns), sym->name); assign_id: - if (sym->ns != NS_CPP) + if (sym->ns != NS_CPP || sym->ns != NS_LABEL) sym->id = (curctx) ? ++localcnt : ++globalcnt; return sym; diff --git a/cc1/tests/test004.c b/cc1/tests/test004.c @@ -22,9 +22,9 @@ A2 I x A2 A2 A2 #I3 <I #I1 #I0 ?I +I :I A2 A2 A2 #I1 >I #I1 #I0 ?I +I :I A2 A2 A2 #I4 <I #I1 #I0 ?I +I :I - j L0 A2 #I4 =I + j L3 A2 #I4 =I yI #I1 -L0 +L3 yI #I0 } */ @@ -52,4 +52,4 @@ main() if(x != 4) return 1; return 0; -} -\ No newline at end of file +} diff --git a/cc1/tests/test005.c b/cc1/tests/test005.c @@ -12,9 +12,9 @@ A2 I x A2 A2 #I0 =I #I1 #I0 ?I :I A2 A2 ~I :I A2 A2 _I :I - j L0 A2 #I2 =I + j L3 A2 #I2 =I yI #I1 -L0 +L3 yI #I0 } */