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