pass_1.pas 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. {
  2. $Id$
  3. Copyright (c) 1998-2000 by Florian Klaempfl
  4. This unit handles the typecheck and node conversion 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 pass_1;
  19. {$i defines.inc}
  20. interface
  21. uses
  22. node;
  23. procedure firstpass(var p : tnode);
  24. function do_firstpass(var p : tnode) : boolean;
  25. var
  26. { the block node of the current exception block to check gotos }
  27. aktexceptblock : tnode;
  28. implementation
  29. uses
  30. globtype,systems,
  31. cutils,cobjects,verbose,globals,
  32. aasm,symtable,types,
  33. htypechk,
  34. cpubase,cpuasm
  35. {$ifdef newcg}
  36. ,cgbase
  37. ,tgcpu
  38. {$else newcg}
  39. ,hcodegen
  40. {$ifdef i386}
  41. ,tgeni386
  42. {$endif}
  43. {$ifdef m68k}
  44. ,tgen68k
  45. {$endif}
  46. {$endif}
  47. ;
  48. {*****************************************************************************
  49. Global procedures
  50. *****************************************************************************}
  51. procedure firstpass(var p : tnode);
  52. var
  53. oldcodegenerror : boolean;
  54. oldlocalswitches : tlocalswitches;
  55. oldpos : tfileposinfo;
  56. hp : tnode;
  57. {$ifdef extdebug}
  58. {$ifdef dummy}
  59. str1,str2 : string;
  60. oldp : tnode;
  61. {$endif}
  62. not_first : boolean;
  63. {$endif extdebug}
  64. begin
  65. {$ifdef extdebug}
  66. inc(total_of_firstpass);
  67. if (p.firstpasscount>0) and only_one_pass then
  68. exit;
  69. {$endif extdebug}
  70. oldcodegenerror:=codegenerror;
  71. oldpos:=aktfilepos;
  72. oldlocalswitches:=aktlocalswitches;
  73. {$ifdef extdebug}
  74. if p.firstpasscount>0 then
  75. begin
  76. {$ifdef dummy}
  77. move(p^,str1[1],sizeof(ttree));
  78. str1[0]:=char(sizeof(ttree));
  79. new(oldp);
  80. old^:=p^;
  81. {$endif}
  82. not_first:=true;
  83. inc(firstpass_several);
  84. end
  85. else
  86. not_first:=false;
  87. {$endif extdebug}
  88. if not(nf_error in p.flags) then
  89. begin
  90. codegenerror:=false;
  91. aktfilepos:=p.fileinfo;
  92. aktlocalswitches:=p.localswitches;
  93. hp:=p.pass_1;
  94. { should the node be replaced? }
  95. if assigned(hp) then
  96. begin
  97. p.free;
  98. p:=hp;
  99. end;
  100. aktlocalswitches:=oldlocalswitches;
  101. aktfilepos:=oldpos;
  102. if codegenerror then
  103. include(p.flags,nf_error);
  104. codegenerror:=codegenerror or oldcodegenerror;
  105. end
  106. else
  107. codegenerror:=true;
  108. {$ifdef extdebug}
  109. if not_first then
  110. begin
  111. {$ifdef dummy}
  112. { dirty trick to compare two ttree's (PM) }
  113. move(p^,str2[1],sizeof(ttree));
  114. str2[0]:=char(sizeof(ttree));
  115. if str1<>str2 then
  116. begin
  117. comment(v_debug,'tree changed after first counting pass '
  118. +tostr(longint(p.treetype)));
  119. compare_trees(oldp,p);
  120. end;
  121. dispose(oldp);
  122. {$endif dummy}
  123. end;
  124. if count_ref then
  125. inc(p.firstpasscount);
  126. {$endif extdebug}
  127. end;
  128. function do_firstpass(var p : tnode) : boolean;
  129. begin
  130. aktexceptblock:=nil;
  131. codegenerror:=false;
  132. firstpass(p);
  133. do_firstpass:=codegenerror;
  134. end;
  135. end.
  136. {
  137. $Log$
  138. Revision 1.9 2000-10-14 10:14:51 peter
  139. * moehrendorf oct 2000 rewrite
  140. Revision 1.8 2000/10/01 19:48:25 peter
  141. * lot of compile updates for cg11
  142. Revision 1.7 2000/09/30 16:08:45 peter
  143. * more cg11 updates
  144. Revision 1.6 2000/09/28 19:49:52 florian
  145. *** empty log message ***
  146. Revision 1.5 2000/09/24 21:15:34 florian
  147. * some errors fix to get more stuff compilable
  148. Revision 1.4 2000/09/24 15:06:21 peter
  149. * use defines.inc
  150. Revision 1.3 2000/09/19 23:09:07 pierre
  151. * problems wih extdebug cond. solved
  152. Revision 1.2 2000/07/13 11:32:44 michael
  153. + removed logs
  154. }