cpupi.pas 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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,cpubase,tgcpu,aasmdata,aasmcpu,aasmtai,
  34. tgobj,paramgr,symconst,symcpu;
  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. procedure replace_local_frame_pointer(asmlist: TAsmList);
  55. var
  56. hp: tai;
  57. instr: taicpu;
  58. l: Integer;
  59. begin
  60. if not assigned(asmlist) then
  61. exit;
  62. hp:=tai(asmlist.first);
  63. while assigned(hp) do
  64. begin
  65. if hp.typ=ait_instruction then
  66. begin
  67. instr:=taicpu(hp);
  68. for l:=0 to instr.ops-1 do
  69. if (instr.oper[l]^.typ=top_reg) and (instr.oper[l]^.reg=NR_LOCAL_FRAME_POINTER_REG) then
  70. instr.loadref(l,tcpuprocdef(current_procinfo.procdef).frame_pointer_ref);
  71. end;
  72. hp:=tai(hp.Next);
  73. end;
  74. end;
  75. var
  76. templist : TAsmList;
  77. l : TWasmLocal;
  78. first_tai_local, last_tai_local: tai_local;
  79. begin
  80. templist := TAsmList.create;
  81. l := ttgwasm(tg).localvars.first;
  82. while Assigned(l) do begin
  83. templist.Concat( tai_local.create(l.typ));
  84. l := l.nextseq;
  85. end;
  86. aktproccode.insertListBefore(findfirst_tai_local(aktproccode),templist);
  87. templist.Free;
  88. first_tai_local:=findfirst_tai_local(aktproccode);
  89. if assigned(first_tai_local) then
  90. begin
  91. first_tai_local.first:=true;
  92. { also find the last tai_local in the group }
  93. last_tai_local:=first_tai_local;
  94. while assigned(last_tai_local.Next) and (tai(last_tai_local.Next).typ=ait_local) do
  95. last_tai_local:=tai_local(last_tai_local.Next);
  96. last_tai_local.last:=true;
  97. end;
  98. replace_local_frame_pointer(aktproccode);
  99. inherited postprocess_code;
  100. end;
  101. procedure tcpuprocinfo.set_first_temp_offset;
  102. var
  103. sz : integer;
  104. i : integer;
  105. sym: tsym;
  106. begin
  107. {
  108. Stackframe layout:
  109. sp:
  110. <incoming parameters>
  111. sp+first_temp_offset:
  112. <locals>
  113. <temp>
  114. }
  115. procdef.init_paraloc_info(calleeside);
  116. sz := procdef.calleeargareasize;
  117. tg.setfirsttemp(sz);
  118. end;
  119. initialization
  120. cprocinfo:=tcpuprocinfo;
  121. end.