Browse Source

+ introduced methods for writing endian-specific integers to TObjSection

Nikolay Nikolov 1 year ago
parent
commit
526de20d9a
1 changed files with 120 additions and 0 deletions
  1. 120 0
      compiler/ogbase.pas

+ 120 - 0
compiler/ogbase.pas

@@ -343,6 +343,18 @@ interface
        constructor create(AList:TFPHashObjectList;const Aname:string;Aalign:longint;Aoptions:TObjSectionOptions);virtual;
        destructor  destroy;override;
        function  write(const d;l:TObjSectionOfs):TObjSectionOfs;
+       procedure writeInt16LE(v: int16);
+       procedure writeInt16BE(v: int16);
+       procedure writeInt32LE(v: int32);
+       procedure writeInt32BE(v: int32);
+       procedure writeInt64LE(v: int64);
+       procedure writeInt64BE(v: int64);
+       procedure writeUInt16LE(v: uint16);
+       procedure writeUInt16BE(v: uint16);
+       procedure writeUInt32LE(v: uint32);
+       procedure writeUInt32BE(v: uint32);
+       procedure writeUInt64LE(v: uint64);
+       procedure writeUInt64BE(v: uint64);
        { writes string plus zero byte }
        function  writestr(const s:string):TObjSectionOfs;
        function  WriteZeros(l:longword):TObjSectionOfs;
@@ -1063,6 +1075,114 @@ implementation
       end;
 
 
+    procedure TObjSection.writeInt16LE(v: int16);
+      begin
+{$ifdef FPC_BIG_ENDIAN}
+        v:=SwapEndian(v);
+{$endif FPC_BIG_ENDIAN}
+        write(v,2);
+      end;
+
+
+    procedure TObjSection.writeInt16BE(v: int16);
+      begin
+{$ifdef FPC_LITTLE_ENDIAN}
+        v:=SwapEndian(v);
+{$endif FPC_LITTLE_ENDIAN}
+        write(v,2);
+      end;
+
+
+    procedure TObjSection.writeInt32LE(v: int32);
+      begin
+{$ifdef FPC_BIG_ENDIAN}
+        v:=SwapEndian(v);
+{$endif FPC_BIG_ENDIAN}
+        write(v,4);
+      end;
+
+
+    procedure TObjSection.writeInt32BE(v: int32);
+      begin
+{$ifdef FPC_LITTLE_ENDIAN}
+        v:=SwapEndian(v);
+{$endif FPC_LITTLE_ENDIAN}
+        write(v,4);
+      end;
+
+
+    procedure TObjSection.writeInt64LE(v: int64);
+      begin
+{$ifdef FPC_BIG_ENDIAN}
+        v:=SwapEndian(v);
+{$endif FPC_BIG_ENDIAN}
+        write(v,8);
+      end;
+
+
+    procedure TObjSection.writeInt64BE(v: int64);
+      begin
+{$ifdef FPC_LITTLE_ENDIAN}
+        v:=SwapEndian(v);
+{$endif FPC_LITTLE_ENDIAN}
+        write(v,8);
+      end;
+
+
+    procedure TObjSection.writeUInt16LE(v: uint16);
+      begin
+{$ifdef FPC_BIG_ENDIAN}
+        v:=SwapEndian(v);
+{$endif FPC_BIG_ENDIAN}
+        write(v,2);
+      end;
+
+
+    procedure TObjSection.writeUInt16BE(v: uint16);
+      begin
+{$ifdef FPC_LITTLE_ENDIAN}
+        v:=SwapEndian(v);
+{$endif FPC_LITTLE_ENDIAN}
+        write(v,2);
+      end;
+
+
+    procedure TObjSection.writeUInt32LE(v: uint32);
+      begin
+{$ifdef FPC_BIG_ENDIAN}
+        v:=SwapEndian(v);
+{$endif FPC_BIG_ENDIAN}
+        write(v,4);
+      end;
+
+
+    procedure TObjSection.writeUInt32BE(v: uint32);
+      begin
+{$ifdef FPC_LITTLE_ENDIAN}
+        v:=SwapEndian(v);
+{$endif FPC_LITTLE_ENDIAN}
+        write(v,4);
+      end;
+
+
+    procedure TObjSection.writeUInt64LE(v: uint64);
+      begin
+{$ifdef FPC_BIG_ENDIAN}
+        v:=SwapEndian(v);
+{$endif FPC_BIG_ENDIAN}
+        write(v,8);
+      end;
+
+
+    procedure TObjSection.writeUInt64BE(v: uint64);
+      begin
+{$ifdef FPC_LITTLE_ENDIAN}
+        v:=SwapEndian(v);
+{$endif FPC_LITTLE_ENDIAN}
+        write(v,8);
+      end;
+
+
     function TObjSection.writestr(const s:string):TObjSectionOfs;
       var
         b: byte;