procinfo.pas 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. Information about the current procedure that is being compiled
  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 procinfo;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. { common }
  22. cclasses,
  23. { global }
  24. globtype,globals,verbose,
  25. { symtable }
  26. symconst,symtype,symdef,symsym,
  27. { aasm }
  28. cpubase,cpuinfo,cgbase,cgutils,
  29. aasmbase,aasmtai,aasmdata,
  30. optutils
  31. ;
  32. const
  33. inherited_inlining_flags : tprocinfoflags =
  34. [pi_do_call,
  35. { the stack frame can't be removed in this case }
  36. pi_has_assembler_block,
  37. pi_uses_exceptions];
  38. type
  39. {# This object gives information on the current routine being
  40. compiled.
  41. }
  42. tprocinfo = class(tlinkedlistitem)
  43. { pointer to parent in nested procedures }
  44. parent : tprocinfo;
  45. {# the definition of the routine itself }
  46. procdef : tprocdef;
  47. { procinfo of the main procedure that is inlining
  48. the current function, only used in tcgcallnode.inlined_pass2 }
  49. inlining_procinfo : tprocinfo;
  50. { file location of begin of procedure }
  51. entrypos : tfileposinfo;
  52. { file location of end of procedure }
  53. exitpos : tfileposinfo;
  54. { local switches at begin of procedure }
  55. entryswitches : tlocalswitches;
  56. { local switches at end of procedure }
  57. exitswitches : tlocalswitches;
  58. { Size of the parameters on the stack }
  59. para_stack_size : longint;
  60. { Offset of temp after para/local are allocated }
  61. tempstart : longint;
  62. {# some collected informations about the procedure
  63. see pi_xxxx constants above
  64. }
  65. flags : tprocinfoflags;
  66. { register used as frame pointer }
  67. framepointer : tregister;
  68. { register containing currently the got }
  69. got : tregister;
  70. CurrGOTLabel : tasmlabel;
  71. { Holds the reference used to store all saved registers. }
  72. save_regs_ref : treference;
  73. { Labels for TRUE/FALSE condition, BREAK and CONTINUE }
  74. CurrBreakLabel,
  75. CurrContinueLabel,
  76. CurrTrueLabel,
  77. CurrFalseLabel : tasmlabel;
  78. { label to leave the sub routine }
  79. CurrExitLabel : tasmlabel;
  80. {# The code for the routine itself, excluding entry and
  81. exit code. This is a linked list of tai classes.
  82. }
  83. aktproccode : TAsmList;
  84. { Data (like jump tables) that belongs to this routine }
  85. aktlocaldata : TAsmList;
  86. { max. of space need for parameters }
  87. maxpushedparasize : aint;
  88. constructor create(aparent:tprocinfo);virtual;
  89. destructor destroy;override;
  90. procedure allocate_push_parasize(size:longint);
  91. function calc_stackframe_size:longint;virtual;
  92. { Set the address of the first temp, can be used to allocate
  93. space for pushing parameters }
  94. procedure set_first_temp_offset;virtual;
  95. { Generate parameter information }
  96. procedure generate_parameter_info;virtual;
  97. { Allocate got register }
  98. procedure allocate_got_register(list: TAsmList);virtual;
  99. end;
  100. tcprocinfo = class of tprocinfo;
  101. var
  102. cprocinfo : tcprocinfo;
  103. { information about the current sub routine being parsed (@var(pprocinfo))}
  104. current_procinfo : tprocinfo;
  105. implementation
  106. uses
  107. cutils,systems,
  108. tgobj,cgobj,
  109. paramgr
  110. ;
  111. {****************************************************************************
  112. TProcInfo
  113. ****************************************************************************}
  114. constructor tprocinfo.create(aparent:tprocinfo);
  115. begin
  116. parent:=aparent;
  117. procdef:=nil;
  118. para_stack_size:=0;
  119. flags:=[];
  120. framepointer:=NR_FRAME_POINTER_REG;
  121. maxpushedparasize:=0;
  122. { asmlists }
  123. aktproccode:=TAsmList.Create;
  124. aktlocaldata:=TAsmList.Create;
  125. reference_reset(save_regs_ref,sizeof(aint));
  126. { labels }
  127. current_asmdata.getjumplabel(CurrExitLabel);
  128. current_asmdata.getjumplabel(CurrGOTLabel);
  129. CurrBreakLabel:=nil;
  130. CurrContinueLabel:=nil;
  131. CurrTrueLabel:=nil;
  132. CurrFalseLabel:=nil;
  133. maxpushedparasize:=0;
  134. end;
  135. destructor tprocinfo.destroy;
  136. begin
  137. aktproccode.free;
  138. aktlocaldata.free;
  139. end;
  140. procedure tprocinfo.allocate_push_parasize(size:longint);
  141. begin
  142. if size>maxpushedparasize then
  143. maxpushedparasize:=size;
  144. end;
  145. function tprocinfo.calc_stackframe_size:longint;
  146. begin
  147. result:=Align(tg.direction*tg.lasttemp,current_settings.alignment.localalignmin);
  148. end;
  149. procedure tprocinfo.set_first_temp_offset;
  150. begin
  151. end;
  152. procedure tprocinfo.generate_parameter_info;
  153. begin
  154. { generate callee paraloc register info, it returns the size that
  155. is allocated on the stack }
  156. para_stack_size:=paramanager.create_paraloc_info(procdef,calleeside);
  157. end;
  158. procedure tprocinfo.allocate_got_register(list: TAsmList);
  159. begin
  160. { most os/cpu combo's don't use this yet, so not yet abstract }
  161. end;
  162. end.