Fix recordtoken writing into ppu files to allow correct

handling in cross-configuration with different endianess.

  The code has been modified to use the same scheme as the writing of
  the other parts of the ppu, i.e. change_endian filed has been
  added also to tscannerfile class of scanner unit.
  This field is then used to swap values that required endianess
  conversion.

  * scanner.pas: change_endian filed added to tscannerfile class.
    The value of this field is set as the same field in tentryfile class of entfile unit.
    Token read and write methods converted to use change_endian field.

  * ppu.pas: Increase CurrentPPILongVersion

  * utils/ppuutils/ppudump.pp: Remove unneeded FPC_BIG_ENDIAN code
    which was needed because tokens were previously written using a
    different rule.

git-svn-id: trunk@42527 -
This commit is contained in:
pierre 2019-07-29 05:33:00 +00:00
parent 3ef319c0b0
commit f2b200e4f0
3 changed files with 25 additions and 83 deletions

View File

@ -50,7 +50,7 @@ const
CurrentPPUVersion = 207;
{ for any other changes to the ppu format, increase this version number
(it's a cardinal) }
CurrentPPULongVersion = 4;
CurrentPPULongVersion = 5;
{ unit flags }
uf_big_endian = $000004;

View File

@ -145,6 +145,8 @@ interface
{ true, if we are parsing preprocessor expressions }
in_preproc_comp_expr : boolean;
{ true if cross-compiling for a CPU in opposite endianess}
change_endian : boolean;
constructor Create(const fn:string; is_macro: boolean = false);
destructor Destroy;override;
@ -2707,7 +2709,12 @@ type
lasttoken:=NOTOKEN;
nexttoken:=NOTOKEN;
ignoredirectives:=TFPHashList.Create;
end;
{$ifdef FPC_BIG_ENDIAN}
change_endian:=(target_info.endian=endian_little);
{$else}
change_endian:=(target_info.endian=endian_big);
{$endif}
end;
procedure tscannerfile.firstfile;
@ -2879,17 +2886,11 @@ type
procedure tscannerfile.tokenwritesizeint(val : asizeint);
begin
{$ifdef FPC_BIG_ENDIAN}
val:=swapendian(val);
{$endif}
recordtokenbuf.write(val,sizeof(asizeint));
end;
procedure tscannerfile.tokenwritelongint(val : longint);
begin
{$ifdef FPC_BIG_ENDIAN}
val:=swapendian(val);
{$endif}
recordtokenbuf.write(val,sizeof(longint));
end;
@ -2900,17 +2901,11 @@ type
procedure tscannerfile.tokenwriteword(val : word);
begin
{$ifdef FPC_BIG_ENDIAN}
val:=swapendian(val);
{$endif}
recordtokenbuf.write(val,sizeof(word));
end;
procedure tscannerfile.tokenwritelongword(val : longword);
begin
{$ifdef FPC_BIG_ENDIAN}
val:=swapendian(val);
{$endif}
recordtokenbuf.write(val,sizeof(longword));
end;
@ -2919,9 +2914,8 @@ type
val : asizeint;
begin
replaytokenbuf.read(val,sizeof(asizeint));
{$ifdef FPC_BIG_ENDIAN}
val:=swapendian(val);
{$endif}
if change_endian then
val:=swapendian(val);
result:=val;
end;
@ -2930,9 +2924,8 @@ type
val : longword;
begin
replaytokenbuf.read(val,sizeof(longword));
{$ifdef FPC_BIG_ENDIAN}
val:=swapendian(val);
{$endif}
if change_endian then
val:=swapendian(val);
result:=val;
end;
@ -2941,9 +2934,8 @@ type
val : longint;
begin
replaytokenbuf.read(val,sizeof(longint));
{$ifdef FPC_BIG_ENDIAN}
val:=swapendian(val);
{$endif}
if change_endian then
val:=swapendian(val);
result:=val;
end;
@ -2968,9 +2960,8 @@ type
val : smallint;
begin
replaytokenbuf.read(val,sizeof(smallint));
{$ifdef FPC_BIG_ENDIAN}
val:=swapendian(val);
{$endif}
if change_endian then
val:=swapendian(val);
result:=val;
end;
@ -2979,9 +2970,8 @@ type
val : word;
begin
replaytokenbuf.read(val,sizeof(word));
{$ifdef FPC_BIG_ENDIAN}
val:=swapendian(val);
{$endif}
if change_endian then
val:=swapendian(val);
result:=val;
end;
@ -2998,16 +2988,13 @@ type
end;
procedure tscannerfile.tokenreadset(var b;size : longint);
{$ifdef FPC_BIG_ENDIAN}
var
i : longint;
{$endif}
begin
replaytokenbuf.read(b,size);
{$ifdef FPC_BIG_ENDIAN}
for i:=0 to size-1 do
Pbyte(@b)[i]:=reverse_byte(Pbyte(@b)[i]);
{$endif}
if change_endian then
for i:=0 to size-1 do
Pbyte(@b)[i]:=reverse_byte(Pbyte(@b)[i]);
end;
procedure tscannerfile.tokenwriteenum(var b;size : longint);
@ -3016,22 +3003,8 @@ type
end;
procedure tscannerfile.tokenwriteset(var b;size : longint);
{$ifdef FPC_BIG_ENDIAN}
var
i: longint;
tmpset: array[0..31] of byte;
{$endif}
begin
{$ifdef FPC_BIG_ENDIAN}
{ satisfy DFA because it assumes that size may be 0 and doesn't know that
recordtokenbuf.write wouldn't use tmpset in that case }
tmpset[0]:=0;
for i:=0 to size-1 do
tmpset[i]:=reverse_byte(Pbyte(@b)[i]);
recordtokenbuf.write(tmpset,size);
{$else}
recordtokenbuf.write(b,size);
{$endif}
end;

View File

@ -2235,10 +2235,6 @@ const
inc(tbi,sizeof(dword));
if ppufile.change_endian then
var32:=swapendian(var32);
{$ifdef FPC_BIG_ENDIAN}
{ Tokens seems to be swapped to little endian in compiler code }
var32:=swapendian(var32);
{$endif}
result:=var32;
end;
@ -2250,10 +2246,6 @@ const
inc(tbi,sizeof(word));
if ppufile.change_endian then
var16:=swapendian(var16);
{$ifdef FPC_BIG_ENDIAN}
{ Tokens seems to be swapped to little endian in compiler code }
var16:=swapendian(var16);
{$endif}
result:=var16;
end;
@ -2265,10 +2257,6 @@ const
inc(tbi,sizeof(longint));
if ppufile.change_endian then
var32:=swapendian(var32);
{$ifdef FPC_BIG_ENDIAN}
{ Tokens seems to be swapped to little endian in compiler code }
var32:=swapendian(var32);
{$endif}
result:=var32;
end;
@ -2280,25 +2268,18 @@ const
inc(tbi,sizeof(shortint));
if ppufile.change_endian then
var16:=swapendian(var16);
{$ifdef FPC_BIG_ENDIAN}
{ Tokens seems to be swapped to little endian in compiler code }
var16:=swapendian(var16);
{$endif}
result:=var16;
end;
procedure tokenreadset(var b;size : longint);
{$ifdef FPC_BIG_ENDIAN}
var
i : longint;
{$endif}
begin
move(tokenbuf[tbi],b,size);
inc(tbi,size);
{$ifdef FPC_BIG_ENDIAN}
for i:=0 to size-1 do
Pbyte(@b)[i]:=reverse_byte(Pbyte(@b)[i]);
{$endif}
if ppufile.change_endian then
for i:=0 to size-1 do
Pbyte(@b)[i]:=reverse_byte(Pbyte(@b)[i]);
end;
function gettokenbufbyte : byte;
@ -2332,10 +2313,6 @@ const
inc(tbi,sizeof(int64));
if ppufile.change_endian then
var64:=swapendian(var64);
{$ifdef FPC_BIG_ENDIAN}
{ Tokens seems to be swapped to little endian in compiler code }
var64:=swapendian(var64);
{$endif}
result:=var64;
end
else if CpuAddrBitSize[cpu]=32 then
@ -2344,10 +2321,6 @@ const
inc(tbi,sizeof(longint));
if ppufile.change_endian then
var32:=swapendian(var32);
{$ifdef FPC_BIG_ENDIAN}
{ Tokens seems to be swapped to little endian in compiler code }
var32:=swapendian(var32);
{$endif}
result:=var32;
end
else if CpuAddrBitSize[cpu]=16 then
@ -2356,10 +2329,6 @@ const
inc(tbi,sizeof(smallint));
if ppufile.change_endian then
var16:=swapendian(var16);
{$ifdef FPC_BIG_ENDIAN}
{ Tokens seems to be swapped to little endian in compiler code }
var16:=swapendian(var16);
{$endif}
result:=var16;
end
else