Push em_ego.c through clang-format before working on it.

This commit is contained in:
David Given 2016-08-21 18:45:25 +02:00
parent 1a7b4f8729
commit 03a0b182c4
2 changed files with 390 additions and 328 deletions

11
.clang-format Normal file
View file

@ -0,0 +1,11 @@
---
BasedOnStyle: WebKit
AllowShortLoopsOnASingleLine: 'false'
AlwaysBreakAfterDefinitionReturnType: false
BreakBeforeBraces: Allman
IndentCaseLabels: 'true'
PointerAlignment: Left
TabWidth: '4'
UseTab: ForIndentation
...

View file

@ -87,22 +87,26 @@ cleanup()
{ {
/* Cleanup temporaries */ /* Cleanup temporaries */
if (! keeptemps) { if (!keeptemps)
{
register int i; register int i;
for (i = NTEMPS*2; i > 0; i--) { for (i = NTEMPS * 2; i > 0; i--)
{
register char* f = phargs[i]; register char* f = phargs[i];
if (f != 0 && *f != '\0' && *f != '-') (void) unlink(f); if (f != 0 && *f != '\0' && *f != '-')
(void)unlink(f);
} }
if (ddump[0] != '\0') (void) unlink(ddump); if (ddump[0] != '\0')
if (pdump[0] != '\0') (void) unlink(pdump); (void)unlink(ddump);
if (pdump[0] != '\0')
(void)unlink(pdump);
} }
} }
/*VARARGS1*/ /*VARARGS1*/
static void static void
fatal(s, s2) fatal(s, s2) char* s;
char *s;
char* s2; char* s2;
{ {
/* A fatal error occurred; exit gracefully */ /* A fatal error occurred; exit gracefully */
@ -116,27 +120,26 @@ fatal(s, s2)
} }
static void static void
add_file(s) add_file(s) char* s;
char *s;
{ {
/* Add an input file to the list */ /* Add an input file to the list */
if (nfiles >= MAXARGS) fatal("too many files"); if (nfiles >= MAXARGS)
fatal("too many files");
phargs[nfiles++] = s; phargs[nfiles++] = s;
} }
static void static void
add_uphase(p) add_uphase(p) int p;
int p;
{ {
/* Add an optimizer phase to the list of phases to run */ /* Add an optimizer phase to the list of phases to run */
if (nuphases >= MAXUPHASES) fatal("too many phases"); if (nuphases >= MAXUPHASES)
fatal("too many phases");
uphases[nuphases++] = p; uphases[nuphases++] = p;
} }
static void static void catch ()
catch()
{ {
/* Catch interrupts and exit gracefully */ /* Catch interrupts and exit gracefully */
@ -151,9 +154,11 @@ old_infiles()
register int i; register int i;
if (phargs[1] == pdump || keeptemps) return; if (phargs[1] == pdump || keeptemps)
return;
for (i = 1; i <= NTEMPS; i++) (void) unlink(phargs[i]); for (i = 1; i <= NTEMPS; i++)
(void)unlink(phargs[i]);
} }
static void static void
@ -165,7 +170,8 @@ get_infiles()
register char** dst = &phargs[1]; register char** dst = &phargs[1];
register char** src = &phargs[NTEMPS + 1]; register char** src = &phargs[NTEMPS + 1];
for (i = 1; i <= NTEMPS; i++) { for (i = 1; i <= NTEMPS; i++)
{
*dst++ = *src++; *dst++ = *src++;
} }
} }
@ -180,26 +186,29 @@ new_outfiles()
register int i; register int i;
register char** dst = &phargs[NTEMPS + 1]; register char** dst = &phargs[NTEMPS + 1];
if (! Bindex) { if (!Bindex)
{
Bindex = strrchr(tmpbufs[0], 'B') - tmpbufs[0]; Bindex = strrchr(tmpbufs[0], 'B') - tmpbufs[0];
} }
for (i = 1; i <= NTEMPS; i++) { for (i = 1; i <= NTEMPS; i++)
{
*dst = tmpbufs[tmpindex]; *dst = tmpbufs[tmpindex];
(*dst)[Bindex - 1] = dig2; (*dst)[Bindex - 1] = dig2;
(*dst)[Bindex] = dig1; (*dst)[Bindex] = dig1;
tmpindex++; tmpindex++;
dst++; dst++;
} }
if (tmpindex >= 2*NTEMPS) tmpindex = 0; if (tmpindex >= 2 * NTEMPS)
if (++dig1 > '9') { tmpindex = 0;
if (++dig1 > '9')
{
++dig2; ++dig2;
dig1 = '0'; dig1 = '0';
} }
} }
static void static void
run_phase(phase) run_phase(phase) int phase;
int phase;
{ {
/* Run one phase of the global optimizer; special cases are /* Run one phase of the global optimizer; special cases are
IC and CA. IC and CA.
@ -215,11 +224,13 @@ run_phase(phase)
(void)strcat(buf, "/"); (void)strcat(buf, "/");
(void)strcat(buf, phnames[phase]); (void)strcat(buf, phnames[phase]);
switch(phase) { switch (phase)
{
case IC: case IC:
phargs[1] = pdump; phargs[1] = pdump;
phargs[2] = ddump; phargs[2] = ddump;
for (i = 3; i <= NTEMPS; i++) phargs[i] = "-"; for (i = 3; i <= NTEMPS; i++)
phargs[i] = "-";
new_outfiles(); new_outfiles();
argc = nfiles; argc = nfiles;
phargs[argc] = 0; phargs[argc] = 0;
@ -230,7 +241,8 @@ run_phase(phase)
get_infiles(); get_infiles();
phargs[NTEMPS + 1] = pdump; phargs[NTEMPS + 1] = pdump;
phargs[NTEMPS + 2] = ddump; phargs[NTEMPS + 2] = ddump;
for (i = NTEMPS+3; i <= 2*NTEMPS; i++) phargs[i] = "-"; for (i = NTEMPS + 3; i <= 2 * NTEMPS; i++)
phargs[i] = "-";
argc = 2 * NTEMPS + 1; argc = 2 * NTEMPS + 1;
phargs[argc] = 0; phargs[argc] = 0;
break; break;
@ -239,24 +251,30 @@ run_phase(phase)
old_infiles(); old_infiles();
get_infiles(); get_infiles();
new_outfiles(); new_outfiles();
if (! flags_added) { if (!flags_added)
{
flags_added = 1; flags_added = 1;
argc = 2 * NTEMPS + 1; argc = 2 * NTEMPS + 1;
while (--nphase_args >= 0) { while (--nphase_args >= 0)
{
phargs[argc++] = *phase_args++; phargs[argc++] = *phase_args++;
} }
phargs[argc] = 0; phargs[argc] = 0;
} }
break; break;
} }
if ((pid = fork()) < 0) { if ((pid = fork()) < 0)
{
fatal("Could not fork"); fatal("Could not fork");
} }
else if (pid == 0) { else if (pid == 0)
if (v_flag) { {
if (v_flag)
{
register int i = 0; register int i = 0;
while (phargs[i]) { while (phargs[i])
{
fprint(STDERR, "%s ", phargs[i]); fprint(STDERR, "%s ", phargs[i]);
i++; i++;
} }
@ -266,35 +284,45 @@ run_phase(phase)
fatal("Could not exec %s", phargs[0]); fatal("Could not exec %s", phargs[0]);
sys_stop(S_EXIT); sys_stop(S_EXIT);
} }
else { else
while (wait(&status) != pid) /* nothing */ ; {
if ((status & 0177) != 0) { while (wait(&status) != pid) /* nothing */
;
if ((status & 0177) != 0)
{
fatal("%s got a unix signal", phargs[0]); fatal("%s got a unix signal", phargs[0]);
} }
if (((status >> 8) & 0377) != 0) { if (((status >> 8) & 0377) != 0)
{
cleanup(); cleanup();
sys_stop(S_EXIT); sys_stop(S_EXIT);
} }
} }
} }
main(argc, argv) main(argc, argv) int argc;
int argc;
char* argv[]; char* argv[];
{ {
register int i = 0; register int i = 0;
if (signal(SIGHUP, catch) == SIG_IGN) (void) signal(SIGHUP, SIG_IGN); if (signal(SIGHUP, catch) == SIG_IGN)
if (signal(SIGQUIT, catch) == SIG_IGN) (void) signal(SIGQUIT, SIG_IGN); (void)signal(SIGHUP, SIG_IGN);
if (signal(SIGINT, catch) == SIG_IGN) (void) signal(SIGINT, SIG_IGN); if (signal(SIGQUIT, catch) == SIG_IGN)
(void)signal(SIGQUIT, SIG_IGN);
if (signal(SIGINT, catch) == SIG_IGN)
(void)signal(SIGINT, SIG_IGN);
prog_name = argv[0]; prog_name = argv[0];
phase_args = &argv[1]; phase_args = &argv[1];
while (--argc > 0) { while (--argc > 0)
{
argv++; argv++;
if (argv[0][0] == '-') { if (argv[0][0] == '-')
switch(argv[0][1]) { {
switch (argv[0][1])
{
case 'P': case 'P':
if (argv[0][2] == '\0') { if (argv[0][2] == '\0')
{
opt_dir = argv[1]; opt_dir = argv[1];
argc--; argc--;
argv++; argv++;
@ -302,7 +330,8 @@ main(argc, argv)
} }
break; break;
case 't': case 't':
if (argv[0][2] == '\0') { if (argv[0][2] == '\0')
{
keeptemps = 1; keeptemps = 1;
/* no continue; IL also needs this */ /* no continue; IL also needs this */
} }
@ -311,60 +340,71 @@ main(argc, argv)
v_flag = 1; v_flag = 1;
break; break;
case 'O': case 'O':
if (argv[0][2] == '2' || argv[0][2] == '\0') continue; if (argv[0][2] == '2' || argv[0][2] == '\0')
if (argv[0][2] == '3') { continue;
if (argv[0][2] == '3')
{
Ophase = &O3phases[0]; Ophase = &O3phases[0];
continue; continue;
} }
Ophase = &O4phases[0]; Ophase = &O4phases[0];
continue; continue;
case 'I': case 'I':
if (! strcmp(&argv[0][1], "IL")) { if (!strcmp(&argv[0][1], "IL"))
{
add_uphase(IL); add_uphase(IL);
add_uphase(CF); add_uphase(CF);
continue; continue;
} }
break; break;
case 'B': case 'B':
if (! strcmp(&argv[0][1], "BO")) { if (!strcmp(&argv[0][1], "BO"))
{
add_uphase(BO); add_uphase(BO);
continue; continue;
} }
break; break;
case 'R': case 'R':
if (! strcmp(&argv[0][1], "RA")) { if (!strcmp(&argv[0][1], "RA"))
{
add_uphase(RA); add_uphase(RA);
continue; continue;
} }
break; break;
case 'U': case 'U':
if (! strcmp(&argv[0][1], "UD")) { if (!strcmp(&argv[0][1], "UD"))
{
add_uphase(UD); add_uphase(UD);
continue; continue;
} }
break; break;
case 'L': case 'L':
if (! strcmp(&argv[0][1], "LV")) { if (!strcmp(&argv[0][1], "LV"))
{
add_uphase(LV); add_uphase(LV);
continue; continue;
} }
break; break;
case 'C': case 'C':
if (! strcmp(&argv[0][1], "CS")) { if (!strcmp(&argv[0][1], "CS"))
{
add_uphase(CS); add_uphase(CS);
continue; continue;
} }
if (! strcmp(&argv[0][1], "CJ")) { if (!strcmp(&argv[0][1], "CJ"))
{
add_uphase(CJ); add_uphase(CJ);
continue; continue;
} }
break; break;
case 'S': case 'S':
if (! strcmp(&argv[0][1], "SR")) { if (!strcmp(&argv[0][1], "SR"))
{
add_uphase(SR); add_uphase(SR);
continue; continue;
} }
if (! strcmp(&argv[0][1], "SP")) { if (!strcmp(&argv[0][1], "SP"))
{
add_uphase(SP); add_uphase(SP);
continue; continue;
} }
@ -372,24 +412,29 @@ main(argc, argv)
} }
phase_args[i++] = argv[0]; phase_args[i++] = argv[0];
} }
else { else
{
add_file(argv[0]); add_file(argv[0]);
} }
} }
phase_args[i] = 0; phase_args[i] = 0;
nphase_args = i; nphase_args = i;
if (nuphases) Ophase = uphases; if (nuphases)
Ophase = uphases;
if (nfiles == 2*NTEMPS+1) { if (nfiles == 2 * NTEMPS + 1)
{
/* 2*NTEMPS+1 was the starting value; nothing to do */ /* 2*NTEMPS+1 was the starting value; nothing to do */
sys_stop(S_END); sys_stop(S_END);
} }
if (! opt_dir) { if (!opt_dir)
{
fatal("no correct -P flag given"); fatal("no correct -P flag given");
} }
if (keeptemps) { if (keeptemps)
{
(void)strcpy(ddump, "."); (void)strcpy(ddump, ".");
(void)strcpy(pdump, "."); (void)strcpy(pdump, ".");
(void)strcpy(tmpbufs[0], "."); (void)strcpy(tmpbufs[0], ".");
@ -401,17 +446,23 @@ main(argc, argv)
(void)strcat(tmpbufs[0], "/ego.A.BB.XXXXXX"); (void)strcat(tmpbufs[0], "/ego.A.BB.XXXXXX");
(void)mktemp(tmpbufs[0]); (void)mktemp(tmpbufs[0]);
for (i = 2*NTEMPS-1; i >= 1; i--) { for (i = 2 * NTEMPS - 1; i >= 1; i--)
{
(void)strcpy(tmpbufs[i], tmpbufs[0]); (void)strcpy(tmpbufs[i], tmpbufs[0]);
} }
i = strrchr(tmpbufs[0], 'A') - tmpbufs[0]; i = strrchr(tmpbufs[0], 'A') - tmpbufs[0];
tmpbufs[0][i] = 'p'; tmpbufs[NTEMPS+0][i] = 'p'; tmpbufs[0][i] = 'p';
tmpbufs[1][i] = 'd'; tmpbufs[NTEMPS+1][i] = 'd'; tmpbufs[NTEMPS + 0][i] = 'p';
tmpbufs[2][i] = 'l'; tmpbufs[NTEMPS+2][i] = 'l'; tmpbufs[1][i] = 'd';
tmpbufs[3][i] = 'b'; tmpbufs[NTEMPS+3][i] = 'b'; tmpbufs[NTEMPS + 1][i] = 'd';
tmpbufs[2][i] = 'l';
tmpbufs[NTEMPS + 2][i] = 'l';
tmpbufs[3][i] = 'b';
tmpbufs[NTEMPS + 3][i] = 'b';
run_phase(IC); run_phase(IC);
run_phase(CF); run_phase(CF);
while (*Ophase) { while (*Ophase)
{
run_phase(*Ophase++); run_phase(*Ophase++);
} }
run_phase(CA); run_phase(CA);