{ $Id$ Copyright (c) 1998-2000 by Florian Klaempfl This unit handles the codegeneration pass This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. **************************************************************************** } unit pass_2; {$i defines.inc} interface uses node; type tenumflowcontrol = (fc_exit,fc_break,fc_continue); tflowcontrol = set of tenumflowcontrol; var flowcontrol : tflowcontrol; { produces assembler for the expression in variable p } { and produces an assembler node at the end } procedure generatecode(var p : tnode); { produces the actual code } function do_secondpass(var p : tnode) : boolean; procedure secondpass(var p : tnode); implementation uses {$ifdef logsecondpass} cutils, {$endif} globtype,systems,verbose, cclasses,globals, symconst,symbase,symtype,symsym,aasm, pass_1,hcodegen,temp_gen,regvars,nflw,tgcpu; {***************************************************************************** SecondPass *****************************************************************************} {$ifdef logsecondpass} procedure logsecond(ht:tnodetype; entry: boolean); const secondnames: array[tnodetype] of string[13] = ('add-addn', {addn} 'add-muln', {muln} 'add-subn', {subn} 'moddiv-divn', {divn} 'add-symdifn', {symdifn} 'moddiv-modn', {modn} 'assignment', {assignn} 'load', {loadn} 'nothing-range', {range} 'add-ltn', {ltn} 'add-lten', {lten} 'add-gtn', {gtn} 'add-gten', {gten} 'add-equaln', {equaln} 'add-unequaln', {unequaln} 'in', {inn} 'add-orn', {orn} 'add-xorn', {xorn} 'shlshr-shrn', {shrn} 'shlshr-shln', {shln} 'add-slashn', {slashn} 'add-andn', {andn} 'subscriptn', {subscriptn} 'dderef', {derefn} 'addr', {addrn} 'doubleaddr', {doubleaddrn} 'ordconst', {ordconstn} 'typeconv', {typeconvn} 'calln', {calln} 'nothing-callp', {callparan} 'realconst', {realconstn} 'fixconst', {fixconstn} 'unaryminus', {unaryminusn} 'asm', {asmn} 'vecn', {vecn} 'pointerconst', {pointerconstn} 'stringconst', {stringconstn} 'funcret', {funcretn} 'selfn', {selfn} 'not', {notn} 'inline', {inlinen} 'niln', {niln} 'error', {errorn} 'nothing-typen', {typen} 'hnewn', {hnewn} 'hdisposen', {hdisposen} 'newn', {newn} 'simplenewDISP', {simpledisposen} 'setelement', {setelementn} 'setconst', {setconstn} 'blockn', {blockn} 'statement', {statementn} 'nothing-loopn', {loopn} 'ifn', {ifn} 'breakn', {breakn} 'continuen', {continuen} '_while_REPEAT', {repeatn} '_WHILE_repeat', {whilen} 'for', {forn} 'exitn', {exitn} 'with', {withn} 'case', {casen} 'label', {labeln} 'goto', {goton} 'simpleNEWdisp', {simplenewn} 'tryexcept', {tryexceptn} 'raise', {raisen} 'nothing-swtch', {switchesn} 'tryfinally', {tryfinallyn} 'on', {onn} 'is', {isn} 'as', {asn} 'error-caret', {caretn} 'fail', {failn} 'add-startstar', {starstarn} 'procinline', {procinlinen} 'arrayconstruc', {arrayconstructn} 'noth-arrcnstr', {arrayconstructrangen} 'nothing-nothg', {nothingn} 'loadvmt' {loadvmtn} ); var p: pchar; begin if entry then p := strpnew('second'+secondnames[ht]+' (entry)') else p := strpnew('second'+secondnames[ht]+' (exit)'); exprasmlist.concat(tai_asm_comment.create(p)); end; {$endif logsecondpass} procedure secondpass(var p : tnode); var oldcodegenerror : boolean; oldlocalswitches : tlocalswitches; oldpos : tfileposinfo; {$ifdef TEMPREGDEBUG} prevp : pptree; {$endif TEMPREGDEBUG} begin if not(nf_error in p.flags) then begin oldcodegenerror:=codegenerror; oldlocalswitches:=aktlocalswitches; oldpos:=aktfilepos; {$ifdef TEMPREGDEBUG} testregisters32; prevp:=curptree; curptree:=@p; p^.usableregs:=usablereg32; {$endif TEMPREGDEBUG} aktfilepos:=p.fileinfo; aktlocalswitches:=p.localswitches; codegenerror:=false; {$ifdef logsecondpass} logsecond(p.nodetype,true); {$endif logsecondpass} p.pass_2; {$ifdef logsecondpass} logsecond(p.nodetype,false); {$endif logsecondpass} if codegenerror then include(p.flags,nf_error); codegenerror:=codegenerror or oldcodegenerror; aktlocalswitches:=oldlocalswitches; aktfilepos:=oldpos; {$ifdef TEMPREGDEBUG} curptree:=prevp; {$endif TEMPREGDEBUG} {$ifdef EXTTEMPREGDEBUG} if p.usableregs-usablereg32>p.reallyusedregs then p.reallyusedregs:=p.usableregs-usablereg32; if p.reallyusedregs