Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

141 lines
2.9 KiB

  1. // Copyright (c) 1993-1999 Microsoft Corporation
  2. /* Edits:
  3. * 06-Dec-80 Broken out of y4.c, impure data in y4imp.c.
  4. * 18-Dec-80 ZAPFILE not used for decus compiler, fmkdl() used.
  5. */
  6. #include "y4.h"
  7. void
  8. callopt( void )
  9. {
  10. SSIZE_T i, j, k, *p, *q;
  11. /* read the arrays from tempfile and set parameters */
  12. if( (finput=fopen(TEMPNAME,"r")) == NULL ) error( "optimizer cannot open tempfile" );
  13. pgo[0] = 0;
  14. yypact[0] = 0;
  15. nstate = 0;
  16. nnonter = 0;
  17. for(;;)
  18. {
  19. switch( gtnm() )
  20. {
  21. case '\n':
  22. yypact[++nstate] = (--pmem) - mem0;
  23. case ',':
  24. continue;
  25. case '$':
  26. break;
  27. default:
  28. error( "bad tempfile" );
  29. }
  30. break;
  31. }
  32. yypact[nstate] = yypgo[0] = (--pmem) - mem0;
  33. for(;;)
  34. {
  35. switch( gtnm() )
  36. {
  37. case '\n':
  38. yypgo[++nnonter]= pmem-mem0;
  39. case '\r':
  40. case ',' :
  41. continue;
  42. case -1: /* EOF */
  43. break;
  44. default:
  45. error( "bad tempfile" );
  46. }
  47. break;
  48. }
  49. yypgo[nnonter--] = (--pmem) - mem0;
  50. for( i=0; i<nstate; ++i )
  51. {
  52. k = 32000;
  53. j = 0;
  54. q = mem0 + yypact[i+1];
  55. for( p = mem0 + yypact[i]; p<q ; p += 2 )
  56. {
  57. if( *p > j ) j = *p;
  58. if( *p < k ) k = *p;
  59. }
  60. if( k <= j )
  61. {
  62. /* nontrivial situation */
  63. /* temporarily, kill this for compatibility
  64. j -= k; j is now the range */
  65. if( k > maxoff ) maxoff = k;
  66. }
  67. greed[i] = (yypact[i+1]-yypact[i]) + 2*j;
  68. if( j > maxspr ) maxspr = j;
  69. }
  70. /* initialize ggreed table */
  71. for( i=1; i<=nnonter; ++i )
  72. {
  73. ggreed[i] = 1;
  74. j = 0;
  75. /* minimum entry index is always 0 */
  76. q = mem0 + yypgo[i+1] -1;
  77. for( p = mem0+yypgo[i]; p<q ; p += 2 )
  78. {
  79. ggreed[i] += 2;
  80. if( *p > j ) j = *p;
  81. }
  82. ggreed[i] = ggreed[i] + 2*j;
  83. if( j > maxoff ) maxoff = j;
  84. }
  85. /* now, prepare to put the shift actions into the a array */
  86. for( i=0; i<ACTSIZE; ++i ) a[i] = 0;
  87. maxa = a;
  88. for( i=0; i<nstate; ++i )
  89. {
  90. if( greed[i]==0 && adb>1 ) fprintf( ftable, "State %d: null\n", i );
  91. pa[i] = YYFLAG1;
  92. }
  93. while( (i = nxti()) != NOMORE )
  94. {
  95. if( i >= 0 ) stin(i);
  96. else gin(-i);
  97. }
  98. if( adb>2 )
  99. {
  100. /* print a array */
  101. for( p=a; p <= maxa; p += 10)
  102. {
  103. fprintf( ftable, "%4d ", p-a );
  104. for( i=0; i<10; ++i ) fprintf( ftable, "%4d ", p[i] );
  105. fprintf( ftable, "\n" );
  106. }
  107. }
  108. /* write out the output appropriate to the language */
  109. aoutput();
  110. osummary();
  111. fclose(finput);
  112. ZAPFILE(TEMPNAME);
  113. }