llvmbase.pas 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. {
  2. Copyright (c) 2007-2008, 2013 by Jonas Maebe
  3. Contains the base types for LLVM
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. { This Unit contains the base types for LLVM
  18. }
  19. unit llvmbase;
  20. {$i fpcdefs.inc}
  21. interface
  22. uses
  23. strings,globtype,
  24. cutils,cclasses,aasmbase,cpubase,cpuinfo,cgbase;
  25. {*****************************************************************************
  26. Assembler Opcodes
  27. *****************************************************************************}
  28. type
  29. tllvmop = (la_none,
  30. { terminator instructions }
  31. la_ret, la_br, la_switch, la_indirectbr,
  32. la_invoke, la_resume,
  33. la_unreachable,
  34. { binary operations }
  35. la_add, la_fadd, la_sub, la_fsub, la_mul, la_fmul,
  36. la_udiv,la_sdiv, la_fdiv, la_urem, la_srem, la_frem,
  37. { bitwise binary operations }
  38. la_shl, la_lshr, la_ashr, la_and, la_or, la_xor,
  39. { vector operations }
  40. la_extractelement, la_insertelement, la_shufflevector,
  41. { aggregate operations }
  42. la_extractvalue, la_insertvalue,
  43. { memory access and memory addressing operations }
  44. la_alloca,
  45. la_load, la_store,
  46. la_fence, la_cmpxchg, la_atomicrmw,
  47. la_getelementptr,
  48. { conversion operations }
  49. la_trunc, la_zext, la_sext, la_fptrunc, la_fpext,
  50. la_fptoui, la_fptosi, la_uitofp, la_sitofp,
  51. la_ptrtoint, la_inttoptr,
  52. la_bitcast,
  53. { other operations }
  54. la_icmp, la_fcmp,
  55. la_phi, la_select, la_call,
  56. la_va_arg, la_landingpad,
  57. { fpc pseudo opcodes }
  58. la_type, { type definition }
  59. la_x_to_inttoptr, { have to convert something first to int before it can be converted to a pointer }
  60. la_ptrtoint_to_x { have to convert a pointer first to int before it can be converted to something else }
  61. );
  62. tllvmvalueextension = (lve_none, lve_zeroext, lve_signext);
  63. const
  64. llvmterminatoropcodes = [la_ret, la_br, la_switch, la_indirectbr,
  65. la_invoke, la_resume,
  66. la_unreachable];
  67. llvmvalueextension2str: array[tllvmvalueextension] of TSymStr = ('',
  68. ' zeroext',' signext');
  69. type
  70. tllvmfpcmp = (
  71. lfc_invalid,
  72. lfc_false,
  73. lfc_oeq, lfc_ogt, lfc_oge, lfc_olt, lfc_ole, lfc_one, lfc_ord,
  74. lfc_ueq, lfc_ugt, lfc_uge, lfc_ult, lfc_ule, lfc_une, lfc_uno,
  75. lfc_true);
  76. {# This should define the array of instructions as string }
  77. llvmop2strtable=array[tllvmop] of string[14];
  78. const
  79. { = max(cpubase.max_operands,7) }
  80. max_operands = ((-ord(cpubase.max_operands<=7)) and 7) or ((-ord(cpubase.max_operands>7)) and cpubase.max_operands);
  81. function llvm_target_name: ansistring;
  82. implementation
  83. uses
  84. globals,
  85. systems;
  86. {$j-}
  87. const
  88. llvmsystemcpu: array[tsystemcpu] of ansistring =
  89. ('unknown',
  90. 'i386',
  91. 'm68k',
  92. 'alpha',
  93. 'powerpc',
  94. 'sparc',
  95. 'unknown',
  96. 'ia64',
  97. 'x86_64',
  98. 'mips',
  99. 'arm',
  100. 'powerpc64',
  101. 'avr',
  102. 'mipsel',
  103. 'unknown',
  104. 'unknown',
  105. 'aarch64'
  106. );
  107. function llvm_target_name: ansistring;
  108. begin
  109. { architecture }
  110. {$ifdef arm}
  111. llvm_target_name:=lower(cputypestr[current_settings.cputype]);
  112. {$else arm}
  113. llvm_target_name:=llvmsystemcpu[target_info.cpu];
  114. {$endif}
  115. { vendor and/or OS }
  116. if target_info.system in systems_darwin then
  117. begin
  118. llvm_target_name:=llvm_target_name+'-apple';
  119. if not(target_info.system in [system_arm_darwin,system_i386_iphonesim]) then
  120. llvm_target_name:=llvm_target_name+'-macosx'+MacOSXVersionMin
  121. else
  122. llvm_target_name:=llvm_target_name+'-ios'+iPhoneOSVersionMin;
  123. end
  124. else if target_info.system in (systems_linux+systems_android) then
  125. llvm_target_name:=llvm_target_name+'-linux'
  126. else if target_info.system in systems_windows then
  127. begin
  128. { WinCE isn't supported (yet) by llvm, but if/when added this is
  129. presumably how they will differentiate it }
  130. if not(target_info.system in [system_i386_wince,system_arm_wince]) then
  131. llvm_target_name:=llvm_target_name+'-pc';
  132. llvm_target_name:=llvm_target_name+'-win32'
  133. end
  134. else if target_info.system in systems_freebsd then
  135. llvm_target_name:=llvm_target_name+'-freebsd'
  136. else if target_info.system in systems_openbsd then
  137. llvm_target_name:=llvm_target_name+'-openbsd'
  138. else if target_info.system in systems_netbsd then
  139. llvm_target_name:=llvm_target_name+'-netbsd'
  140. else if target_info.system in systems_aix then
  141. llvm_target_name:=llvm_target_name+'-ibm-aix'
  142. else if target_info.system in [system_i386_haiku] then
  143. llvm_target_name:=llvm_target_name+'-haiku'
  144. else if target_info.system in systems_embedded then
  145. llvm_target_name:=llvm_target_name+'-none'
  146. else
  147. llvm_target_name:=llvm_target_name+'-unknown';
  148. { environment/ABI }
  149. if target_info.system in systems_android then
  150. llvm_target_name:=llvm_target_name+'-android';
  151. {$if defined(FPC_ARMHF)}
  152. llvm_target_name:=llvm_target_name+'-gnueabihf';
  153. {$elseif defined(FPC_ARMEL)}
  154. if target_info.system in systems_embedded then
  155. llvm_target_name:=llvm_target_name+'-eabi'
  156. else if target_info.system=system_arm_android then
  157. { handled above already
  158. llvm_target_name:=llvm_target_name+'-android' }
  159. else
  160. llvm_target_name:=llvm_target_name+'-gnueabi';
  161. {$endif FPC_ARM_HF}
  162. end;
  163. end.