ncgbas.pas 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. {
  2. $Id$
  3. Copyright (c) 2000 by Florian Klaempfl
  4. This unit implements some basic nodes
  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 ncgbas;
  19. {$i defines.inc}
  20. interface
  21. uses
  22. node,nbas;
  23. type
  24. tcgnothingnode = class(tnothingnode)
  25. procedure pass_2;override;
  26. end;
  27. tcgasmnode = class(tasmnode)
  28. procedure pass_2;override;
  29. end;
  30. tcgstatementnode = class(tstatementnode)
  31. procedure pass_2;override;
  32. end;
  33. tcgblocknode = class(tblocknode)
  34. procedure pass_2;override;
  35. end;
  36. implementation
  37. uses
  38. globtype,systems,
  39. cutils,cclasses,verbose,globals,
  40. aasm,symconst,symsym,symtable,types,
  41. htypechk,
  42. cpubase,cpuasm,
  43. nflw,pass_2
  44. {$ifdef newcg}
  45. ,cgbase
  46. {$else newcg}
  47. ,hcodegen
  48. {$endif}
  49. {$ifdef i386}
  50. ,cgai386
  51. {$endif}
  52. ,tgcpu
  53. ;
  54. {*****************************************************************************
  55. TNOTHING
  56. *****************************************************************************}
  57. procedure tcgnothingnode.pass_2;
  58. begin
  59. { avoid an abstract rte }
  60. end;
  61. {*****************************************************************************
  62. TSTATEMENTNODE
  63. *****************************************************************************}
  64. procedure tcgstatementnode.pass_2;
  65. var
  66. hp : tnode;
  67. begin
  68. hp:=self;
  69. while assigned(hp) do
  70. begin
  71. if assigned(tstatementnode(hp).right) then
  72. begin
  73. cleartempgen;
  74. secondpass(tstatementnode(hp).right);
  75. end;
  76. hp:=tstatementnode(hp).left;
  77. end;
  78. end;
  79. {*****************************************************************************
  80. TASMNODE
  81. *****************************************************************************}
  82. procedure tcgasmnode.pass_2;
  83. procedure ReLabel(var p:tasmsymbol);
  84. begin
  85. if p.proclocal then
  86. begin
  87. if not assigned(p.altsymbol) then
  88. begin
  89. { generatealtsymbol will also increase the refs }
  90. p.GenerateAltSymbol;
  91. UsedAsmSymbolListInsert(p);
  92. end
  93. else
  94. begin
  95. { increase the refs, they will be decreased when the
  96. asmnode is destroyed }
  97. inc(p.refs);
  98. end;
  99. p:=p.altsymbol;
  100. end;
  101. end;
  102. var
  103. hp,hp2 : tai;
  104. localfixup,parafixup,
  105. i : longint;
  106. skipnode : boolean;
  107. begin
  108. if inlining_procedure then
  109. begin
  110. CreateUsedAsmSymbolList;
  111. localfixup:=aktprocsym.definition.localst.address_fixup;
  112. parafixup:=aktprocsym.definition.parast.address_fixup;
  113. hp:=tai(p_asm.first);
  114. while assigned(hp) do
  115. begin
  116. hp2:=tai(hp.getcopy);
  117. skipnode:=false;
  118. case hp2.typ of
  119. ait_label :
  120. begin
  121. { regenerate the labels by setting altsymbol }
  122. ReLabel(tasmsymbol(tai_label(hp2).l));
  123. end;
  124. ait_const_rva,
  125. ait_const_symbol :
  126. begin
  127. ReLabel(tai_const_symbol(hp2).sym);
  128. end;
  129. ait_instruction :
  130. begin
  131. { fixup the references }
  132. for i:=1 to taicpu(hp2).ops do
  133. begin
  134. with taicpu(hp2).oper[i-1] do
  135. begin
  136. case typ of
  137. top_ref :
  138. begin
  139. case ref^.options of
  140. ref_parafixup :
  141. ref^.offsetfixup:=parafixup;
  142. ref_localfixup :
  143. ref^.offsetfixup:=localfixup;
  144. end;
  145. if assigned(ref^.symbol) then
  146. ReLabel(ref^.symbol);
  147. end;
  148. top_symbol :
  149. begin
  150. ReLabel(sym);
  151. end;
  152. end;
  153. end;
  154. end;
  155. end;
  156. ait_marker :
  157. begin
  158. { it's not an assembler block anymore }
  159. if (tai_marker(hp2).kind in [AsmBlockStart, AsmBlockEnd]) then
  160. skipnode:=true;
  161. end;
  162. else
  163. end;
  164. if not skipnode then
  165. exprasmList.concat(hp2)
  166. else
  167. hp2.free;
  168. hp:=tai(hp.next);
  169. end;
  170. { restore used symbols }
  171. UsedAsmSymbolListResetAltSym;
  172. DestroyUsedAsmSymbolList;
  173. end
  174. else
  175. begin
  176. { if the routine is an inline routine, then we must hold a copy
  177. because it can be necessary for inlining later }
  178. if (pocall_inline in aktprocsym.definition.proccalloptions) then
  179. exprasmList.concatlistcopy(p_asm)
  180. else
  181. exprasmList.concatlist(p_asm);
  182. end;
  183. if not (nf_object_preserved in flags) then
  184. maybe_loadself;
  185. end;
  186. {*****************************************************************************
  187. TBLOCKNODE
  188. *****************************************************************************}
  189. procedure tcgblocknode.pass_2;
  190. begin
  191. { do second pass on left node }
  192. if assigned(left) then
  193. secondpass(left);
  194. end;
  195. begin
  196. cnothingnode:=tcgnothingnode;
  197. casmnode:=tcgasmnode;
  198. cstatementnode:=tcgstatementnode;
  199. cblocknode:=tcgblocknode;
  200. end.
  201. {
  202. $Log$
  203. Revision 1.4 2001-06-02 19:22:15 peter
  204. * refs count for relabeled asmsymbols fixed
  205. Revision 1.3 2001/05/18 22:31:06 peter
  206. * tasmnode.pass_2 is independent of cpu, moved to ncgbas
  207. * include ncgbas for independent nodes
  208. Revision 1.2 2001/04/13 01:22:08 peter
  209. * symtable change to classes
  210. * range check generation and errors fixed, make cycle DEBUG=1 works
  211. * memory leaks fixed
  212. Revision 1.1 2000/10/14 10:14:50 peter
  213. * moehrendorf oct 2000 rewrite
  214. }