procinfo.pas 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl
  4. Information about the current procedure that is being compiled
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit procinfo;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. { common }
  23. cclasses,
  24. { global }
  25. globtype,globals,verbose,
  26. { symtable }
  27. symconst,symtype,symdef,symsym,
  28. { aasm }
  29. cpubase,cpuinfo,cgbase,
  30. aasmbase,aasmtai
  31. ;
  32. type
  33. tprocinfoflag=(
  34. {# procedure uses asm }
  35. pi_uses_asm,
  36. {# procedure does a call }
  37. pi_do_call,
  38. {# procedure has a try statement = no register optimization }
  39. pi_uses_exceptions,
  40. {# procedure is declared as @var(assembler), don't optimize}
  41. pi_is_assembler,
  42. {# procedure contains data which needs to be finalized }
  43. pi_needs_implicit_finally
  44. );
  45. tprocinfoflags=set of tprocinfoflag;
  46. type
  47. {# This object gives information on the current routine being
  48. compiled.
  49. }
  50. tprocinfo = class(tlinkedlistitem)
  51. { pointer to parent in nested procedures }
  52. parent : tprocinfo;
  53. {# the definition of the routine itself }
  54. procdef : tprocdef;
  55. { file location of begin of procedure }
  56. entrypos : tfileposinfo;
  57. { file location of end of procedure }
  58. exitpos : tfileposinfo;
  59. { local switches at begin of procedure }
  60. entryswitches : tlocalswitches;
  61. { local switches at end of procedure }
  62. exitswitches : tlocalswitches;
  63. { Size of the parameters on the stack }
  64. para_stack_size : longint;
  65. {# some collected informations about the procedure
  66. see pi_xxxx constants above
  67. }
  68. flags : tprocinfoflags;
  69. { register used as frame pointer }
  70. framepointer : tregister;
  71. { Holds the reference used to store alll saved registers. }
  72. save_regs_ref : treference;
  73. { label to leave the sub routine }
  74. aktexitlabel : tasmlabel;
  75. {# The code for the routine itself, excluding entry and
  76. exit code. This is a linked list of tai classes.
  77. }
  78. aktproccode : taasmoutput;
  79. { Data (like jump tables) that belongs to this routine }
  80. aktlocaldata : taasmoutput;
  81. constructor create(aparent:tprocinfo);virtual;
  82. destructor destroy;override;
  83. { Allocate framepointer so it can not be used by the
  84. register allocator }
  85. procedure allocate_framepointer_reg;virtual;
  86. procedure allocate_push_parasize(size:longint);virtual;
  87. function calc_stackframe_size:longint;virtual;
  88. { Set the address of the first temp, can be used to allocate
  89. space for pushing parameters }
  90. procedure set_first_temp_offset;virtual;
  91. { Generate parameter information }
  92. procedure generate_parameter_info;virtual;
  93. { This procedure is called after the pass 1 of the subroutine body is done.
  94. Here the address fix ups to generate code for the body must be done.
  95. }
  96. {procedure after_pass1;virtual;}
  97. end;
  98. pregvarinfo = ^tregvarinfo;
  99. tregvarinfo = record
  100. regvars : array[1..maxvarregs] of tvarsym;
  101. regvars_para : array[1..maxvarregs] of boolean;
  102. regvars_refs : array[1..maxvarregs] of longint;
  103. fpuregvars : array[1..maxfpuvarregs] of tvarsym;
  104. fpuregvars_para : array[1..maxfpuvarregs] of boolean;
  105. fpuregvars_refs : array[1..maxfpuvarregs] of longint;
  106. end;
  107. tcprocinfo = class of tprocinfo;
  108. var
  109. cprocinfo : tcprocinfo;
  110. { information about the current sub routine being parsed (@var(pprocinfo))}
  111. current_procinfo : tprocinfo;
  112. { save the size of pushed parameter, needed for aligning }
  113. pushedparasize : longint;
  114. implementation
  115. uses
  116. cutils,systems,
  117. cresstr,
  118. tgobj,rgobj,
  119. defutil,
  120. fmodule
  121. ,symbase,paramgr
  122. ;
  123. {****************************************************************************
  124. TProcInfo
  125. ****************************************************************************}
  126. constructor tprocinfo.create(aparent:tprocinfo);
  127. begin
  128. parent:=aparent;
  129. procdef:=nil;
  130. para_stack_size:=0;
  131. flags:=[];
  132. framepointer:=NR_FRAME_POINTER_REG;
  133. { asmlists }
  134. aktproccode:=Taasmoutput.Create;
  135. aktlocaldata:=Taasmoutput.Create;
  136. reference_reset(save_regs_ref);
  137. { labels }
  138. objectlibrary.getlabel(aktexitlabel);
  139. end;
  140. destructor tprocinfo.destroy;
  141. begin
  142. aktproccode.free;
  143. aktlocaldata.free;
  144. end;
  145. procedure tprocinfo.allocate_framepointer_reg;
  146. begin
  147. if framepointer=NR_FRAME_POINTER_REG then
  148. begin
  149. { Make sure the register allocator won't allocate registers
  150. into ebp }
  151. include(rg.used_in_proc_int,RS_FRAME_POINTER_REG);
  152. exclude(rg.unusedregsint,RS_FRAME_POINTER_REG);
  153. end;
  154. end;
  155. procedure tprocinfo.allocate_push_parasize(size:longint);
  156. begin
  157. end;
  158. function tprocinfo.calc_stackframe_size:longint;
  159. begin
  160. result:=Align(tg.direction*tg.lasttemp,aktalignment.localalignmin);
  161. end;
  162. procedure tprocinfo.set_first_temp_offset;
  163. begin
  164. end;
  165. procedure tprocinfo.generate_parameter_info;
  166. begin
  167. { generate callee paraloc register info, it returns the size that
  168. is allocated on the stack }
  169. para_stack_size:=paramanager.create_paraloc_info(procdef,calleeside);
  170. end;
  171. end.
  172. {
  173. $Log$
  174. Revision 1.2 2003-10-03 22:00:33 peter
  175. * parameter alignment fixes
  176. Revision 1.1 2003/10/01 20:34:49 peter
  177. * procinfo unit contains tprocinfo
  178. * cginfo renamed to cgbase
  179. * moved cgmessage to verbose
  180. * fixed ppc and sparc compiles
  181. }