nllvmcon.pas 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. current_asmdata.CurrAsmList.concat(taillvm.op_reg_size_const_size(la_bitcast,location.register,resultdef,trunc(value_real),resultdef));
  56. {$ifdef cpuextended}
  57. s80real,sc80real:
  58. current_asmdata.CurrAsmList.concat(taillvm.op_reg_size_fpconst80_size(la_bitcast,location.register,resultdef,value_real,resultdef));
  59. {$endif cpuextended}
  60. else
  61. internalerror(2013102501);
  62. end;
  63. end;
  64. begin
  65. crealconstnode:=tllvmrealconstnode;
  66. end.