From 464941f039e8786aa68852b518bf7fc3c348a593 Mon Sep 17 00:00:00 2001 From: svenbarth Date: Sat, 19 Mar 2016 12:22:55 +0000 Subject: [PATCH] At least in principle prepare the Mach-O writer for other CPU types. ogmacho.pas: + TMachoObjectOutput: new method current_cpu_type to retrieve the cpu_type_t matching the compiler's target platform * TMachoObjectOutput.writedata: initialize cputarget using current_cpu_type and use cputarget instead of CPU_TYPE_I386 in the call to AllocMachoWriter * surround the RegisterAssembler call with ifdefs for i386 git-svn-id: trunk@33286 - --- compiler/ogmacho.pas | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/compiler/ogmacho.pas b/compiler/ogmacho.pas index 2b54875efb..17e52b62ef 100644 --- a/compiler/ogmacho.pas +++ b/compiler/ogmacho.pas @@ -112,6 +112,7 @@ type relcount : integer; protected procedure TrailZeros; + function current_cpu_type: cpu_type_t;inline; {sections} procedure FixSectionRelocs(s: TMachoObjSection); @@ -1000,6 +1001,25 @@ uses end; + function TMachoObjectOutput.current_cpu_type: cpu_type_t; + begin +{$if defined(powerpc)} + result:=CPU_TYPE_POWERPC; +{$elseif defined(powerpc64)} + result:=CPU_TYPE_POWERPC64; +{$elseif defined(i386)} + result:=CPU_TYPE_I386; +{$elseif defined(x86_64)} + result:=CPU_TYPE_X86_64; +{$elseif defined(arm)} + result:=CPU_TYPE_ARM; +{$elseif defined(aarch64)} + result:=CPU_TYPE_ARM64; +{$else} + result:=CPU_TYPE_ANY; +{$endif} + end; + function TMachoObjectOutput.writedata(data: TObjData): boolean; var header : TMachHeader; @@ -1020,7 +1040,7 @@ uses result:=false; machoData:=TMachoObjData(data); - cputarget:=CPU_TYPE_i386; + cputarget:=current_cpu_type; segSize:=sizeSegment(cputarget); sctSize:=sizeSection(cputarget); @@ -1055,7 +1075,7 @@ uses fileofs:=AlignAddr(cputarget, fileofs); {creating actual mach-o file writer} - mfile:=AllocMachoWriter(CPU_TYPE_I386, TMachoRawWriter.Create(writer), true); + mfile:=AllocMachoWriter(cputarget, TMachoRawWriter.Create(writer), true); {writing macho-o header} mfile.WriteHeader(header); @@ -1222,7 +1242,9 @@ uses ); initialization +{$ifdef i386} RegisterAssembler(as_i386_darwin_info,TMachoAssembler); +{$endif i386} end.