scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

main.c (998B)


      1 #include <errno.h>
      2 #include <stdarg.h>
      3 #include <stdio.h>
      4 #include <stdlib.h>
      5 #include <string.h>
      6 
      7 #include <scc/arg.h>
      8 #include <scc/scc.h>
      9 #include "cc2.h"
     10 #include "error.h"
     11 
     12 char *argv0;
     13 
     14 void
     15 error(unsigned nerror, ...)
     16 {
     17 	va_list va;
     18 	va_start(va, nerror);
     19 	fputs("cc2:", stderr);
     20 	vfprintf(stderr, errlist[nerror], va);
     21 	va_end(va);
     22 	putc('\n', stderr);
     23 	exit(1);
     24 }
     25 
     26 static int
     27 moreinput(void)
     28 {
     29 	int c;
     30 
     31 repeat:
     32 	if (feof(stdin))
     33 		return 0;
     34 	if ((c = getchar()) == '\n' || c == EOF)
     35 		goto repeat;
     36 	ungetc(c, stdin);
     37 	return 1;
     38 }
     39 
     40 static void
     41 usage(void)
     42 {
     43 	fputs("usage: cc2 [irfile]\n", stderr);
     44 	exit(1);
     45 }
     46 
     47 int
     48 main(int argc, char *argv[])
     49 {
     50 	ARGBEGIN {
     51 	default:
     52 		usage();
     53 	} ARGEND
     54 
     55 	if (argv[0] && !freopen(argv[0], "r", stdin))
     56 		die("cc2: %s: %s", argv[0], strerror(errno));
     57 
     58 	while (moreinput()) {
     59 		parse();
     60 		apply(optm_ind);
     61 		apply(optm_dep);
     62 		apply(sethi);
     63 		apply(cgen);
     64 		getbblocks();  /* TODO: run apply over asm ins too */
     65 		peephole();
     66 		writeout();
     67 	}
     68 	return 0;
     69 }