2
0

procinfo.pas 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. ;
  31. const
  32. inherited_inlining_flags : tprocinfoflags = [pi_do_call];
  33. type
  34. {# This object gives information on the current routine being
  35. compiled.
  36. }
  37. tprocinfo = class(tlinkedlistitem)
  38. { pointer to parent in nested procedures }
  39. parent : tprocinfo;
  40. {# the definition of the routine itself }
  41. procdef : tprocdef;
  42. { procinfo of the main procedure that is inlining
  43. the current function, only used in tcgcallnode.inlined_pass2 }
  44. inlining_procinfo : tprocinfo;
  45. { file location of begin of procedure }
  46. entrypos : tfileposinfo;
  47. { file location of end of procedure }
  48. exitpos : tfileposinfo;
  49. { local switches at begin of procedure }
  50. entryswitches : tlocalswitches;
  51. { local switches at end of procedure }
  52. exitswitches : tlocalswitches;
  53. { Size of the parameters on the stack }
  54. para_stack_size : longint;
  55. { Offset of temp after para/local are allocated }
  56. tempstart : longint;
  57. {# some collected informations about the procedure
  58. see pi_xxxx constants above
  59. }
  60. flags : tprocinfoflags;
  61. { register used as frame pointer }
  62. framepointer : tregister;
  63. { register containing currently the got }
  64. got : tregister;
  65. CurrGOTLabel : tasmlabel;
  66. { Holds the reference used to store all saved registers. }
  67. save_regs_ref : treference;
  68. { Labels for TRUE/FALSE condition, BREAK and CONTINUE }
  69. CurrBreakLabel,
  70. CurrContinueLabel,
  71. CurrTrueLabel,
  72. CurrFalseLabel : tasmlabel;
  73. { label to leave the sub routine }
  74. CurrExitLabel : 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 : TAsmList;
  79. { Data (like jump tables) that belongs to this routine }
  80. aktlocaldata : TAsmList;
  81. { max. of space need for parameters }
  82. maxpushedparasize : aint;
  83. constructor create(aparent:tprocinfo);virtual;
  84. destructor destroy;override;
  85. procedure allocate_push_parasize(size:longint);
  86. function calc_stackframe_size:longint;virtual;
  87. { Set the address of the first temp, can be used to allocate
  88. space for pushing parameters }
  89. procedure set_first_temp_offset;virtual;
  90. { Generate parameter information }
  91. procedure generate_parameter_info;virtual;
  92. end;
  93. tcprocinfo = class of tprocinfo;
  94. var
  95. cprocinfo : tcprocinfo;
  96. { information about the current sub routine being parsed (@var(pprocinfo))}
  97. current_procinfo : tprocinfo;
  98. implementation
  99. uses
  100. cutils,systems,
  101. tgobj,cgobj,
  102. paramgr
  103. ;
  104. {****************************************************************************
  105. TProcInfo
  106. ****************************************************************************}
  107. constructor tprocinfo.create(aparent:tprocinfo);
  108. begin
  109. parent:=aparent;
  110. procdef:=nil;
  111. para_stack_size:=0;
  112. flags:=[];
  113. framepointer:=NR_FRAME_POINTER_REG;
  114. maxpushedparasize:=0;
  115. { asmlists }
  116. aktproccode:=TAsmList.Create;
  117. aktlocaldata:=TAsmList.Create;
  118. reference_reset(save_regs_ref);
  119. { labels }
  120. current_asmdata.getjumplabel(CurrExitLabel);
  121. current_asmdata.getjumplabel(CurrGOTLabel);
  122. CurrBreakLabel:=nil;
  123. CurrContinueLabel:=nil;
  124. CurrTrueLabel:=nil;
  125. CurrFalseLabel:=nil;
  126. maxpushedparasize:=0;
  127. end;
  128. destructor tprocinfo.destroy;
  129. begin
  130. aktproccode.free;
  131. aktlocaldata.free;
  132. end;
  133. procedure tprocinfo.allocate_push_parasize(size:longint);
  134. begin
  135. if size>maxpushedparasize then
  136. maxpushedparasize:=size;
  137. end;
  138. function tprocinfo.calc_stackframe_size:longint;
  139. begin
  140. result:=Align(tg.direction*tg.lasttemp,current_settings.alignment.localalignmin);
  141. end;
  142. procedure tprocinfo.set_first_temp_offset;
  143. begin
  144. end;
  145. procedure tprocinfo.generate_parameter_info;
  146. begin
  147. { generate callee paraloc register info, it returns the size that
  148. is allocated on the stack }
  149. para_stack_size:=paramanager.create_paraloc_info(procdef,calleeside);
  150. end;
  151. end.