1988-10-26 15:21:11 +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.
|
|
|
|
The routines use "ProcScope" instead of "CurrentScope", because
|
|
|
|
"CurrentScope" also reflects WITH statements, and these scopes do not
|
|
|
|
have local variables.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "debug.h"
|
|
|
|
|
|
|
|
#include <alloc.h>
|
|
|
|
#include <em_arith.h>
|
|
|
|
#include <em_label.h>
|
|
|
|
#include <em_reg.h>
|
2019-02-23 17:15:23 +00:00
|
|
|
#include <em_code.h>
|
1988-10-26 15:21:11 +00:00
|
|
|
|
|
|
|
#include "def.h"
|
|
|
|
#include "main.h"
|
|
|
|
#include "scope.h"
|
|
|
|
#include "type.h"
|
|
|
|
|
|
|
|
struct tmpvar {
|
|
|
|
struct tmpvar *next;
|
|
|
|
arith t_offset; /* offset from LocalBase */
|
|
|
|
};
|
|
|
|
|
|
|
|
/* ALLOCDEF "tmpvar" 10 */
|
|
|
|
|
|
|
|
static struct tmpvar *TmpInts, /* for integer temporaries */
|
|
|
|
*TmpPtrs; /* for pointer temporaries */
|
|
|
|
static struct scope *ProcScope; /* scope of procedure in which the
|
|
|
|
temporaries are allocated
|
|
|
|
*/
|
|
|
|
|
2019-02-23 16:44:50 +00:00
|
|
|
void TmpOpen(struct scope *sc)
|
1988-10-26 15:21:11 +00:00
|
|
|
{
|
|
|
|
/* Initialize for temporaries in scope "sc".
|
|
|
|
*/
|
|
|
|
ProcScope = sc;
|
|
|
|
}
|
|
|
|
|
2019-02-23 16:44:50 +00:00
|
|
|
arith TmpSpace(arith sz, int al)
|
1988-10-26 15:21:11 +00:00
|
|
|
{
|
|
|
|
register struct scope *sc = ProcScope;
|
|
|
|
|
|
|
|
sc->sc_off = - WA(align(sz - sc->sc_off, al));
|
|
|
|
return sc->sc_off;
|
|
|
|
}
|
|
|
|
|
2019-02-23 16:44:50 +00:00
|
|
|
static arith NewTmp(struct tmpvar **plist, arith sz, int al, int regtype, int priority)
|
1988-10-26 15:21:11 +00:00
|
|
|
{
|
|
|
|
register arith offset;
|
|
|
|
register struct tmpvar *tmp;
|
|
|
|
|
|
|
|
if( !*plist ) {
|
|
|
|
offset = TmpSpace(sz, al);
|
|
|
|
if( !options['n'] ) C_ms_reg(offset, sz, regtype, priority);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
tmp = *plist;
|
|
|
|
offset = tmp->t_offset;
|
|
|
|
*plist = tmp->next;
|
|
|
|
free_tmpvar(tmp);
|
|
|
|
}
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
2019-02-23 16:44:50 +00:00
|
|
|
arith NewInt(int reg_prior)
|
1988-10-26 15:21:11 +00:00
|
|
|
{
|
|
|
|
return NewTmp(&TmpInts, int_size, int_align, reg_any, reg_prior);
|
|
|
|
}
|
|
|
|
|
2019-02-23 16:44:50 +00:00
|
|
|
arith NewPtr(int reg_prior)
|
1988-10-26 15:21:11 +00:00
|
|
|
{
|
|
|
|
return NewTmp(&TmpPtrs, pointer_size, pointer_align, reg_pointer, reg_prior);
|
|
|
|
}
|
|
|
|
|
2019-02-23 16:44:50 +00:00
|
|
|
static void FreeTmp(struct tmpvar **plist, arith off)
|
1988-10-26 15:21:11 +00:00
|
|
|
{
|
|
|
|
register struct tmpvar *tmp = new_tmpvar();
|
|
|
|
|
|
|
|
tmp->next = *plist;
|
|
|
|
tmp->t_offset = off;
|
|
|
|
*plist = tmp;
|
|
|
|
}
|
|
|
|
|
2019-02-23 16:44:50 +00:00
|
|
|
void FreeInt(arith off)
|
1988-10-26 15:21:11 +00:00
|
|
|
{
|
|
|
|
FreeTmp(&TmpInts, off);
|
|
|
|
}
|
|
|
|
|
2019-02-23 16:44:50 +00:00
|
|
|
void FreePtr(arith off)
|
1988-10-26 15:21:11 +00:00
|
|
|
{
|
|
|
|
FreeTmp(&TmpPtrs, off);
|
|
|
|
}
|
|
|
|
|
2019-02-23 16:44:50 +00:00
|
|
|
void TmpClose(void)
|
1988-10-26 15:21:11 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|