* loop node flags from node flags splitted

This commit is contained in:
florian 2002-11-28 11:17:01 +00:00
parent 757728dcd8
commit e8bb7d10c3
3 changed files with 46 additions and 26 deletions

View File

@ -125,7 +125,7 @@ implementation
load_all_regvars(exprasmlist); load_all_regvars(exprasmlist);
{ handling code at the end as it is much more efficient, and makes { handling code at the end as it is much more efficient, and makes
while equal to repeat loop, only the end true/false is swapped (PFV) } while equal to repeat loop, only the end true/false is swapped (PFV) }
if nf_testatbegin in flags then if lnf_testatbegin in loopflags then
cg.a_jmp_always(exprasmlist,lcont); cg.a_jmp_always(exprasmlist,lcont);
if not(cs_littlesize in aktglobalswitches) then if not(cs_littlesize in aktglobalswitches) then
@ -145,7 +145,7 @@ implementation
cg.a_label(exprasmlist,lcont); cg.a_label(exprasmlist,lcont);
otlabel:=truelabel; otlabel:=truelabel;
oflabel:=falselabel; oflabel:=falselabel;
if nf_checknegate in flags then if lnf_checknegate in loopflags then
begin begin
truelabel:=lbreak; truelabel:=lbreak;
falselabel:=lloop; falselabel:=lloop;
@ -352,7 +352,7 @@ implementation
secondpass(left); secondpass(left);
count_var_is_signed:=is_signed(t2.resulttype.def); count_var_is_signed:=is_signed(t2.resulttype.def);
if nf_backward in flags then if lnf_backward in loopflags then
if count_var_is_signed then if count_var_is_signed then
hcond:=OC_LT hcond:=OC_LT
else else
@ -372,7 +372,7 @@ implementation
end end
else else
begin begin
if nf_testatbegin in flags then if lnf_testatbegin in loopflags then
begin begin
cg.a_cmp_const_loc_label(exprasmlist,opsize,hcond, cg.a_cmp_const_loc_label(exprasmlist,opsize,hcond,
aword(tordconstnode(right).value), aword(tordconstnode(right).value),
@ -380,7 +380,7 @@ implementation
end; end;
end; end;
if nf_backward in flags then if lnf_backward in loopflags then
hop:=OP_ADD hop:=OP_ADD
else else
hop:=OP_SUB; hop:=OP_SUB;
@ -392,7 +392,7 @@ implementation
cg.a_label(exprasmlist,l3); cg.a_label(exprasmlist,l3);
{ according to count direction DEC or INC... } { according to count direction DEC or INC... }
if nf_backward in flags then if lnf_backward in loopflags then
hop:=OP_SUB hop:=OP_SUB
else else
hop:=OP_ADD; hop:=OP_ADD;
@ -411,7 +411,7 @@ implementation
{ makes no problems there } { makes no problems there }
rg.cleartempgen; rg.cleartempgen;
if nf_backward in flags then if lnf_backward in loopflags then
if count_var_is_signed then if count_var_is_signed then
hcond:=OC_GT hcond:=OC_GT
else else
@ -1247,7 +1247,10 @@ begin
end. end.
{ {
$Log$ $Log$
Revision 1.44 2002-11-25 17:43:17 peter Revision 1.45 2002-11-28 11:17:01 florian
* loop node flags from node flags splitted
Revision 1.44 2002/11/25 17:43:17 peter
* splitted defbase in defutil,symutil,defcmp * splitted defbase in defutil,symutil,defcmp
* merged isconvertable and is_equal into compare_defs(_ext) * merged isconvertable and is_equal into compare_defs(_ext)
* made operator search faster by walking the list only once * made operator search faster by walking the list only once

View File

@ -35,9 +35,25 @@ interface
{$endif} {$endif}
symppu,symtype,symbase,symdef,symsym; symppu,symtype,symbase,symdef,symsym;
type
{ flags used by loop nodes }
tloopflags = (
{ set if it is a for ... downto ... do loop }
lnf_backward,
{ Do we need to parse childs to set var state? }
lnf_varstate,
{ Do a test at the begin of the loop?}
lnf_testatbegin,
{ Negate the loop test? }
lnf_checknegate);
const
{ loop flags which must match to consider loop nodes equal regarding the flags }
loopflagsequal = [lnf_backward];
type type
tloopnode = class(tbinarynode) tloopnode = class(tbinarynode)
t1,t2 : tnode; t1,t2 : tnode;
loopflags : set of tloopflags;
constructor create(tt : tnodetype;l,r,_t1,_t2 : tnode);virtual; constructor create(tt : tnodetype;l,r,_t1,_t2 : tnode);virtual;
destructor destroy;override; destructor destroy;override;
function getcopy : tnode;override; function getcopy : tnode;override;
@ -322,6 +338,7 @@ implementation
begin begin
docompare := docompare :=
inherited docompare(p) and inherited docompare(p) and
(loopflags*loopflagsequal=tloopnode(p).loopflags*loopflagsequal) and
t1.isequal(tloopnode(p).t1) and t1.isequal(tloopnode(p).t1) and
t2.isequal(tloopnode(p).t2); t2.isequal(tloopnode(p).t2);
end; end;
@ -335,9 +352,9 @@ implementation
begin begin
inherited create(whilerepeatn,l,r,_t1,nil); inherited create(whilerepeatn,l,r,_t1,nil);
if tab then if tab then
include(flags,nf_testatbegin); include(loopflags, lnf_testatbegin);
if cn then if cn then
include(flags,nf_checknegate); include(loopflags,lnf_checknegate);
end; end;
function twhilerepeatnode.det_resulttype:tnode; function twhilerepeatnode.det_resulttype:tnode;
@ -360,7 +377,7 @@ implementation
RunError(255); RunError(255);
{$else} {$else}
{Symdif operator, in case you are wondering:} {Symdif operator, in case you are wondering:}
flags:=flags >< [nf_checknegate]; loopflags:=loopflags >< [lnf_checknegate];
{$endif} {$endif}
end; end;
{ loop instruction } { loop instruction }
@ -435,7 +452,7 @@ implementation
done:=false; done:=false;
firsttest:=true; firsttest:=true;
{For repeat until statements, first do a pass through the code.} {For repeat until statements, first do a pass through the code.}
if not(nf_testatbegin in flags) then if not(lnf_testatbegin in flags) then
begin begin
code:=right.getcopy; code:=right.getcopy;
if code.track_state_pass(exec_known) then if code.track_state_pass(exec_known) then
@ -635,8 +652,8 @@ implementation
begin begin
inherited create(forn,l,r,_t1,_t2); inherited create(forn,l,r,_t1,_t2);
if back then if back then
include(flags,nf_backward); include(loopflags,lnf_backward);
include(flags,nf_testatbegin); include(loopflags,lnf_testatbegin);
end; end;
{$ifdef var_notification} {$ifdef var_notification}
@ -664,14 +681,14 @@ implementation
{Can we spare the first comparision?} {Can we spare the first comparision?}
if (right.nodetype=ordconstn) and (Tassignmentnode(left).right.nodetype=ordconstn) then if (right.nodetype=ordconstn) and (Tassignmentnode(left).right.nodetype=ordconstn) then
if ( if (
(nf_backward in flags) and (lnf_backward in loopflags) and
(Tordconstnode(Tassignmentnode(left).right).value>=Tordconstnode(right).value) (Tordconstnode(Tassignmentnode(left).right).value>=Tordconstnode(right).value)
) )
or not( or not(
(nf_backward in flags) and (lnf_backward in loopflags) and
(Tordconstnode(Tassignmentnode(left).right).value<=Tordconstnode(right).value) (Tordconstnode(Tassignmentnode(left).right).value<=Tordconstnode(right).value)
) then ) then
exclude(flags,nf_testatbegin); exclude(loopflags,lnf_testatbegin);
{ save counter var } { save counter var }
t2:=tassignmentnode(left).left.getcopy; t2:=tassignmentnode(left).left.getcopy;
@ -1412,7 +1429,10 @@ begin
end. end.
{ {
$Log$ $Log$
Revision 1.56 2002-11-25 17:43:18 peter Revision 1.57 2002-11-28 11:17:02 florian
* loop node flags from node flags splitted
Revision 1.56 2002/11/25 17:43:18 peter
* splitted defbase in defutil,symutil,defcmp * splitted defbase in defutil,symutil,defcmp
* merged isconvertable and is_equal into compare_defs(_ext) * merged isconvertable and is_equal into compare_defs(_ext)
* made operator search faster by walking the list only once * made operator search faster by walking the list only once

View File

@ -227,12 +227,6 @@ interface
{ flags used by tcallparanode } { flags used by tcallparanode }
nf_varargs_para, { belongs this para to varargs } nf_varargs_para, { belongs this para to varargs }
{ flags used by loop nodes }
nf_backward, { set if it is a for ... downto ... do loop }
nf_varstate, { do we need to parse childs to set var state }
nf_testatbegin,{ Do a test at the begin of the loop?}
nf_checknegate,{ Negate the loop test?}
{ taddrnode } { taddrnode }
nf_procvarload, nf_procvarload,
@ -282,7 +276,7 @@ interface
const const
{ contains the flags which must be equal for the equality } { contains the flags which must be equal for the equality }
{ of nodes } { of nodes }
flagsequal : tnodeflagset = [nf_error,nf_static_call,nf_backward]; flagsequal : tnodeflagset = [nf_error,nf_static_call];
type type
tnodelist = class tnodelist = class
@ -979,7 +973,10 @@ implementation
end. end.
{ {
$Log$ $Log$
Revision 1.44 2002-10-05 00:48:57 peter Revision 1.45 2002-11-28 11:17:04 florian
* loop node flags from node flags splitted
Revision 1.44 2002/10/05 00:48:57 peter
* support inherited; support for overload as it is handled by * support inherited; support for overload as it is handled by
delphi. This is only for delphi mode as it is working is delphi. This is only for delphi mode as it is working is
undocumented and hard to predict what is done undocumented and hard to predict what is done