Do not use the allocation mechanism for the desig structure; overkill

This commit is contained in:
ceriel 1991-03-14 11:10:40 +00:00
parent 86bc055fa1
commit 5ebc2017a0
7 changed files with 66 additions and 58 deletions

View file

@ -20,7 +20,7 @@ def.H
def.c
defmodule.c
desig.c
desig.H
desig.h
em_m2.6
enter.c
error.c

View file

@ -76,15 +76,15 @@ OBJ = $(COBJ) $(LOBJ) Lpars.o $(EXTRA_O)
GENH = errout.h \
idfsize.h numsize.h strsize.h target_sizes.h bigresult.h \
inputtype.h density.h squeeze.h nocross.h nostrict.h \
def.h debugcst.h type.h Lpars.h node.h desig.h strict3rd.h real.h \
def.h debugcst.h type.h Lpars.h node.h strict3rd.h real.h \
use_insert.h dbsymtab.h uns_arith.h
HFILES =LLlex.h \
chk_expr.h class.h debug.h f_info.h idf.h \
chk_expr.h class.h debug.h desig.h f_info.h idf.h \
input.h main.h misc.h scope.h standards.h tokenname.h \
walk.h warning.h SYSTEM.h $(GENH)
#
GENFILES = $(GENGFILES) $(GENC) $(GENH)
NEXTFILES = def.H type.H node.H desig.H real.H scope.C tmpvar.C casestat.C
NEXTFILES = def.H type.H node.H real.H scope.C tmpvar.C casestat.C
#EXCLEXCLEXCLEXCL
@ -161,7 +161,6 @@ def.h: make.allocd
type.h: make.allocd
real.h: make.allocd
node.h: make.allocd
desig.h: make.allocd
scope.c: make.allocd
tmpvar.c: make.allocd
casestat.c: make.allocd

View file

@ -490,11 +490,13 @@ arith *
MkSet(size)
unsigned size;
{
register arith *s;
register arith *s, *t;
s = (arith *) Malloc(size);
s = t = (arith *) Malloc(size);
clear((char *) s , size);
s++;
size /= sizeof(arith);
while (size--) *t++ = 0;
inc_refcount(s);
return s;
}

View file

@ -36,6 +36,7 @@ extern char *long2str();
extern char *symbol2str();
extern int proclevel;
extern char options[];
extern t_desig null_desig;
int fp_used;
CodeConst(cst, size)
@ -880,7 +881,9 @@ CodeOper(expr, true_label, false_label)
case OR:
case AND: {
label l_maybe = ++text_label, l_end = NO_LABEL;
t_desig *Des = new_desig();
t_desig Des;
Des = null_desig;
if (true_label == NO_LABEL) {
true_label = ++text_label;
@ -889,12 +892,12 @@ CodeOper(expr, true_label, false_label)
}
if (expr->nd_symb == OR) {
CodeExpr(leftop, Des, true_label, l_maybe);
CodeExpr(leftop, &Des, true_label, l_maybe);
}
else CodeExpr(leftop, Des, l_maybe, false_label);
else CodeExpr(leftop, &Des, l_maybe, false_label);
def_ilb(l_maybe);
clear((char *) Des, sizeof(t_desig));
CodeExpr(rightop, Des, true_label, false_label);
Des = null_desig;
CodeExpr(rightop, &Des, true_label, false_label);
if (l_end != NO_LABEL) {
def_ilb(true_label);
c_loc(1);
@ -903,7 +906,6 @@ CodeOper(expr, true_label, false_label)
c_loc(0);
def_ilb(l_end);
}
free_desig(Des);
break;
}
default:
@ -1048,11 +1050,11 @@ CodePExpr(nd)
/* Generate code to push the value of the expression "nd"
on the stack.
*/
register t_desig *designator = new_desig();
t_desig designator;
CodeExpr(nd, designator, NO_LABEL, NO_LABEL);
CodeValue(designator, nd->nd_type);
free_desig(designator);
designator = null_desig;
CodeExpr(nd, &designator, NO_LABEL, NO_LABEL);
CodeValue(&designator, nd->nd_type);
}
CodeDAddress(nd, chk_controlvar)
@ -1062,14 +1064,15 @@ CodeDAddress(nd, chk_controlvar)
on the stack.
*/
register t_desig *designator = new_desig();
t_desig designator;
int chkptr;
designator = null_desig;
if (chk_controlvar) ChkForFOR(nd);
CodeDesig(nd, designator);
chkptr = designator->dsg_kind==DSG_PLOADED ||
designator->dsg_kind==DSG_PFIXED;
CodeAddress(designator);
CodeDesig(nd, &designator);
chkptr = designator.dsg_kind==DSG_PLOADED ||
designator.dsg_kind==DSG_PFIXED;
CodeAddress(&designator);
/* Generate dummy use of pointer, to get possible error message
as soon as possible
@ -1079,7 +1082,6 @@ CodeDAddress(nd, chk_controlvar)
C_loi((arith) 1);
C_asp(word_size);
}
free_desig(designator);
}
CodeDStore(nd)
@ -1089,12 +1091,12 @@ CodeDStore(nd)
designator "nd".
*/
register t_desig *designator = new_desig();
t_desig designator;
designator = null_desig;
ChkForFOR(nd);
CodeDesig(nd, designator);
CodeStore(designator, nd->nd_type);
free_desig(designator);
CodeDesig(nd, &designator);
CodeStore(&designator, nd->nd_type);
}
DoHIGH(df)

