This is the main program of the compiler. It initializes some data, reads configuration file, processes command line parameters, loads library (reports error if it is not found), initializes module data, checks for the main file, resets compilation timer, compiles the source file and writes compilation status.
Error handling is done with few routines which save and restore stack position so any compiler error always returns control flow to the main program.
Compilation timer actually measures the time for the Compile procedure. This time is reported after successful compilation and includes also I/O operations so it is usually shorter on the second run when the source files are already cached.
If command line switch
/F was used then instead of compilation status the source file position is displayed. The error reported if the source position is found is actually not an error, only a message ‘Target address found‘ is displayed.
GreetingString: PChar = 'Turbo Pascal Version 7.0 Copyright (c) 1983,92 Borland International';
Program TPC16; Uses Strings, Parser, Scanner, IOUtils, ResWords, CommVars; begin Writeln (GreetingString); CmdPtr := Ptr (PrefixSeg, $80); CmdPtr [Byte (CmdPtr ) + 1] := #0; CmdPtr  := ' '; CfgPtr := FileBuffer; Get_TPL_CFG_Directory; Read_TPC_CFG; CompilerModeOptions := [cmoCreateExeFile, cmoCompileToDisk]; LinkerOptions := ; CommandLineConditionalDefines := InitialConditionalDefines; StartOfSourceFileStructures := @FileStructure; ProcessCompilerParameters; StrCopy (TempStr, GlobalModuleData^.LibraryName); CurrentFileName := TempStr; FindFilePath (TempStr, Dir_TPL_CFG or Ext_Original); LoadLibrary; Case LastError of FileNotFound: Writeln ('Warning: ', TempStr, ' not found.'); NoError: else WriteCompilationErrorAndHalt; end; With GlobalModuleData^ do begin InitialEnvironmentFlags := EnvironmentFlags; InitialCompilerSwitches := CompilerSwitches; ModuleStack := Stack; ModuleHeapMin := HeapMin; ModuleHeapMax := HeapMax; end; CurrentFileName := MainFileName; FindFilePath (CurrentFileName, Dir_None or Ext_PAS); StartCounter := InterruptCounter; CompilationInProgress := True; Compile; CompilationInProgress := False; StopCounter := InterruptCounter; If LastError <> NoError then WriteCompilationErrorAndHalt; If cmoFindError in CompilerModeOptions then begin FindAndWriteSourceLine; WriteCompilationErrorAndHalt; end; WriteCompilationStatus; end.