home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / historic / v92.tgz / v92.tar / v92 / src / icont / tmem.c < prev    next >
C/C++ Source or Header  |  1996-03-22  |  2KB  |  93 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 "tglobals.h"
  8. #include "tsym.h"
  9. #include "tree.h"
  10.  
  11. struct tlentry **lhash;        /* hash area for local table */
  12. struct tgentry **ghash;        /* hash area for global table */
  13. struct tcentry **chash;        /* hash area for constant table */
  14.  
  15. struct tlentry *lfirst;        /* first local table entry */
  16. struct tlentry *llast;        /* last local table entry */
  17. struct tcentry *cfirst;        /* first constant table entry */
  18. struct tcentry *clast;        /* last constant table entry */
  19. struct tgentry *gfirst;        /* first global table entry */
  20. struct tgentry *glast;        /* last global table entry */
  21.  
  22. extern struct str_buf lex_sbuf;
  23.  
  24.  
  25. /*
  26.  * tmalloc - allocate memory for the translator
  27.  */
  28.  
  29. novalue tmalloc()
  30. {
  31.    chash = (struct tcentry **) tcalloc(lchsize, sizeof (struct tcentry *));
  32.    ghash = (struct tgentry **) tcalloc(ghsize, sizeof (struct tgentry *));
  33.    lhash = (struct tlentry **) tcalloc(lhsize, sizeof (struct tlentry *));
  34.    init_str();
  35.    init_sbuf(&lex_sbuf);
  36.    }
  37.  
  38. /*
  39.  * meminit - clear tables for use in translating the next file
  40.  */
  41. novalue tminit()
  42.    {
  43.    register struct tlentry **lp;
  44.    register struct tgentry **gp;
  45.    register struct tcentry **cp;
  46.  
  47.    lfirst = NULL;
  48.    llast = NULL;
  49.    cfirst = NULL;
  50.    clast = NULL;
  51.    gfirst = NULL;
  52.    glast = NULL;
  53.  
  54.    /*
  55.     * Zero out the hash tables.
  56.     */
  57.    for (lp = lhash; lp < &lhash[lhsize]; lp++)
  58.       *lp = NULL;
  59.    for (gp = ghash; gp < &ghash[ghsize]; gp++)
  60.       *gp = NULL;
  61.    for (cp = chash; cp < &chash[lchsize]; cp++)
  62.       *cp = NULL;
  63.    }
  64.  
  65. /*
  66.  * tmfree - free memory used by the translator
  67.  */
  68. novalue tmfree()
  69.    {
  70.    struct tgentry *gp, *gp1;
  71.  
  72. #ifndef VarTran
  73.    loc_init();            /* free constant and local table entries */
  74.  
  75.    /*
  76.     * Free global table entries.
  77.     */
  78.    for (gp = gfirst; gp != NULL; gp = gp1) {
  79.       gp1 = gp->g_next;
  80.       free((char *)gp);
  81.       }
  82.    gfirst = NULL;
  83.    glast = NULL;
  84. #endif                    /* VarTran */
  85.  
  86.    free((char *) chash);   chash = NULL;
  87.    free((char *) ghash);   ghash = NULL;
  88.    free((char *) lhash);   lhash = NULL;
  89.  
  90.    free_stbl();           /* free string table */
  91.    clear_sbuf(&lex_sbuf); /* free buffer store for strings */
  92.    }
  93.