* State tracker work

* The whilen and repeatn are now completely unified into whilerepeatn. This
  allows the state tracker to change while nodes automatically into
  repeat nodes.
* Resulttypepass improvements to the notn. 'not not a' is optimized away and
  'not(a>b)' is optimized into 'a<=b'.
* Resulttypepass improvements to the whilerepeatn. 'while not a' is optimized
  by removing the notn and later switchting the true and falselabels. The
  same is done with 'repeat until not a'.
This commit is contained in:
daniel 2002-07-19 11:41:34 +00:00
parent 9fef30d585
commit 399036f1c2
12 changed files with 339 additions and 85 deletions

View File

@ -35,7 +35,7 @@ interface
function pass_1 : tnode;override; function pass_1 : tnode;override;
function det_resulttype:tnode;override; function det_resulttype:tnode;override;
{$ifdef state_tracking} {$ifdef state_tracking}
procedure track_state_pass(exec_known:boolean);override; function track_state_pass(exec_known:boolean):boolean;override;
{$endif} {$endif}
protected protected
{ override the following if you want to implement } { override the following if you want to implement }
@ -1624,20 +1624,35 @@ implementation
end; end;
{$ifdef state_tracking} {$ifdef state_tracking}
procedure Taddnode.track_state_pass(exec_known:boolean); function Taddnode.track_state_pass(exec_known:boolean):boolean;
var factval:Tnode; var factval:Tnode;
begin begin
track_state_pass:=false;
if left.track_state_pass(exec_known) then
begin
track_state_pass:=true;
left.resulttype.def:=nil;
do_resulttypepass(left);
end;
factval:=aktstate.find_fact(left); factval:=aktstate.find_fact(left);
if factval<>nil then if factval<>nil then
begin begin
track_state_pass:=true;
left.destroy; left.destroy;
left:=factval.getcopy; left:=factval.getcopy;
end; end;
if right.track_state_pass(exec_known) then
begin
track_state_pass:=true;
right.resulttype.def:=nil;
do_resulttypepass(right);
end;
factval:=aktstate.find_fact(right); factval:=aktstate.find_fact(right);
if factval<>nil then if factval<>nil then
begin begin
track_state_pass:=true;
right.destroy; right.destroy;
right:=factval.getcopy; right:=factval.getcopy;
end; end;
@ -1649,7 +1664,18 @@ begin
end. end.
{ {
$Log$ $Log$
Revision 1.52 2002-07-14 18:00:43 daniel Revision 1.53 2002-07-19 11:41:34 daniel
* State tracker work
* The whilen and repeatn are now completely unified into whilerepeatn. This
allows the state tracker to change while nodes automatically into
repeat nodes.
* Resulttypepass improvements to the notn. 'not not a' is optimized away and
'not(a>b)' is optimized into 'a<=b'.
* Resulttypepass improvements to the whilerepeatn. 'while not a' is optimized
by removing the notn and later switchting the true and falselabels. The
same is done with 'repeat until not a'.
Revision 1.52 2002/07/14 18:00:43 daniel
+ Added the beginning of a state tracker. This will track the values of + Added the beginning of a state tracker. This will track the values of
variables through procedures and optimize things away. variables through procedures and optimize things away.

View File

@ -70,7 +70,7 @@ interface
function pass_1 : tnode;override; function pass_1 : tnode;override;
function det_resulttype:tnode;override; function det_resulttype:tnode;override;
{$ifdef state_tracking} {$ifdef state_tracking}
procedure track_state_pass(exec_known:boolean);override; function track_state_pass(exec_known:boolean):boolean;override;
{$endif state_tracking} {$endif state_tracking}
end; end;
tblocknodeclass = class of tblocknode; tblocknodeclass = class of tblocknode;
@ -437,15 +437,17 @@ implementation
end; end;
{$ifdef state_tracking} {$ifdef state_tracking}
procedure Tblocknode.track_state_pass(exec_known:boolean); function Tblocknode.track_state_pass(exec_known:boolean):boolean;
var hp:Tstatementnode; var hp:Tstatementnode;
begin begin
track_state_pass:=false;
hp:=Tstatementnode(left); hp:=Tstatementnode(left);
while assigned(hp) do while assigned(hp) do
begin begin
hp.right.track_state_pass(exec_known); if hp.right.track_state_pass(exec_known) then
track_state_pass:=true;
hp:=Tstatementnode(hp.left); hp:=Tstatementnode(hp.left);
end; end;
end; end;
@ -692,7 +694,18 @@ begin
end. end.
{ {
$Log$ $Log$
Revision 1.28 2002-07-14 18:00:43 daniel Revision 1.29 2002-07-19 11:41:35 daniel
* State tracker work
* The whilen and repeatn are now completely unified into whilerepeatn. This
allows the state tracker to change while nodes automatically into
repeat nodes.
* Resulttypepass improvements to the notn. 'not not a' is optimized away and
'not(a>b)' is optimized into 'a<=b'.
* Resulttypepass improvements to the whilerepeatn. 'while not a' is optimized
by removing the notn and later switchting the true and falselabels. The
same is done with 'repeat until not a'.
Revision 1.28 2002/07/14 18:00:43 daniel
+ Added the beginning of a state tracker. This will track the values of + Added the beginning of a state tracker. This will track the values of
variables through procedures and optimize things away. variables through procedures and optimize things away.

View File

@ -67,7 +67,7 @@ interface
function pass_1 : tnode;override; function pass_1 : tnode;override;
function det_resulttype:tnode;override; function det_resulttype:tnode;override;
{$ifdef state_tracking} {$ifdef state_tracking}
procedure track_state_pass(exec_known:boolean);override; function track_state_pass(exec_known:boolean):boolean;override;
{$endif state_tracking} {$endif state_tracking}
function docompare(p: tnode): boolean; override; function docompare(p: tnode): boolean; override;
procedure set_procvar(procvar:tnode); procedure set_procvar(procvar:tnode);
@ -1783,20 +1783,28 @@ implementation
end; end;
{$ifdef state_tracking} {$ifdef state_tracking}
procedure Tcallnode.track_state_pass(exec_known:boolean); function Tcallnode.track_state_pass(exec_known:boolean):boolean;
var hp:Tcallparanode; var hp:Tcallparanode;
value:Tnode; value:Tnode;
begin begin
track_state_pass:=false;
hp:=Tcallparanode(left); hp:=Tcallparanode(left);
while assigned(hp) do while assigned(hp) do
begin begin
if left.track_state_pass(exec_known) then
begin
left.resulttype.def:=nil;
do_resulttypepass(left);
end;
value:=aktstate.find_fact(hp.left); value:=aktstate.find_fact(hp.left);
if value<>nil then if value<>nil then
begin begin
track_state_pass:=true;
hp.left.destroy; hp.left.destroy;
hp.left:=value.getcopy; hp.left:=value.getcopy;
do_resulttypepass(hp.left);
end; end;
hp:=Tcallparanode(hp.right); hp:=Tcallparanode(hp.right);
end; end;
@ -1896,7 +1904,18 @@ begin
end. end.
{ {
$Log$ $Log$
Revision 1.81 2002-07-15 18:03:14 florian Revision 1.82 2002-07-19 11:41:35 daniel
* State tracker work
* The whilen and repeatn are now completely unified into whilerepeatn. This
allows the state tracker to change while nodes automatically into
repeat nodes.
* Resulttypepass improvements to the notn. 'not not a' is optimized away and
'not(a>b)' is optimized into 'a<=b'.
* Resulttypepass improvements to the whilerepeatn. 'while not a' is optimized
by removing the notn and later switchting the true and falselabels. The
same is done with 'repeat until not a'.
Revision 1.81 2002/07/15 18:03:14 florian
* readded removed changes * readded removed changes
Revision 1.79 2002/07/11 14:41:27 florian Revision 1.79 2002/07/11 14:41:27 florian

View File

@ -101,7 +101,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 nodetype=whilen then if testatbegin then
cg.a_jmp_always(exprasmlist,lcont); cg.a_jmp_always(exprasmlist,lcont);
{ align loop target } { align loop target }
@ -119,20 +119,19 @@ implementation
cg.a_label(exprasmlist,lcont); cg.a_label(exprasmlist,lcont);
otlabel:=truelabel; otlabel:=truelabel;
oflabel:=falselabel; oflabel:=falselabel;
if nodetype=whilen then if checknegate then
begin
truelabel:=lloop;
falselabel:=lbreak;
end
{ repeatn }
else
begin begin
truelabel:=lbreak; truelabel:=lbreak;
falselabel:=lloop; falselabel:=lloop;
end
else
begin
truelabel:=lloop;
falselabel:=lbreak;
end; end;
rg.cleartempgen; rg.cleartempgen;
secondpass(left); secondpass(left);
maketojumpbool(exprasmlist,left,lr_load_regvars); maketojumpbool(exprasmlist,left,lr_load_regvars);
cg.a_label(exprasmlist,lbreak); cg.a_label(exprasmlist,lbreak);
truelabel:=otlabel; truelabel:=otlabel;
@ -629,7 +628,18 @@ begin
end. end.
{ {
$Log$ $Log$
Revision 1.22 2002-07-04 20:43:01 florian Revision 1.23 2002-07-19 11:41:35 daniel
* State tracker work
* The whilen and repeatn are now completely unified into whilerepeatn. This
allows the state tracker to change while nodes automatically into
repeat nodes.
* Resulttypepass improvements to the notn. 'not not a' is optimized away and
'not(a>b)' is optimized into 'a<=b'.
* Resulttypepass improvements to the whilerepeatn. 'while not a' is optimized
by removing the notn and later switchting the true and falselabels. The
same is done with 'repeat until not a'.
Revision 1.22 2002/07/04 20:43:01 florian
* first x86-64 patches * first x86-64 patches
Revision 1.21 2002/07/01 18:46:22 peter Revision 1.21 2002/07/01 18:46:22 peter

View File

@ -45,10 +45,12 @@ interface
end; end;
twhilerepeatnode = class(tloopnode) twhilerepeatnode = class(tloopnode)
testatbegin,checknegate:boolean;
constructor create(l,r,_t1:Tnode;tab,cn:boolean);virtual;
function det_resulttype:tnode;override; function det_resulttype:tnode;override;
function pass_1 : tnode;override; function pass_1 : tnode;override;
{$ifdef state_tracking} {$ifdef state_tracking}
procedure track_state_pass(exec_known:boolean);override; function track_state_pass(exec_known:boolean):boolean;override;
{$endif} {$endif}
end; end;
twhilerepeatnodeclass = class of twhilerepeatnode; twhilerepeatnodeclass = class of twhilerepeatnode;
@ -198,10 +200,13 @@ implementation
case t of case t of
ifn: ifn:
p:=cifnode.create(l,r,n1); p:=cifnode.create(l,r,n1);
repeatn: whilerepeatn:
p:=cwhilerepeatnode.create(repeatn,l,r,n1,nil); if back then
whilen: {Repeat until.}
p:=cwhilerepeatnode.create(whilen,l,r,n1,nil); p:=cwhilerepeatnode.create(l,r,n1,false,true)
else
{While do.}
p:=cwhilerepeatnode.create(l,r,n1,true,false);
forn: forn:
p:=cfornode.create(l,r,n1,nil,back); p:=cfornode.create(l,r,n1,nil,back);
end; end;
@ -274,12 +279,31 @@ implementation
TWHILEREPEATNODE TWHILEREPEATNODE
*****************************************************************************} *****************************************************************************}
constructor Twhilerepeatnode.create(l,r,_t1:Tnode;tab,cn:boolean);
begin
inherited create(whilerepeatn,l,r,_t1,nil);
testatbegin:=tab;
checknegate:=cn;
end;
function twhilerepeatnode.det_resulttype:tnode; function twhilerepeatnode.det_resulttype:tnode;
var
t:Tunarynode;
begin begin
result:=nil; result:=nil;
resulttype:=voidtype; resulttype:=voidtype;
resulttypepass(left); resulttypepass(left);
{A not node can be removed.}
if left.nodetype=notn then
begin
t:=Tunarynode(left);
left:=Tunarynode(left).left;
t.left:=nil;
t.destroy;
checknegate:=not checknegate;
end;
{ loop instruction } { loop instruction }
if assigned(right) then if assigned(right) then
resulttypepass(right); resulttypepass(right);
@ -337,33 +361,44 @@ implementation
end; end;
{$ifdef state_tracking} {$ifdef state_tracking}
procedure Twhilerepeatnode.track_state_pass(exec_known:boolean); function Twhilerepeatnode.track_state_pass(exec_known:boolean):boolean;
var condition:Tnode; var condition:Tnode;
code:Tnode; code:Tnode;
done:boolean; done:boolean;
value:boolean; value:boolean;
begin begin
track_state_pass:=false;
done:=false; done:=false;
writeln('Oeps!');
repeat repeat
condition:=left.getcopy; condition:=left.getcopy;
condition.track_state_pass(exec_known); if condition.track_state_pass(exec_known) then
{Force new resulttype pass.} begin
condition.resulttype.def:=nil; track_state_pass:=true;
do_resulttypepass(condition); {Force new resulttype pass.}
condition.resulttype.def:=nil;
do_resulttypepass(condition);
end;
code:=right.getcopy; code:=right.getcopy;
if is_constboolnode(condition) then if is_constboolnode(condition) then
begin begin
value:=Tordconstnode(condition).value<>0; value:=Tordconstnode(condition).value<>0;
if value then if value then
code.track_state_pass(exec_known) begin
if code.track_state_pass(exec_known) then
track_state_pass:=true;
end
else else
done:=true; done:=true;
end end
else else
{Remove any modified variables from the state.} begin
code.track_state_pass(false); {Remove any modified variables from the state.}
code.track_state_pass(false);
done:=true;
end;
code.destroy; code.destroy;
condition.destroy; condition.destroy;
until done; until done;
@ -372,14 +407,17 @@ implementation
begin begin
... ...
end; end;
When the loop is done, we do know that i<10 = false. When the loop is done, we do know that i<10 = false.
} }
condition:=left.getcopy; condition:=left.getcopy;
condition.track_state_pass(exec_known); if condition.track_state_pass(exec_known) then
{Force new resulttype pass.} begin
condition.resulttype.def:=nil; track_state_pass:=true;
do_resulttypepass(condition); {Force new resulttype pass.}
condition.resulttype.def:=nil;
do_resulttypepass(condition);
end;
aktstate.store_fact(condition,cordconstnode.create(0,booltype)); aktstate.store_fact(condition,cordconstnode.create(0,booltype));
end; end;
{$endif} {$endif}
@ -1166,7 +1204,18 @@ begin
end. end.
{ {
$Log$ $Log$
Revision 1.37 2002-07-16 13:57:02 florian Revision 1.38 2002-07-19 11:41:35 daniel
* State tracker work
* The whilen and repeatn are now completely unified into whilerepeatn. This
allows the state tracker to change while nodes automatically into
repeat nodes.
* Resulttypepass improvements to the notn. 'not not a' is optimized away and
'not(a>b)' is optimized into 'a<=b'.
* Resulttypepass improvements to the whilerepeatn. 'while not a' is optimized
by removing the notn and later switchting the true and falselabels. The
same is done with 'repeat until not a'.
Revision 1.37 2002/07/16 13:57:02 florian
* raise takes now a void pointer as at and frame address * raise takes now a void pointer as at and frame address
instead of a longint instead of a longint

View File

@ -58,7 +58,7 @@ interface
function pass_1 : tnode;override; function pass_1 : tnode;override;
function det_resulttype:tnode;override; function det_resulttype:tnode;override;
{$ifdef state_tracking} {$ifdef state_tracking}
procedure track_state_pass(exec_known:boolean);override; function track_state_pass(exec_known:boolean):boolean;override;
{$endif state_tracking} {$endif state_tracking}
function docompare(p: tnode): boolean; override; function docompare(p: tnode): boolean; override;
end; end;
@ -578,14 +578,15 @@ implementation
end; end;
{$ifdef state_tracking} {$ifdef state_tracking}
procedure Tassignmentnode.track_state_pass(exec_known:boolean); function Tassignmentnode.track_state_pass(exec_known:boolean):boolean;
var se:Tstate_entry; var se:Tstate_entry;
begin begin
track_state_pass:=false;
if exec_known then if exec_known then
begin begin
right.track_state_pass(exec_known); track_state_pass:=right.track_state_pass(exec_known);
{Force a new resulttype pass.} {Force a new resulttype pass.}
right.resulttype.def:=nil; right.resulttype.def:=nil;
do_resulttypepass(right); do_resulttypepass(right);
@ -597,7 +598,6 @@ implementation
end; end;
{$endif} {$endif}
{***************************************************************************** {*****************************************************************************
TFUNCRETNODE TFUNCRETNODE
*****************************************************************************} *****************************************************************************}
@ -983,7 +983,18 @@ begin
end. end.
{ {
$Log$ $Log$
Revision 1.45 2002-07-15 18:03:15 florian Revision 1.46 2002-07-19 11:41:36 daniel
* State tracker work
* The whilen and repeatn are now completely unified into whilerepeatn. This
allows the state tracker to change while nodes automatically into
repeat nodes.
* Resulttypepass improvements to the notn. 'not not a' is optimized away and
'not(a>b)' is optimized into 'a<=b'.
* Resulttypepass improvements to the whilerepeatn. 'while not a' is optimized
by removing the notn and later switchting the true and falselabels. The
same is done with 'repeat until not a'.
Revision 1.45 2002/07/15 18:03:15 florian
* readded removed changes * readded removed changes
Revision 1.43 2002/07/11 14:41:28 florian Revision 1.43 2002/07/11 14:41:28 florian

View File

@ -58,6 +58,9 @@ interface
constructor create(expr : tnode);virtual; constructor create(expr : tnode);virtual;
function pass_1 : tnode;override; function pass_1 : tnode;override;
function det_resulttype:tnode;override; function det_resulttype:tnode;override;
{$ifdef state_tracking}
function track_state_pass(exec_known:boolean):boolean;override;
{$endif}
end; end;
tnotnodeclass = class of tnotnode; tnotnodeclass = class of tnotnode;
@ -515,6 +518,9 @@ implementation
TNOTNODE TNOTNODE
****************************************************************************} ****************************************************************************}
const boolean_reverse:array[ltn..unequaln] of Tnodetype=
(gten,gtn,lten,ltn,unequaln,equaln);
constructor tnotnode.create(expr : tnode); constructor tnotnode.create(expr : tnode);
begin begin
@ -533,6 +539,28 @@ implementation
if codegenerror then if codegenerror then
exit; exit;
resulttype:=left.resulttype;
{Try optmimizing ourself away.}
if left.nodetype=notn then
begin
{Double not. Remove both.}
t:=Tnotnode(left).left;
Tnotnode(left).left:=nil;
left:=t;
result:=t;
exit;
end;
if left.nodetype in [ltn,lten,equaln,unequaln,gtn,gten] then
begin
{Not of boolean expression. Turn around the operator and remove
the not.}
result:=left;
left.nodetype:=boolean_reverse[left.nodetype];
left:=nil;
exit;
end;
{ constant folding } { constant folding }
if (left.nodetype=ordconstn) then if (left.nodetype=ordconstn) then
begin begin
@ -572,7 +600,6 @@ implementation
exit; exit;
end; end;
resulttype:=left.resulttype;
if is_boolean(resulttype.def) then if is_boolean(resulttype.def) then
begin begin
end end
@ -669,6 +696,19 @@ implementation
location.loc:=LOC_REGISTER; location.loc:=LOC_REGISTER;
end end
end; end;
{$ifdef state_tracking}
function Tnotnode.track_state_pass(exec_known:boolean):boolean;
begin
track_state_pass:=true;
if left.track_state_pass(exec_known) then
begin
left.resulttype.def:=nil;
do_resulttypepass(left);
end;
end;
{$endif}
begin begin
cmoddivnode:=tmoddivnode; cmoddivnode:=tmoddivnode;
@ -678,7 +718,18 @@ begin
end. end.
{ {
$Log$ $Log$
Revision 1.34 2002-05-18 13:34:10 peter Revision 1.35 2002-07-19 11:41:36 daniel
* State tracker work
* The whilen and repeatn are now completely unified into whilerepeatn. This
allows the state tracker to change while nodes automatically into
repeat nodes.
* Resulttypepass improvements to the notn. 'not not a' is optimized away and
'not(a>b)' is optimized into 'a<=b'.
* Resulttypepass improvements to the whilerepeatn. 'while not a' is optimized
by removing the notn and later switchting the true and falselabels. The
same is done with 'repeat until not a'.
Revision 1.34 2002/05/18 13:34:10 peter
* readded missing revisions * readded missing revisions
Revision 1.33 2002/05/16 19:46:39 carl Revision 1.33 2002/05/16 19:46:39 carl

View File

@ -94,34 +94,35 @@ interface
ifn, {An if statement.} ifn, {An if statement.}
breakn, {A break statement.} breakn, {A break statement.}
continuen, {A continue statement.} continuen, {A continue statement.}
repeatn, {A repeat until block.} (* repeatn, {A repeat until block.}
whilen, {A while do statement.} whilen, {A while do statement.}*)
forn, {A for loop.} whilerepeatn, {A while or repeat statement.}
exitn, {An exit statement.} forn, {A for loop.}
withn, {A with statement.} exitn, {An exit statement.}
casen, {A case statement.} withn, {A with statement.}
labeln, {A label.} casen, {A case statement.}
goton, {A goto statement.} labeln, {A label.}
tryexceptn, {A try except block.} goton, {A goto statement.}
raisen, {A raise statement.} tryexceptn, {A try except block.}
tryfinallyn, {A try finally statement.} raisen, {A raise statement.}
onn, { for an on statement in exception code } tryfinallyn, {A try finally statement.}
isn, {Represents the is operator.} onn, {For an on statement in exception code.}
asn, {Represents the as typecast.} isn, {Represents the is operator.}
caretn, {Represents the ^ operator.} asn, {Represents the as typecast.}
failn, {Represents the fail statement.} caretn, {Represents the ^ operator.}
starstarn, {Represents the ** operator exponentiation } failn, {Represents the fail statement.}
procinlinen, {Procedures that can be inlined } starstarn, {Represents the ** operator exponentiation }
procinlinen, {Procedures that can be inlined }
arrayconstructorn, {Construction node for [...] parsing} arrayconstructorn, {Construction node for [...] parsing}
arrayconstructorrangen, {Range element to allow sets in array construction tree} arrayconstructorrangen, {Range element to allow sets in array construction tree}
tempn, { for temps in the result/firstpass } tempn, { for temps in the result/firstpass }
temprefn, { references to temps } temprefn, { references to temps }
{ added for optimizations where we cannot suppress } { added for optimizations where we cannot suppress }
addoptn, addoptn,
nothingn, nothingn,
loadvmtn, loadvmtn,
guidconstn, guidconstn,
rttin { rtti information so they can be accessed in result/firstpass } rttin {Rtti information so they can be accessed in result/firstpass.}
); );
const const
@ -179,8 +180,9 @@ interface
'ifn', 'ifn',
'breakn', 'breakn',
'continuen', 'continuen',
'repeatn', (* 'repeatn',
'whilen', 'whilen',*)
'whilerepeatn',
'forn', 'forn',
'exitn', 'exitn',
'withn', 'withn',
@ -332,7 +334,7 @@ interface
{$ifdef state_tracking} {$ifdef state_tracking}
{ Does optimizations by keeping track of the variable states { Does optimizations by keeping track of the variable states
in a procedure } in a procedure }
procedure track_state_pass(exec_known:boolean);virtual; function track_state_pass(exec_known:boolean):boolean;virtual;
{$endif} {$endif}
procedure det_temp;virtual;abstract; procedure det_temp;virtual;abstract;
@ -522,9 +524,10 @@ implementation
end; end;
{$ifdef state_tracking} {$ifdef state_tracking}
procedure Tnode.track_state_pass(exec_known:boolean); function Tnode.track_state_pass(exec_known:boolean):boolean;
begin begin
track_state_pass:=false;
end; end;
{$endif state_tracking} {$endif state_tracking}
@ -818,7 +821,18 @@ implementation
end. end.
{ {
$Log$ $Log$
Revision 1.29 2002-07-14 18:00:44 daniel Revision 1.30 2002-07-19 11:41:36 daniel
* State tracker work
* The whilen and repeatn are now completely unified into whilerepeatn. This
allows the state tracker to change while nodes automatically into
repeat nodes.
* Resulttypepass improvements to the notn. 'not not a' is optimized away and
'not(a>b)' is optimized into 'a<=b'.
* Resulttypepass improvements to the whilerepeatn. 'while not a' is optimized
by removing the notn and later switchting the true and falselabels. The
same is done with 'repeat until not a'.
Revision 1.29 2002/07/14 18:00:44 daniel
+ Added the beginning of a state tracker. This will track the values of + Added the beginning of a state tracker. This will track the values of
variables through procedures and optimize things away. variables through procedures and optimize things away.

View File

@ -52,6 +52,9 @@ implementation
{$ifdef extdebug} {$ifdef extdebug}
htypechk, htypechk,
{$endif extdebug} {$endif extdebug}
{$ifdef state_tracking}
nstate,
{$endif}
tgobj tgobj
; ;
@ -162,9 +165,9 @@ implementation
aktfilepos:=oldpos; aktfilepos:=oldpos;
codegenerror:=codegenerror or oldcodegenerror; codegenerror:=codegenerror or oldcodegenerror;
end; end;
{ first pass }
if not(nf_error in p.flags) then if not(nf_error in p.flags) then
begin begin
{ first pass }
aktfilepos:=p.fileinfo; aktfilepos:=p.fileinfo;
aktlocalswitches:=p.localswitches; aktlocalswitches:=p.localswitches;
hp:=p.pass_1; hp:=p.pass_1;
@ -194,6 +197,15 @@ implementation
begin begin
codegenerror:=false; codegenerror:=false;
firstpass(p); firstpass(p);
{$ifdef state_tracking}
writeln('TRACKSTART');
writeln('before');
writenode(p);
do_track_state_pass(p);
writeln('after');
writenode(p);
writeln('TRACKDONE');
{$endif}
do_firstpass:=codegenerror; do_firstpass:=codegenerror;
end; end;
@ -201,14 +213,27 @@ implementation
procedure do_track_state_pass(p:Tnode); procedure do_track_state_pass(p:Tnode);
begin begin
aktstate:=Tstate_storage.create;
p.track_state_pass(true); p.track_state_pass(true);
aktstate.destroy;
end; end;
{$endif} {$endif}
end. end.
{ {
$Log$ $Log$
Revision 1.25 2002-07-14 18:00:44 daniel Revision 1.26 2002-07-19 11:41:36 daniel
* State tracker work
* The whilen and repeatn are now completely unified into whilerepeatn. This
allows the state tracker to change while nodes automatically into
repeat nodes.
* Resulttypepass improvements to the notn. 'not not a' is optimized away and
'not(a>b)' is optimized into 'a<=b'.
* Resulttypepass improvements to the whilerepeatn. 'while not a' is optimized
by removing the notn and later switchting the true and falselabels. The
same is done with 'repeat until not a'.
Revision 1.25 2002/07/14 18:00:44 daniel
+ Added the beginning of a state tracker. This will track the values of + Added the beginning of a state tracker. This will track the values of
variables through procedures and optimize things away. variables through procedures and optimize things away.

View File

@ -117,8 +117,9 @@ implementation
'ifn', {ifn} 'ifn', {ifn}
'breakn', {breakn} 'breakn', {breakn}
'continuen', {continuen} 'continuen', {continuen}
'_while_REPEAT', {repeatn} (* '_while_REPEAT', {repeatn}
'_WHILE_repeat', {whilen} '_WHILE_repeat', {whilen}*)
'while_repeat', {whilerepeatn}
'for', {forn} 'for', {forn}
'exitn', {exitn} 'exitn', {exitn}
'with', {withn} 'with', {withn}
@ -322,7 +323,18 @@ implementation
end. end.
{ {
$Log$ $Log$
Revision 1.31 2002-07-01 18:46:25 peter Revision 1.32 2002-07-19 11:41:36 daniel
* State tracker work
* The whilen and repeatn are now completely unified into whilerepeatn. This
allows the state tracker to change while nodes automatically into
repeat nodes.
* Resulttypepass improvements to the notn. 'not not a' is optimized away and
'not(a>b)' is optimized into 'a<=b'.
* Resulttypepass improvements to the whilerepeatn. 'while not a' is optimized
by removing the notn and later switchting the true and falselabels. The
same is done with 'repeat until not a'.
Revision 1.31 2002/07/01 18:46:25 peter
* internal linker * internal linker
* reorganized aasm layer * reorganized aasm layer

View File

@ -344,7 +344,7 @@ implementation
first:=cblocknode.create(first); first:=cblocknode.create(first);
p_e:=comp_expr(true); p_e:=comp_expr(true);
repeat_statement:=genloopnode(repeatn,p_e,first,nil,false); repeat_statement:=genloopnode(whilerepeatn,p_e,first,nil,true);
end; end;
@ -358,7 +358,7 @@ implementation
p_e:=comp_expr(true); p_e:=comp_expr(true);
consume(_DO); consume(_DO);
p_a:=statement; p_a:=statement;
while_statement:=genloopnode(whilen,p_e,p_a,nil,false); while_statement:=genloopnode(whilerepeatn,p_e,p_a,nil,false);
end; end;
@ -1231,7 +1231,18 @@ implementation
end. end.
{ {
$Log$ $Log$
Revision 1.62 2002-07-16 15:34:20 florian Revision 1.63 2002-07-19 11:41:36 daniel
* State tracker work
* The whilen and repeatn are now completely unified into whilerepeatn. This
allows the state tracker to change while nodes automatically into
repeat nodes.
* Resulttypepass improvements to the notn. 'not not a' is optimized away and
'not(a>b)' is optimized into 'a<=b'.
* Resulttypepass improvements to the whilerepeatn. 'while not a' is optimized
by removing the notn and later switchting the true and falselabels. The
same is done with 'repeat until not a'.
Revision 1.62 2002/07/16 15:34:20 florian
* exit is now a syssym instead of a keyword * exit is now a syssym instead of a keyword
Revision 1.61 2002/07/11 14:41:28 florian Revision 1.61 2002/07/11 14:41:28 florian

View File

@ -248,7 +248,7 @@ implementation
aktbreaklabel:=nil; aktbreaklabel:=nil;
aktcontinuelabel:=nil; aktcontinuelabel:=nil;
{$ifdef state_tracking} {$ifdef state_tracking}
aktstate:=Tstate_storage.create; { aktstate:=Tstate_storage.create;}
{$endif state_tracking} {$endif state_tracking}
{ insert symtables for the class, by only if it is no nested function } { insert symtables for the class, by only if it is no nested function }
@ -320,7 +320,9 @@ implementation
aktprocdef.forwarddef:=false; aktprocdef.forwarddef:=false;
{$ifdef state_tracking} {$ifdef state_tracking}
{ writenode(code);
do_track_state_pass(code); do_track_state_pass(code);
writenode(code);}
{$endif} {$endif}
{ only generate the code if no type errors are found, else { only generate the code if no type errors are found, else
@ -456,7 +458,7 @@ implementation
aktmaxfpuregisters:=oldaktmaxfpuregisters; aktmaxfpuregisters:=oldaktmaxfpuregisters;
{$ifdef state_tracking} {$ifdef state_tracking}
aktstate.destroy; { aktstate.destroy;}
{$endif state_tracking} {$endif state_tracking}
{ restore filepos, the switches are already set } { restore filepos, the switches are already set }
aktfilepos:=savepos; aktfilepos:=savepos;
@ -829,7 +831,18 @@ implementation
end. end.
{ {
$Log$ $Log$
Revision 1.59 2002-07-15 18:03:15 florian Revision 1.60 2002-07-19 11:41:36 daniel
* State tracker work
* The whilen and repeatn are now completely unified into whilerepeatn. This
allows the state tracker to change while nodes automatically into
repeat nodes.
* Resulttypepass improvements to the notn. 'not not a' is optimized away and
'not(a>b)' is optimized into 'a<=b'.
* Resulttypepass improvements to the whilerepeatn. 'while not a' is optimized
by removing the notn and later switchting the true and falselabels. The
same is done with 'repeat until not a'.
Revision 1.59 2002/07/15 18:03:15 florian
* readded removed changes * readded removed changes
Revision 1.57 2002/07/11 14:41:28 florian Revision 1.57 2002/07/11 14:41:28 florian