mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-18 03:29:33 +02:00
+ nmat refactored to have simplify
git-svn-id: trunk@142 -
This commit is contained in:
parent
9c717f2a35
commit
e920b10d7a
@ -1,5 +1,5 @@
|
||||
{
|
||||
Copyright (c) 2000-2002 by Florian Klaempfl
|
||||
Copyright (c) 2000-2005 by Florian Klaempfl
|
||||
|
||||
Type checking and register allocation for math nodes
|
||||
|
||||
@ -32,6 +32,7 @@ interface
|
||||
tmoddivnode = class(tbinopnode)
|
||||
function pass_1 : tnode;override;
|
||||
function det_resulttype:tnode;override;
|
||||
function simplify : tnode;override;
|
||||
protected
|
||||
{$ifndef cpu64bit}
|
||||
{ override the following if you want to implement }
|
||||
@ -46,6 +47,7 @@ interface
|
||||
tshlshrnode = class(tbinopnode)
|
||||
function pass_1 : tnode;override;
|
||||
function det_resulttype:tnode;override;
|
||||
function simplify : tnode;override;
|
||||
{$ifndef cpu64bit}
|
||||
{ override the following if you want to implement }
|
||||
{ parts explicitely in the code generator (CEC)
|
||||
@ -61,6 +63,7 @@ interface
|
||||
constructor create(expr : tnode);virtual;
|
||||
function pass_1 : tnode;override;
|
||||
function det_resulttype:tnode;override;
|
||||
function simplify : tnode;override;
|
||||
end;
|
||||
tunaryminusnodeclass = class of tunaryminusnode;
|
||||
|
||||
@ -68,6 +71,7 @@ interface
|
||||
constructor create(expr : tnode);virtual;
|
||||
function pass_1 : tnode;override;
|
||||
function det_resulttype:tnode;override;
|
||||
function simplify : tnode;override;
|
||||
{$ifdef state_tracking}
|
||||
function track_state_pass(exec_known:boolean):boolean;override;
|
||||
{$endif}
|
||||
@ -80,7 +84,6 @@ interface
|
||||
cunaryminusnode : tunaryminusnodeclass;
|
||||
cnotnode : tnotnodeclass;
|
||||
|
||||
|
||||
implementation
|
||||
|
||||
uses
|
||||
@ -96,11 +99,47 @@ implementation
|
||||
TMODDIVNODE
|
||||
****************************************************************************}
|
||||
|
||||
function tmoddivnode.simplify:tnode;
|
||||
var
|
||||
t : tnode;
|
||||
rd,ld : torddef;
|
||||
rv,lv : tconstexprint;
|
||||
begin
|
||||
result:=nil;
|
||||
|
||||
if is_constintnode(right) and is_constintnode(left) then
|
||||
begin
|
||||
rd:=torddef(right.resulttype.def);
|
||||
ld:=torddef(left.resulttype.def);
|
||||
|
||||
rv:=tordconstnode(right).value;
|
||||
lv:=tordconstnode(left).value;
|
||||
|
||||
case nodetype of
|
||||
modn:
|
||||
if (torddef(ld).typ <> u64bit) or
|
||||
(torddef(rd).typ <> u64bit) then
|
||||
t:=genintconstnode(lv mod rv)
|
||||
else
|
||||
t:=genintconstnode(int64(qword(lv) mod qword(rv)));
|
||||
divn:
|
||||
if (torddef(ld).typ <> u64bit) or
|
||||
(torddef(rd).typ <> u64bit) then
|
||||
t:=genintconstnode(lv div rv)
|
||||
else
|
||||
t:=genintconstnode(int64(qword(lv) div qword(rv)));
|
||||
end;
|
||||
result:=t;
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
function tmoddivnode.det_resulttype:tnode;
|
||||
var
|
||||
hp,t : tnode;
|
||||
rd,ld : torddef;
|
||||
rv,lv : tconstexprint;
|
||||
rv : tconstexprint;
|
||||
begin
|
||||
result:=nil;
|
||||
resulttypepass(left);
|
||||
@ -131,28 +170,11 @@ implementation
|
||||
{ recover }
|
||||
rv:=1;
|
||||
end;
|
||||
if is_constintnode(left) then
|
||||
begin
|
||||
lv:=tordconstnode(left).value;
|
||||
end;
|
||||
|
||||
case nodetype of
|
||||
modn:
|
||||
if (torddef(ld).typ <> u64bit) or
|
||||
(torddef(rd).typ <> u64bit) then
|
||||
t:=genintconstnode(lv mod rv)
|
||||
else
|
||||
t:=genintconstnode(int64(qword(lv) mod qword(rv)));
|
||||
divn:
|
||||
if (torddef(ld).typ <> u64bit) or
|
||||
(torddef(rd).typ <> u64bit) then
|
||||
t:=genintconstnode(lv div rv)
|
||||
else
|
||||
t:=genintconstnode(int64(qword(lv) div qword(rv)));
|
||||
end;
|
||||
result:=t;
|
||||
result:=simplify;
|
||||
if assigned(result) then
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
|
||||
{ allow operator overloading }
|
||||
t:=self;
|
||||
@ -425,18 +447,11 @@ implementation
|
||||
TSHLSHRNODE
|
||||
****************************************************************************}
|
||||
|
||||
function tshlshrnode.det_resulttype:tnode;
|
||||
function tshlshrnode.simplify:tnode;
|
||||
var
|
||||
t : tnode;
|
||||
begin
|
||||
result:=nil;
|
||||
resulttypepass(left);
|
||||
resulttypepass(right);
|
||||
set_varstate(right,vs_used,[vsf_must_be_valid]);
|
||||
set_varstate(left,vs_used,[vsf_must_be_valid]);
|
||||
if codegenerror then
|
||||
exit;
|
||||
|
||||
{ constant folding }
|
||||
if is_constintnode(left) and is_constintnode(right) then
|
||||
begin
|
||||
@ -450,6 +465,25 @@ implementation
|
||||
exit;
|
||||
end;
|
||||
|
||||
end;
|
||||
|
||||
|
||||
function tshlshrnode.det_resulttype:tnode;
|
||||
var
|
||||
t : tnode;
|
||||
begin
|
||||
result:=nil;
|
||||
resulttypepass(left);
|
||||
resulttypepass(right);
|
||||
set_varstate(right,vs_used,[vsf_must_be_valid]);
|
||||
set_varstate(left,vs_used,[vsf_must_be_valid]);
|
||||
if codegenerror then
|
||||
exit;
|
||||
|
||||
result:=simplify;
|
||||
if assigned(result) then
|
||||
exit;
|
||||
|
||||
{ allow operator overloading }
|
||||
t:=self;
|
||||
if isbinaryoverloaded(t) then
|
||||
@ -535,16 +569,9 @@ implementation
|
||||
end;
|
||||
|
||||
|
||||
function tunaryminusnode.det_resulttype : tnode;
|
||||
var
|
||||
t : tnode;
|
||||
function tunaryminusnode.simplify:tnode;
|
||||
begin
|
||||
result:=nil;
|
||||
resulttypepass(left);
|
||||
set_varstate(left,vs_used,[vsf_must_be_valid]);
|
||||
if codegenerror then
|
||||
exit;
|
||||
|
||||
{ constant folding }
|
||||
if is_constintnode(left) then
|
||||
begin
|
||||
@ -558,6 +585,22 @@ implementation
|
||||
left:=nil;
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
function tunaryminusnode.det_resulttype : tnode;
|
||||
var
|
||||
t : tnode;
|
||||
begin
|
||||
result:=nil;
|
||||
resulttypepass(left);
|
||||
set_varstate(left,vs_used,[vsf_must_be_valid]);
|
||||
if codegenerror then
|
||||
exit;
|
||||
|
||||
result:=simplify;
|
||||
if assigned(result) then
|
||||
exit;
|
||||
|
||||
resulttype:=left.resulttype;
|
||||
if (left.resulttype.def.deftype=floatdef) then
|
||||
@ -666,26 +709,19 @@ implementation
|
||||
end;
|
||||
|
||||
|
||||
function tnotnode.det_resulttype : tnode;
|
||||
function tnotnode.simplify:tnode;
|
||||
var
|
||||
v : tconstexprint;
|
||||
t : tnode;
|
||||
tt : ttype;
|
||||
v : tconstexprint;
|
||||
begin
|
||||
result:=nil;
|
||||
resulttypepass(left);
|
||||
set_varstate(left,vs_used,[]);
|
||||
if codegenerror then
|
||||
exit;
|
||||
|
||||
resulttype:=left.resulttype;
|
||||
|
||||
{ Try optmimizing ourself away }
|
||||
if left.nodetype=notn then
|
||||
begin
|
||||
{ Double not. Remove both }
|
||||
result:=Tnotnode(left).left;
|
||||
Tnotnode(left).left:=nil;
|
||||
tnotnode(left).left:=nil;
|
||||
exit;
|
||||
end;
|
||||
|
||||
@ -739,6 +775,24 @@ implementation
|
||||
result:=t;
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
function tnotnode.det_resulttype : tnode;
|
||||
var
|
||||
t : tnode;
|
||||
begin
|
||||
result:=nil;
|
||||
resulttypepass(left);
|
||||
set_varstate(left,vs_used,[]);
|
||||
if codegenerror then
|
||||
exit;
|
||||
|
||||
resulttype:=left.resulttype;
|
||||
|
||||
result:=simplify;
|
||||
if assigned(result) then
|
||||
exit;
|
||||
|
||||
if is_boolean(resulttype.def) then
|
||||
begin
|
||||
|
Loading…
Reference in New Issue
Block a user