ack/lang/m2/comp/tmpvar.C

131 lines
2.2 KiB
C++
Raw Normal View History

1986-05-23 09:46:31 +00:00
/* T E M P O R A R Y V A R I A B L E S */
/* Code for the allocation and de-allocation of temporary variables,
allowing re-use.
1986-06-10 13:18:52 +00:00
The routines use "ProcScope" instead of "CurrentScope", because
"CurrentScope" also reflects WITH statements, and these scopes do not
have local variabes.
1986-05-23 09:46:31 +00:00
*/
#include "debug.h"
#include <em_arith.h>
#include <em_label.h>
#include <em_reg.h>
#include <alloc.h>
#include <assert.h>
#include "def.h"
#include "type.h"
#include "scope.h"
1986-06-26 09:39:36 +00:00
#include "main.h"
1986-05-23 09:46:31 +00:00
struct tmpvar {
struct tmpvar *next;
arith t_offset; /* offset from LocalBase */
};
1986-10-06 20:36:30 +00:00
/* STATICALLOCDEF "tmpvar" 10 */
1986-05-23 09:46:31 +00:00
static struct tmpvar *TmpInts, /* for integer temporaries */
*TmpPtrs; /* for pointer temporaries */
1986-07-08 14:59:02 +00:00
static struct scope *ProcScope; /* scope of procedure in which the
1986-06-10 13:18:52 +00:00
temporaries are allocated
*/
1986-05-23 09:46:31 +00:00
1986-07-08 14:59:02 +00:00
TmpOpen(sc) struct scope *sc;
{
/* Initialize for temporaries in scope "sc".
*/
ProcScope = sc;
}
1986-11-26 16:40:45 +00:00
arith
TmpSpace(sz, al)
arith sz;
{
register struct scope *sc = ProcScope;
sc->sc_off = - WA(align(sz - sc->sc_off, al));
return sc->sc_off;
}
1986-05-23 09:46:31 +00:00
arith
NewInt()
{
1986-10-06 20:36:30 +00:00
register arith offset;
1986-05-23 09:46:31 +00:00
register struct tmpvar *tmp;
if (!TmpInts) {
1986-11-26 16:40:45 +00:00
offset = TmpSpace(int_size, int_align);
1986-06-26 09:39:36 +00:00
if (! options['n']) C_ms_reg(offset, int_size, reg_any, 0);
1986-05-23 09:46:31 +00:00
}
else {
tmp = TmpInts;
offset = tmp->t_offset;
TmpInts = tmp->next;
free_tmpvar(tmp);
}
return offset;
}
arith
NewPtr()
{
1986-10-06 20:36:30 +00:00
register arith offset;
1986-05-23 09:46:31 +00:00
register struct tmpvar *tmp;
if (!TmpPtrs) {
1986-11-26 16:40:45 +00:00
offset = TmpSpace(pointer_size, pointer_align);
1986-06-26 09:39:36 +00:00
if (! options['n']) C_ms_reg(offset, pointer_size, reg_pointer, 0);
1986-05-23 09:46:31 +00:00
}
else {
tmp = TmpPtrs;
offset = tmp->t_offset;
TmpPtrs = tmp->next;
free_tmpvar(tmp);
}
return offset;
}
FreeInt(off)
arith off;
{
register struct tmpvar *tmp;
tmp = new_tmpvar();
tmp->next = TmpInts;
tmp->t_offset = off;
TmpInts = tmp;
}
FreePtr(off)
arith off;
{
register struct tmpvar *tmp;
tmp = new_tmpvar();
tmp->next = TmpPtrs;
tmp->t_offset = off;
TmpPtrs = tmp;
}
TmpClose()
{
register struct tmpvar *tmp, *tmp1;
tmp = TmpInts;
while (tmp) {
tmp1 = tmp;
tmp = tmp->next;
free_tmpvar(tmp1);
}
tmp = TmpPtrs;
while (tmp) {
tmp1 = tmp;
tmp = tmp->next;
free_tmpvar(tmp1);
}
TmpInts = TmpPtrs = 0;
}