Procházet zdrojové kódy

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 -

pierre před 6 roky
rodič
revize
f2b200e4f0
3 změnil soubory, kde provedl 25 přidání a 83 odebrání
  1. 1 1
      compiler/ppu.pas
  2. 21 48
      compiler/scanner.pas
  3. 3 34
      compiler/utils/ppuutils/ppudump.pp

+ 1 - 1
compiler/ppu.pas

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

+ 21 - 48
compiler/scanner.pas

@@ -145,6 +145,8 @@ interface
 
 
           { true, if we are parsing preprocessor expressions }
           { true, if we are parsing preprocessor expressions }
           in_preproc_comp_expr : boolean;
           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);
           constructor Create(const fn:string; is_macro: boolean = false);
           destructor Destroy;override;
           destructor Destroy;override;
@@ -2707,7 +2709,12 @@ type
         lasttoken:=NOTOKEN;
         lasttoken:=NOTOKEN;
         nexttoken:=NOTOKEN;
         nexttoken:=NOTOKEN;
         ignoredirectives:=TFPHashList.Create;
         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;
     procedure tscannerfile.firstfile;
@@ -2879,17 +2886,11 @@ type
 
 
     procedure tscannerfile.tokenwritesizeint(val : asizeint);
     procedure tscannerfile.tokenwritesizeint(val : asizeint);
       begin
       begin
-{$ifdef FPC_BIG_ENDIAN}
-        val:=swapendian(val);
-{$endif}
         recordtokenbuf.write(val,sizeof(asizeint));
         recordtokenbuf.write(val,sizeof(asizeint));
       end;
       end;
 
 
     procedure tscannerfile.tokenwritelongint(val : longint);
     procedure tscannerfile.tokenwritelongint(val : longint);
       begin
       begin
-{$ifdef FPC_BIG_ENDIAN}
-        val:=swapendian(val);
-{$endif}
         recordtokenbuf.write(val,sizeof(longint));
         recordtokenbuf.write(val,sizeof(longint));
       end;
       end;
 
 
@@ -2900,17 +2901,11 @@ type
 
 
     procedure tscannerfile.tokenwriteword(val : word);
     procedure tscannerfile.tokenwriteword(val : word);
       begin
       begin
-{$ifdef FPC_BIG_ENDIAN}
-        val:=swapendian(val);
-{$endif}
         recordtokenbuf.write(val,sizeof(word));
         recordtokenbuf.write(val,sizeof(word));
       end;
       end;
 
 
     procedure tscannerfile.tokenwritelongword(val : longword);
     procedure tscannerfile.tokenwritelongword(val : longword);
       begin
       begin
-{$ifdef FPC_BIG_ENDIAN}
-        val:=swapendian(val);
-{$endif}
         recordtokenbuf.write(val,sizeof(longword));
         recordtokenbuf.write(val,sizeof(longword));
       end;
       end;
 
 
@@ -2919,9 +2914,8 @@ type
         val : asizeint;
         val : asizeint;
       begin
       begin
         replaytokenbuf.read(val,sizeof(asizeint));
         replaytokenbuf.read(val,sizeof(asizeint));
-{$ifdef FPC_BIG_ENDIAN}
-        val:=swapendian(val);
-{$endif}
+        if change_endian then
+          val:=swapendian(val);
         result:=val;
         result:=val;
       end;
       end;
 
 
@@ -2930,9 +2924,8 @@ type
         val : longword;
         val : longword;
       begin
       begin
         replaytokenbuf.read(val,sizeof(longword));
         replaytokenbuf.read(val,sizeof(longword));
-{$ifdef FPC_BIG_ENDIAN}
-        val:=swapendian(val);
-{$endif}
+        if change_endian then
+          val:=swapendian(val);
         result:=val;
         result:=val;
       end;
       end;
 
 
@@ -2941,9 +2934,8 @@ type
         val : longint;
         val : longint;
       begin
       begin
         replaytokenbuf.read(val,sizeof(longint));
         replaytokenbuf.read(val,sizeof(longint));
-{$ifdef FPC_BIG_ENDIAN}
-        val:=swapendian(val);
-{$endif}
+        if change_endian then
+          val:=swapendian(val);
         result:=val;
         result:=val;
       end;
       end;
 
 
@@ -2968,9 +2960,8 @@ type
         val : smallint;
         val : smallint;
       begin
       begin
         replaytokenbuf.read(val,sizeof(smallint));
         replaytokenbuf.read(val,sizeof(smallint));
-{$ifdef FPC_BIG_ENDIAN}
-        val:=swapendian(val);
-{$endif}
+        if change_endian then
+          val:=swapendian(val);
         result:=val;
         result:=val;
       end;
       end;
 
 
@@ -2979,9 +2970,8 @@ type
         val : word;
         val : word;
       begin
       begin
         replaytokenbuf.read(val,sizeof(word));
         replaytokenbuf.read(val,sizeof(word));
-{$ifdef FPC_BIG_ENDIAN}
-        val:=swapendian(val);
-{$endif}
+        if change_endian then
+          val:=swapendian(val);
         result:=val;
         result:=val;
       end;
       end;
 
 
@@ -2998,16 +2988,13 @@ type
    end;
    end;
 
 
    procedure tscannerfile.tokenreadset(var b;size : longint);
    procedure tscannerfile.tokenreadset(var b;size : longint);
-{$ifdef FPC_BIG_ENDIAN}
    var
    var
      i : longint;
      i : longint;
-{$endif}
    begin
    begin
      replaytokenbuf.read(b,size);
      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;
    end;
 
 
    procedure tscannerfile.tokenwriteenum(var b;size : longint);
    procedure tscannerfile.tokenwriteenum(var b;size : longint);
@@ -3016,22 +3003,8 @@ type
    end;
    end;
 
 
    procedure tscannerfile.tokenwriteset(var b;size : longint);
    procedure tscannerfile.tokenwriteset(var b;size : longint);
-{$ifdef FPC_BIG_ENDIAN}
-   var
-     i: longint;
-     tmpset: array[0..31] of byte;
-{$endif}
    begin
    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);
      recordtokenbuf.write(b,size);
-{$endif}
    end;
    end;
 
 
 
 

+ 3 - 34
compiler/utils/ppuutils/ppudump.pp

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