cpupi.pas 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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_functype(asmlist: TAsmList): tai_functype;
  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_functype then
  76. begin
  77. result:=tai_functype(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: Boolean;
  108. local: tai_local;
  109. begin
  110. templist:=TAsmList.create;
  111. local:=nil;
  112. first:=true;
  113. l:=ttgwasm(tg).localvars.first;
  114. while Assigned(l) do
  115. begin
  116. local:=tai_local.create(l.typ);
  117. local.first:=first;
  118. first:=false;
  119. templist.Concat(local);
  120. l:=l.nextseq;
  121. end;
  122. if assigned(local) then
  123. local.last:=true;
  124. aktproccode.insertListAfter(findfirst_tai_functype(aktproccode),templist);
  125. templist.Free;
  126. replace_local_frame_pointer(aktproccode);
  127. inherited postprocess_code;
  128. end;
  129. procedure tcpuprocinfo.set_first_temp_offset;
  130. var
  131. sz : integer;
  132. i : integer;
  133. sym: tsym;
  134. begin
  135. {
  136. Stackframe layout:
  137. sp:
  138. <incoming parameters>
  139. sp+first_temp_offset:
  140. <locals>
  141. <temp>
  142. }
  143. procdef.init_paraloc_info(calleeside);
  144. sz := procdef.calleeargareasize;
  145. tg.setfirsttemp(sz);
  146. end;
  147. initialization
  148. cprocinfo:=tcpuprocinfo;
  149. end.