ncgbas.pas 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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. p.GenerateAltSymbol;
  90. UsedAsmSymbolListInsert(p);
  91. end;
  92. p:=p.altsymbol;
  93. end;
  94. end;
  95. var
  96. hp,hp2 : tai;
  97. localfixup,parafixup,
  98. i : longint;
  99. skipnode : boolean;
  100. begin
  101. if inlining_procedure then
  102. begin
  103. CreateUsedAsmSymbolList;
  104. localfixup:=aktprocsym.definition.localst.address_fixup;
  105. parafixup:=aktprocsym.definition.parast.address_fixup;
  106. hp:=tai(p_asm.first);
  107. while assigned(hp) do
  108. begin
  109. hp2:=tai(hp.getcopy);
  110. skipnode:=false;
  111. case hp2.typ of
  112. ait_label :
  113. begin
  114. { regenerate the labels by setting altsymbol }
  115. ReLabel(tasmsymbol(tai_label(hp2).l));
  116. end;
  117. ait_const_rva,
  118. ait_const_symbol :
  119. begin
  120. ReLabel(tai_const_symbol(hp2).sym);
  121. end;
  122. ait_instruction :
  123. begin
  124. { fixup the references }
  125. for i:=1 to taicpu(hp2).ops do
  126. begin
  127. with taicpu(hp2).oper[i-1] do
  128. begin
  129. case typ of
  130. top_ref :
  131. begin
  132. case ref^.options of
  133. ref_parafixup :
  134. ref^.offsetfixup:=parafixup;
  135. ref_localfixup :
  136. ref^.offsetfixup:=localfixup;
  137. end;
  138. if assigned(ref^.symbol) then
  139. ReLabel(ref^.symbol);
  140. end;
  141. top_symbol :
  142. begin
  143. ReLabel(sym);
  144. end;
  145. end;
  146. end;
  147. end;
  148. end;
  149. ait_marker :
  150. begin
  151. { it's not an assembler block anymore }
  152. if (tai_marker(hp2).kind in [AsmBlockStart, AsmBlockEnd]) then
  153. skipnode:=true;
  154. end;
  155. else
  156. end;
  157. if not skipnode then
  158. exprasmList.concat(hp2)
  159. else
  160. hp2.free;
  161. hp:=tai(hp.next);
  162. end;
  163. { restore used symbols }
  164. UsedAsmSymbolListResetAltSym;
  165. DestroyUsedAsmSymbolList;
  166. end
  167. else
  168. begin
  169. { if the routine is an inline routine, then we must hold a copy
  170. because it can be necessary for inlining later }
  171. if (pocall_inline in aktprocsym.definition.proccalloptions) then
  172. exprasmList.concatlistcopy(p_asm)
  173. else
  174. exprasmList.concatlist(p_asm);
  175. end;
  176. if not (nf_object_preserved in flags) then
  177. maybe_loadself;
  178. end;
  179. {*****************************************************************************
  180. TBLOCKNODE
  181. *****************************************************************************}
  182. procedure tcgblocknode.pass_2;
  183. begin
  184. { do second pass on left node }
  185. if assigned(left) then
  186. secondpass(left);
  187. end;
  188. begin
  189. cnothingnode:=tcgnothingnode;
  190. casmnode:=tcgasmnode;
  191. cstatementnode:=tcgstatementnode;
  192. cblocknode:=tcgblocknode;
  193. end.
  194. {
  195. $Log$
  196. Revision 1.3 2001-05-18 22:31:06 peter
  197. * tasmnode.pass_2 is independent of cpu, moved to ncgbas
  198. * include ncgbas for independent nodes
  199. Revision 1.2 2001/04/13 01:22:08 peter
  200. * symtable change to classes
  201. * range check generation and errors fixed, make cycle DEBUG=1 works
  202. * memory leaks fixed
  203. Revision 1.1 2000/10/14 10:14:50 peter
  204. * moehrendorf oct 2000 rewrite
  205. }