From 23b95cc2912748bbf942e6b2e6f14ec0b5c99574 Mon Sep 17 00:00:00 2001 From: nickysn Date: Wed, 8 Apr 2015 14:13:35 +0000 Subject: [PATCH] + added classes for writing EXTDEF omf records git-svn-id: trunk@30496 - --- compiler/omfbase.pas | 74 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/compiler/omfbase.pas b/compiler/omfbase.pas index 2a7c4779df..7443c15351 100644 --- a/compiler/omfbase.pas +++ b/compiler/omfbase.pas @@ -354,6 +354,31 @@ interface property NextIndex: Integer read FNextIndex write FNextIndex; 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 = class(TOmfParsedRecord) @@ -909,6 +934,55 @@ implementation NextIndex:=LastIncludedIndex+1; 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 } procedure TOmfRecord_MODEND.DecodeFrom(RawRecord: TOmfRawRecord);