C:/Users/Dennis/src/lang/russell.orig/src/RIC_to_C/tmp_tab.c

Go to the documentation of this file.
00001 /* A table containing free/allocated information for temporaries. */
00002 /* Represented as a single bit vector.                            */
00003 
00004 # include <stdio.h>
00005 # include "../parm.h"
00006 # include "tables.h"
00007 
00008 # define MAX_TMPS 4096
00009 # define BITS_PER_LONG 32
00010 # define LONGS_TO_BITS(n) ((n) << 5)
00011 # define BITS_TO_LONGS(n) ((n) >> 5)
00012 # define ALL_ONES (-1L)
00013 
00014 # define SZ_TMPS_ALLOCD ((MAX_TMPS + BITS_PER_LONG)/BITS_PER_LONG)
00015 
00016 long tmps_allocd[SZ_TMPS_ALLOCD];       /* 1 bit ==> allocated.        */
00017                                         /* bits numbered right to left */
00018                                         /* within a long.              */
00019                                         /* Temporaries are numbered    */
00020                                         /* starting at 0.              */
00021 int max_tmp = -1;    /* Highest numbered temporary allocated */
00022 
00023 /* Return the number of the lowest numbered available temporary */
00024 /* and mark it as allocated.                                    */
00025 int get_next_free()
00026 {
00027     register int i,j;
00028     register long w;
00029 
00030     for (i = 0; (w = tmps_allocd[i]) == ALL_ONES; i++) {
00031         if (i > SZ_TMPS_ALLOCD) {
00032             fprintf(stderr, "Too many temporaries\n");
00033             exit(1);
00034         }
00035     }
00036     for (j = 0; w & 1; w >>= 1) j++;
00037     tmps_allocd[i] |= (1 << j);
00038     j += LONGS_TO_BITS(i);
00039     if (j > max_tmp) max_tmp = j;
00040     return(j);
00041 }
00042 
00043 /* Mark temporary i as no longer being in use.  */
00044 void free_tmp(i)
00045 int i;
00046 {
00047     int word_no = BITS_TO_LONGS(i);
00048     int bit_no = i - LONGS_TO_BITS(word_no);
00049 
00050     tmps_allocd[word_no] &= ~(1 << bit_no);
00051 }
00052 
00053 /* Make sure no temporaries are still in use, and reset max_tmp */
00054 void reset_tmps()
00055 {
00056     register int i,lim;
00057     register long w;
00058     int j;
00059 
00060     lim = BITS_TO_LONGS(max_tmp + 1);
00061     for (i = 0; i < lim; i++) {
00062       if ((w = tmps_allocd[i]) != 0) {
00063         for (j = 0; !(w & 1); w >>= 1) j++;
00064         fprintf(stderr, "Temporary %d not deallocated\n",
00065                 LONGS_TO_BITS(i) + j);
00066         tmps_allocd[i] = 0;
00067       }
00068     }
00069     max_tmp = -1;
00070 }
00071 
00072 /* Return the name associated with the ith temporary */
00073 char * tmp_name(i)
00074 long i;
00075 {
00076     register char * result;
00077 
00078     if (i < 100) {
00079         /* A fast version for the common case: */
00080         result = (char *) GC_malloc_atomic(6);
00081         result[0] = 't';
00082         result[1] = 'm';
00083         result[2] = 'p';
00084         result[3] = i / 10 + '0';
00085         result[4] = i % 10 + '0';
00086         result[5] = '\0';
00087     } else if (i & ARG_FLAG) {
00088         result = (char *) GC_malloc_atomic(12);
00089         sprintf(result, "arg%d", i & ~ARG_FLAG);
00090     } else {
00091         result = (char *) GC_malloc_atomic(12);
00092         sprintf(result, "tmp%d", i);
00093     }
00094     return(result);
00095 }
00096  
00097 
00098 
00099 typedef struct tmp_list {
00100     long tl_no;
00101     struct tmp_list * tl_next;
00102 } tl;
00103 #define TL_NIL ((tl *) 0)
00104 
00105 tl * rmd_tmps;   /* List of temporaries that correspond to dead virtual regs */
00106                  /* but that may still appear inside remembered exprs.       */
00107 
00108 /* Free all temporaries on rmd_tmps list */
00109 void rem_tmps()
00110 {
00111     register tl * p;
00112     
00113     for (p = rmd_tmps; p  != TL_NIL; p = p -> tl_next) {
00114         free_tmp(p -> tl_no);
00115     }
00116     rmd_tmps = TL_NIL;
00117 }
00118 
00119 /* Add an entry to a list of dead temporaries */
00120 void dead_tmp(n)
00121 long n;
00122 {
00123     tl * result = (tl *) GC_malloc(sizeof (tl));
00124 
00125     result -> tl_no = n;
00126     result -> tl_next = rmd_tmps;
00127     rmd_tmps = result;
00128 }
00129 

Generated on Fri Jan 25 10:39:48 2008 for russell by  doxygen 1.5.4