main.c 1.8 KB

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