ref: 97f296d2d458fd1a887b903aec6b6dd72c64efa2
parent: 8b6e44b558a3894da366323db38df4dd358ced29
author: Roberto E. Vargas Caballero <[email protected]>
date: Wed May 6 15:04:17 EDT 2015
Convert emitsymid() to private of code.c We have emit(), so we don't need emitsymid() as public.
--- a/cc1/cc1.h
+++ b/cc1/cc1.h
@@ -169,7 +169,6 @@
emitdcl(Symbol *), emitefun(void),
emit(uint8_t, void *),
emitprint(Node *),
- emitsymid(uint8_t op, Symbol *sym),
emitbloop(void), emiteloop(void),
emitswitch(short),
emitret(Type *tp),
--- a/cc1/code.c
+++ b/cc1/code.c
@@ -10,7 +10,8 @@
static void emitbin(uint8_t, void *), emitunary(uint8_t, void *),
emitternary(uint8_t, void *), emitcast(uint8_t, void *),
emitsym(uint8_t, void *), emitfield(uint8_t, void *),
- emitsizeof(uint8_t, void *), emitexp(uint8_t op, void *arg);
+ emitsizeof(uint8_t, void *), emitexp(uint8_t op, void *arg),
+ emitsymid(uint8_t op, void *arg);
char *optxt[] = {
[OADD] = "+",
@@ -100,7 +101,13 @@
[OSYM] = emitsym,
[OASK] = emitternary,
[OFIELD]= emitfield,
- [OEXPR] = emitexp
+ [OEXPR] = emitexp,
+ [OLABEL] = emitsymid,
+ [ODEFAULT] = emitsymid,
+ [OCASE] = emitsymid,
+ [OSTRUCT] = emitsymid,
+ [OJUMP] = emitsymid,
+ [OBRANCH] = emitsymid,
};
void
@@ -285,9 +292,10 @@
puts("\tb");
}
-void
-emitsymid(uint8_t op, Symbol *sym)
+static void
+emitsymid(uint8_t op, void *arg)
{
+ Symbol *sym = arg;
printf(optxt[op], sym->id);
}
--- a/cc1/decl.c
+++ b/cc1/decl.c
@@ -315,7 +315,7 @@
if (tagtype->defined)
error("redefinition of struct/union '%s'", yytext);
tagtype->defined = 1;
- emitsymid(OSTRUCT, tagsym);
+ emit(OSTRUCT, tagsym);
while (!accept('}')) {
Type *base, *tp;
--- a/cc1/stmt.c
+++ b/cc1/stmt.c
@@ -87,15 +87,15 @@
expect(WHILE);
np = condition();
- emitsymid(OJUMP, cond);
+ emit(OJUMP, cond);
emitbloop();
- emitsymid(OLABEL, begin);
+ emit(OLABEL, begin);
stmt(end, begin, lswitch);
- emitsymid(OLABEL, cond);
- emitsymid(OBRANCH, begin);
+ emit(OLABEL, cond);
+ emit(OBRANCH, begin);
emit(OEXPR, np);
emiteloop();
- emitsymid(OLABEL, end);
+ emit(OLABEL, end);
freetree(np);
}
@@ -119,16 +119,16 @@
expect(')');
emit(OEXPR, einit);
- emitsymid(OJUMP, cond);
+ emit(OJUMP, cond);
emitbloop();
- emitsymid(OLABEL, begin);
+ emit(OLABEL, begin);
stmt(end, begin, lswitch);
emit(OEXPR, einc);
- emitsymid(OLABEL, cond);
- emitsymid(OBRANCH, begin);
+ emit(OLABEL, cond);
+ emit(OBRANCH, begin);
emit(OEXPR, econd);
emiteloop();
- emitsymid(OLABEL, end);
+ emit(OLABEL, end);
freetree(einit);
freetree(econd);
freetree(einc);
@@ -144,14 +144,14 @@
end = install("", NS_LABEL);
expect(DO);
emitbloop();
- emitsymid(OLABEL, begin);
+ emit(OLABEL, begin);
stmt(end, begin, lswitch);
expect(WHILE);
np = condition();
- emitsymid(OBRANCH, begin);
+ emit(OBRANCH, begin);
emit(OEXPR, np);
emiteloop();
- emitsymid(OLABEL, end);
+ emit(OLABEL, end);
freetree(np);
}
@@ -185,7 +185,7 @@
expect(BREAK);
if (!lbreak)
error("break statement not within loop or switch");
- emitsymid(OJUMP, lbreak);
+ emit(OJUMP, lbreak);
expect(';');
}
@@ -196,7 +196,7 @@
{
switch (yytoken) {
case IDEN: case TYPEIDEN:
- emitsymid(OLABEL, label(yytext, 1));
+ emit(OLABEL, label(yytext, 1));
next();
expect(':');
stmt(lbreak, lcont, lswitch);
@@ -212,7 +212,7 @@
expect(CONTINUE);
if (!lcont)
error("continue statement not within loop");
- emitsymid(OJUMP, lcont);
+ emit(OJUMP, lcont);
expect(';');
}
@@ -223,7 +223,7 @@
if (yytoken != IDEN)
unexpected();
- emitsymid(OJUMP, label(yytext, 0));
+ emit(OJUMP, label(yytext, 0));
next();
expect(';');
}
@@ -246,13 +246,13 @@
lbreak = install("", NS_LABEL);
lcond = install("", NS_LABEL);
- emitsymid(OJUMP, lcond);
+ emit(OJUMP, lcond);
stmt(lbreak, lcont, &lcase);
- emitsymid(OLABEL, lcond);
+ emit(OLABEL, lcond);
emitswitch(lcase.nr);
emit(OEXPR, cond);
for (p = lcase.head; p; p = next) {
- emitsymid(OCASE, p->label);
+ emit(OCASE, p->label);
emit(OEXPR, p->expr);
next = p->next;
freetree(p->expr);
@@ -259,8 +259,8 @@
free(p);
}
if (lcase.deflabel)
- emitsymid(ODEFAULT, lcase.deflabel);
- emitsymid(OLABEL, lbreak);
+ emit(ODEFAULT, lcase.deflabel);
+ emit(OLABEL, lbreak);
freetree(cond);
}
@@ -280,7 +280,7 @@
pcase = xmalloc(sizeof(*pcase));
pcase->expr = np;
pcase->next = lswitch->head;
- emitsymid(OLABEL, pcase->label = install("", NS_LABEL));
+ emit(OLABEL, pcase->label = install("", NS_LABEL));
lswitch->head = pcase;
++lswitch->nr;
}
@@ -292,7 +292,7 @@
expect(DEFAULT);
expect(':');
- emitsymid(OLABEL, ldefault);
+ emit(OLABEL, ldefault);
lswitch->deflabel = ldefault;
}
@@ -306,17 +306,17 @@
expect(IF);
np = condition();
NEGATE(np, 1);
- emitsymid(OBRANCH, lelse);
+ emit(OBRANCH, lelse);
emit(OEXPR, np);
stmt(lbreak, lcont, lswitch);
if (accept(ELSE)) {
end = install("", NS_LABEL);
- emitsymid(OJUMP, end);
- emitsymid(OLABEL, lelse);
+ emit(OJUMP, end);
+ emit(OLABEL, lelse);
stmt(lbreak, lcont, lswitch);
- emitsymid(OLABEL, end);
+ emit(OLABEL, end);
} else {
- emitsymid(OLABEL, lelse);
+ emit(OLABEL, lelse);
}
freetree(np);
}