home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / icon / dos / src / icont / tmem.c < prev    next >
C/C++ Source or Header  |  1992-02-10  |  3KB  |  106 lines

  1. /*
  2.  * tmem.c -- memory initialization and allocation for the translator.
  3.  */
  4.  
  5. #include "../h/gsupport.h"
  6. #include "tproto.h"
  7. #include "globals.h"
  8. #include "trans.h"
  9. #include "tsym.h"
  10. #include "tree.h"
  11.  
  12. struct tlentry **lhash;        /* hash area for local table */
  13. struct tgentry **ghash;        /* hash area for global table */
  14. struct tcentry **chash;        /* hash area for constant table */
  15. struct tientry **ihash;        /* hash area for identifier table */
  16.  
  17. nodeptr tree;            /* parse tree space */
  18. nodeptr tend;            /* end of parse tree space */
  19. struct tlentry *ltable;        /* local table */
  20. struct tgentry *gtable;        /* global table */
  21. struct tcentry *ctable;        /* constant table */
  22. struct tientry *itable;        /* identifier table */
  23.  
  24. char *strings;            /* string space */
  25. char *stre;            /* end of string space */
  26.  
  27. nodeptr tfree;            /* free pointer for parse tree space */
  28. struct tlentry *lfree;        /* free pointer for local table */
  29. struct tgentry *gfree;        /* free pointer for global table */
  30. struct tcentry *ctfree;        /* free pointer to constant table */
  31. struct tientry *ifree;        /* free pointer for identifier table */
  32. char *strf;            /* free pointer for string space */
  33.  
  34.  
  35. /*
  36.  * tmalloc - allocate memory for the translator
  37.  */
  38.  
  39. novalue tmalloc()
  40. {
  41.    chash = (struct tcentry **) tcalloc(chsize, sizeof (struct tcentry *));
  42.    ghash = (struct tgentry **) tcalloc(ghsize, sizeof (struct tgentry *));
  43.    ihash = (struct tientry **) tcalloc(ihsize, sizeof (struct tientry *));
  44.    lhash = (struct tlentry **) tcalloc(lhsize, sizeof (struct tlentry *));
  45.  
  46.    ctable = (struct tcentry *) tcalloc(csize, sizeof (struct tcentry));
  47.    gtable = (struct tgentry *) tcalloc(gsize, sizeof (struct tgentry));
  48.    itable = (struct tientry *) tcalloc(isize, sizeof (struct tientry));
  49.    ltable = (struct tlentry *) tcalloc(lsize, sizeof (struct tlentry));
  50.  
  51.    strings = (char *) tcalloc(stsize, sizeof(char));
  52.    stre = strings + stsize;
  53.  
  54.    tree = (nodeptr) tcalloc(tsize, sizeof(word));
  55.    tend = (nodeptr) ((word *)tree + tsize);
  56.    }
  57.  
  58. /*
  59.  * meminit - clear tables for use in translating the next file
  60.  */
  61. novalue tminit()
  62.    {
  63.    register struct tlentry **lp;
  64.    register struct tgentry **gp;
  65.    register struct tcentry **cp;
  66.    register struct tientry **ip;
  67.  
  68.    /*
  69.     * Reset the free pointer for each region.
  70.     */
  71.    lfree = ltable;
  72.    gfree = gtable;
  73.    ctfree = ctable;
  74.    ifree = itable;
  75.    strf = strings;
  76.    tfree = tree;
  77.    /*
  78.     * Zero out the hash tables.
  79.     */
  80.    for (lp = lhash; lp < &lhash[lhsize]; lp++)
  81.       *lp = NULL;
  82.    for (gp = ghash; gp < &ghash[ghsize]; gp++)
  83.       *gp = NULL;
  84.    for (cp = chash; cp < &chash[chsize]; cp++)
  85.       *cp = NULL;
  86.    for (ip = ihash; ip < &ihash[ihsize]; ip++)
  87.       *ip = NULL;
  88.    }
  89.  
  90. /*
  91.  * tmfree - free memory used by the translator
  92.  */
  93. novalue tmfree()
  94.    {
  95.    free((char *) chash);   chash = NULL;
  96.    free((char *) ghash);   ghash = NULL;
  97.    free((char *) ihash);   ihash = NULL;
  98.    free((char *) lhash);   lhash = NULL;
  99.    free((char *) ctable);  ctable = NULL;
  100.    free((char *) gtable);  gtable = NULL;
  101.    free((char *) itable);  itable = NULL;
  102.    free((char *) ltable);  ltable = NULL;
  103.    free((char *) strings); strings = NULL;
  104.    free((char *) tree);    tree = NULL;
  105.    }
  106.