main.c 1.7 KB

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