narmcon.pas 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. lastlabel : tasmlabel;
  48. realait : taitype;
  49. hiloswapped : boolean;
  50. begin
  51. location_reset_ref(location,LOC_CREFERENCE,def_cgsize(resultdef),4);
  52. lastlabel:=nil;
  53. realait:=floattype2ait[tfloatdef(resultdef).floattype];
  54. hiloswapped:=is_double_hilo_swapped;
  55. { const already used ? }
  56. if not assigned(lab_real) then
  57. begin
  58. current_asmdata.getjumplabel(lastlabel);
  59. lab_real:=lastlabel;
  60. current_procinfo.aktlocaldata.concat(Tai_label.Create(lastlabel));
  61. location.reference.symboldata:=current_procinfo.aktlocaldata.last;
  62. case realait of
  63. ait_real_32bit :
  64. begin
  65. current_procinfo.aktlocaldata.concat(Tai_real_32bit.Create(ts32real(value_real)));
  66. { range checking? }
  67. if ((cs_check_range in current_settings.localswitches) or
  68. (cs_check_overflow in current_settings.localswitches)) and
  69. (tai_real_32bit(current_procinfo.aktlocaldata.last).value=MathInf.Value) then
  70. Message(parser_e_range_check_error);
  71. end;
  72. ait_real_64bit :
  73. begin
  74. if hiloswapped then
  75. current_procinfo.aktlocaldata.concat(Tai_real_64bit.Create_hiloswapped(ts64real(value_real)))
  76. else
  77. current_procinfo.aktlocaldata.concat(Tai_real_64bit.Create(ts64real(value_real)));
  78. { range checking? }
  79. if ((cs_check_range in current_settings.localswitches) or
  80. (cs_check_overflow in current_settings.localswitches)) and
  81. (tai_real_64bit(current_procinfo.aktlocaldata.last).value=MathInf.Value) then
  82. Message(parser_e_range_check_error);
  83. end;
  84. ait_real_80bit :
  85. begin
  86. current_procinfo.aktlocaldata.concat(Tai_real_80bit.Create(value_real));
  87. { range checking? }
  88. if ((cs_check_range in current_settings.localswitches) or
  89. (cs_check_overflow in current_settings.localswitches)) and
  90. (tai_real_80bit(current_procinfo.aktlocaldata.last).value=MathInf.Value) then
  91. Message(parser_e_range_check_error);
  92. end;
  93. {$ifdef cpufloat128}
  94. ait_real_128bit :
  95. begin
  96. current_procinfo.aktlocaldata.concat(Tai_real_128bit.Create(value_real));
  97. { range checking? }
  98. if ((cs_check_range in current_settings.localswitches) or
  99. (cs_check_overflow in current_settings.localswitches)) and
  100. (tai_real_128bit(current_procinfo.aktlocaldata.last).value=MathInf.Value) then
  101. Message(parser_e_range_check_error);
  102. end;
  103. {$endif cpufloat128}
  104. { the round is necessary for native compilers where comp isn't a float }
  105. ait_comp_64bit :
  106. if (value_real>9223372036854775807.0) or (value_real<-9223372036854775808.0) then
  107. message(parser_e_range_check_error)
  108. else
  109. current_procinfo.aktlocaldata.concat(Tai_comp_64bit.Create(round(value_real)));
  110. else
  111. internalerror(2005092401);
  112. end;
  113. end;
  114. location.reference.symbol:=lab_real;
  115. location.reference.base:=NR_R15;
  116. end;
  117. begin
  118. crealconstnode:=tarmrealconstnode;
  119. end.