nrvcon.pas 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. Code generation for const nodes on the Risc-V
  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 nrvcon;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. ncgcon,cpubase;
  22. type
  23. trvrealconstnode = 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,symdef,
  32. defutil,
  33. cgbase,cgutils,
  34. procinfo,
  35. ncon;
  36. {*****************************************************************************
  37. TARMREALCONSTNODE
  38. *****************************************************************************}
  39. procedure trvrealconstnode.pass_generate_code;
  40. { I suppose the parser/pass_1 must make sure the generated real }
  41. { constants are actually supported by the target processor? (JM) }
  42. const
  43. floattype2ait:array[tfloattype] of tairealconsttype=
  44. (aitrealconst_s32bit,aitrealconst_s64bit,aitrealconst_s80bit,aitrealconst_s80bit,aitrealconst_s64comp,aitrealconst_s64comp,aitrealconst_s128bit);
  45. var
  46. lastlabel : tasmlabel;
  47. realait : tairealconsttype;
  48. begin
  49. location_reset_ref(location,LOC_CREFERENCE,def_cgsize(resultdef),4);
  50. lastlabel:=nil;
  51. realait:=floattype2ait[tfloatdef(resultdef).floattype];
  52. { const already used ? }
  53. if not assigned(lab_real) then
  54. begin
  55. current_asmdata.getjumplabel(lastlabel);
  56. lab_real:=lastlabel;
  57. current_procinfo.aktlocaldata.concat(Tai_label.Create(lastlabel));
  58. location.reference.symboldata:=current_procinfo.aktlocaldata.last;
  59. case realait of
  60. aitrealconst_s32bit :
  61. begin
  62. current_procinfo.aktlocaldata.concat(tai_realconst.create_s32real(ts32real(value_real)));
  63. { range checking? }
  64. if floating_point_range_check_error and
  65. (tai_realconst(current_procinfo.aktlocaldata.last).value.s32val=MathInf.Value) then
  66. Message(parser_e_range_check_error);
  67. end;
  68. aitrealconst_s64bit :
  69. begin
  70. current_procinfo.aktlocaldata.concat(tai_realconst.create_s64real(ts64real(value_real)));
  71. { range checking? }
  72. if floating_point_range_check_error and
  73. (tai_realconst(current_procinfo.aktlocaldata.last).value.s64val=MathInf.Value) then
  74. Message(parser_e_range_check_error);
  75. end;
  76. aitrealconst_s80bit :
  77. begin
  78. current_procinfo.aktlocaldata.concat(tai_realconst.create_s80real(value_real,tfloatdef(resultdef).size));
  79. { range checking? }
  80. if floating_point_range_check_error and
  81. (tai_realconst(current_procinfo.aktlocaldata.last).value.s80val=MathInf.Value) then
  82. Message(parser_e_range_check_error);
  83. end;
  84. {$ifdef cpufloat128}
  85. aitrealconst_s128bit :
  86. begin
  87. current_procinfo.aktlocaldata.concat(tai_realconst.create_s128real(value_real));
  88. { range checking? }
  89. if floating_point_range_check_error and
  90. (tai_realconst(current_procinfo.aktlocaldata.last).value.s128val=MathInf.Value) then
  91. Message(parser_e_range_check_error);
  92. end;
  93. {$endif cpufloat128}
  94. { the round is necessary for native compilers where comp isn't a float }
  95. aitrealconst_s64comp :
  96. if (value_real>9223372036854775807.0) or (value_real<-9223372036854775808.0) then
  97. message(parser_e_range_check_error)
  98. else
  99. current_procinfo.aktlocaldata.concat(tai_realconst.create_s64compreal(round(value_real)));
  100. else
  101. internalerror(2005092401);
  102. end;
  103. end;
  104. location.reference.symbol:=lab_real;
  105. location.reference.refaddr:=addr_pcrel;
  106. end;
  107. begin
  108. crealconstnode:=trvrealconstnode;
  109. end.