nllvmcon.pas 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. {
  2. Copyright (c) 2013 by Jonas Maebe, member of the Free Pascal Compiler
  3. development team
  4. Generate llvm bitcode for constants
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit nllvmcon;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. node,ncgcon;
  23. type
  24. tllvmrealconstnode = class(tcgrealconstnode)
  25. function pass_1 : tnode;override;
  26. procedure pass_generate_code;override;
  27. end;
  28. implementation
  29. uses
  30. globtype,verbose,
  31. symdef,defutil,
  32. aasmdata,
  33. ncon,
  34. llvmbase,aasmllvm,hlcgobj,
  35. cgbase,cgutils;
  36. {*****************************************************************************
  37. tllvmrealconstnode
  38. *****************************************************************************}
  39. function tllvmrealconstnode.pass_1 : tnode;
  40. begin
  41. result:=nil;
  42. expectloc:=LOC_FPUREGISTER;
  43. end;
  44. procedure tllvmrealconstnode.pass_generate_code;
  45. begin
  46. { llvm supports floating point constants directly }
  47. location_reset(location,LOC_FPUREGISTER,def_cgsize(resultdef));
  48. location.register:=hlcg.getfpuregister(current_asmdata.CurrAsmList,resultdef);
  49. case tfloatdef(resultdef).floattype of
  50. s32real,s64real:
  51. current_asmdata.CurrAsmList.concat(taillvm.op_reg_size_fpconst_size(la_bitcast,location.register,resultdef,value_real,resultdef));
  52. { comp and currency are handled as int64 at the llvm level }
  53. s64comp,
  54. s64currency:
  55. { sc80floattype instead of resultdef, see comment in thlcgllvm.a_loadfpu_ref_reg }
  56. current_asmdata.CurrAsmList.concat(taillvm.op_reg_size_const_size(la_sitofp,location.register,s64inttype,trunc(value_real),sc80floattype));
  57. {$ifdef cpuextended}
  58. s80real,sc80real:
  59. current_asmdata.CurrAsmList.concat(taillvm.op_reg_size_fpconst80_size(la_bitcast,location.register,resultdef,value_real,resultdef));
  60. {$endif cpuextended}
  61. else
  62. internalerror(2013102501);
  63. end;
  64. end;
  65. begin
  66. crealconstnode:=tllvmrealconstnode;
  67. end.