njvmcal.pas 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. {
  2. Copyright (c) 2011 by Jonas Maebe
  3. JVM-specific code for call nodes
  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 njvmcal;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. symdef,
  22. ncgcal;
  23. type
  24. { tjvmcallnode }
  25. tjvmcallnode = class(tcgcallnode)
  26. protected
  27. procedure set_result_location(realresdef: tstoreddef); override;
  28. procedure release_unused_return_value_cpu;override;
  29. procedure extra_post_call_code; override;
  30. end;
  31. implementation
  32. uses
  33. verbose,globtype,
  34. symtype,defutil,ncal,
  35. cgbase,cgutils,tgobj,
  36. cpubase,aasmdata,aasmcpu,
  37. hlcgobj,hlcgcpu;
  38. {*****************************************************************************
  39. TJVMCALLNODE
  40. *****************************************************************************}
  41. procedure tjvmcallnode.set_result_location(realresdef: tstoreddef);
  42. begin
  43. location_reset_ref(location,LOC_REFERENCE,def_cgsize(realresdef),1);
  44. tg.gettemp(current_asmdata.CurrAsmList,realresdef.size,1,tt_normal,location.reference);
  45. end;
  46. procedure tjvmcallnode.release_unused_return_value_cpu;
  47. begin
  48. case resultdef.size of
  49. 0:
  50. ;
  51. 1..4:
  52. begin
  53. current_asmdata.CurrAsmList.concat(taicpu.op_none(a_pop));
  54. thlcgjvm(hlcg).decstack(1);
  55. end;
  56. 8:
  57. begin
  58. current_asmdata.CurrAsmList.concat(taicpu.op_none(a_pop2));
  59. thlcgjvm(hlcg).decstack(2);
  60. end
  61. else
  62. internalerror(2011010305);
  63. end;
  64. end;
  65. procedure tjvmcallnode.extra_post_call_code;
  66. var
  67. totalremovesize: longint;
  68. realresdef: tdef;
  69. begin
  70. if not assigned(typedef) then
  71. realresdef:=tstoreddef(resultdef)
  72. else
  73. realresdef:=tstoreddef(typedef);
  74. totalremovesize:=pushedparasize-realresdef.size;
  75. { remove parameters from internal evaluation stack counter (in case of
  76. e.g. no parameters and a result, it can also increase) }
  77. if totalremovesize>0 then
  78. thlcgjvm(hlcg).decstack(totalremovesize shr 2)
  79. else if totalremovesize<0 then
  80. thlcgjvm(hlcg).incstack((-totalremovesize) shr 2);
  81. end;
  82. begin
  83. ccallnode:=tjvmcallnode;
  84. end.