2
0
Эх сурвалжийг харах

* mark all external assemblers using an LLVM tool using af_llvm
+ added support for constructing target triplets
* pass "-target triplet" when using an LLVM assembler
o removed no longer needed $DARWINVERSION and $ARCH parameters
* consistently use as_clang_gas when clang is used to assembler GAS-style
assembly, and rename as_llcm_clang to as_clang_llvm (for consistency)
* support pipe assembling when using clang on *nix in all cases

git-svn-id: trunk@45807 -

Jonas Maebe 5 жил өмнө
parent
commit
eb7ba1690e

+ 18 - 0
.gitattributes

@@ -48,6 +48,7 @@ compiler/aarch64/racpu.pas svneol=native#text/plain
 compiler/aarch64/racpugas.pas svneol=native#text/plain
 compiler/aarch64/rgcpu.pas svneol=native#text/plain
 compiler/aarch64/symcpu.pas svneol=native#text/plain
+compiler/aarch64/tripletcpu.pas svneol=native#text/plain
 compiler/aasmbase.pas svneol=native#text/plain
 compiler/aasmcfi.pas svneol=native#text/plain
 compiler/aasmcnst.pas svneol=native#text/plain
@@ -107,6 +108,7 @@ compiler/arm/rarmstd.inc svneol=native#text/plain
 compiler/arm/rarmsup.inc svneol=native#text/plain
 compiler/arm/rgcpu.pas svneol=native#text/plain
 compiler/arm/symcpu.pas svneol=native#text/plain
+compiler/arm/tripletcpu.pas svneol=native#text/plain
 compiler/armgen/aoptarm.pas svneol=native#text/pascal
 compiler/armgen/armpara.pas svneol=native#text/plain
 compiler/assemble.pas svneol=native#text/plain
@@ -145,6 +147,7 @@ compiler/avr/ravrstd.inc svneol=native#text/plain
 compiler/avr/ravrsup.inc svneol=native#text/plain
 compiler/avr/rgcpu.pas svneol=native#text/plain
 compiler/avr/symcpu.pas svneol=native#text/plain
+compiler/avr/tripletcpu.pas svneol=native#text/plain
 compiler/blockutl.pas svneol=native#text/plain
 compiler/browcol.pas svneol=native#text/plain
 compiler/catch.pas svneol=native#text/plain
@@ -248,6 +251,7 @@ compiler/i386/ra386att.pas svneol=native#text/plain
 compiler/i386/ra386int.pas svneol=native#text/plain
 compiler/i386/rgcpu.pas svneol=native#text/plain
 compiler/i386/symcpu.pas svneol=native#text/plain
+compiler/i386/tripletcpu.pas svneol=native#text/plain
 compiler/i8086/aoptcpu.pas svneol=native#text/plain
 compiler/i8086/aoptcpub.pas svneol=native#text/plain
 compiler/i8086/aoptcpud.pas svneol=native#text/plain
@@ -296,6 +300,7 @@ compiler/i8086/ra8086int.pas svneol=native#text/plain
 compiler/i8086/rgcpu.pas svneol=native#text/plain
 compiler/i8086/symcpu.pas svneol=native#text/plain
 compiler/i8086/tgcpu.pas svneol=native#text/plain
+compiler/i8086/tripletcpu.pas svneol=native#text/plain
 compiler/impdef.pas svneol=native#text/plain
 compiler/import.pas svneol=native#text/plain
 compiler/jvm/aasmcpu.pas svneol=native#text/plain
@@ -339,6 +344,7 @@ compiler/jvm/rjvmstd.inc svneol=native#text/plain
 compiler/jvm/rjvmsup.inc svneol=native#text/plain
 compiler/jvm/symcpu.pas svneol=native#text/plain
 compiler/jvm/tgcpu.pas svneol=native#text/plain
+compiler/jvm/tripletcpu.pas svneol=native#text/plain
 compiler/ldscript.pas svneol=native#text/plain
 compiler/link.pas svneol=native#text/plain
 compiler/llvm/aasmllvm.pas svneol=native#text/plain
@@ -419,6 +425,7 @@ compiler/m68k/ra68k.pas svneol=native#text/plain
 compiler/m68k/ra68kmot.pas svneol=native#text/plain
 compiler/m68k/rgcpu.pas svneol=native#text/plain
 compiler/m68k/symcpu.pas svneol=native#text/plain
+compiler/m68k/tripletcpu.pas svneol=native#text/plain
 compiler/macho.pas svneol=native#text/plain
 compiler/machoutils.pas svneol=native#text/plain
 compiler/mips/aasmcpu.pas svneol=native#text/plain
@@ -461,6 +468,7 @@ compiler/mips/rmipsstd.inc svneol=native#text/plain
 compiler/mips/rmipssup.inc svneol=native#text/plain
 compiler/mips/strinst.inc svneol=native#text/plain
 compiler/mips/symcpu.pas svneol=native#text/plain
+compiler/mips/tripletcpu.pas svneol=native#text/plain
 compiler/msg/errorct.msg svneol=native#text/plain
 compiler/msg/errord.msg svneol=native#text/plain
 compiler/msg/errorda.msg svneol=native#text/plain
@@ -605,6 +613,7 @@ compiler/powerpc/rppcstab.inc svneol=native#text/plain
 compiler/powerpc/rppcstd.inc svneol=native#text/plain
 compiler/powerpc/rppcsup.inc svneol=native#text/plain
 compiler/powerpc/symcpu.pas svneol=native#text/plain
+compiler/powerpc/tripletcpu.pas svneol=native#text/plain
 compiler/powerpc64/aoptcpu.pas svneol=native#text/plain
 compiler/powerpc64/aoptcpub.pas svneol=native#text/plain
 compiler/powerpc64/aoptcpud.pas svneol=native#text/plain
@@ -641,6 +650,7 @@ compiler/powerpc64/rppcstab.inc svneol=native#text/plain
 compiler/powerpc64/rppcstd.inc svneol=native#text/plain
 compiler/powerpc64/rppcsup.inc svneol=native#text/plain
 compiler/powerpc64/symcpu.pas svneol=native#text/plain
+compiler/powerpc64/tripletcpu.pas svneol=native#text/plain
 compiler/pp.lpi svneol=native#text/plain
 compiler/pp.pas svneol=native#text/plain
 compiler/pparautl.pas svneol=native#text/plain
@@ -731,6 +741,7 @@ compiler/riscv32/rrv32std.inc svneol=native#text/plain
 compiler/riscv32/rrv32sup.inc svneol=native#text/plain
 compiler/riscv32/rv32reg.dat svneol=native#text/plain
 compiler/riscv32/symcpu.pas svneol=native#text/plain
