home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 1 / crawlyvol1.bin / program / compiler / nasm20b / nasm_src / stats.c < prev    next >
C/C++ Source or Header  |  1993-01-19  |  4KB  |  99 lines

  1. /* ---------------------------------------------------------------------- */
  2. /*                   Copyright (C) 1991 by Natürlich!                     */
  3. /*                      This file is copyrighted!                         */
  4. /*                Refer to the documentation for details.                 */
  5. /* ---------------------------------------------------------------------- */
  6. #include "defines.h"
  7.  
  8. #if STATISTICS
  9.  
  10. # include "nasm.h"
  11. # include "imm.h"
  12. # include "seg.h"
  13. # include OSBIND
  14. # include NMALLOC_H
  15. # include <time.h>
  16. # include <stdio.h>
  17.  
  18.  
  19. word  _m_expr,    _a_expr,  _efrees, _erfrees,
  20.       _m_label,   _a_label,
  21.       _m_llabel,  _a_llabel,
  22.       _m_char,    _a_char,
  23.       _m_lexpr,   _a_lexpr,
  24.       _m_ref,     _a_ref,
  25.       _m_seg,     _a_seg,
  26.       _m_imm,     _a_imm,
  27.       _m_fix,           _a_fix,
  28.       _m_macro;
  29. long  _s_expr,  _s_label, _s_char,   _z_char, _s_ref,
  30.       _s_macro, _s_lexpr, _s_llabel, _s_imm,  _s_seg, _s_fix,
  31.       _mused, _maxused;
  32.  
  33. extern word  tok_remain;
  34.  
  35.  
  36. static void p( what, alls, malls, size, isize, usage)
  37. char    *what;
  38. word    alls, malls;
  39. long    size;
  40. size_t  isize;
  41. word    usage;
  42. {
  43.    printf("%4u %8s [à %2ld bytes]: %5ld bytes, %2d%% usage (%2d mallocs à %ld bytes)\n",
  44.             alls, what, (long) isize, size * malls, usage, malls, size);
  45. }
  46.  
  47. # if __NSTDC__
  48.  
  49. #  define yy( x)                                                                                                                                        \
  50.         (word) ((_m_ ## x * _s_ ## x)                                  \
  51.                 ?       ((sizeof( x) * _a_ ## x * 100) / (_m_ ## x * _s_ ## x))  \
  52.                 :       0)
  53. #  define xy( x, y)                                                                                                                             \
  54.         (word) ((_m_ ## x * _s_ ## x)                                  \
  55.                 ?       ((sizeof( y) * _a_ ## x * 100) / (_m_ ## x * _s_ ## x))  \
  56.                 :       0)
  57.  
  58. # else
  59.  
  60. #  define yy( x)                                                                                                                                        \
  61.         (word) ((_m_/**/x * _s_/**/x)                                  \
  62.                 ?       ((sizeof( x) * _a_/**/x * 100) / (_m_/**/x * _s_/**/x))  \
  63.                 :       0)
  64. #  define xy( x, y)                                               \
  65.         (word) ((_m_/**/x * _s_/**/x)                                  \
  66.                 ?       ((sizeof( y) * _a_/**/x * 100) / (_m_/**/x * _s_/**/x))  \
  67.                 :       0)
  68.  
  69. # endif
  70.  
  71.  
  72. void stats()
  73. {
  74.    long  res, res2;
  75.  
  76.    printf("\nINTERNAL STATS:\n");
  77.    p("exprs",  _a_expr,  _m_expr,  _s_expr,  sizeof( expr),  yy( expr));
  78.    p("labels", _a_label, _m_label, _s_label, sizeof( label), yy( label));
  79.    p("llabels",_a_llabel,_m_llabel,_s_llabel,sizeof( label), xy( llabel, label));
  80.    p("lexprs" ,_a_lexpr, _m_lexpr, _s_lexpr, sizeof( lexpr), yy( lexpr));
  81.    p("refs",   _a_ref,   _m_ref,   _s_ref,   sizeof( ref),   yy( ref));
  82.    p("imms",   _a_imm,   _m_imm,   _s_imm,   sizeof( imm),   yy( imm));
  83.    p("segs",   _a_seg,   _m_seg,   _s_seg,   sizeof( seg),   yy( seg));
  84.    p("fixes",  _a_fix,   _m_fix,   _s_fix,   sizeof( fix),   yy( fix));
  85.    if( res = _m_macro * _s_macro)
  86.       res  = ((res - (tok_remain * 6)) * 100) / res;
  87.    else
  88.       res = 0;
  89.    p("macros", _m_macro, _m_macro, _s_macro, (size_t) 1, (word) res);
  90.    res = _m_char * _s_char;
  91.    if( res)
  92.       res = (_z_char * 100 + _m_char * _s_char) / res;
  93.    p("strings", _a_char,  _m_char, _s_char, (size_t) 1, (word) res);
  94.    printf("\n%5u expr giveback tries (%u w/success).\n", _efrees, _erfrees);
  95.    printf("   Maximal memory consumption: %ld bytes.\n", _maxused);
  96. }
  97. #endif
  98.  
  99.