View file

@ -341,6 +341,8 @@ CodeCopy(lhs, rhs, sz, psize)
}
}
t_desig null_desig;
CodeMove(rhs, left, rtp)
register t_desig *rhs;
register t_node *left;
@ -351,31 +353,32 @@ CodeMove(rhs, left, rtp)
Go through some (considerable) trouble to see if a BLM can be
generated.
*/
register t_desig *lhs = new_desig();
t_desig lhs;
register t_type *tp = left->nd_type;
int loadedflag = 0;
lhs = null_desig;
ChkForFOR(left);
switch(rhs->dsg_kind) {
case DSG_LOADED:
CodeDesig(left, lhs);
CodeDesig(left, &lhs);
if (rtp->tp_fund == T_STRING) {
/* size of a string literal fits in an
int of size word_size
*/
CodeAddress(lhs);
CodeAddress(&lhs);
C_loc(rtp->tp_size);
C_loc(tp->tp_size);
CAL("StringAssign", (int)pointer_size + (int)pointer_size + (int)dword_size);
break;
}
CodeStore(lhs, tp);
CodeStore(&lhs, tp);
break;
case DSG_FIXED:
CodeDesig(left, lhs);
if (lhs->dsg_kind == DSG_FIXED &&
CodeDesig(left, &lhs);
if (lhs.dsg_kind == DSG_FIXED &&
fit(tp->tp_size, (int) word_size) &&
(int) (lhs->dsg_offset) % word_align ==
(int) (lhs.dsg_offset) % word_align ==
(int) (rhs->dsg_offset) % word_align) {
register int sz = 1;
arith size = tp->tp_size;
@ -384,16 +387,16 @@ CodeMove(rhs, left, rtp)
/* First copy up to word-aligned
boundaries
*/
if (!((int)(lhs->dsg_offset)%(sz+sz))) {
if (!((int)(lhs.dsg_offset)%(sz+sz))) {
sz += sz;
}
else CodeCopy(lhs, rhs, (arith) sz, &size);
else CodeCopy(&lhs, rhs, (arith) sz, &size);
}
/* Now copy the bulk
*/
sz = (int) size % (int) word_size;
size -= sz;
CodeCopy(lhs, rhs, size, &size);
CodeCopy(&lhs, rhs, size, &size);
size = sz;
sz = word_size;
while (size) {
@ -401,12 +404,12 @@ CodeMove(rhs, left, rtp)
*/
sz >>= 1;
if (size >= sz) {
CodeCopy(lhs, rhs, (arith) sz, &size);
CodeCopy(&lhs, rhs, (arith) sz, &size);
}
}
break;
}
CodeAddress(lhs);
CodeAddress(&lhs);
loadedflag = 1;
/* Fall through */
case DSG_PLOADED:
@ -417,8 +420,8 @@ CodeMove(rhs, left, rtp)
C_exg(pointer_size);
}
else {
CodeDesig(left, lhs);
CodeAddress(lhs);
CodeDesig(left, &lhs);
CodeAddress(&lhs);
}
switch (suitable_move(tp)) {
case USE_BLM:
@ -440,7 +443,6 @@ CodeMove(rhs, left, rtp)
default:
crash("CodeMove");
}
free_desig(lhs);
}
CodeAddress(ds)

