cpupi.pas 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. {
  2. Copyright (c) 2008 by Florian Klaempfl
  3. This unit contains the CPU specific part of tprocinfo
  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. { This unit contains the CPU specific part of tprocinfo. }
  18. unit cpupi;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. globtype,cutils,
  23. procinfo,cpuinfo,psub;
  24. type
  25. tcpuprocinfo = class(tcgprocinfo)
  26. // procedure handle_body_start;override;
  27. // procedure after_pass1;override;
  28. procedure set_first_temp_offset;override;
  29. function calc_stackframe_size:longint;override;
  30. procedure postprocess_code;override;
  31. end;
  32. implementation
  33. uses
  34. globals,systems,verbose,
  35. cpubase,
  36. aasmtai,aasmdata,
  37. tgobj,
  38. symconst,symsym,paramgr,
  39. cgbase,
  40. cgobj,
  41. aasmcpu;
  42. procedure tcpuprocinfo.set_first_temp_offset;
  43. begin
  44. if tg.direction = -1 then
  45. tg.setfirsttemp(-1)
  46. else if not (po_nostackframe in procdef.procoptions) then
  47. tg.setfirsttemp(maxpushedparasize+1)
  48. else
  49. tg.setfirsttemp(maxpushedparasize);
  50. end;
  51. function tcpuprocinfo.calc_stackframe_size:longint;
  52. begin
  53. if tg.lasttemp=2 then
  54. { correct that lasttemp is 2 in case of an empty stack due to the post-decrement pushing and an additional correction
  55. in tgobj.setfirsttemp.
  56. }
  57. result:=maxpushedparasize
  58. else
  59. result:=tg.direction*tg.lasttemp+maxpushedparasize;
  60. end;
  61. procedure tcpuprocinfo.postprocess_code;
  62. begin
  63. { because of the limited branch distance of cond. branches, they must be replaced
  64. sometimes by normal jmps and an inverse branch }
  65. if not(finalizeavrcode(aktproccode)) then
  66. message1(cg_w_cannot_compile_subroutine,procdef.fullprocname(false));
  67. end;
  68. begin
  69. cprocinfo:=tcpuprocinfo;
  70. end.