n386bas.pas 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. {
  2. $Id$
  3. Copyright (c) 1998-2000 by Florian Klaempfl
  4. This unit handles the codegeneration pass
  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 n386bas;
  19. {$i defines.inc}
  20. interface
  21. uses
  22. node,nbas;
  23. type
  24. ti386statementnode = class(tstatementnode)
  25. procedure pass_2;override;
  26. end;
  27. ti386blocknode = class(tblocknode)
  28. procedure pass_2;override;
  29. end;
  30. ti386asmnode = class(tasmnode)
  31. procedure pass_2;override;
  32. end;
  33. implementation
  34. uses
  35. globals,
  36. aasm,cpubase,cpuasm,
  37. symtable,symconst,
  38. pass_2,tgeni386,
  39. cgai386;
  40. procedure ti386asmnode.pass_2;
  41. procedure ReLabel(var p:pasmsymbol);
  42. begin
  43. if p^.proclocal then
  44. begin
  45. if not assigned(p^.altsymbol) then
  46. begin
  47. p^.GenerateAltSymbol;
  48. UsedAsmSymbolListInsert(p);
  49. end;
  50. p:=p^.altsymbol;
  51. end;
  52. end;
  53. var
  54. hp,hp2 : pai;
  55. localfixup,parafixup,
  56. i : longint;
  57. skipnode : boolean;
  58. begin
  59. if inlining_procedure then
  60. begin
  61. InitUsedAsmSymbolList;
  62. localfixup:=aktprocsym^.definition^.localst^.address_fixup;
  63. parafixup:=aktprocsym^.definition^.parast^.address_fixup;
  64. hp:=pai(p_asm^.first);
  65. while assigned(hp) do
  66. begin
  67. hp2:=pai(hp^.getcopy);
  68. skipnode:=false;
  69. case hp2^.typ of
  70. ait_label :
  71. begin
  72. { regenerate the labels by setting altsymbol }
  73. ReLabel(pasmsymbol(pai_label(hp2)^.l));
  74. end;
  75. ait_const_rva,
  76. ait_const_symbol :
  77. begin
  78. ReLabel(pai_const_symbol(hp2)^.sym);
  79. end;
  80. ait_instruction :
  81. begin
  82. {$ifdef i386}
  83. { fixup the references }
  84. for i:=1 to paicpu(hp2)^.ops do
  85. begin
  86. with paicpu(hp2)^.oper[i-1] do
  87. begin
  88. case typ of
  89. top_ref :
  90. begin
  91. case ref^.options of
  92. ref_parafixup :
  93. ref^.offsetfixup:=parafixup;
  94. ref_localfixup :
  95. ref^.offsetfixup:=localfixup;
  96. end;
  97. if assigned(ref^.symbol) then
  98. ReLabel(ref^.symbol);
  99. end;
  100. top_symbol :
  101. begin
  102. ReLabel(sym);
  103. end;
  104. end;
  105. end;
  106. end;
  107. {$endif i386}
  108. end;
  109. ait_marker :
  110. begin
  111. { it's not an assembler block anymore }
  112. if (pai_marker(hp2)^.kind in [AsmBlockStart, AsmBlockEnd]) then
  113. skipnode:=true;
  114. end;
  115. else
  116. end;
  117. if not skipnode then
  118. exprasmlist^.concat(hp2)
  119. else
  120. dispose(hp2,done);
  121. hp:=pai(hp^.next);
  122. end;
  123. { restore used symbols }
  124. UsedAsmSymbolListResetAltSym;
  125. DoneUsedAsmSymbolList;
  126. end
  127. else
  128. begin
  129. { if the routine is an inline routine, then we must hold a copy
  130. becuase it can be necessary for inlining later }
  131. if (pocall_inline in aktprocsym^.definition^.proccalloptions) then
  132. exprasmlist^.concatlistcopy(p_asm)
  133. else
  134. exprasmlist^.concatlist(p_asm);
  135. end;
  136. if not (nf_object_preserved in flags) then
  137. begin
  138. {$ifdef i386}
  139. maybe_loadesi;
  140. {$endif}
  141. {$ifdef m68k}
  142. maybe_loada5;
  143. {$endif}
  144. end;
  145. end;
  146. procedure ti386statementnode.pass_2;
  147. var
  148. hp : tnode;
  149. begin
  150. hp:=self;
  151. while assigned(hp) do
  152. begin
  153. if assigned(tstatementnode(hp).right) then
  154. begin
  155. cleartempgen;
  156. {!!!!!!
  157. oldrl:=temptoremove;
  158. temptoremove:=new(plinkedlist,init);
  159. }
  160. secondpass(tstatementnode(hp).right);
  161. { !!!!!!!
  162. some temporary data which can't be released elsewhere
  163. removetemps(exprasmlist,temptoremove);
  164. dispose(temptoremove,done);
  165. temptoremove:=oldrl;
  166. }
  167. end;
  168. hp:=tstatementnode(hp).left;
  169. end;
  170. end;
  171. procedure ti386blocknode.pass_2;
  172. begin
  173. { do second pass on left node }
  174. if assigned(left) then
  175. secondpass(left);
  176. end;
  177. begin
  178. cstatementnode:=ti386statementnode;
  179. cblocknode:=ti386blocknode;
  180. casmnode:=ti386asmnode;
  181. end.
  182. {
  183. $Log$
  184. Revision 1.1 2000-10-15 09:33:31 peter
  185. * moved n386*.pas to i386/ cpu_target dir
  186. Revision 1.1 2000/10/14 10:14:48 peter
  187. * moehrendorf oct 2000 rewrite
  188. }