ref: f6bedbd384f66b022d44140e44d2d0e63f7b1532
dir: /cc2/main.c/
/* See LICENSE file for copyright and license details. */
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include "../inc/cc.h"
#include "cc2.h"
#include "error.h"
void
error(unsigned nerror, ...)
{
va_list va;
va_start(va, nerror);
vfprintf(stderr, errlist[nerror], va);
va_end(va);
putc('\n', stderr);
exit(1);
}
static int
moreinput(void)
{
int c;
repeat:
if (feof(stdin))
return 0;
if ((c = getchar()) == '\n' || c == EOF)
goto repeat;
ungetc(c, stdin);
return 1;
}
int
main(int argc, char *argv[])
{
if (argc > 2)
die("usage: cc2 [irfile]");
if (argv[1] && !freopen(argv[1], "r", stdin))
die("cc2: cannot open %s", argv[1]);
while (moreinput()) {
parse();
apply(optm_ind);
apply(optm_dep);
apply(sethi);
apply(cgen);
getbblocks(); /* TODO: run apply over asm ins too */
peephole();
writeout();
}
return 0;
}