Browse Source

+ added classes for writing EXTDEF omf records

git-svn-id: trunk@30496 -
nickysn 10 years ago
parent
commit
23b95cc291
1 changed files with 74 additions and 0 deletions
  1. 74 0
      compiler/omfbase.pas

+ 74 - 0
compiler/omfbase.pas

@@ -354,6 +354,31 @@ interface
       property NextIndex: Integer read FNextIndex write FNextIndex;
       property NextIndex: Integer read FNextIndex write FNextIndex;
     end;
     end;
 
 
+    { TOmfExternalNameElement }
+
+    TOmfExternalNameElement = class(TFPHashObject)
+    private
+      FTypeIndex: Integer;
+    public
+      function GetLengthInFile: Integer;
+
+      property TypeIndex: Integer read FTypeIndex write FTypeIndex;
+    end;
+
+    { TOmfRecord_EXTDEF }
+
+    TOmfRecord_EXTDEF = class(TOmfParsedRecord)
+    private
+      FExternalNames: TFPHashObjectList;
+      FNextIndex: Integer;
+    public
+      procedure DecodeFrom(RawRecord: TOmfRawRecord);override;
+      procedure EncodeTo(RawRecord: TOmfRawRecord);override;
+
+      property ExternalNames: TFPHashObjectList read FExternalNames write FExternalNames;
+      property NextIndex: Integer read FNextIndex write FNextIndex;
+    end;
+
     { TOmfRecord_MODEND }
     { TOmfRecord_MODEND }
 
 
     TOmfRecord_MODEND = class(TOmfParsedRecord)
     TOmfRecord_MODEND = class(TOmfParsedRecord)
@@ -909,6 +934,55 @@ implementation
       NextIndex:=LastIncludedIndex+1;
       NextIndex:=LastIncludedIndex+1;
     end;
     end;
 
 
+  { TOmfExternalNameElement }
+
+  function TOmfExternalNameElement.GetLengthInFile: Integer;
+    begin
+      Result:=1+Length(Name)+1;
+      if TypeIndex>=$80 then
+        Inc(Result);
+    end;
+
+  { TOmfRecord_EXTDEF }
+
+  procedure TOmfRecord_EXTDEF.DecodeFrom(RawRecord: TOmfRawRecord);
+    begin
+      {TODO: implement}
+      internalerror(2015040101);
+    end;
+
+  procedure TOmfRecord_EXTDEF.EncodeTo(RawRecord: TOmfRawRecord);
+    const
+      RecordLengthLimit = 1024;
+    var
+      Len,LastIncludedIndex,NextOfs,I: Integer;
+      ExtName: TOmfExternalNameElement;
+    begin
+      RawRecord.RecordType:=RT_EXTDEF;
+      NextOfs:=0;
+
+      { find out how many external names can we include until we reach the length limit }
+      Len:=NextOfs;
+      LastIncludedIndex:=NextIndex-1;
+      repeat
+        Inc(LastIncludedIndex);
+        Inc(Len,TOmfExternalNameElement(ExternalNames[LastIncludedIndex]).GetLengthInFile);
+      until (LastIncludedIndex>=(ExternalNames.Count-1)) or ((Len+TOmfExternalNameElement(ExternalNames[LastIncludedIndex+1]).GetLengthInFile)>=RecordLengthLimit);
+
+      { write the external names... }
+      for I:=NextIndex to LastIncludedIndex do
+        begin
+          ExtName:=TOmfExternalNameElement(ExternalNames[I]);
+          NextOfs:=RawRecord.WriteStringAt(NextOfs,ExtName.Name);
+          NextOfs:=RawRecord.WriteIndexedRef(NextOfs,ExtName.TypeIndex);
+        end;
+      RawRecord.RecordLength:=Len+1;
+      RawRecord.CalculateChecksumByte;
+
+      { update NextIndex }
+      NextIndex:=LastIncludedIndex+1;
+    end;
+
   { TOmfRecord_MODEND }
   { TOmfRecord_MODEND }
 
 
   procedure TOmfRecord_MODEND.DecodeFrom(RawRecord: TOmfRawRecord);
   procedure TOmfRecord_MODEND.DecodeFrom(RawRecord: TOmfRawRecord);