+compiler/riscv32/tripletcpu.pas svneol=native#text/plain
 compiler/riscv64/aoptcpu.pas svneol=native#text/plain
 compiler/riscv64/aoptcpub.pas svneol=native#text/plain
 compiler/riscv64/aoptcpuc.pas svneol=native#text/plain
@@ -762,6 +773,7 @@ compiler/riscv64/rrv32std.inc svneol=native#text/plain
 compiler/riscv64/rrv32sup.inc svneol=native#text/plain
 compiler/riscv64/rv32reg.dat svneol=native#text/plain
 compiler/riscv64/symcpu.pas svneol=native#text/plain
+compiler/riscv64/tripletcpu.pas svneol=native#text/plain
 compiler/scandir.pas svneol=native#text/plain
 compiler/scanner.pas svneol=native#text/plain
 compiler/sparc/aoptcpud.pas svneol=native#text/plain
@@ -780,6 +792,7 @@ compiler/sparc/rspsri.inc svneol=native#text/plain
 compiler/sparc/rspstab.inc svneol=native#text/plain
 compiler/sparc/rspstd.inc svneol=native#text/plain
 compiler/sparc/rspsup.inc svneol=native#text/plain
+compiler/sparc/tripletcpu.pas svneol=native#text/plain
 compiler/sparc64/cgcpu.pas svneol=native#text/pascal
 compiler/sparc64/cpugas.pas svneol=native#text/pascal
 compiler/sparc64/cpuinfo.pas svneol=native#text/plain
@@ -796,6 +809,7 @@ compiler/sparc64/rsp64stab.inc svneol=native#text/pascal
 compiler/sparc64/rsp64std.inc svneol=native#text/pascal
 compiler/sparc64/rsp64sup.inc svneol=native#text/pascal
 compiler/sparc64/tgcpu.pas svneol=native#text/plain
+compiler/sparc64/tripletcpu.pas svneol=native#text/plain
 compiler/sparcgen/aasmcpu.pas svneol=native#text/plain
 compiler/sparcgen/aoptcpu.pas svneol=native#text/plain
 compiler/sparcgen/aoptcpub.pas svneol=native#text/plain
@@ -902,6 +916,7 @@ compiler/systems/t_win16.pas svneol=native#text/plain
 compiler/systems/t_zxspectrum.pas svneol=native#text/plain
 compiler/tgobj.pas svneol=native#text/plain
 compiler/tokens.pas svneol=native#text/plain
+compiler/triplet.pas svneol=native#text/plain
 compiler/utils/Makefile svneol=native#text/plain
 compiler/utils/Makefile.fpc svneol=native#text/plain
 compiler/utils/README.txt svneol=native#text/plain
@@ -1022,6 +1037,7 @@ compiler/x86_64/rax64att.pas svneol=native#text/plain
 compiler/x86_64/rax64int.pas svneol=native#text/plain
 compiler/x86_64/rgcpu.pas svneol=native#text/plain
 compiler/x86_64/symcpu.pas svneol=native#text/plain
+compiler/x86_64/tripletcpu.pas svneol=native#text/plain
 compiler/x86_64/win64unw.pas svneol=native#text/plain
 compiler/x86_64/x8664ats.inc svneol=native#text/plain
 compiler/x86_64/x8664att.inc svneol=native#text/plain
@@ -1062,6 +1078,7 @@ compiler/xtensa/rxtensasta.inc svneol=native#text/plain
 compiler/xtensa/rxtensastd.inc svneol=native#text/plain
 compiler/xtensa/rxtensasup.inc svneol=native#text/plain
 compiler/xtensa/symcpu.pas svneol=native#text/pascal
+compiler/xtensa/tripletcpu.pas svneol=native#text/plain
 compiler/xtensa/xtensaatt.inc svneol=native#text/plain
 compiler/xtensa/xtensaop.inc svneol=native#text/plain
 compiler/xtensa/xtensareg.dat svneol=native#text/plain
@@ -1100,6 +1117,7 @@ compiler/z80/rz80std.inc svneol=native#text/plain
 compiler/z80/rz80sup.inc svneol=native#text/plain
 compiler/z80/symcpu.pas svneol=native#text/plain
 compiler/z80/tgcpu.pas svneol=native#text/plain
+compiler/z80/tripletcpu.pas svneol=native#text/plain
 compiler/z80/z80ins.dat svneol=native#text/plain
 compiler/z80/z80nop.inc svneol=native#text/plain
 compiler/z80/z80op.inc svneol=native#text/plain

+ 5 - 5
compiler/aarch64/agcpugas.pas

