narmcon.pas 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. {
  2. Copyright (c) 2005 by Florian Klaempfl
  3. Code generation for const nodes on the ARM
  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. unit narmcon;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. node,ncgcon,cpubase;
  22. type
  23. tarmrealconstnode = class(tcgrealconstnode)
  24. procedure pass_generate_code;override;
  25. end;
  26. implementation
  27. uses
  28. verbose,
  29. globtype,globals,
  30. cpuinfo,
  31. aasmbase,aasmtai,aasmdata,
  32. symconst,symdef,
  33. defutil,
  34. cgbase,cgutils,
  35. procinfo,
  36. ncon;
  37. {*****************************************************************************
  38. TARMREALCONSTNODE
  39. *****************************************************************************}
  40. procedure tarmrealconstnode.pass_generate_code;
  41. { I suppose the parser/pass_1 must make sure the generated real }
  42. { constants are actually supported by the target processor? (JM) }
  43. const
  44. floattype2ait:array[tfloattype] of taitype=
  45. (ait_real_32bit,ait_real_64bit,ait_real_80bit,ait_comp_64bit,ait_comp_64bit,ait_real_128bit);
  46. var
  47. hp1 : tai;
  48. lastlabel : tasmlabel;
  49. realait : taitype;
  50. hiloswapped : boolean;
  51. begin
  52. location_reset(location,LOC_CREFERENCE,def_cgsize(resultdef));
  53. lastlabel:=nil;
  54. realait:=floattype2ait[tfloatdef(resultdef).floattype];
  55. hiloswapped:=(current_settings.fputype in [fpu_fpa,fpu_fpa10,fpu_fpa11]) and
  56. not(cs_fp_emulation in current_settings.moduleswitches);
  57. {$ifdef FPC_DOUBLE_HILO_SWAPPED}
  58. hiloswapped:=not hiloswapped;
  59. {$endif FPC_DOUBLE_HILO_SWAPPED}
  60. { const already used ? }
  61. if not assigned(lab_real) then
  62. begin
  63. current_asmdata.getjumplabel(lastlabel);
  64. lab_real:=lastlabel;
  65. current_procinfo.aktlocaldata.concat(Tai_label.Create(lastlabel));
  66. location.reference.symboldata:=current_procinfo.aktlocaldata.last;
  67. case realait of
  68. ait_real_32bit :
  69. begin
  70. current_procinfo.aktlocaldata.concat(Tai_real_32bit.Create(ts32real(value_real)));
  71. { range checking? }
  72. if ((cs_check_range in current_settings.localswitches) or
  73. (cs_check_overflow in current_settings.localswitches)) and
  74. (tai_real_32bit(current_asmdata.asmlists[al_typedconsts].last).value=MathInf.Value) then
  75. Message(parser_e_range_check_error);
  76. end;
  77. ait_real_64bit :
  78. begin
  79. if hiloswapped then
  80. current_procinfo.aktlocaldata.concat(Tai_real_64bit.Create_hiloswapped(ts64real(value_real)))
  81. else
  82. current_procinfo.aktlocaldata.concat(Tai_real_64bit.Create(ts64real(value_real)));
  83. { range checking? }
  84. if ((cs_check_range in current_settings.localswitches) or
  85. (cs_check_overflow in current_settings.localswitches)) and
  86. (tai_real_64bit(current_asmdata.asmlists[al_typedconsts].last).value=MathInf.Value) then
  87. Message(parser_e_range_check_error);
  88. end;
  89. ait_real_80bit :
  90. begin
  91. current_procinfo.aktlocaldata.concat(Tai_real_80bit.Create(value_real));
  92. { range checking? }
  93. if ((cs_check_range in current_settings.localswitches) or
  94. (cs_check_overflow in current_settings.localswitches)) and
  95. (tai_real_80bit(current_asmdata.asmlists[al_typedconsts].last).value=MathInf.Value) then
  96. Message(parser_e_range_check_error);
  97. end;
  98. {$ifdef cpufloat128}
  99. ait_real_128bit :
  100. begin
  101. current_procinfo.aktlocaldata.concat(Tai_real_128bit.Create(value_real));
  102. { range checking? }
  103. if ((cs_check_range in current_settings.localswitches) or
  104. (cs_check_overflow in current_settings.localswitches)) and
  105. (tai_real_128bit(current_asmdata.asmlists[al_typedconsts].last).value=MathInf.Value) then
  106. Message(parser_e_range_check_error);
  107. end;
  108. {$endif cpufloat128}
  109. { the round is necessary for native compilers where comp isn't a float }
  110. ait_comp_64bit :
  111. if (value_real>9223372036854775807.0) or (value_real<-9223372036854775808.0) then
  112. message(parser_e_range_check_error)
  113. else
  114. current_procinfo.aktlocaldata.concat(Tai_comp_64bit.Create(round(value_real)));
  115. else
  116. internalerror(2005092401);
  117. end;
  118. end;
  119. location.reference.symbol:=lab_real;
  120. location.reference.base:=NR_R15;
  121. end;
  122. begin
  123. crealconstnode:=tarmrealconstnode;
  124. end.