cpupi.pas 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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,globtype,
  22. procinfo,cpuinfo, symtype,aasmbase,
  23. psub, cclasses;
  24. type
  25. { tcpuprocinfo }
  26. tcpuprocinfo=class(tcgprocinfo)
  27. public
  28. procedure setup_eh; override;
  29. procedure postprocess_code; override;
  30. procedure set_first_temp_offset;override;
  31. end;
  32. implementation
  33. uses
  34. systems,globals,cpubase,tgcpu,aasmdata,aasmcpu,aasmtai,cgexcept,
  35. tgobj,paramgr,symconst,symcpu;
  36. {*****************************************************************************
  37. twasmexceptionstatehandler
  38. *****************************************************************************}
  39. type
  40. twasmexceptionstatehandler = class(tcgexceptionstatehandler)
  41. class procedure new_exception(list:TAsmList;const t:texceptiontemps; const exceptframekind: texceptframekind; out exceptstate: texceptionstate); override;
  42. class procedure free_exception(list: TAsmList; const t: texceptiontemps; const s: texceptionstate; a: aint; endexceptlabel: tasmlabel; onlyfree:boolean); override;
  43. class procedure handle_nested_exception(list:TAsmList;var t:texceptiontemps;var entrystate: texceptionstate); override;
  44. end;
  45. class procedure twasmexceptionstatehandler.new_exception(list:TAsmList;const t:texceptiontemps; const exceptframekind: texceptframekind; out exceptstate: texceptionstate);
  46. begin
  47. list.Concat(tai_comment.Create(strpnew('TODO: new_exception')));
  48. end;
  49. class procedure twasmexceptionstatehandler.free_exception(list: TAsmList; const t: texceptiontemps; const s: texceptionstate; a: aint; endexceptlabel: tasmlabel; onlyfree:boolean);
  50. begin
  51. list.Concat(tai_comment.Create(strpnew('TODO: free_exception')));
  52. end;
  53. class procedure twasmexceptionstatehandler.handle_nested_exception(list:TAsmList;var t:texceptiontemps;var entrystate: texceptionstate);
  54. begin
  55. list.Concat(tai_comment.Create(strpnew('TODO: handle_nested_exception')));
  56. end;
  57. {*****************************************************************************
  58. tcpuprocinfo
  59. *****************************************************************************}
  60. procedure tcpuprocinfo.setup_eh;
  61. begin
  62. cexceptionstatehandler:=twasmexceptionstatehandler;
  63. end;
  64. procedure tcpuprocinfo.postprocess_code;
  65. function findfirst_tai_local(asmlist: TAsmList): tai_local;
  66. var
  67. hp: tai;
  68. begin
  69. result:=nil;
  70. if not assigned(asmlist) then
  71. exit;
  72. hp:=tai(asmlist.first);
  73. while assigned(hp) do
  74. begin
  75. if hp.typ=ait_local then
  76. begin
  77. result:=tai_local(hp);
  78. exit;
  79. end;
  80. hp:=tai(hp.Next);
  81. end;
  82. end;
  83. procedure replace_local_frame_pointer(asmlist: TAsmList);
  84. var
  85. hp: tai;
  86. instr: taicpu;
  87. l: Integer;
  88. begin
  89. if not assigned(asmlist) then
  90. exit;
  91. hp:=tai(asmlist.first);
  92. while assigned(hp) do
  93. begin
  94. if hp.typ=ait_instruction then
  95. begin
  96. instr:=taicpu(hp);
  97. for l:=0 to instr.ops-1 do
  98. if (instr.oper[l]^.typ=top_reg) and (instr.oper[l]^.reg=NR_LOCAL_FRAME_POINTER_REG) then
  99. instr.loadref(l,tcpuprocdef(current_procinfo.procdef).frame_pointer_ref);
  100. end;
  101. hp:=tai(hp.Next);
  102. end;
  103. end;
  104. var
  105. templist : TAsmList;
  106. l : TWasmLocal;
  107. first_tai_local, last_tai_local: tai_local;
  108. begin
  109. templist := TAsmList.create;
  110. l := ttgwasm(tg).localvars.first;
  111. while Assigned(l) do begin
  112. templist.Concat( tai_local.create(l.typ));
  113. l := l.nextseq;
  114. end;
  115. aktproccode.insertListBefore(findfirst_tai_local(aktproccode),templist);
  116. templist.Free;
  117. first_tai_local:=findfirst_tai_local(aktproccode);
  118. if assigned(first_tai_local) then
  119. begin
  120. first_tai_local.first:=true;
  121. { also find the last tai_local in the group }
  122. last_tai_local:=first_tai_local;
  123. while assigned(last_tai_local.Next) and (tai(last_tai_local.Next).typ=ait_local) do
  124. last_tai_local:=tai_local(last_tai_local.Next);
  125. last_tai_local.last:=true;
  126. end;
  127. replace_local_frame_pointer(aktproccode);
  128. inherited postprocess_code;
  129. end;
  130. procedure tcpuprocinfo.set_first_temp_offset;
  131. var
  132. sz : integer;
  133. i : integer;
  134. sym: tsym;
  135. begin
  136. {
  137. Stackframe layout:
  138. sp:
  139. <incoming parameters>
  140. sp+first_temp_offset:
  141. <locals>
  142. <temp>
  143. }
  144. procdef.init_paraloc_info(calleeside);
  145. sz := procdef.calleeargareasize;
  146. tg.setfirsttemp(sz);
  147. end;
  148. initialization
  149. cprocinfo:=tcpuprocinfo;
  150. end.