|
@@ -271,6 +271,9 @@ interface
|
|
pnode = ^tnode;
|
|
pnode = ^tnode;
|
|
{ basic class for the intermediated representation fpc uses }
|
|
{ basic class for the intermediated representation fpc uses }
|
|
tnode = class
|
|
tnode = class
|
|
|
|
+ private
|
|
|
|
+ fppuidx : longint;
|
|
|
|
+ function getppuidx:longint;
|
|
public
|
|
public
|
|
{ type of this node }
|
|
{ type of this node }
|
|
nodetype : tnodetype;
|
|
nodetype : tnodetype;
|
|
@@ -291,7 +294,6 @@ interface
|
|
successor : tnode;
|
|
successor : tnode;
|
|
{ there are some properties about the node stored }
|
|
{ there are some properties about the node stored }
|
|
flags : tnodeflags;
|
|
flags : tnodeflags;
|
|
- ppuidx : longint;
|
|
|
|
resultdef : tdef;
|
|
resultdef : tdef;
|
|
resultdefderef : tderef;
|
|
resultdefderef : tderef;
|
|
fileinfo : tfileposinfo;
|
|
fileinfo : tfileposinfo;
|
|
@@ -306,7 +308,7 @@ interface
|
|
procedure ppuwrite(ppufile:tcompilerppufile);virtual;
|
|
procedure ppuwrite(ppufile:tcompilerppufile);virtual;
|
|
procedure buildderefimpl;virtual;
|
|
procedure buildderefimpl;virtual;
|
|
procedure derefimpl;virtual;
|
|
procedure derefimpl;virtual;
|
|
- procedure derefnode;virtual;
|
|
|
|
|
|
+ procedure resolveppuidx;virtual;
|
|
|
|
|
|
{ toggles the flag }
|
|
{ toggles the flag }
|
|
procedure toggleflag(f : tnodeflag);
|
|
procedure toggleflag(f : tnodeflag);
|
|
@@ -345,7 +347,7 @@ interface
|
|
|
|
|
|
{ does the real copying of a node }
|
|
{ does the real copying of a node }
|
|
function dogetcopy : tnode;virtual;
|
|
function dogetcopy : tnode;virtual;
|
|
-
|
|
|
|
|
|
+
|
|
{ returns the real loadn/temprefn a node refers to,
|
|
{ returns the real loadn/temprefn a node refers to,
|
|
skipping (absolute) equal type conversions }
|
|
skipping (absolute) equal type conversions }
|
|
function actualtargetnode: tnode;virtual;
|
|
function actualtargetnode: tnode;virtual;
|
|
@@ -362,6 +364,7 @@ interface
|
|
|
|
|
|
{ ensures that the optimizer info record is allocated }
|
|
{ ensures that the optimizer info record is allocated }
|
|
function allocoptinfo : poptinfo;inline;
|
|
function allocoptinfo : poptinfo;inline;
|
|
|
|
+ property ppuidx:longint read getppuidx;
|
|
end;
|
|
end;
|
|
|
|
|
|
tnodeclass = class of tnode;
|
|
tnodeclass = class of tnode;
|
|
@@ -380,7 +383,6 @@ interface
|
|
procedure ppuwrite(ppufile:tcompilerppufile);override;
|
|
procedure ppuwrite(ppufile:tcompilerppufile);override;
|
|
procedure buildderefimpl;override;
|
|
procedure buildderefimpl;override;
|
|
procedure derefimpl;override;
|
|
procedure derefimpl;override;
|
|
- procedure derefnode;override;
|
|
|
|
procedure concattolist(l : tlinkedlist);override;
|
|
procedure concattolist(l : tlinkedlist);override;
|
|
function ischild(p : tnode) : boolean;override;
|
|
function ischild(p : tnode) : boolean;override;
|
|
function docompare(p : tnode) : boolean;override;
|
|
function docompare(p : tnode) : boolean;override;
|
|
@@ -398,7 +400,6 @@ interface
|
|
procedure ppuwrite(ppufile:tcompilerppufile);override;
|
|
procedure ppuwrite(ppufile:tcompilerppufile);override;
|
|
procedure buildderefimpl;override;
|
|
procedure buildderefimpl;override;
|
|
procedure derefimpl;override;
|
|
procedure derefimpl;override;
|
|
- procedure derefnode;override;
|
|
|
|
procedure concattolist(l : tlinkedlist);override;
|
|
procedure concattolist(l : tlinkedlist);override;
|
|
function ischild(p : tnode) : boolean;override;
|
|
function ischild(p : tnode) : boolean;override;
|
|
function docompare(p : tnode) : boolean;override;
|
|
function docompare(p : tnode) : boolean;override;
|
|
@@ -418,7 +419,6 @@ interface
|
|
procedure ppuwrite(ppufile:tcompilerppufile);override;
|
|
procedure ppuwrite(ppufile:tcompilerppufile);override;
|
|
procedure buildderefimpl;override;
|
|
procedure buildderefimpl;override;
|
|
procedure derefimpl;override;
|
|
procedure derefimpl;override;
|
|
- procedure derefnode;override;
|
|
|
|
procedure concattolist(l : tlinkedlist);override;
|
|
procedure concattolist(l : tlinkedlist);override;
|
|
function ischild(p : tnode) : boolean;override;
|
|
function ischild(p : tnode) : boolean;override;
|
|
function docompare(p : tnode) : boolean;override;
|
|
function docompare(p : tnode) : boolean;override;
|
|
@@ -441,8 +441,6 @@ interface
|
|
procedure ppuwritenode(ppufile:tcompilerppufile;n:tnode);
|
|
procedure ppuwritenode(ppufile:tcompilerppufile;n:tnode);
|
|
function ppuloadnodetree(ppufile:tcompilerppufile):tnode;
|
|
function ppuloadnodetree(ppufile:tcompilerppufile):tnode;
|
|
procedure ppuwritenodetree(ppufile:tcompilerppufile;n:tnode);
|
|
procedure ppuwritenodetree(ppufile:tcompilerppufile;n:tnode);
|
|
- procedure ppuwritenoderef(ppufile:tcompilerppufile;n:tnode);
|
|
|
|
- function ppuloadnoderef(ppufile:tcompilerppufile) : tnode;
|
|
|
|
|
|
|
|
const
|
|
const
|
|
printnodespacing = ' ';
|
|
printnodespacing = ' ';
|
|
@@ -481,40 +479,59 @@ implementation
|
|
****************************************************************************}
|
|
****************************************************************************}
|
|
|
|
|
|
var
|
|
var
|
|
- nodeppudata : tdynamicarray;
|
|
|
|
|
|
+ nodeppulist : TFPObjectList;
|
|
nodeppuidx : longint;
|
|
nodeppuidx : longint;
|
|
|
|
|
|
|
|
|
|
procedure nodeppuidxcreate;
|
|
procedure nodeppuidxcreate;
|
|
begin
|
|
begin
|
|
- nodeppudata:=tdynamicarray.create(1024);
|
|
|
|
|
|
+ nodeppulist:=TFPObjectList.Create(false);
|
|
nodeppuidx:=0;
|
|
nodeppuidx:=0;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
+ procedure nodeppuidxresolve;
|
|
|
|
+ var
|
|
|
|
+ i : longint;
|
|
|
|
+ n : tnode;
|
|
|
|
+ begin
|
|
|
|
+ for i:=0 to nodeppulist.count-1 do
|
|
|
|
+ begin
|
|
|
|
+ n:=tnode(nodeppulist[i]);
|
|
|
|
+ if assigned(n) then
|
|
|
|
+ n.resolveppuidx;
|
|
|
|
+ end;
|
|
|
|
+ end;
|
|
|
|
+
|
|
|
|
+
|
|
procedure nodeppuidxfree;
|
|
procedure nodeppuidxfree;
|
|
begin
|
|
begin
|
|
- nodeppudata.free;
|
|
|
|
- nodeppudata:=nil;
|
|
|
|
|
|
+ nodeppulist.free;
|
|
|
|
+ nodeppulist:=nil;
|
|
|
|
+ nodeppuidx:=0;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure nodeppuidxadd(n:tnode);
|
|
procedure nodeppuidxadd(n:tnode);
|
|
|
|
+ var
|
|
|
|
+ i : longint;
|
|
begin
|
|
begin
|
|
- if n.ppuidx<0 then
|
|
|
|
|
|
+ i:=n.ppuidx;
|
|
|
|
+ if i<=0 then
|
|
internalerror(200311072);
|
|
internalerror(200311072);
|
|
- nodeppudata.seek(n.ppuidx*sizeof(pointer));
|
|
|
|
- nodeppudata.write(n,sizeof(pointer));
|
|
|
|
|
|
+ if i>=nodeppulist.capacity then
|
|
|
|
+ nodeppulist.capacity:=((i div 1024)+1)*1024;
|
|
|
|
+ if i>=nodeppulist.count then
|
|
|
|
+ nodeppulist.count:=i+1;
|
|
|
|
+ nodeppulist[i]:=n;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
function nodeppuidxget(i:longint):tnode;
|
|
function nodeppuidxget(i:longint):tnode;
|
|
begin
|
|
begin
|
|
- if i<0 then
|
|
|
|
- internalerror(200311072);
|
|
|
|
- nodeppudata.seek(i*sizeof(pointer));
|
|
|
|
- if nodeppudata.read(result,sizeof(pointer))<>sizeof(pointer) then
|
|
|
|
|
|
+ if i<=0 then
|
|
internalerror(200311073);
|
|
internalerror(200311073);
|
|
|
|
+ result:=tnode(nodeppulist[i]);
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
@@ -540,7 +557,7 @@ implementation
|
|
//writeln('load: ',nodetype2str[t]);
|
|
//writeln('load: ',nodetype2str[t]);
|
|
{ generate node of the correct class }
|
|
{ generate node of the correct class }
|
|
result:=nodeclass[t].ppuload(t,ppufile);
|
|
result:=nodeclass[t].ppuload(t,ppufile);
|
|
- result.ppuidx:=hppuidx;
|
|
|
|
|
|
+ result.fppuidx:=hppuidx;
|
|
nodeppuidxadd(result);
|
|
nodeppuidxadd(result);
|
|
end
|
|
end
|
|
else
|
|
else
|
|
@@ -555,10 +572,6 @@ implementation
|
|
{ type, read by ppuloadnode }
|
|
{ type, read by ppuloadnode }
|
|
if assigned(n) then
|
|
if assigned(n) then
|
|
begin
|
|
begin
|
|
- if n.ppuidx=-1 then
|
|
|
|
- internalerror(200311071);
|
|
|
|
- n.ppuidx:=nodeppuidx;
|
|
|
|
- inc(nodeppuidx);
|
|
|
|
ppufile.putbyte(byte(n.nodetype));
|
|
ppufile.putbyte(byte(n.nodetype));
|
|
ppufile.putlongint(n.ppuidx);
|
|
ppufile.putlongint(n.ppuidx);
|
|
//writeln('write: ',nodetype2str[n.nodetype]);
|
|
//writeln('write: ',nodetype2str[n.nodetype]);
|
|
@@ -569,38 +582,23 @@ implementation
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
- procedure ppuwritenoderef(ppufile:tcompilerppufile;n:tnode);
|
|
|
|
- begin
|
|
|
|
- { writing of node references isn't implemented yet (FK) }
|
|
|
|
- internalerror(200506181);
|
|
|
|
- end;
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- function ppuloadnoderef(ppufile:tcompilerppufile) : tnode;
|
|
|
|
- begin
|
|
|
|
- { reading of node references isn't implemented yet (FK) }
|
|
|
|
- internalerror(200506182);
|
|
|
|
- { avoid warning }
|
|
|
|
- result := nil;
|
|
|
|
- end;
|
|
|
|
-
|
|
|
|
-
|
|
|
|
function ppuloadnodetree(ppufile:tcompilerppufile):tnode;
|
|
function ppuloadnodetree(ppufile:tcompilerppufile):tnode;
|
|
begin
|
|
begin
|
|
if ppufile.readentry<>ibnodetree then
|
|
if ppufile.readentry<>ibnodetree then
|
|
Message(unit_f_ppu_read_error);
|
|
Message(unit_f_ppu_read_error);
|
|
nodeppuidxcreate;
|
|
nodeppuidxcreate;
|
|
result:=ppuloadnode(ppufile);
|
|
result:=ppuloadnode(ppufile);
|
|
- result.derefnode;
|
|
|
|
|
|
+ nodeppuidxresolve;
|
|
nodeppuidxfree;
|
|
nodeppuidxfree;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure ppuwritenodetree(ppufile:tcompilerppufile;n:tnode);
|
|
procedure ppuwritenodetree(ppufile:tcompilerppufile;n:tnode);
|
|
begin
|
|
begin
|
|
- nodeppuidx:=0;
|
|
|
|
|
|
+ nodeppuidxcreate;
|
|
ppuwritenode(ppufile,n);
|
|
ppuwritenode(ppufile,n);
|
|
ppufile.writeentry(ibnodetree);
|
|
ppufile.writeentry(ibnodetree);
|
|
|
|
+ nodeppuidxfree;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
@@ -691,7 +689,6 @@ implementation
|
|
localswitches:=current_settings.localswitches;
|
|
localswitches:=current_settings.localswitches;
|
|
resultdef:=nil;
|
|
resultdef:=nil;
|
|
flags:=[];
|
|
flags:=[];
|
|
- ppuidx:=-1;
|
|
|
|
end;
|
|
end;
|
|
|
|
|
|
constructor tnode.createforcopy;
|
|
constructor tnode.createforcopy;
|
|
@@ -713,7 +710,6 @@ implementation
|
|
expectloc:=LOC_INVALID;
|
|
expectloc:=LOC_INVALID;
|
|
{ updated by secondpass }
|
|
{ updated by secondpass }
|
|
location.loc:=LOC_INVALID;
|
|
location.loc:=LOC_INVALID;
|
|
- ppuidx:=-1;
|
|
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
@@ -727,20 +723,31 @@ implementation
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
- procedure tnode.buildderefimpl;
|
|
|
|
|
|
+ function tnode.getppuidx:longint;
|
|
|
|
+ begin
|
|
|
|
+ if fppuidx=0 then
|
|
|
|
+ begin
|
|
|
|
+ inc(nodeppuidx);
|
|
|
|
+ fppuidx:=nodeppuidx;
|
|
|
|
+ end;
|
|
|
|
+ result:=fppuidx;
|
|
|
|
+ end;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ procedure tnode.resolveppuidx;
|
|
begin
|
|
begin
|
|
- resultdefderef.build(resultdef);
|
|
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
- procedure tnode.derefimpl;
|
|
|
|
|
|
+ procedure tnode.buildderefimpl;
|
|
begin
|
|
begin
|
|
- resultdef:=tdef(resultdefderef.resolve);
|
|
|
|
|
|
+ resultdefderef.build(resultdef);
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
- procedure tnode.derefnode;
|
|
|
|
|
|
+ procedure tnode.derefimpl;
|
|
begin
|
|
begin
|
|
|
|
+ resultdef:=tdef(resultdefderef.resolve);
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
@@ -944,14 +951,6 @@ implementation
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
- procedure tunarynode.derefnode;
|
|
|
|
- begin
|
|
|
|
- inherited derefnode;
|
|
|
|
- if assigned(left) then
|
|
|
|
- left.derefnode;
|
|
|
|
- end;
|
|
|
|
-
|
|
|
|
-
|
|
|
|
function tunarynode.docompare(p : tnode) : boolean;
|
|
function tunarynode.docompare(p : tnode) : boolean;
|
|
begin
|
|
begin
|
|
docompare:=(inherited docompare(p) and
|
|
docompare:=(inherited docompare(p) and
|
|
@@ -1047,14 +1046,6 @@ implementation
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
- procedure tbinarynode.derefnode;
|
|
|
|
- begin
|
|
|
|
- inherited derefnode;
|
|
|
|
- if assigned(right) then
|
|
|
|
- right.derefnode;
|
|
|
|
- end;
|
|
|
|
-
|
|
|
|
-
|
|
|
|
procedure tbinarynode.concattolist(l : tlinkedlist);
|
|
procedure tbinarynode.concattolist(l : tlinkedlist);
|
|
begin
|
|
begin
|
|
{ we could change that depending on the number of }
|
|
{ we could change that depending on the number of }
|
|
@@ -1188,14 +1179,6 @@ implementation
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
- procedure ttertiarynode.derefnode;
|
|
|
|
- begin
|
|
|
|
- inherited derefnode;
|
|
|
|
- if assigned(third) then
|
|
|
|
- third.derefnode;
|
|
|
|
- end;
|
|
|
|
-
|
|
|
|
-
|
|
|
|
function ttertiarynode.docompare(p : tnode) : boolean;
|
|
function ttertiarynode.docompare(p : tnode) : boolean;
|
|
begin
|
|
begin
|
|
docompare:=(inherited docompare(p) and
|
|
docompare:=(inherited docompare(p) and
|