1987-04-29 10:22:07 +00:00
|
|
|
/*
|
|
|
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
|
|
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
|
|
|
*
|
|
|
|
* Author: Ceriel J.H. Jacobs
|
|
|
|
*/
|
|
|
|
|
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 */
|
|
|
|
|
1994-06-24 14:02:31 +00:00
|
|
|
/* $Id$ */
|
1987-04-29 10:22:07 +00:00
|
|
|
|
1986-05-23 09:46:31 +00:00
|
|
|
/* 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
|
|
|
*/
|
|
|
|
|
2019-03-01 17:39:25 +00:00
|
|
|
#include "parameters.h"
|
1986-05-23 09:46:31 +00:00
|
|
|
#include "debug.h"
|
|
|
|
|
|
|
|
#include <em_arith.h>
|
|
|
|
#include <em_label.h>
|
1987-11-11 13:10:08 +00:00
|
|
|
#include <em_code.h>
|
1986-05-23 09:46:31 +00:00
|
|
|
#include <em_reg.h>
|
|
|
|
#include <alloc.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
1987-07-30 13:37:39 +00:00
|
|
|
#include "LLlex.h"
|
1986-05-23 09:46:31 +00:00
|
|
|
#include "def.h"
|
|
|
|
#include "type.h"
|
|
|
|
#include "scope.h"
|
2019-03-01 17:39:25 +00:00
|
|
|
#include "tmpvar.h"
|
1986-06-26 09:39:36 +00:00
|
|
|
#include "main.h"
|
1986-05-23 09:46:31 +00:00
|
|
|
|
|
|
|
struct tmpvar {
|
1987-07-17 13:50:04 +00:00
|
|
|
struct tmpvar *t_next;
|
1986-05-23 09:46:31 +00:00
|
|
|
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 */
|
1987-09-24 13:07:31 +00:00
|
|
|
static t_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
|
|
|
|
2019-03-01 17:39:25 +00:00
|
|
|
void TmpOpen(t_scope *sc)
|
1986-07-08 14:59:02 +00:00
|
|
|
{
|
|
|
|
/* Initialize for temporaries in scope "sc".
|
|
|
|
*/
|
|
|
|
ProcScope = sc;
|
|
|
|
}
|
|
|
|
|
2019-03-01 17:39:25 +00:00
|
|
|
arith TmpSpace(arith sz, int al)
|
1986-11-26 16:40:45 +00:00
|
|
|
{
|
1987-09-24 13:07:31 +00:00
|
|
|
register t_scope *sc = ProcScope;
|
1986-11-26 16:40:45 +00:00
|
|
|
|
|
|
|
sc->sc_off = - WA(align(sz - sc->sc_off, al));
|
|
|
|
return sc->sc_off;
|
|
|
|
}
|
|
|
|
|
2019-03-01 17:39:25 +00:00
|
|
|
static arith NewTmp(struct tmpvar **plist, arith sz, int al, int regtype)
|
1986-05-23 09:46:31 +00:00
|
|
|
{
|
1986-10-06 20:36:30 +00:00
|
|
|
register arith offset;
|
1986-05-23 09:46:31 +00:00
|
|
|
register struct tmpvar *tmp;
|
|
|
|
|
1987-05-21 09:37:28 +00:00
|
|
|
if (!*plist) {
|
|
|
|
offset = TmpSpace(sz, al);
|
|
|
|
if (! options['n']) C_ms_reg(offset, sz, regtype, 0);
|
1986-05-23 09:46:31 +00:00
|
|
|
}
|
|
|
|
else {
|
1987-05-21 09:37:28 +00:00
|
|
|
tmp = *plist;
|
1986-05-23 09:46:31 +00:00
|
|
|
offset = tmp->t_offset;
|
1987-07-17 13:50:04 +00:00
|
|
|
*plist = tmp->t_next;
|
1986-05-23 09:46:31 +00:00
|
|
|
free_tmpvar(tmp);
|
|
|
|
}
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
2019-03-01 17:39:25 +00:00
|
|
|
arith NewInt(void)
|
1986-05-23 09:46:31 +00:00
|
|
|
{
|
1987-05-21 09:37:28 +00:00
|
|
|
return NewTmp(&TmpInts, int_size, int_align, reg_any);
|
|
|
|
}
|
1986-05-23 09:46:31 +00:00
|
|
|
|
2019-03-01 17:39:25 +00:00
|
|
|
arith NewPtr(void)
|
1987-05-21 09:37:28 +00:00
|
|
|
{
|
|
|
|
return NewTmp(&TmpPtrs, pointer_size, pointer_align, reg_pointer);
|
1986-05-23 09:46:31 +00:00
|
|
|
}
|
|
|
|
|
2019-03-01 17:39:25 +00:00
|
|
|
|
|
|
|
static void FreeTmp(struct tmpvar **plist, arith off)
|
1986-05-23 09:46:31 +00:00
|
|
|
{
|
1987-05-21 09:37:28 +00:00
|
|
|
register struct tmpvar *tmp = new_tmpvar();
|
1986-05-23 09:46:31 +00:00
|
|
|
|
1987-07-17 13:50:04 +00:00
|
|
|
tmp->t_next = *plist;
|
1986-05-23 09:46:31 +00:00
|
|
|
tmp->t_offset = off;
|
1987-05-21 09:37:28 +00:00
|
|
|
*plist = tmp;
|
1986-05-23 09:46:31 +00:00
|
|
|
}
|
|
|
|
|
2019-03-01 17:39:25 +00:00
|
|
|
void FreeInt(arith off)
|
1986-05-23 09:46:31 +00:00
|
|
|
{
|
1987-05-21 09:37:28 +00:00
|
|
|
FreeTmp(&TmpInts, off);
|
|
|
|
}
|
1986-05-23 09:46:31 +00:00
|
|
|
|
2019-03-01 17:39:25 +00:00
|
|
|
void FreePtr(arith off)
|
1987-05-21 09:37:28 +00:00
|
|
|
{
|
|
|
|
FreeTmp(&TmpPtrs, off);
|
1986-05-23 09:46:31 +00:00
|
|
|
}
|
|
|
|
|
2019-03-01 17:39:25 +00:00
|
|
|
void TmpClose(void)
|
1986-05-23 09:46:31 +00:00
|
|
|
{
|
|
|
|
register struct tmpvar *tmp, *tmp1;
|
|
|
|
|
|
|
|
tmp = TmpInts;
|
|
|
|
while (tmp) {
|
|
|
|
tmp1 = tmp;
|
1987-07-17 13:50:04 +00:00
|
|
|
tmp = tmp->t_next;
|
1986-05-23 09:46:31 +00:00
|
|
|
free_tmpvar(tmp1);
|
|
|
|
}
|
|
|
|
tmp = TmpPtrs;
|
|
|
|
while (tmp) {
|
|
|
|
tmp1 = tmp;
|
1987-07-17 13:50:04 +00:00
|
|
|
tmp = tmp->t_next;
|
1986-05-23 09:46:31 +00:00
|
|
|
free_tmpvar(tmp1);
|
|
|
|
}
|
|
|
|
TmpInts = TmpPtrs = 0;
|
|
|
|
}
|