Pristine Ack-5.5
[Ack-5.5.git] / mach / proto / cg / main.c
1 #ifndef NORCSID
2 static char rcsid[] = "$Id: main.c,v 2.6 1994/06/24 13:23:50 ceriel Exp $";
3 #endif
4
5 #include "param.h"
6 #include "mach.h"
7
8 /*
9  * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
10  * See the copyright notice in the ACK home directory, in the file "Copyright".
11  *
12  * Author: Hans van Staveren
13  */
14
15 char *progname;
16 extern char startupcode[];
17 int maxply=1;
18 #ifndef NDEBUG
19 int Debug=0;
20 #endif
21
22 extern int endofprog;
23
24 main(argc,argv) char **argv; {
25         register unsigned n;
26         extern unsigned cc1,cc2,cc3,cc4;
27         unsigned ggd();
28
29         progname = argv[0];
30         while (--argc && **++argv == '-') {
31                 switch(argv[0][1]) {
32 #ifndef NDEBUG
33                 case 'd':
34                         Debug++; break;
35 #endif
36                 case 'p':
37                         maxply = atoi(argv[0]+2);
38                         break;
39                 case 'w':       /* weight percentage for size */
40                         n=atoi(argv[0]+2);
41                         cc1 *= n;
42                         cc2 *= 50;
43                         cc3 *= (100-n);
44                         cc4 *= 50;
45                         n=ggd(cc1,cc2);
46                         cc1 /= n;
47                         cc2 /= n;
48                         n=ggd(cc3,cc4);
49                         cc3 /= n;
50                         cc4 /= n;
51                         break;
52                 default:
53 #ifdef MACH_OPTIONS
54                         mach_option(argv[0]);
55 #else
56                         error("Unknown flag %c",argv[0][1]);
57 #endif
58                         break;
59                 }
60         }
61         if (argc < 1 || argc > 2)
62                 error("Usage: %s EMfile [ asfile ]",progname);
63         in_init(argv[0]);
64         out_init(argv[1]);
65         in_start();
66         codegen(startupcode,maxply,TRUE,MAXINT,0);
67         in_finish();
68         if (!endofprog)
69                 error("Bombed out of codegen");
70         out_finish();
71 }
72
73 unsigned ggd(a,b) register unsigned a,b; {
74         register unsigned c;
75
76         do {
77                 c = a%b; a=b; b=c;
78         } while (c!=0);
79         return(a);
80 }