nx86cal.pas 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. Common x86 support 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 nx86cal;
  18. {$i fpcdefs.inc}
  19. interface
  20. { $define AnsiStrRef}
  21. uses
  22. symdef,
  23. cgutils,
  24. ncgcal;
  25. type
  26. { tx86callnode }
  27. tx86callnode = class(tcgcallnode)
  28. protected
  29. procedure do_release_unused_return_value;override;
  30. procedure set_result_location(realresdef: tstoreddef);override;
  31. function can_call_ref(var ref: treference):boolean;override;
  32. procedure do_call_ref(ref: treference);override;
  33. end;
  34. implementation
  35. uses
  36. cgobj,
  37. cgbase,cpubase,cgx86,cga,aasmdata,aasmcpu;
  38. {*****************************************************************************
  39. TX86CALLNODE
  40. *****************************************************************************}
  41. procedure tx86callnode.do_release_unused_return_value;
  42. begin
  43. case location.loc of
  44. LOC_FPUREGISTER :
  45. begin
  46. { release FPU stack }
  47. emit_reg(A_FSTP,S_NO,NR_FPU_RESULT_REG);
  48. tcgx86(cg).dec_fpu_stack;
  49. end
  50. else
  51. inherited do_release_unused_return_value;
  52. end;
  53. end;
  54. procedure tx86callnode.set_result_location(realresdef: tstoreddef);
  55. begin
  56. if (retloc.location^.loc=LOC_FPUREGISTER) then
  57. begin
  58. tcgx86(cg).inc_fpu_stack;
  59. location_reset(location,LOC_FPUREGISTER,retloc.location^.size);
  60. location.register:=retloc.location^.register;
  61. end
  62. else
  63. inherited set_result_location(realresdef);
  64. end;
  65. function tx86callnode.can_call_ref(var ref: treference): boolean;
  66. begin
  67. tcgx86(cg).make_simple_ref(current_asmdata.CurrAsmList,ref);
  68. result:=true;
  69. end;
  70. procedure tx86callnode.do_call_ref(ref: treference);
  71. begin
  72. current_asmdata.CurrAsmList.concat(taicpu.op_ref(A_CALL,S_NO,ref));
  73. end;
  74. end.