@@ -799,12 +799,12 @@ unit agcpugas;
 
        as_aarch64_clang_darwin_info : tasminfo =
           (
-            id     : as_clang;
+            id     : as_clang_asdarwin;
             idtxt  : 'CLANG';
             asmbin : 'clang';
-            asmcmd : '-c -o $OBJ $EXTRAOPT -arch arm64 $DARWINVERSION -x assembler $ASM';
+            asmcmd : '-x assembler -c -target $TRIPLET -o $OBJ $EXTRAOPT -x assembler $ASM';
             supported_targets : [system_aarch64_ios,system_aarch64_darwin];
-            flags : [af_needar,af_smartlink_sections,af_supports_dwarf];
+            flags : [af_needar,af_smartlink_sections,af_supports_dwarf,af_llvm];
             labelprefix : 'L';
             labelmaxlen : -1;
             comment : '# ';
@@ -816,9 +816,9 @@ unit agcpugas;
             id     : as_clang_gas;
             idtxt  : 'CLANG';
             asmbin : 'clang';
-            asmcmd : '-c -o $OBJ $EXTRAOPT -target $TARGET -x assembler $ASM';
+            asmcmd : '-x assembler -c -target $TRIPLET -o $OBJ $EXTRAOPT -x assembler $ASM';
             supported_targets : [system_aarch64_win64];
-            flags : [af_needar,af_smartlink_sections,af_supports_dwarf];
+            flags : [af_needar,af_smartlink_sections,af_supports_dwarf,af_llvm];
             labelprefix : '.L';
             labelmaxlen : -1;
             comment : '// ';

+ 48 - 0
compiler/aarch64/tripletcpu.pas

@@ -0,0 +1,48 @@
+{
+    Copyright (c) 2020 by Jonas Maebe
+
+    Construct the cpu part of the triplet
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ ****************************************************************************
+}
+unit tripletcpu;
+
+{$i fpcdefs.inc}
+
+interface
+
+uses
+  globtype;
+
+function tripletcpustr(tripletstyle: ttripletstyle): ansistring;
+
+implementation
+
+uses
+  globals, systems, cpuinfo;
+
+function tripletcpustr(tripletstyle: ttripletstyle): ansistring;
+  begin
+    if target_info.system in systems_darwin then
+      result:='arm64'
+    else
+      result:='aarch64'
+  end;
+
+
+end.
+

+ 4 - 4
compiler/arm/agarmgas.pas

@@ -171,7 +171,7 @@ unit agarmgas;
     function TArmAppleGNUAssembler.MakeCmdLine: TCmdStr;
       begin
         result:=inherited MakeCmdLine;
-	if (asminfo^.id = as_clang) then
+	if (asminfo^.id in [as_clang_gas,as_clang_asdarwin]) then
           begin
             if fputypestrllvm[current_settings.fputype] <> '' then
               result:='-m'+fputypestrllvm[current_settings.fputype]+' '+result;
@@ -473,12 +473,12 @@ unit agarmgas;
 
        as_arm_clang_darwin_info : tasminfo =
           (
-            id     : as_clang;
+            id     : as_clang_asdarwin;
             idtxt  : 'CLANG';
             asmbin : 'clang';
-            asmcmd : '-c -o $OBJ $EXTRAOPT -arch $ARCH $DARWINVERSION -x assembler $ASM';
+            asmcmd : '-x assembler -c -target $TRIPLET -o $OBJ $EXTRAOPT -x assembler $ASM';
             supported_targets : [system_arm_ios];
-            flags : [af_needar,af_smartlink_sections,af_supports_dwarf];
+            flags : [af_needar,af_smartlink_sections,af_supports_dwarf,af_llvm];
             labelprefix : 'L';
             labelmaxlen : -1;
             comment : '# ';

+ 51 - 0
compiler/arm/tripletcpu.pas

@@ -0,0 +1,51 @@
+{
+    Copyright (c) 2020 by Jonas Maebe
+
+    Construct the cpu part of the triplet
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ ****************************************************************************
+}
+unit tripletcpu;
+
+{$i fpcdefs.inc}
+
+interface
+
+uses
+  globtype;
+
+function tripletcpustr(tripletstyle: ttripletstyle): ansistring;
+
+implementation
+
+uses
+  globals, cutils, systems, cpuinfo;
+
+function tripletcpustr(tripletstyle: ttripletstyle): ansistring;
+  begin
+    result:=lower(cputypestr[current_settings.cputype]);
+    { llvm replaces the cpu name with thumb for when generating thumb code}
+    if (tripletstyle=triplet_llvm) and
+       (current_settings.instructionset=is_thumb) then
+      result:='thumb'+copy(result,4,255);
+    if target_info.endian=endian_big then
+      result:=result+'be';
+  end;
+
+
+end.
+

+ 9 - 13
compiler/assemble.pas

@@ -264,7 +264,7 @@ Implementation
 {$endif FPC_SOFT_FPUX80}
 {$endif}
       cscript,fmodule,verbose,
-      cpuinfo,
+      cpuinfo,triplet,
       aasmcpu;
 
     var
@@ -745,7 +745,7 @@ Implementation
 {$ifdef hasunix}
         DoPipe:=(cs_asm_pipe in current_settings.globalswitches) and
                 (([cs_asm_extern,cs_asm_leave,cs_link_on_target] * current_settings.globalswitches) = []) and
-                ((asminfo^.id in [as_gas,as_ggas,as_darwin,as_powerpc_xcoff,as_clang,as_solaris_as]));
+                ((asminfo^.id in [as_gas,as_ggas,as_darwin,as_powerpc_xcoff,as_clang_gas,as_clang_llvm,as_solaris_as]));
 {$else hasunix}
         DoPipe:=false;
 {$endif}
@@ -929,17 +929,13 @@ Implementation
 
       begin
         result:=asminfo^.asmcmd;
-        { for Xcode 7.x and later }
-        if MacOSXVersionMin<>'' then
-          Replace(result,'$DARWINVERSION','-mmacosx-version-min='+MacOSXVersionMin)
-        else if iPhoneOSVersionMin<>'' then
-          Replace(result,'$DARWINVERSION','-miphoneos-version-min='+iPhoneOSVersionMin)
-        else
-          Replace(result,'$DARWINVERSION','');
+        if af_llvm in target_asm.flags then
+          Replace(result,'$TRIPLET',targettriplet(triplet_llvm))
 {$ifdef arm}
-        if (target_info.system=system_arm_ios) then
-          Replace(result,'$ARCH',lower(cputypestr[current_settings.cputype]));
+        else if (target_info.system=system_arm_ios) then
+          Replace(result,'$ARCH',lower(cputypestr[current_settings.cputype]))
 {$endif arm}
+        ;
         if (cs_link_on_target in current_settings.globalswitches) then
          begin
            Replace(result,'$ASM',maybequoted(ScriptFixFileName(AsmFileName)));
@@ -949,7 +945,7 @@ Implementation
          begin
 {$ifdef hasunix}
           if DoPipe then
-            if asminfo^.id<>as_clang then
+            if not(asminfo^.id in [as_clang_gas,as_clang_asdarwin,as_clang_llvm]) then
               Replace(result,'$ASM','')
             else
               Replace(result,'$ASM','-')
@@ -2536,7 +2532,7 @@ Implementation
       var
         asmkind: tasm;
       begin
-        for asmkind in [as_gas,as_ggas,as_darwin] do
+        for asmkind in [as_gas,as_ggas,as_darwin,as_clang_gas,as_clang_asdarwin] do
           if assigned(asminfos[asmkind]) and
              (target_info.system in asminfos[asmkind]^.supported_targets) then
             begin

+ 45 - 0
compiler/avr/tripletcpu.pas

@@ -0,0 +1,45 @@
+{
+    Copyright (c) 2020 by Jonas Maebe
+
+    Construct the cpu part of the triplet
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ ****************************************************************************
+}
+unit tripletcpu;
+
+{$i fpcdefs.inc}
+
+interface
+
+uses
+  globtype;
+
+function tripletcpustr(tripletstyle: ttripletstyle): ansistring;
+
+implementation
+
+uses
+  globals, cpuinfo;
+
+function tripletcpustr(tripletstyle: ttripletstyle): ansistring;
+  begin
+    result:='avr';
+  end;
+
+
+end.
+

+ 6 - 0
compiler/globtype.pas

@@ -354,6 +354,12 @@ interface
        );
        twpoptimizerswitches = set of twpoptimizerswitch;
 
+       { platform triplet style }
+       ttripletstyle = (
+         triplet_llvm
+         { , triple_gnu }
+       );
+
        { module flags (extra unit flags not in ppu header) }
        tmoduleflag = (
          mf_init,                     { unit has initialization section }

+ 49 - 0
compiler/i386/tripletcpu.pas

@@ -0,0 +1,49 @@
+{
+    Copyright (c) 2020 by Jonas Maebe
+
+    Construct the cpu part of the triplet
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ ****************************************************************************
+}
+unit tripletcpu;
+
+{$i fpcdefs.inc}
+
+interface
+
+uses
+  globtype;
+
+function tripletcpustr(tripletstyle: ttripletstyle): ansistring;
+
+implementation
+
+uses
+  globals, systems, cpuinfo;
+
+function tripletcpustr(tripletstyle: ttripletstyle): ansistring;
+  begin
+    if (target_info.system in systems_darwin) or
+       (current_settings.cputype<cpu_Pentium2) then
+      result:='i386'
+    else
+      result:='i686'
+  end;
+
+
+end.
+

+ 45 - 0
compiler/i8086/tripletcpu.pas

@@ -0,0 +1,45 @@
+{
+    Copyright (c) 2020 by Jonas Maebe
+
+    Construct the cpu part of the triplet
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ ****************************************************************************
+}
+unit tripletcpu;
+
+{$i fpcdefs.inc}
+
+interface
+
+uses
+  globtype;
+
+function tripletcpustr(tripletstyle: ttripletstyle): ansistring;
+
+implementation
+
+uses
+  globals, cpuinfo;
+
+function tripletcpustr(tripletstyle: ttripletstyle): ansistring;
+  begin
+    result:='i8086';
+  end;
+
+
+end.
+

+ 45 - 0
compiler/jvm/tripletcpu.pas

@@ -0,0 +1,45 @@
+{
+    Copyright (c) 2020 by Jonas Maebe
+
+    Construct the cpu part of the triplet
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ ****************************************************************************
+}
+unit tripletcpu;
+
+{$i fpcdefs.inc}
+
+interface
+
+uses
+  globtype;
+
+function tripletcpustr(tripletstyle: ttripletstyle): ansistring;
+
+implementation
+
+uses
+  globals, cpuinfo;
+
+function tripletcpustr(tripletstyle: ttripletstyle): ansistring;
+  begin
+    result:='jvm';
+  end;
+
+
+end.
+

+ 8 - 79
compiler/llvm/agllvm.pas

@@ -72,11 +72,6 @@ interface
         InstrWriter: TLLVMInstrWriter;
       end;
 
-      TLLVMLLCAssember=class(TLLVMAssember)
-      public
-       function MakeCmdLine: TCmdStr; override;
-      end;
-
       TLLVMClangAssember=class(TLLVMAssember)
       public
        function MakeCmdLine: TCmdStr; override;
@@ -118,7 +113,7 @@ implementation
       objcasm,
       aasmcnst,symconst,symdef,symtable,
       llvmbase,itllvm,llvmdef,
-      cgbase,cgutils,cpubase,cpuinfo,llvminfo;
+      cgbase,cgutils,cpubase,cpuinfo,triplet,llvminfo;
 
     const
       line_length = 70;
@@ -849,7 +844,7 @@ implementation
         writer.AsmWrite(target_info.llvmdatalayout);
         writer.AsmWriteln('"');
         writer.AsmWrite('target triple = "');
-        writer.AsmWrite(llvm_target_name);
+        writer.AsmWrite(targettriplet(triplet_llvm));
         writer.AsmWriteln('"');
       end;
 
@@ -1593,49 +1588,6 @@ implementation
        end;
 
 
-{****************************************************************************}
-{                               llc Assember                                 }
-{****************************************************************************}
-
-     function TLLVMLLCAssember.MakeCmdLine: TCmdStr;
-       var
-         optstr: TCmdStr;
-       begin
-         result:=inherited;
-         { standard optimization flags for llc -- todo: this needs to be split
-           into a call to opt and one to llc }
-         if cs_opt_level3 in current_settings.optimizerswitches then
-           optstr:='-O3'
-         else if cs_opt_level2 in current_settings.optimizerswitches then
-           optstr:='-O2'
-         else if cs_opt_level1 in current_settings.optimizerswitches then
-           optstr:='-O1'
-         else
-           optstr:='-O0';
-         { stack frame elimination }
-         if not(cs_opt_stackframe in current_settings.optimizerswitches) then
-           optstr:=optstr+' -disable-fp-elim';
-         { fast math }
-         if cs_opt_fastmath in current_settings.optimizerswitches then
-           optstr:=optstr+' -enable-unsafe-fp-math -fp-contract=fast';  { -enable-fp-mad support depends on version }
-         { smart linking }
-         if cs_create_smart in current_settings.moduleswitches then
-           optstr:=optstr+' -data-sections -function-sections';
-         { pic }
-         if cs_create_pic in current_settings.moduleswitches then
-           optstr:=optstr+' -relocation-model=pic'
-         else if not(target_info.system in systems_darwin) then
-           optstr:=optstr+' -relocation-model=static'
-         else
-           optstr:=optstr+' -relocation-model=dynamic-no-pic';
-         { force object output instead of textual assembler code }
-         optstr:=optstr+' -filetype=obj';
-         if fputypestrllvm[current_settings.fputype]<>'' then
-           optstr:=optstr+' -mattr=+'+fputypestrllvm[current_settings.fputype];
-         replace(result,'$OPT',optstr);
-       end;
-
-
 {****************************************************************************}
 {                               clang Assember                               }
 {****************************************************************************}
@@ -1661,8 +1613,6 @@ implementation
             end;
           end;
         result:=inherited;
-        { standard optimization flags for llc -- todo: this needs to be split
-          into a call to opt and one to llc }
         if cs_opt_level3 in current_settings.optimizerswitches then
           optstr:='-O3'
         else if cs_opt_level2 in current_settings.optimizerswitches then
@@ -1690,10 +1640,6 @@ implementation
           optstr:=optstr+' -static'
         else
           optstr:=optstr+' -mdynamic-no-pic';
-        if not(target_info.system in systems_darwin) then
-          begin
-            optstr:=optstr+' --target='+llvm_target_name;
-          end;
 
         if fputypestrllvm[current_settings.fputype]<>'' then
           optstr:=optstr+' -m'+fputypestrllvm[current_settings.fputype];
@@ -1727,29 +1673,13 @@ implementation
 
 
    const
-     as_llvm_llc_info : tasminfo =
-        (
-          id     : as_llvm_llc;
-
-          idtxt  : 'LLVM-LLC';
-          asmbin : 'llc';
-          asmcmd: '$OPT -o $OBJ $ASM';
-          supported_targets : [system_x86_64_linux,system_x86_64_darwin,system_aarch64_linux,system_arm_linux];
-          flags : [af_smartlink_sections,af_llvm];
-          labelprefix : 'L';
-          labelmaxlen : -1;
-          comment : '; ';
-          dollarsign: '$';
-        );
-
-     as_llvm_clang_info : tasminfo =
+     as_clang_llvm_info : tasminfo =
         (
-          id     : as_llvm_clang;
-
-          idtxt  : 'LLVM-CLANG';
+          id     : as_clang_llvm;
+          idtxt  : 'CLANG-LLVM';
           asmbin : 'clang';
-          asmcmd: '$OPT $DARWINVERSION -c -o $OBJ $ASM';
-          supported_targets : [system_x86_64_linux,system_x86_64_darwin,system_aarch64_linux,system_arm_linux];
+          asmcmd: '-x ir -target $TARGET $OPT -target $TRIPLET -c -o $OBJ $ASM $EXTRAOPT';
+          supported_targets : [system_x86_64_linux,system_x86_64_darwin,system_aarch64_darwin,system_aarch64_linux,system_arm_linux];
           flags : [af_smartlink_sections,af_llvm];
           labelprefix : 'L';
           labelmaxlen : -1;
@@ -1758,6 +1688,5 @@ implementation
         );
 
 begin
-  RegisterAssembler(as_llvm_llc_info,TLLVMLLCAssember);
-  RegisterAssembler(as_llvm_clang_info,TLLVMClangAssember);
+  RegisterAssembler(as_clang_llvm_info,TLLVMClangAssember);
 end.

+ 0 - 94
compiler/llvm/llvmbase.pas

@@ -102,8 +102,6 @@ interface
     { = max(cpubase.max_operands,8) }
     max_operands = ((-ord(cpubase.max_operands<=8)) and 15) or ((-ord(cpubase.max_operands>8)) and cpubase.max_operands);
 
-  function llvm_target_name: ansistring;
-
   function llvm_callingconvention_name(c: tproccalloption): ansistring;
 
 implementation
@@ -112,98 +110,6 @@ implementation
     globals,
     systems;
 
-{$j-}
-{$ifndef arm}
-  const
-    llvmsystemcpu: array[tsystemcpu] of ansistring =
-      ('unknown',
-       'i386',
-       'm68k',
-       'alpha',
-       'powerpc',
-       'sparc',
-       'unknown',
-       'ia64',
-       'x86_64',
-       'mips',
-       'arm',
-       'powerpc64',
-       'avr',
-       'mipsel',
-       'unknown',
-       'unknown',
-       'aarch64',
-       'wasm32',
-       'sparc64',
-       'riscv32',
-       'riscv64',
-       'xtensa',
-       'z80'
-      );
-{$endif}
-
-  function llvm_target_name: ansistring;
-    begin
-      { architecture }
-{$ifdef arm}
-      llvm_target_name:=lower(cputypestr[current_settings.cputype]);
-{$else arm}
-      llvm_target_name:=llvmsystemcpu[target_info.cpu];
-{$endif}
-      { vendor and/or OS }
-      if target_info.system in systems_darwin then
-        begin
-          llvm_target_name:=llvm_target_name+'-apple';
-          if not(target_info.system in [system_arm_ios,system_i386_iphonesim]) then
-            llvm_target_name:=llvm_target_name+'-macosx'+MacOSXVersionMin
-          else
-            llvm_target_name:=llvm_target_name+'-ios'+iPhoneOSVersionMin;
-        end
-      else if target_info.system in (systems_linux+systems_android) then
-        llvm_target_name:=llvm_target_name+'-unknown-linux'
-      else if target_info.system in systems_all_windows then
-        begin
-          { WinCE isn't supported (yet) by llvm, but if/when added this is
-            presumably how they will differentiate it }
-          if target_info.system in systems_windows then
-            llvm_target_name:=llvm_target_name+'-pc';
-          llvm_target_name:=llvm_target_name+'-windows-msvc19'
-        end
-      else if target_info.system in systems_freebsd then
-        llvm_target_name:=llvm_target_name+'-freebsd'
-      else if target_info.system in systems_openbsd then
-        llvm_target_name:=llvm_target_name+'-openbsd'
-      else if target_info.system in systems_netbsd then
-        llvm_target_name:=llvm_target_name+'-netbsd'
-      else if target_info.system in systems_aix then
-        llvm_target_name:=llvm_target_name+'-ibm-aix'
-      else if target_info.system in [system_i386_haiku] then
-        llvm_target_name:=llvm_target_name+'-haiku'
-      else if target_info.system in systems_embedded then
-        llvm_target_name:=llvm_target_name+'-none'
-      else
-        llvm_target_name:=llvm_target_name+'-unknown';
-
-      { environment/ABI }
-      if target_info.system in systems_android then
-        llvm_target_name:=llvm_target_name+'-android';
-{$if defined(FPC_ARMHF)}
-      llvm_target_name:=llvm_target_name+'-gnueabihf';
-{$elseif defined(FPC_ARMEL)}
-      if target_info.system in systems_embedded then
-        llvm_target_name:=llvm_target_name+'-eabi'
-      else if target_info.system=system_arm_android then
-        { handled above already
-        llvm_target_name:=llvm_target_name+'-android' }
-      else
-        llvm_target_name:=llvm_target_name+'-gnueabi';
-{$else}
-      if target_info.system in systems_linux then
-        llvm_target_name:=llvm_target_name+'-gnu';
-{$endif}
-    end;
-
-
   function llvm_callingconvention_name(c: tproccalloption): ansistring;
     begin
       // TODO (unsupported by LLVM at this time):

+ 45 - 0
compiler/m68k/tripletcpu.pas

@@ -0,0 +1,45 @@
+{
+    Copyright (c) 2020 by Jonas Maebe
+
+    Construct the cpu part of the triplet
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ ****************************************************************************
+}
+unit tripletcpu;
+
+{$i fpcdefs.inc}
+
+interface
+
+uses
+  globtype;
+
+function tripletcpustr(tripletstyle: ttripletstyle): ansistring;
+
+implementation
+
+uses
+  globals, cpuinfo;
+
+function tripletcpustr(tripletstyle: ttripletstyle): ansistring;
+  begin
+    result:='m68k';
+  end;
+
+
+end.
+

+ 48 - 0
compiler/mips/tripletcpu.pas

@@ -0,0 +1,48 @@
+{
+    Copyright (c) 2020 by Jonas Maebe
+
+    Construct the cpu part of the triplet
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ ****************************************************************************
+}
+unit tripletcpu;
+
+{$i fpcdefs.inc}
+
+interface
+
+uses
+  globtype;
+
+function tripletcpustr(tripletstyle: ttripletstyle): ansistring;
+
+implementation
+
+uses
+  globals, systems, cpuinfo;
+
+function tripletcpustr(tripletstyle: ttripletstyle): ansistring;
+  begin
+    if target_info.endian=endian_big then
+      result:='mips'
+    else
+      result:='mipsel'
+  end;
+
+
+end.
+

+ 2 - 2
compiler/options.pas

@@ -4171,7 +4171,7 @@ begin
   { default to clang }
   if (option.paratargetasm=as_none) then
     begin
-      option.paratargetasm:=as_llvm_clang;
+      option.paratargetasm:=as_clang_llvm;
     end;
 {$endif llvm}
   { maybe override assembler }
@@ -4219,7 +4219,7 @@ begin
    begin
      Message(option_switch_bin_to_src_assembler);
 {$ifdef llvm}
-     set_target_asm(as_llvm_clang);
+     set_target_asm(as_clang_llvm);
 {$else}
      set_target_asm(target_info.assemextern);
 {$endif}

+ 45 - 0
compiler/powerpc/tripletcpu.pas

@@ -0,0 +1,45 @@
+{
+    Copyright (c) 2020 by Jonas Maebe
+
+    Construct the cpu part of the triplet
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ ****************************************************************************
+}
+unit tripletcpu;
+
+{$i fpcdefs.inc}
+
+interface
+
+uses
+  globtype;
+
+function tripletcpustr(tripletstyle: ttripletstyle): ansistring;
+
+implementation
+
+uses
+  globals, cpuinfo;
+
+function tripletcpustr(tripletstyle: ttripletstyle): ansistring;
+  begin
+    result:='ppc32';
+  end;
+
+
+end.
+

+ 48 - 0
compiler/powerpc64/tripletcpu.pas

@@ -0,0 +1,48 @@
+{
+    Copyright (c) 2020 by Jonas Maebe
+
+    Construct the cpu part of the triplet
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ ****************************************************************************
+}
+unit tripletcpu;
+
+{$i fpcdefs.inc}
+
+interface
+
+uses
+  globtype;
+
+function tripletcpustr(tripletstyle: ttripletstyle): ansistring;
+
+implementation
+
+uses
+  globals, systems, cpuinfo;
+
+function tripletcpustr(tripletstyle: ttripletstyle): ansistring;
+  begin
+    if target_info.endian=endian_little then
+      result:='ppc64le'
+    else
+      result:='ppc64'
+  end;
+
+
+end.
+

+ 3 - 3
compiler/ppcgen/agppcgas.pas

@@ -734,12 +734,12 @@ unit agppcgas;
 
     as_ppc_clang_darwin_info : tasminfo =
        (
-         id     : as_clang;
+         id     : as_clang_asdarwin;
          idtxt  : 'CLANG';
          asmbin : 'clang';
-         asmcmd : '-c -o $OBJ $EXTRAOPT -arch $ARCH $DARWINVERSION -x assembler $ASM';
+         asmcmd : '-x assembler -c -target $TRIPLET -o $OBJ $EXTRAOPT -x assembler $ASM';
          supported_targets : [system_powerpc_macosclassic, system_powerpc_darwin, system_powerpc64_darwin];
-         flags : [af_needar,af_smartlink_sections,af_supports_dwarf];
+         flags : [af_needar,af_smartlink_sections,af_supports_dwarf,af_llvm];
          labelprefix : 'L';
          labelmaxlen : -1;
          comment : '# ';

+ 1 - 1
compiler/ppcgen/ngppcadd.pas

@@ -339,7 +339,7 @@ implementation
               { clang does not recognize fcmpo instruction,
                 so we need to fall back to fcmpu, which does not
                 generate the same exeception information }
-              if target_asm.id = as_clang then
+              if target_asm.id in [as_clang_gas,as_clang_asdarwin] then
                 op:=A_FCMPU
               else
                 op:=A_FCMPO;

+ 45 - 0
compiler/riscv32/tripletcpu.pas

@@ -0,0 +1,45 @@
+{
+    Copyright (c) 2020 by Jonas Maebe
+
+    Construct the cpu part of the triplet
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ ****************************************************************************
+}
+unit tripletcpu;
+
+{$i fpcdefs.inc}
+
+interface
+
+uses
+  globtype;
+
+function tripletcpustr(tripletstyle: ttripletstyle): ansistring;
+
+implementation
+
+uses
+  globals, cpuinfo;
+
+function tripletcpustr(tripletstyle: ttripletstyle): ansistring;
+  begin
+    result:='riscv32';
+  end;
+
+
+end.
+

+ 48 - 0
compiler/riscv64/tripletcpu.pas

@@ -0,0 +1,48 @@
+{
+    Copyright (c) 2020 by Jonas Maebe
+
+    Construct the cpu part of the triplet
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ ****************************************************************************
+}
+unit tripletcpu;
+
+{$i fpcdefs.inc}
+
+interface
+
+uses
+  globtype;
+
+function tripletcpustr(tripletstyle: ttripletstyle): ansistring;
+
+implementation
+
+uses
+  globals, cpuinfo;
+
+function tripletcpustr(tripletstyle: ttripletstyle): ansistring;
+  begin
+    if tripletstyle=triplet_llvm then
+      result:='sparcv9'
+    else
+      result:='sparc64'
+  end;
+
+
+end.
+

+ 48 - 0
compiler/sparc/tripletcpu.pas

@@ -0,0 +1,48 @@
+{
+    Copyright (c) 2020 by Jonas Maebe
+
+    Construct the cpu part of the triplet
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ ****************************************************************************
+}
+unit tripletcpu;
+
+{$i fpcdefs.inc}
+
+interface
+
+uses
+  globtype;
+
+function tripletcpustr(tripletstyle: ttripletstyle): ansistring;
+
+implementation
+
+uses
+  globals, systems, cpuinfo;
+
+function tripletcpustr(tripletstyle: ttripletstyle): ansistring;
+  begin
+    if target_info.endian=endian_big then
+      result:='sparc'
+    else
+      result:='sparcle'
+  end;
+
+
+end.
+

+ 45 - 0
compiler/sparc64/tripletcpu.pas

@@ -0,0 +1,45 @@
+{
+    Copyright (c) 2020 by Jonas Maebe
+
+    Construct the cpu part of the triplet
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ ****************************************************************************
+}
+unit tripletcpu;
+
+{$i fpcdefs.inc}
+
+interface
+
+uses
+  globtype;
+
+function tripletcpustr(tripletstyle: ttripletstyle): ansistring;
+
+implementation
+
+uses
+  globals, cpuinfo;
+
+function tripletcpustr(tripletstyle: ttripletstyle): ansistring;
+  begin
+    result:='sparc64';
+  end;
+
+
+end.
+

+ 3 - 4
compiler/systems.inc

@@ -248,15 +248,14 @@
              ,as_gas_powerpc_xcoff
              ,as_arm_elf32
              ,as_i8086_omf
-             ,as_llvm_llc
-             ,as_clang
+             ,as_clang_asdarwin        { machine code assembler in Darwin as style assembled by clang }
              ,as_solaris_as
              ,as_m68k_vasm
              ,as_m68k_as_aout
              ,as_wasm_binaryen
              ,as_powerpc_gas_legacy    { for systems with very old GAS versions only, which don't support eg. named sections }
-             ,as_llvm_clang
-             ,as_clang_gas
+             ,as_clang_llvm
+             ,as_clang_gas             { machine code assembler in gas style assembled by clang }
              ,as_z80asm
              ,as_sdcc_sdasz80
              ,as_z80_vasm

+ 5 - 3
compiler/systems.pas

@@ -76,6 +76,7 @@ interface
          ,af_no_debug
          ,af_stabs_use_function_absolute_addresses
          ,af_no_stabs
+         { assembler is part of the LLVM toolchain }
          ,af_llvm
        );
 
@@ -285,11 +286,12 @@ interface
                              system_i8086_win16];
 
        { all darwin systems }
-       systems_darwin = [system_powerpc_darwin,system_i386_darwin,
+       systems_ios = [system_arm_ios,system_aarch64_ios];
+       systems_iphonesym = [system_i386_iphonesim,system_x86_64_iphonesim];
+       systems_macosx = [system_powerpc_darwin,system_i386_darwin,
                          system_powerpc64_darwin,system_x86_64_darwin,
-                         system_arm_ios,system_i386_iphonesim,
-                         system_aarch64_ios,system_x86_64_iphonesim,
                          system_aarch64_darwin];
+       systems_darwin = systems_ios + systems_iphonesym + systems_macosx;
 
        {all solaris systems }
        systems_solaris = [system_sparc_solaris, system_i386_solaris,

+ 16 - 15
compiler/systems/i_darwin.pas

@@ -152,8 +152,8 @@ const
         Cprefix      : '_';
         newline      : #10;
         dirsep       : '/';
-        assem        : as_clang;
-        assemextern  : as_clang;
+        assem        : as_clang_asdarwin;
+        assemextern  : as_clang_asdarwin;
         link         : ld_none;
         linkextern   : ld_darwin;
         ar           : ar_gnu_ar;
@@ -221,8 +221,8 @@ const
         Cprefix      : '_';
         newline      : #10;
         dirsep       : '/';
-        assem        : as_clang;
-        assemextern  : as_clang;
+        assem        : as_clang_asdarwin;
+        assemextern  : as_clang_asdarwin;
         link         : ld_none;
         linkextern   : ld_darwin;
         ar           : ar_gnu_ar;
@@ -359,8 +359,8 @@ const
         Cprefix      : '_';
         newline      : #10;
         dirsep       : '/';
-        assem        : as_clang;
-        assemextern  : as_clang;
+        assem        : as_clang_asdarwin;
+        assemextern  : as_clang_asdarwin;
         link         : ld_none;
         linkextern   : ld_darwin;
         ar           : ar_gnu_ar;
@@ -427,8 +427,8 @@ const
         Cprefix      : '_';
         newline      : #10;
         dirsep       : '/';
-        assem        : as_clang;
-        assemextern  : as_clang;
+        assem        : as_clang_asdarwin;
+        assemextern  : as_clang_asdarwin;
         link         : ld_none;
         linkextern   : ld_darwin;
         ar           : ar_gnu_ar;
@@ -495,8 +495,8 @@ const
         Cprefix      : '_';
         newline      : #10;
         dirsep       : '/';
-        assem        : as_clang;
-        assemextern  : as_clang;
+        assem        : as_clang_asdarwin;
+        assemextern  : as_clang_asdarwin;
         link         : ld_none;
         linkextern   : ld_darwin;
         ar           : ar_gnu_ar;
@@ -564,8 +564,8 @@ const
         Cprefix      : '_';
         newline      : #10;
         dirsep       : '/';
-        assem        : as_clang;
-        assemextern  : as_clang;
+        assem        : as_clang_asdarwin;
+        assemextern  : as_clang_asdarwin;
         link         : ld_none;
         linkextern   : ld_darwin;
         ar           : ar_gnu_ar;
@@ -604,7 +604,8 @@ const
         name         : 'Darwin for AArch64';
         shortname    : 'Darwin';
         flags        : [tf_p_ext_support,tf_requires_proper_alignment,tf_files_case_sensitive,tf_smartlink_sections,tf_dwarf_relative_addresses,
-                        tf_dwarf_only_local_labels,tf_pic_default,tf_has_winlike_resources,tf_supports_symbolorderfile,tf_supports_hidden_symbols];
+                        tf_dwarf_only_local_labels,tf_pic_default,tf_has_winlike_resources,tf_supports_symbolorderfile,tf_supports_hidden_symbols
+                        {$ifdef llvm},tf_use_psabieh{$endif}];
         cpu          : cpu_aarch64;
         unit_env     : 'BSDUNITS';
         extradefines : 'UNIX;BSD;HASUNIX';
@@ -631,8 +632,8 @@ const
         Cprefix      : '_';
         newline      : #10;
         dirsep       : '/';
-        assem        : as_clang;
-        assemextern  : as_clang;
+        assem        : as_clang_asdarwin;
+        assemextern  : as_clang_asdarwin;
         link         : ld_none;
         linkextern   : ld_darwin;
         ar           : ar_gnu_ar;

+ 101 - 0
compiler/triplet.pas

@@ -0,0 +1,101 @@
+{
+    Copyright (c) 2007-2008, 2013, 2019-2020 by Jonas Maebe
+
+    This unit handles constructing target triples
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ ****************************************************************************
+}
+unit triplet;
+
+{$i fpcdefs.inc}
+
+interface
+
+uses
+  globtype;
+
+function targettriplet(tripletstyle: ttripletstyle): ansistring;
+
+implementation
+
+uses
+  globals,systems,
+  cpuinfo,tripletcpu;
+
+  function targettriplet(tripletstyle: ttripletstyle): ansistring;
+    begin
+      { architecture }
+      result:=tripletcpustr(tripletstyle);
+      { vendor and/or OS }
+      if target_info.system in systems_darwin then
+        begin
+          result:=result+'-apple';
+          if target_info.system in systems_macosx then
+            result:=result+'-macosx'+MacOSXVersionMin
+          else
+            result:=result+'-ios'+iPhoneOSVersionMin;
+        end
+      else if target_info.system in (systems_linux+systems_android) then
+        result:=result+'-unknown-linux'
+      else if target_info.system in systems_all_windows then
+        begin
+          { WinCE isn't supported (yet) by llvm, but if/when added this is
+            presumably how they will differentiate it }
+          if target_info.system in systems_windows then
+            result:=result+'-pc';
+          result:=result+'-windows-msvc19'
+        end
+      else if target_info.system in systems_freebsd then
+        result:=result+'-unknown-freebsd'
+      else if target_info.system in systems_openbsd then
+        result:=result+'-unknown-openbsd'
+      else if target_info.system in systems_netbsd then
+        result:=result+'-unknown-netbsd'
+      else if target_info.system in systems_solaris then
+        result:=result+'-sun-solaris2'
+      else if target_info.system in systems_aix then
+        result:=result+'-ibm-aix53'
+      else if target_info.system in [system_i386_haiku] then
+        result:=result+'-unknown-haiku'
+      else if target_info.system in systems_embedded then
+        result:=result+'-none'
+      else
+        result:=result+'-unknown';
+
+      { environment/ABI }
+      if target_info.system in systems_android then
+        result:=result+'-android'
+      else
+{$ifdef arm}
+      if target_info.abi=abi_eabihf then
+        result:=result+'-gnueabihf'
+      else if target_info.system in systems_embedded then
+        result:=result+'-eabi'
+      else if target_info.abi=abi_eabi then
+        result:=result+'-gnueabi'
+      else
+{$endif}
+      if target_info.system in systems_embedded then
+        result:=result+'-elf'
+      else if target_info.system in systems_linux then
+        result:=result+'-gnu';
+    end;
+
+
+
+end.
+

+ 6 - 6
compiler/x86/agx86att.pas

@@ -507,12 +507,12 @@ interface
 
        as_x86_64_clang_darwin_info : tasminfo =
           (
-            id     : as_clang;
+            id     : as_clang_asdarwin;
             idtxt  : 'CLANG';
             asmbin : 'clang';
-            asmcmd : '-c -o $OBJ $EXTRAOPT -arch x86_64 $DARWINVERSION -x assembler $ASM';
+            asmcmd : '-x assembler -c -target $TRIPLET -o $OBJ $EXTRAOPT -x assembler $ASM';
             supported_targets : [system_x86_64_darwin,system_x86_64_iphonesim];
-            flags : [af_needar,af_smartlink_sections,af_supports_dwarf,af_no_stabs];
+            flags : [af_needar,af_smartlink_sections,af_supports_dwarf,af_no_stabs,af_llvm];
             labelprefix : 'L';
             labelmaxlen : -1;
             comment : '# ';
@@ -586,12 +586,12 @@ interface
 
        as_i386_clang_darwin_info : tasminfo =
           (
-            id     : as_clang;
+            id     : as_clang_asdarwin;
             idtxt  : 'CLANG';
             asmbin : 'clang';
-            asmcmd : '-c -o $OBJ $EXTRAOPT -arch i386 $DARWINVERSION -x assembler $ASM';
+            asmcmd : '-x assembler -c -target $TRIPLET -o $OBJ $EXTRAOPT -x assembler $ASM';
             supported_targets : [system_i386_darwin,system_i386_iphonesim];
-            flags : [af_needar,af_smartlink_sections,af_supports_dwarf,af_no_stabs];
+            flags : [af_needar,af_smartlink_sections,af_supports_dwarf,af_no_stabs,af_llvm];
             labelprefix : 'L';
             labelmaxlen : -1;
             comment : '# ';

+ 45 - 0
compiler/x86_64/tripletcpu.pas

@@ -0,0 +1,45 @@
+{
+    Copyright (c) 2020 by Jonas Maebe
+
+    Construct the cpu part of the triplet
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ ****************************************************************************
+}
+unit tripletcpu;
+
+{$i fpcdefs.inc}
+
+interface
+
+uses
+  globtype;
+
+function tripletcpustr(tripletstyle: ttripletstyle): ansistring;
+
+implementation
+
+uses
+  globals, cpuinfo;
+
+function tripletcpustr(tripletstyle: ttripletstyle): ansistring;
+  begin
+    result:='x86_64';
+  end;
+
+
+end.
+

+ 45 - 0
compiler/xtensa/tripletcpu.pas

@@ -0,0 +1,45 @@
+{
+    Copyright (c) 2020 by Jonas Maebe
+
+    Construct the cpu part of the triplet
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ ****************************************************************************
+}
+unit tripletcpu;
+
+{$i fpcdefs.inc}
+
+interface
+
+uses
+  globtype;
+
+function tripletcpustr(tripletstyle: ttripletstyle): ansistring;
+
+implementation
+
+uses
+  globals, cpuinfo;
+
+function tripletcpustr(tripletstyle: ttripletstyle): ansistring;
+  begin
+    result:='xtensa';
+  end;
+
+
+end.
+

+ 45 - 0
compiler/z80/tripletcpu.pas

@@ -0,0 +1,45 @@
+{
+    Copyright (c) 2020 by Jonas Maebe
+
+    Construct the cpu part of the triplet
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ ****************************************************************************
+}
+unit tripletcpu;
+
+{$i fpcdefs.inc}
+
+interface
+
+uses
+  globtype;
+
+function tripletcpustr(tripletstyle: ttripletstyle): ansistring;
+
+implementation
+
+uses
+  globals, cpuinfo;
+
+function tripletcpustr(tripletstyle: ttripletstyle): ansistring;
+  begin
+    result:='z80';
+  end;
+
+
+end.
+