View file

@ -17,7 +17,7 @@
*/
struct desig {
int dsg_kind;
short dsg_kind;
#define DSG_INIT 0 /* don't know anything yet */
#define DSG_LOADED 1 /* designator loaded on top of the stack */
#define DSG_PLOADED 2 /* designator accessible through pointer on
@ -45,21 +45,23 @@ struct desig {
*/
};
typedef struct desig t_desig;
/* The next structure describes the designator in a with-statement.
We have a linked list of them, as with-statements may be nested.
*/
struct withdesig {
struct withdesig *w_next;
int w_flags; /* D_USED|D_DEFINED */
struct scope *w_scope; /* scope in which fields of this record
reside
*/
struct desig w_desig; /* a desig structure for this particular
t_desig w_desig; /* a desig structure for this particular
designator
*/
};
extern struct withdesig *WithDesigs;
extern struct desig InitDesig;
#define NO_LABEL ((label) 0)

View file

@ -857,6 +857,8 @@ int (*WalkTable[])() = {
WalkLink,
};
extern t_desig null_desig;
ExpectBool(pnd, true_label, false_label)
register t_node **pnd;
label true_label, false_label;
@ -864,17 +866,17 @@ ExpectBool(pnd, true_label, false_label)
/* "pnd" must indicate a boolean expression. Check this and
generate code to evaluate the expression.
*/
register t_desig *ds = new_desig();
t_desig ds;
ds = null_desig;
if (ChkExpression(pnd)) {
if ((*pnd)->nd_type != bool_type &&
(*pnd)->nd_type != error_type) {
node_error(*pnd, "boolean expression expected");
}
CodeExpr(*pnd, ds, true_label, false_label);
CodeExpr(*pnd, &ds, true_label, false_label);
}
free_desig(ds);
}
int
@ -887,7 +889,7 @@ WalkDesignator(pnd, ds, flags)
if (! ChkVariable(pnd, flags)) return 0;
clear((char *) ds, sizeof(t_desig));
*ds = null_desig;
CodeDesig(*pnd, ds);
return 1;
}
@ -967,7 +969,7 @@ DoAssign(nd)
it sais that the left hand side is evaluated first.
DAMN THE BOOK!
*/
register t_desig *dsr;
t_desig dsr;
register t_type *tp;
if (! (ChkExpression(&(nd->nd_RIGHT)) &
@ -979,20 +981,19 @@ DoAssign(nd)
if (! ChkAssCompat(&(nd->nd_RIGHT), tp, "assignment")) {
return;
}
dsr = new_desig();
dsr = null_desig;
#define StackNeededFor(ds) ((ds)->dsg_kind == DSG_PLOADED \
|| (ds)->dsg_kind == DSG_INDEXED)
CodeExpr(nd->nd_RIGHT, dsr, NO_LABEL, NO_LABEL);
#define StackNeededFor(ds) ((ds).dsg_kind == DSG_PLOADED \
|| (ds).dsg_kind == DSG_INDEXED)
CodeExpr(nd->nd_RIGHT, &dsr, NO_LABEL, NO_LABEL);
tp = nd->nd_RIGHT->nd_type;
if (complex(tp)) {
if (StackNeededFor(dsr)) CodeAddress(dsr);
if (StackNeededFor(dsr)) CodeAddress(&dsr);
}
else {
CodeValue(dsr, tp);
CodeValue(&dsr, tp);
}
CodeMove(dsr, nd->nd_LEFT, tp);
free_desig(dsr);
CodeMove(&dsr, nd->nd_LEFT, tp);
}
static