cpupi.pas 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. {
  2. Copyright (c) 2002-2010 by Florian Klaempfl and Jonas Maebe
  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. unit cpupi;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. cutils,
  22. procinfo,cpuinfo, symtype,
  23. psub, cclasses;
  24. type
  25. { tcpuprocinfo }
  26. tcpuprocinfo=class(tcgprocinfo)
  27. public
  28. procedure postprocess_code; override;
  29. procedure set_first_temp_offset;override;
  30. end;
  31. implementation
  32. uses
  33. systems,globals, tgcpu,aasmdata,aasmcpu,aasmtai,
  34. tgobj,paramgr,symconst;
  35. procedure tcpuprocinfo.postprocess_code;
  36. function findfirst_tai_local(asmlist: TAsmList): tai_local;
  37. var
  38. hp: tai;
  39. begin
  40. result:=nil;
  41. if not assigned(asmlist) then
  42. exit;
  43. hp:=tai(asmlist.first);
  44. while assigned(hp) do
  45. begin
  46. if hp.typ=ait_local then
  47. begin
  48. result:=tai_local(hp);
  49. exit;
  50. end;
  51. hp:=tai(hp.Next);
  52. end;
  53. end;
  54. var
  55. templist : TAsmList;
  56. l : TWasmLocal;
  57. first_tai_local, last_tai_local: tai_local;
  58. begin
  59. templist := TAsmList.create;
  60. l := ttgwasm(tg).localvars.first;
  61. while Assigned(l) do begin
  62. templist.Concat( tai_local.create(l.typ));
  63. l := l.nextseq;
  64. end;
  65. aktproccode.insertListBefore(findfirst_tai_local(aktproccode),templist);
  66. templist.Free;
  67. first_tai_local:=findfirst_tai_local(aktproccode);
  68. if assigned(first_tai_local) then
  69. begin
  70. first_tai_local.first:=true;
  71. { also find the last tai_local in the group }
  72. last_tai_local:=first_tai_local;
  73. while assigned(last_tai_local.Next) and (tai(last_tai_local.Next).typ=ait_local) do
  74. last_tai_local:=tai_local(last_tai_local.Next);
  75. last_tai_local.last:=true;
  76. end;
  77. inherited postprocess_code;
  78. end;
  79. procedure tcpuprocinfo.set_first_temp_offset;
  80. var
  81. sz : integer;
  82. i : integer;
  83. sym: tsym;
  84. begin
  85. {
  86. Stackframe layout:
  87. sp:
  88. <incoming parameters>
  89. sp+first_temp_offset:
  90. <locals>
  91. <temp>
  92. }
  93. procdef.init_paraloc_info(calleeside);
  94. sz := procdef.calleeargareasize;
  95. tg.setfirsttemp(sz);
  96. end;
  97. initialization
  98. cprocinfo:=tcpuprocinfo;
  99. end.