3 Copyright (c) 1998-2000 by Florian Klaempfl
5 This unit is the interface of the compiler which can be used by
6 external programs to link in the compiler
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 ****************************************************************************}
25 possible compiler switches:
26 -----------------------------------------------------------------
27 TP to compile the compiler with Turbo or Borland Pascal
28 I386 generate a compiler for the Intel i386+
29 M68K generate a compiler for the M68000
30 GDB support of the GNU Debugger
31 EXTDEBUG some extra debug code is executed
32 SUPPORT_MMX only i386: releases the compiler switch
33 MMX which allows the compiler to generate
35 EXTERN_MSG Don't compile the msgfiles in the compiler, always
36 use external messagefiles
37 NOAG386INT no Intel Assembler output
38 NOAG386NSM no NASM output
39 -----------------------------------------------------------------
43 { One of Alpha, I386 or M68K must be defined }
54 {$fatal cannot define two CPU switches}
62 {$fatal cannot define two CPU switches}
70 {$fatal cannot define two CPU switches}
75 {$fatal One of the switches I386, Alpha, PowerPC or M68K must be defined}
80 {$fatal I386 switch must be on for MMX support}
88 { Use exception catching so the compiler goes futher after a Stop }
99 {$endif ndef NOUSEEXCEPT}
119 verbose
,comphook
,systems
,
120 cobjects
,files
,globals
,options
,parser
,symtable
,link
,import
,export,tokens
;
122 function Compile(const cmd
:string):longint;
125 { do we need to link }
126 IsExe
: boolean = false;
127 IsLibrary
: boolean = false;
135 CompilerInitedAfterArgs
,
136 CompilerInited
: boolean;
137 olddo_stop
: tstopprocedure
;
141 procedure RecoverStop
;{$ifndef FPC}far;{$endif}
143 if recoverpospointer
<>nil then
144 LongJmp(recoverpospointer
^,1)
153 LostMemory
: longint;
154 Procedure CheckMemory(LostMemory
: longint);
156 if LostMemory
<>0 then
158 Writeln('Memory Lost = '+tostr(LostMemory
));
160 def_gdb_stop(V_Warning
);
166 {****************************************************************************
168 ****************************************************************************}
170 procedure DoneCompiler
;
172 if not CompilerInited
then
174 { Free compiler if args are read }
181 if CompilerInitedAfterArgs
then
183 CompilerInitedAfterArgs
:=false;
190 { Free memory for the others }
191 CompilerInited
:=false;
196 recoverpospointer
:=nil;
197 longjump_used
:=false;
202 procedure InitCompiler(const cmd
:string);
204 if CompilerInited
then
206 { inits which need to be done before the arguments are parsed }
218 CompilerInited
:=true;
219 { this is needed here for the IDE
220 in case of compilation failure
221 at the previous compile }
223 { read the arguments }
225 { inits which depend on arguments }
231 CompilerInitedAfterArgs
:=true;
234 procedure minimal_stop
;{$ifndef fpc}far;{$endif}
241 function Compile(const cmd
:string):longint;
247 procedure writepathlist(w
:longint;l
:TSearchPathList
);
249 hp
: pstringqueueitem
;
252 while assigned(hp
) do
254 Message1(w
,hp
^.data
^);
259 function getrealtime
: real;
264 getrealtime
:=h
*3600.0+m
*60.0+s
+s100
/100.0;
270 recoverpos
: jmp_buf
;
276 do_stop
:=minimal_stop
;
278 do_stop
:=@minimal_stop
;
280 { Initialize the compiler }
284 Message1(general_t_compilername
,FixFileName(paramstr(0)));
285 Message1(general_d_sourceos
,source_os
.name
);
286 Message1(general_i_targetos
,target_os
.name
);
287 Message1(general_t_exepath
,exepath
);
288 WritePathList(general_t_unitpath
,unitsearchpath
);
289 WritePathList(general_t_includepath
,includesearchpath
);
290 WritePathList(general_t_librarypath
,librarysearchpath
);
291 WritePathList(general_t_objectpath
,objectsearchpath
);
294 Comment(V_Info
,'Memory: '+tostr(MemAvail
)+' Bytes Free');
299 if setjmp(recoverpos
)=0 then
301 recoverpospointer
:=@recoverpos
;
303 do_stop
:=recoverstop
;
305 do_stop
:=@recoverstop
;
308 starttime
:=getrealtime
;
309 if parapreprocess
then
310 parser
.preprocess(inputdir
+inputfile
+inputextension
)
312 parser
.compile(inputdir
+inputfile
+inputextension
,false);
313 if status
.errorcount
=0 then
315 starttime
:=getrealtime
-starttime
;
317 starttime
:=starttime
+3600.0*24.0;
318 Message2(general_i_abslines_compiled
,tostr(status
.compiledlines
),tostr(trunc(starttime
))+
319 '.'+tostr(trunc(frac(starttime
)*10)));
325 { Stop is always called, so we come here when a program is compiled or not }
327 { Stop the compiler, frees also memory }
328 { no message possible after this !! }
331 { Set the return value if an error has occurred }
332 if status
.errorcount
=0 then
340 LostMemory
:=system
.HeapSize
-MemAvail
-EntryMemUsed
;
341 CheckMemory(LostMemory
);
344 Writeln('Repetitive firstpass = '+tostr(firstpass_several
)+'/'+tostr(total_of_firstpass
));
348 Writeln('Memory used: ',system
.Heapsize
);
350 {$ifdef fixLeaksOnError}
356 {$endif fixLeaksOnError}
363 Revision 1.1 2002/02/19 08:21:58 sasu
366 Revision 1.1.2.4 2000/11/19 00:18:06 pierre
367 + IsLibrary boolean for IDE
369 Revision 1.1.2.3 2000/10/06 23:51:58 pierre
370 * avoid IDE crash after compilation failure
372 Revision 1.1.2.2 2000/08/21 09:09:08 jonas
373 - removed catch unit from uses clause for Linux (clashed with fpcatch
374 from IDE and is already in pp.pas for command line compiler)
376 Revision 1.1.2.1 2000/08/02 19:36:33 peter
379 Revision 1.1 2000/07/13 06:29:48 michael
382 Revision 1.51 2000/06/30 20:23:33 peter
383 * new message files layout with msg numbers (but still no code to
384 show the number on the screen)
386 Revision 1.50 2000/05/29 10:04:40 pierre
387 * New bunch of Gabor changes
389 Revision 1.49 2000/05/03 16:31:22 pierre
390 + easier debug when memory is lost
392 Revision 1.48 2000/04/05 21:18:04 pierre
393 * set NOUSEEXCEPT to remove use of setjump/longjump
395 Revision 1.47 2000/03/18 15:05:33 jonas
396 + added $maxfpuregisters 0 for compile() procedure
398 Revision 1.46 2000/02/09 13:22:50 peter
401 Revision 1.45 2000/01/11 17:16:04 jonas
402 * removed a lot of memory leaks when an error is encountered (caused by
403 procinfo and pstringcontainers). There are still plenty left though :)
405 Revision 1.44 2000/01/11 16:56:22 jonas
406 - removed call to do_stop at the end of compile() since it obviously breaks the
407 automatic compiling of units. Make cycle worked though! 8)
409 Revision 1.43 2000/01/11 16:53:24 jonas
410 + call do_stop at the end of compile()
412 Revision 1.42 2000/01/07 01:14:23 peter
413 * updated copyright to 2000
415 Revision 1.41 1999/12/02 17:34:34 peter
416 * preprocessor support. But it fails on the caret in type blocks
418 Revision 1.40 1999/11/18 13:43:48 pierre
419 + IsExe global var needed for IDE
421 Revision 1.39 1999/11/12 11:03:50 peter
422 * searchpaths changed to stringqueue object
424 Revision 1.38 1999/11/09 23:47:53 pierre
425 + minimal_stop to avoid memory loss with -iTO switch
427 Revision 1.37 1999/11/06 14:34:20 peter
428 * truncated log to 20 revs
430 Revision 1.36 1999/10/12 21:20:41 florian
431 * new codegenerator compiles again
433 Revision 1.35 1999/09/28 19:48:45 florian
436 Revision 1.34 1999/09/16 23:05:52 florian
437 * m68k compiler is again compilable (only gas writer, no assembler reader)
439 Revision 1.33 1999/09/07 15:10:04 pierre
440 * use do_halt instead of halt
442 Revision 1.32 1999/09/02 18:47:44 daniel
443 * Could not compile with TP, some arrays moved to heap
444 * NOAG386BIN default for TP
445 * AG386* files were not compatible with TP, fixed.
447 Revision 1.31 1999/08/20 10:17:01 michael
450 Revision 1.30 1999/08/11 17:26:31 peter
451 * tlinker object is now inherited for win32 and dos
452 * postprocessexecutable is now a method of tlinker
454 Revision 1.29 1999/08/09 22:13:43 peter
455 * fixed writing of lost memory which should be after donecompiler
457 Revision 1.28 1999/08/04 13:02:40 jonas
458 * all tokens now start with an underscore
461 Revision 1.27 1999/08/02 21:28:56 florian
462 * the main branch psub.pas is now used for
465 Revision 1.26 1999/08/02 20:46:57 michael
466 * Alpha aware switch detection