globals.pas 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649
  1. {
  2. $Id$
  3. Copyright (C) 1998-2000 by Florian Klaempfl
  4. This unit implements some support functions and global variables
  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 globals;
  19. {$i defines.inc}
  20. interface
  21. uses
  22. {$ifdef win32}
  23. windows,
  24. {$endif}
  25. {$ifdef unix}
  26. {$ifdef ver1_0}
  27. linux,
  28. {$else}
  29. unix,
  30. {$endif}
  31. {$endif}
  32. {$ifdef os2}
  33. doscalls,
  34. {$endif}
  35. {$ifdef Delphi}
  36. SysUtils,
  37. dmisc,
  38. {$else}
  39. strings,
  40. dos,
  41. {$endif}
  42. cutils,cclasses,
  43. globtype,version,systems;
  44. const
  45. {$ifdef Splitheap}
  46. testsplit : boolean = false;
  47. {$endif Splitheap}
  48. delphimodeswitches : tmodeswitches=
  49. [m_delphi,m_all,m_class,m_objpas,m_result,m_string_pchar,
  50. m_pointer_2_procedure,m_autoderef,m_tp_procvar,m_initfinal,m_default_ansistring,
  51. m_out,m_default_para,m_hintdirective,m_duplicate_names];
  52. fpcmodeswitches : tmodeswitches=
  53. [m_fpc,m_all,m_string_pchar,m_nested_comment,m_repeat_forward,
  54. m_cvar_support,m_initfinal,m_add_pointer];
  55. objfpcmodeswitches : tmodeswitches=
  56. [m_objfpc,m_fpc,m_all,m_class,m_objpas,m_result,m_string_pchar,m_nested_comment,
  57. m_repeat_forward,m_cvar_support,m_initfinal,m_add_pointer,m_out,m_default_para];
  58. tpmodeswitches : tmodeswitches=
  59. [m_tp7,m_all,m_tp_procvar,m_duplicate_names];
  60. gpcmodeswitches : tmodeswitches=
  61. [m_gpc,m_all];
  62. type
  63. pfileposinfo = ^tfileposinfo;
  64. tfileposinfo = record
  65. line : longint;
  66. column : word;
  67. fileindex : word;
  68. { moduleindex : word; }
  69. end;
  70. TSearchPathList = class(TStringList)
  71. procedure AddPath(s:string;addfirst:boolean);
  72. procedure AddList(list:TSearchPathList;addfirst:boolean);
  73. function FindFile(const f : string;var foundfile:string):boolean;
  74. end;
  75. var
  76. { specified inputfile }
  77. inputdir : dirstr;
  78. inputfile : namestr;
  79. inputextension : extstr;
  80. { specified outputfile with -o parameter }
  81. outputfile : namestr;
  82. { specified with -FE or -FU }
  83. outputexedir : dirstr;
  84. outputunitdir : dirstr;
  85. { things specified with parameters }
  86. paralinkoptions,
  87. paradynamiclinker : string;
  88. parapreprocess : boolean;
  89. { directory where the utils can be found (options -FD) }
  90. utilsdirectory : dirstr;
  91. { some flags for global compiler switches }
  92. do_build,
  93. do_release,
  94. do_make : boolean;
  95. not_unit_proc : boolean;
  96. { path for searching units, different paths can be seperated by ; }
  97. exepath : dirstr; { Path to ppc }
  98. librarysearchpath,
  99. unitsearchpath,
  100. objectsearchpath,
  101. includesearchpath : TSearchPathList;
  102. { deffile }
  103. usewindowapi : boolean;
  104. description : string;
  105. dllversion : string;
  106. dllmajor,dllminor,dllrevision : word; { revision only for netware }
  107. akttokenpos, { position of the last token }
  108. aktfilepos : tfileposinfo; { current position }
  109. { ad 18.05.2001: Screen and Threadname for Netware }
  110. nwscreenname : string;
  111. nwthreadname : string;
  112. nwcopyright : string;
  113. block_type : tblock_type; { type of currently parsed block }
  114. in_args : boolean; { arguments must be checked especially }
  115. parsing_para_level : integer; { parameter level, used to convert
  116. proc calls to proc loads in firstcalln }
  117. compile_level : word;
  118. make_ref : boolean;
  119. resolving_forward : boolean; { used to add forward reference as second ref }
  120. use_esp_stackframe : boolean; { to test for call with ESP as stack frame }
  121. inlining_procedure : boolean; { are we inlining a procedure }
  122. statement_level : integer;
  123. exceptblockcounter : integer; { each except block gets a unique number check gotos }
  124. aktexceptblock : integer; { the exceptblock number of the current block (0 if none) }
  125. have_local_threadvars : boolean; { set if a table of local threadvars-tables is present and has to be initialized }
  126. { commandline values }
  127. initdefines : tstringlist;
  128. initglobalswitches : tglobalswitches;
  129. initmoduleswitches : tmoduleswitches;
  130. initlocalswitches : tlocalswitches;
  131. initmodeswitches : tmodeswitches;
  132. {$IFDEF testvarsets}
  133. Initsetalloc, {0=fixed, 1 =var}
  134. {$ENDIF}
  135. initpackenum : longint;
  136. initalignment : talignmentinfo;
  137. initoptprocessor,
  138. initspecificoptprocessor : tprocessors;
  139. initasmmode : tasmmode;
  140. initinterfacetype : tinterfacetypes;
  141. initoutputformat : tasm;
  142. initdefproccall : tproccalloption;
  143. { current state values }
  144. aktglobalswitches : tglobalswitches;
  145. aktmoduleswitches : tmoduleswitches;
  146. aktlocalswitches : tlocalswitches;
  147. nextaktlocalswitches : tlocalswitches;
  148. localswitcheschanged : boolean;
  149. aktmodeswitches : tmodeswitches;
  150. {$IFDEF testvarsets}
  151. aktsetalloc,
  152. {$ENDIF}
  153. aktpackenum : longint;
  154. aktmaxfpuregisters : longint;
  155. aktalignment : talignmentinfo;
  156. aktoptprocessor,
  157. aktspecificoptprocessor : tprocessors;
  158. aktasmmode : tasmmode;
  159. aktinterfacetype : tinterfacetypes;
  160. aktoutputformat : tasm;
  161. aktdefproccall : tproccalloption;
  162. { Memory sizes }
  163. heapsize,
  164. maxheapsize,
  165. stacksize : longint;
  166. {$Ifdef EXTDEBUG}
  167. total_of_firstpass,
  168. firstpass_several : longint;
  169. {$ifdef FPC}
  170. EntryMemUsed : longint;
  171. {$endif FPC}
  172. { parameter switches }
  173. debugstop : boolean;
  174. {$EndIf EXTDEBUG}
  175. { windows / OS/2 application type }
  176. apptype : tapptype;
  177. const
  178. RelocSection : boolean = true;
  179. RelocSectionSetExplicitly : boolean = false;
  180. LinkTypeSetExplicitly : boolean = false;
  181. DLLsource : boolean = false;
  182. DLLImageBase : pstring = nil;
  183. UseDeffileForExport : boolean = true;
  184. ForceDeffileForExport : boolean = false;
  185. { used to set all registers used for each global function
  186. this should dramatically decrease the number of
  187. recompilations needed PM }
  188. simplify_ppu : boolean = true;
  189. { should we allow non static members ? }
  190. allow_only_static : boolean = false;
  191. Inside_asm_statement : boolean = false;
  192. global_unit_count : word = 0;
  193. { for error info in pp.pas }
  194. parser_current_file : string = '';
  195. {$ifdef m68k}
  196. { PalmOS resources }
  197. palmos_applicationname : string = 'FPC Application';
  198. palmos_applicationid : string[4] = 'FPCA';
  199. {$endif m68k}
  200. procedure abstract;
  201. function bstoslash(const s : string) : string;
  202. function getdatestr:string;
  203. function gettimestr:string;
  204. function filetimestring( t : longint) : string;
  205. procedure DefaultReplacements(var s:string);
  206. function GetCurrentDir:string;
  207. function path_absolute(const s : string) : boolean;
  208. Function PathExists ( F : String) : Boolean;
  209. Function FileExists ( Const F : String) : Boolean;
  210. Function RemoveFile(const f:string):boolean;
  211. Function RemoveDir(d:string):boolean;
  212. Function GetFileTime ( Var F : File) : Longint;
  213. Function GetNamedFileTime ( Const F : String) : Longint;
  214. Function SplitPath(const s:string):string;
  215. Function SplitFileName(const s:string):string;
  216. Function SplitName(const s:string):string;
  217. Function SplitExtension(Const HStr:String):String;
  218. Function AddExtension(Const HStr,ext:String):String;
  219. Function ForceExtension(Const HStr,ext:String):String;
  220. Function FixPath(s:string;allowdot:boolean):string;
  221. function FixFileName(const s:string):string;
  222. function TargetFixPath(s:string;allowdot:boolean):string;
  223. function TargetFixFileName(const s:string):string;
  224. procedure SplitBinCmd(const s:string;var bstr,cstr:string);
  225. function FindFile(const f : string;path : string;var foundfile:string):boolean;
  226. function FindExe(const bin:string;var foundfile:string):boolean;
  227. function GetShortName(const n:string):string;
  228. Procedure Shell(const command:string);
  229. function GetEnvPChar(const envname:string):pchar;
  230. procedure FreeEnvPChar(p:pchar);
  231. Function SetCompileMode(const s:string; changeInit: boolean):boolean;
  232. function SetAktProcCall(const s:string; changeInit: boolean):boolean;
  233. procedure InitGlobals;
  234. procedure DoneGlobals;
  235. function string2guid(const s: string; var GUID: TGUID): boolean;
  236. function guid2string(const GUID: TGUID): string;
  237. function UpdateAlignmentStr(s:string;var a:talignmentinfo):boolean;
  238. implementation
  239. uses
  240. comphook;
  241. procedure abstract;
  242. begin
  243. do_internalerror(255);
  244. end;
  245. function bstoslash(const s : string) : string;
  246. {
  247. return string s with all \ changed into /
  248. }
  249. var
  250. i : longint;
  251. begin
  252. for i:=1to length(s) do
  253. if s[i]='\' then
  254. bstoslash[i]:='/'
  255. else
  256. bstoslash[i]:=s[i];
  257. bstoslash[0]:=s[0];
  258. end;
  259. {****************************************************************************
  260. Time Handling
  261. ****************************************************************************}
  262. Function L0(l:longint):string;
  263. {
  264. return the string of value l, if l<10 then insert a zero, so
  265. the string is always at least 2 chars '01','02',etc
  266. }
  267. var
  268. s : string;
  269. begin
  270. Str(l,s);
  271. if l<10 then
  272. s:='0'+s;
  273. L0:=s;
  274. end;
  275. function gettimestr:string;
  276. {
  277. get the current time in a string HH:MM:SS
  278. }
  279. var
  280. hour,min,sec,hsec : word;
  281. begin
  282. {$ifdef delphi}
  283. dmisc.gettime(hour,min,sec,hsec);
  284. {$else delphi}
  285. dos.gettime(hour,min,sec,hsec);
  286. {$endif delphi}
  287. gettimestr:=L0(Hour)+':'+L0(min)+':'+L0(sec);
  288. end;
  289. function getdatestr:string;
  290. {
  291. get the current date in a string YY/MM/DD
  292. }
  293. var
  294. Year,Month,Day,Wday : Word;
  295. begin
  296. {$ifdef delphi}
  297. dmisc.getdate(year,month,day,wday);
  298. {$else}
  299. dos.getdate(year,month,day,wday);
  300. {$endif}
  301. getdatestr:=L0(Year)+'/'+L0(Month)+'/'+L0(Day);
  302. end;
  303. function filetimestring( t : longint) : string;
  304. {
  305. convert dos datetime t to a string YY/MM/DD HH:MM:SS
  306. }
  307. var
  308. DT : DateTime;
  309. begin
  310. if t=-1 then
  311. begin
  312. FileTimeString:='Not Found';
  313. exit;
  314. end;
  315. unpacktime(t,DT);
  316. filetimestring:=L0(dt.Year)+'/'+L0(dt.Month)+'/'+L0(dt.Day)+' '+L0(dt.Hour)+':'+L0(dt.min)+':'+L0(dt.sec);
  317. end;
  318. {****************************************************************************
  319. Default Macro Handling
  320. ****************************************************************************}
  321. procedure DefaultReplacements(var s:string);
  322. begin
  323. { Replace some macro's }
  324. Replace(s,'$FPCVER',version_string);
  325. Replace(s,'$VERSION',version_string);
  326. Replace(s,'$FULLVERSION',full_version_string);
  327. Replace(s,'$FPCDATE',date_string);
  328. Replace(s,'$FPCTARGET',target_cpu_string);
  329. Replace(s,'$FPCCPU',target_cpu_string);
  330. Replace(s,'$TARGET',target_path);
  331. Replace(s,'$FPCOS',target_path);
  332. end;
  333. {****************************************************************************
  334. File Handling
  335. ****************************************************************************}
  336. function GetCurrentDir:string;
  337. var
  338. CurrentDir : string;
  339. begin
  340. GetDir(0,CurrentDir);
  341. GetCurrentDir:=FixPath(CurrentDir,false);
  342. end;
  343. function path_absolute(const s : string) : boolean;
  344. {
  345. is path s an absolute path?
  346. }
  347. begin
  348. path_absolute:=false;
  349. {$ifdef unix}
  350. if (length(s)>0) and (s[1]='/') then
  351. path_absolute:=true;
  352. {$else unix}
  353. {$ifdef amiga}
  354. if ((length(s)>0) and ((s[1]='\') or (s[1]='/'))) or (Pos(':',s) = length(s)) then
  355. path_absolute:=true;
  356. {$else}
  357. if ((length(s)>0) and ((s[1]='\') or (s[1]='/'))) or
  358. ((length(s)>2) and (s[2]=':') and ((s[3]='\') or (s[3]='/'))) then
  359. path_absolute:=true;
  360. {$endif amiga}
  361. {$endif unix}
  362. end;
  363. {$ifndef FPC}
  364. Procedure FindClose(var Info : SearchRec);
  365. Begin
  366. End;
  367. {$endif not FPC}
  368. Function FileExists ( Const F : String) : Boolean;
  369. {$ifndef delphi}
  370. Var
  371. Info : SearchRec;
  372. {$endif}
  373. begin
  374. {$ifdef delphi}
  375. FileExists:=sysutils.FileExists(f);
  376. {$else}
  377. findfirst(F,readonly+archive+hidden,info);
  378. FileExists:=(doserror=0);
  379. findclose(Info);
  380. {$endif delphi}
  381. end;
  382. Function PathExists ( F : String) : Boolean;
  383. Var
  384. Info : SearchRec;
  385. {$ifdef i386}
  386. disk : byte;
  387. {$endif i386}
  388. begin
  389. {$ifdef i386}
  390. if (Length(f)=3) and (F[2]=':') and (F[3] in ['/','\']) then
  391. begin
  392. if F[1] in ['A'..'Z'] then
  393. disk:=ord(F[1])-ord('A')+1
  394. else if F[1] in ['a'..'z'] then
  395. disk:=ord(F[1])-ord('a')+1
  396. else
  397. disk:=255;
  398. if disk=255 then
  399. PathExists:=false
  400. else
  401. PathExists:=(DiskSize(disk)<>-1);
  402. exit;
  403. end;
  404. {$endif i386}
  405. if F[Length(f)] in ['/','\'] then
  406. Delete(f,length(f),1);
  407. findfirst(F,readonly+archive+hidden+directory,info);
  408. PathExists:=(doserror=0) and ((info.attr and directory)=directory);
  409. findclose(Info);
  410. end;
  411. Function RemoveFile(const f:string):boolean;
  412. var
  413. g : file;
  414. begin
  415. assign(g,f);
  416. {$I-}
  417. erase(g);
  418. {$I+}
  419. RemoveFile:=(ioresult=0);
  420. end;
  421. Function RemoveDir(d:string):boolean;
  422. begin
  423. if d[length(d)]=source_info.DirSep then
  424. Delete(d,length(d),1);
  425. {$I-}
  426. rmdir(d);
  427. {$I+}
  428. RemoveDir:=(ioresult=0);
  429. end;
  430. Function SplitPath(const s:string):string;
  431. var
  432. i : longint;
  433. begin
  434. i:=Length(s);
  435. while (i>0) and not(s[i] in ['/','\']) do
  436. dec(i);
  437. SplitPath:=Copy(s,1,i);
  438. end;
  439. Function SplitFileName(const s:string):string;
  440. var
  441. p : dirstr;
  442. n : namestr;
  443. e : extstr;
  444. begin
  445. FSplit(s,p,n,e);
  446. SplitFileName:=n+e;
  447. end;
  448. Function SplitName(const s:string):string;
  449. var
  450. i,j : longint;
  451. begin
  452. i:=Length(s);
  453. j:=Length(s);
  454. while (i>0) and not(s[i] in ['/','\']) do
  455. dec(i);
  456. while (j>0) and (s[j]<>'.') do
  457. dec(j);
  458. if j<=i then
  459. j:=255;
  460. SplitName:=Copy(s,i+1,j-(i+1));
  461. end;
  462. Function SplitExtension(Const HStr:String):String;
  463. var
  464. j : longint;
  465. begin
  466. j:=length(Hstr);
  467. while (j>0) and (Hstr[j]<>'.') do
  468. begin
  469. if hstr[j]=source_info.DirSep then
  470. j:=0
  471. else
  472. dec(j);
  473. end;
  474. if j=0 then
  475. j:=254;
  476. SplitExtension:=Copy(Hstr,j,255);
  477. end;
  478. Function AddExtension(Const HStr,ext:String):String;
  479. begin
  480. if (Ext<>'') and (SplitExtension(HStr)='') then
  481. AddExtension:=Hstr+Ext
  482. else
  483. AddExtension:=Hstr;
  484. end;
  485. Function ForceExtension(Const HStr,ext:String):String;
  486. var
  487. j : longint;
  488. begin
  489. j:=length(Hstr);
  490. while (j>0) and (Hstr[j]<>'.') do
  491. dec(j);
  492. if j=0 then
  493. j:=255;
  494. ForceExtension:=Copy(Hstr,1,j-1)+Ext;
  495. end;
  496. Function FixPath(s:string;allowdot:boolean):string;
  497. var
  498. i : longint;
  499. begin
  500. { Fix separator }
  501. for i:=1 to length(s) do
  502. if s[i] in ['/','\'] then
  503. s[i]:=source_info.DirSep;
  504. { Fix ending / }
  505. if (length(s)>0) and (s[length(s)]<>source_info.DirSep) and
  506. (s[length(s)]<>':') then
  507. s:=s+source_info.DirSep;
  508. { Remove ./ }
  509. if (not allowdot) and (s='.'+source_info.DirSep) then
  510. s:='';
  511. { return }
  512. if source_info.files_case_relevent then
  513. FixPath:=s
  514. else
  515. FixPath:=Lower(s);
  516. end;
  517. function FixFileName(const s:string):string;
  518. var
  519. i : longint;
  520. begin
  521. if source_info.files_case_relevent then
  522. begin
  523. for i:=1 to length(s) do
  524. begin
  525. case s[i] of
  526. '/','\' :
  527. FixFileName[i]:=source_info.dirsep;
  528. else
  529. FixFileName[i]:=s[i];
  530. end;
  531. end;
  532. end
  533. else
  534. begin
  535. for i:=1 to length(s) do
  536. begin
  537. case s[i] of
  538. '/','\' :
  539. FixFileName[i]:=source_info.dirsep;
  540. 'A'..'Z' :
  541. FixFileName[i]:=char(byte(s[i])+32);
  542. else
  543. FixFileName[i]:=s[i];
  544. end;
  545. end;
  546. end;
  547. FixFileName[0]:=s[0];
  548. end;
  549. Function TargetFixPath(s:string;allowdot:boolean):string;
  550. var
  551. i : longint;
  552. begin
  553. { Fix separator }
  554. for i:=1 to length(s) do
  555. if s[i] in ['/','\'] then
  556. s[i]:=target_info.DirSep;
  557. { Fix ending / }
  558. if (length(s)>0) and (s[length(s)]<>target_info.DirSep) and
  559. (s[length(s)]<>':') then
  560. s:=s+target_info.DirSep;
  561. { Remove ./ }
  562. if (not allowdot) and (s='.'+target_info.DirSep) then
  563. s:='';
  564. { return }
  565. if target_info.files_case_relevent then
  566. TargetFixPath:=s
  567. else
  568. TargetFixPath:=Lower(s);
  569. end;
  570. function TargetFixFileName(const s:string):string;
  571. var
  572. i : longint;
  573. begin
  574. if target_info.files_case_relevent then
  575. begin
  576. for i:=1 to length(s) do
  577. begin
  578. case s[i] of
  579. '/','\' :
  580. TargetFixFileName[i]:=target_info.dirsep;
  581. else
  582. TargetFixFileName[i]:=s[i];
  583. end;
  584. end;
  585. end
  586. else
  587. begin
  588. for i:=1 to length(s) do
  589. begin
  590. case s[i] of
  591. '/','\' :
  592. TargetFixFileName[i]:=target_info.dirsep;
  593. 'A'..'Z' :
  594. TargetFixFileName[i]:=char(byte(s[i])+32);
  595. else
  596. TargetFixFileName[i]:=s[i];
  597. end;
  598. end;
  599. end;
  600. TargetFixFileName[0]:=s[0];
  601. end;
  602. procedure SplitBinCmd(const s:string;var bstr,cstr:string);
  603. var
  604. i : longint;
  605. begin
  606. i:=pos(' ',s);
  607. if i>0 then
  608. begin
  609. bstr:=Copy(s,1,i-1);
  610. cstr:=Copy(s,i+1,length(s)-i);
  611. end
  612. else
  613. begin
  614. bstr:=s;
  615. cstr:='';
  616. end;
  617. end;
  618. procedure TSearchPathList.AddPath(s:string;addfirst:boolean);
  619. var
  620. j : longint;
  621. hs,hsd,
  622. CurrentDir,
  623. CurrPath : string;
  624. dir : searchrec;
  625. hp : TStringListItem;
  626. procedure addcurrpath;
  627. begin
  628. if addfirst then
  629. begin
  630. Remove(currPath);
  631. Insert(currPath);
  632. end
  633. else
  634. begin
  635. { Check if already in path, then we don't add it }
  636. hp:=Find(currPath);
  637. if not assigned(hp) then
  638. Concat(currPath);
  639. end;
  640. end;
  641. begin
  642. if s='' then
  643. exit;
  644. { Support default macro's }
  645. DefaultReplacements(s);
  646. { get current dir }
  647. CurrentDir:=GetCurrentDir;
  648. repeat
  649. { get currpath }
  650. if addfirst then
  651. begin
  652. j:=length(s);
  653. while (j>0) and (s[j]<>';') do
  654. dec(j);
  655. CurrPath:=FixPath(Copy(s,j+1,length(s)-j),false);
  656. if j=0 then
  657. s:=''
  658. else
  659. System.Delete(s,j,length(s)-j+1);
  660. end
  661. else
  662. begin
  663. j:=Pos(';',s);
  664. if j=0 then
  665. j:=255;
  666. CurrPath:=FixPath(Copy(s,1,j-1),false);
  667. System.Delete(s,1,j);
  668. end;
  669. { fix pathname }
  670. if CurrPath='' then
  671. CurrPath:='.'+source_info.DirSep
  672. else
  673. begin
  674. CurrPath:=FixPath(FExpand(CurrPath),false);
  675. if (CurrentDir<>'') and (Copy(CurrPath,1,length(CurrentDir))=CurrentDir) then
  676. CurrPath:='.'+source_info.DirSep+Copy(CurrPath,length(CurrentDir)+1,255);
  677. end;
  678. { wildcard adding ? }
  679. if pos('*',currpath)>0 then
  680. begin
  681. if currpath[length(currpath)]=source_info.dirsep then
  682. hs:=Copy(currpath,1,length(CurrPath)-1)
  683. else
  684. hs:=currpath;
  685. hsd:=SplitPath(hs);
  686. findfirst(hs,directory,dir);
  687. while doserror=0 do
  688. begin
  689. if (dir.name<>'.') and
  690. (dir.name<>'..') and
  691. ((dir.attr and directory)<>0) then
  692. begin
  693. currpath:=hsd+dir.name+source_info.dirsep;
  694. hp:=Find(currPath);
  695. if not assigned(hp) then
  696. AddCurrPath;
  697. end;
  698. findnext(dir);
  699. end;
  700. FindClose(dir);
  701. end
  702. else
  703. begin
  704. if PathExists(currpath) then
  705. addcurrpath;
  706. end;
  707. until (s='');
  708. end;
  709. procedure TSearchPathList.AddList(list:TSearchPathList;addfirst:boolean);
  710. var
  711. s : string;
  712. hl : TSearchPathList;
  713. hp,hp2 : TStringListItem;
  714. begin
  715. if list.empty then
  716. exit;
  717. { create temp and reverse the list }
  718. if addfirst then
  719. begin
  720. hl:=TSearchPathList.Create;
  721. hp:=TStringListItem(list.first);
  722. while assigned(hp) do
  723. begin
  724. hl.insert(hp.Str);
  725. hp:=TStringListItem(hp.next);
  726. end;
  727. while not hl.empty do
  728. begin
  729. s:=hl.GetFirst;
  730. Remove(s);
  731. Insert(s);
  732. end;
  733. hl.Free;
  734. end
  735. else
  736. begin
  737. hp:=TStringListItem(list.first);
  738. while assigned(hp) do
  739. begin
  740. hp2:=Find(hp.Str);
  741. { Check if already in path, then we don't add it }
  742. if not assigned(hp2) then
  743. Concat(hp.Str);
  744. hp:=TStringListItem(hp.next);
  745. end;
  746. end;
  747. end;
  748. function TSearchPathList.FindFile(const f : string;var foundfile:string):boolean;
  749. Var
  750. p : TStringListItem;
  751. begin
  752. FindFile:=false;
  753. p:=TStringListItem(first);
  754. while assigned(p) do
  755. begin
  756. {
  757. Search order for case sensitive systems:
  758. 1. lowercase
  759. 2. NormalCase
  760. 3. UPPERCASE
  761. None case sensitive only lowercase
  762. }
  763. FoundFile:=p.Str+Lower(f);
  764. If FileExists(FoundFile) then
  765. begin
  766. FindFile:=true;
  767. exit;
  768. end;
  769. {$ifdef UNIX}
  770. FoundFile:=p.Str+f;
  771. If FileExists(FoundFile) then
  772. begin
  773. FindFile:=true;
  774. exit;
  775. end;
  776. FoundFile:=p.Str+Upper(f);
  777. If FileExists(FoundFile) then
  778. begin
  779. FindFile:=true;
  780. exit;
  781. end;
  782. {$endif UNIX}
  783. p:=TStringListItem(p.next);
  784. end;
  785. { Return original filename if not found }
  786. FoundFile:=f;
  787. end;
  788. Function GetFileTime ( Var F : File) : Longint;
  789. Var
  790. {$ifdef unix}
  791. Info : Stat;
  792. {$endif}
  793. L : longint;
  794. begin
  795. {$ifdef unix}
  796. FStat (F,Info);
  797. L:=Info.Mtime;
  798. {$else}
  799. GetFTime(f,l);
  800. {$endif}
  801. GetFileTime:=L;
  802. end;
  803. Function GetNamedFileTime (Const F : String) : Longint;
  804. begin
  805. GetNamedFileTime:=do_getnamedfiletime(F);
  806. end;
  807. function FindFile(const f : string;path : string;var foundfile:string):boolean;
  808. Var
  809. singlepathstring : string;
  810. i : longint;
  811. begin
  812. {$ifdef Unix}
  813. for i:=1 to length(path) do
  814. if path[i]=':' then
  815. path[i]:=';';
  816. {$endif Unix}
  817. FindFile:=false;
  818. repeat
  819. i:=pos(';',path);
  820. if i=0 then
  821. i:=256;
  822. singlepathstring:=FixPath(copy(path,1,i-1),false);
  823. delete(path,1,i);
  824. {
  825. Search order for case sensitive systems:
  826. 1. lowercase
  827. 2. NormalCase
  828. 3. UPPERCASE
  829. None case sensitive only lowercase
  830. }
  831. FoundFile:=singlepathstring+Lower(f);
  832. If FileExists(FoundFile) then
  833. begin
  834. FindFile:=true;
  835. exit;
  836. end;
  837. {$ifdef UNIX}
  838. FoundFile:=singlepathstring+f;
  839. If FileExists(FoundFile) then
  840. begin
  841. FindFile:=true;
  842. exit;
  843. end;
  844. FoundFile:=singlepathstring+Upper(f);
  845. If FileExists(FoundFile) then
  846. begin
  847. FindFile:=true;
  848. exit;
  849. end;
  850. {$endif UNIX}
  851. until path='';
  852. FoundFile:=f;
  853. end;
  854. function FindExe(const bin:string;var foundfile:string):boolean;
  855. begin
  856. {$ifdef delphi}
  857. FindExe:=FindFile(FixFileName(AddExtension(bin,source_info.exeext)),'.;'+exepath+';'+dmisc.getenv('PATH'),foundfile);
  858. {$else delphi}
  859. FindExe:=FindFile(FixFileName(AddExtension(bin,source_info.exeext)),'.;'+exepath+';'+dos.getenv('PATH'),foundfile);
  860. {$endif delphi}
  861. end;
  862. function GetShortName(const n:string):string;
  863. {$ifdef win32}
  864. var
  865. hs,hs2 : string;
  866. i : longint;
  867. {$endif}
  868. {$ifdef go32v2}
  869. var
  870. hs : string;
  871. {$endif}
  872. begin
  873. GetShortName:=n;
  874. {$ifdef win32}
  875. hs:=n+#0;
  876. i:=Windows.GetShortPathName(@hs[1],@hs2[1],high(hs2));
  877. if (i>0) and (i<=high(hs2)) then
  878. begin
  879. hs2[0]:=chr(strlen(@hs2[1]));
  880. GetShortName:=hs2;
  881. end;
  882. {$endif}
  883. {$ifdef go32v2}
  884. hs:=n;
  885. if Dos.GetShortName(hs) then
  886. GetShortName:=hs;
  887. {$endif}
  888. end;
  889. {****************************************************************************
  890. OS Dependent things
  891. ****************************************************************************}
  892. function GetEnvPChar(const envname:string):pchar;
  893. {$ifdef win32}
  894. var
  895. s : string;
  896. i,len : longint;
  897. hp,p,p2 : pchar;
  898. {$endif}
  899. {$ifdef os2}
  900. var
  901. P1, P2: PChar;
  902. {$endif}
  903. begin
  904. {$ifdef unix}
  905. GetEnvPchar:={$ifdef ver1_0}Linux{$else}Unix{$endif}.Getenv(envname);
  906. {$define GETENVOK}
  907. {$endif}
  908. {$ifdef win32}
  909. GetEnvPchar:=nil;
  910. p:=GetEnvironmentStrings;
  911. hp:=p;
  912. while hp^<>#0 do
  913. begin
  914. s:=strpas(hp);
  915. i:=pos('=',s);
  916. len:=strlen(hp);
  917. if upper(copy(s,1,i-1))=upper(envname) then
  918. begin
  919. GetMem(p2,len-length(envname));
  920. Move(hp[i],p2^,len-length(envname));
  921. GetEnvPchar:=p2;
  922. break;
  923. end;
  924. { next string entry}
  925. hp:=hp+len+1;
  926. end;
  927. FreeEnvironmentStrings(p);
  928. {$define GETENVOK}
  929. {$endif}
  930. {$ifdef os2}
  931. P1 := StrPNew (EnvName);
  932. if Assigned (P1) then
  933. begin
  934. if DosCalls.DosScanEnv (P1, P2) = 0 then
  935. GetEnvPChar := P2
  936. else
  937. GetEnvPChar := nil;
  938. StrDispose (P1);
  939. end else GetEnvPChar := nil;
  940. {$define GETENVOK}
  941. {$endif}
  942. {$ifdef GETENVOK}
  943. {$undef GETENVOK}
  944. {$else}
  945. GetEnvPchar:=StrPNew({$ifdef delphi}DMisc{$else}Dos{$endif}.Getenv(envname));
  946. {$endif}
  947. end;
  948. procedure FreeEnvPChar(p:pchar);
  949. begin
  950. {$ifndef unix}
  951. {$ifndef os2}
  952. StrDispose(p);
  953. {$endif}
  954. {$endif}
  955. end;
  956. Procedure Shell(const command:string);
  957. { This is already defined in the linux.ppu for linux, need for the *
  958. expansion under linux }
  959. {$ifdef unix}
  960. begin
  961. {$ifdef ver1_0}Linux{$else}Unix{$endif}.Shell(command);
  962. end;
  963. {$else}
  964. var
  965. comspec : string;
  966. begin
  967. comspec:=getenv('COMSPEC');
  968. Exec(comspec,' /C '+command);
  969. end;
  970. {$endif}
  971. Function SetCompileMode(const s:string; changeInit: boolean):boolean;
  972. var
  973. b : boolean;
  974. begin
  975. b:=true;
  976. if s='DEFAULT' then
  977. aktmodeswitches:=initmodeswitches
  978. else
  979. if s='DELPHI' then
  980. aktmodeswitches:=delphimodeswitches
  981. else
  982. if s='TP' then
  983. aktmodeswitches:=tpmodeswitches
  984. else
  985. if s='FPC' then
  986. aktmodeswitches:=fpcmodeswitches
  987. else
  988. if s='OBJFPC' then
  989. aktmodeswitches:=objfpcmodeswitches
  990. else
  991. if s='GPC' then
  992. aktmodeswitches:=gpcmodeswitches
  993. else
  994. b:=false;
  995. if b and changeInit then
  996. initmodeswitches := aktmodeswitches;
  997. if b then
  998. begin
  999. { turn ansistrings on by default ? }
  1000. if (m_delphi in aktmodeswitches) then
  1001. begin
  1002. include(aktlocalswitches,cs_ansistrings);
  1003. if changeinit then
  1004. include(initlocalswitches,cs_ansistrings);
  1005. end
  1006. else
  1007. begin
  1008. exclude(aktlocalswitches,cs_ansistrings);
  1009. if changeinit then
  1010. exclude(initlocalswitches,cs_ansistrings);
  1011. end;
  1012. { enum packing }
  1013. if (m_tp7 in aktmodeswitches) then
  1014. aktpackenum:=1
  1015. else
  1016. aktpackenum:=4;
  1017. if changeinit then
  1018. initpackenum:=aktpackenum;
  1019. end;
  1020. SetCompileMode:=b;
  1021. end;
  1022. function SetAktProcCall(const s:string; changeInit:boolean):boolean;
  1023. const
  1024. DefProcCallName : array[tproccalloption] of string[12] = ('',
  1025. 'CDECL',
  1026. 'CPPDECL',
  1027. '', { compilerproc }
  1028. 'FAR16',
  1029. 'FPCCALL',
  1030. 'INLINE',
  1031. '', { internconst }
  1032. '', { internproc }
  1033. '', { palmossyscall }
  1034. 'PASCAL',
  1035. 'REGISTER',
  1036. 'SAFECALL',
  1037. 'STDCALL',
  1038. 'SYSTEM'
  1039. );
  1040. var
  1041. t : tproccalloption;
  1042. begin
  1043. SetAktProcCall:=false;
  1044. for t:=low(tproccalloption) to high(tproccalloption) do
  1045. if DefProcCallName[t]=s then
  1046. begin
  1047. AktDefProcCall:=t;
  1048. SetAktProcCall:=true;
  1049. break;
  1050. end;
  1051. if changeinit then
  1052. InitDefProcCall:=AktDefProcCall;
  1053. end;
  1054. { '('D1:'00000000-'D2:'0000-'D3:'0000-'D4:'0000-000000000000)' }
  1055. function string2guid(const s: string; var GUID: TGUID): boolean;
  1056. function ishexstr(const hs: string): boolean;
  1057. var
  1058. i: integer;
  1059. begin
  1060. ishexstr:=false;
  1061. for i:=1 to Length(hs) do begin
  1062. if not (hs[i] in ['0'..'9','A'..'F','a'..'f']) then
  1063. exit;
  1064. end;
  1065. ishexstr:=true;
  1066. end;
  1067. function hexstr2longint(const hexs: string): longint;
  1068. var
  1069. i: integer;
  1070. rl: longint;
  1071. begin
  1072. rl:=0;
  1073. for i:=1 to length(hexs) do begin
  1074. rl:=rl shl 4;
  1075. case hexs[i] of
  1076. '0'..'9' : inc(rl,ord(hexs[i])-ord('0'));
  1077. 'A'..'F' : inc(rl,ord(hexs[i])-ord('A')+10);
  1078. 'a'..'f' : inc(rl,ord(hexs[i])-ord('a')+10);
  1079. end
  1080. end;
  1081. hexstr2longint:=rl;
  1082. end;
  1083. var
  1084. i: integer;
  1085. begin
  1086. if (Length(s)=38) and (s[1]='{') and (s[38]='}') and
  1087. (s[10]='-') and (s[15]='-') and (s[20]='-') and (s[25]='-') and
  1088. ishexstr(copy(s,2,8)) and ishexstr(copy(s,11,4)) and
  1089. ishexstr(copy(s,16,4)) and ishexstr(copy(s,21,4)) and
  1090. ishexstr(copy(s,26,12)) then begin
  1091. GUID.D1:=dword(hexstr2longint(copy(s,2,8)));
  1092. GUID.D2:=hexstr2longint(copy(s,11,4));
  1093. GUID.D3:=hexstr2longint(copy(s,16,4));
  1094. for i:=0 to 1 do
  1095. GUID.D4[i]:=hexstr2longint(copy(s,21+i*2,2));
  1096. for i:=2 to 7 do
  1097. GUID.D4[i]:=hexstr2longint(copy(s,22+i*2,2));
  1098. string2guid:=true;
  1099. end
  1100. else
  1101. string2guid:=false;
  1102. end;
  1103. function guid2string(const GUID: TGUID): string;
  1104. function long2hex(l, len: longint): string;
  1105. const
  1106. hextbl: array[0..15] of char = '0123456789ABCDEF';
  1107. var
  1108. rs: string;
  1109. i: integer;
  1110. begin
  1111. rs[0]:=chr(len);
  1112. for i:=len downto 1 do begin
  1113. rs[i]:=hextbl[l and $F];
  1114. l:=l shr 4;
  1115. end;
  1116. long2hex:=rs;
  1117. end;
  1118. begin
  1119. guid2string:=
  1120. '{'+long2hex(GUID.D1,8)+
  1121. '-'+long2hex(GUID.D2,4)+
  1122. '-'+long2hex(GUID.D3,4)+
  1123. '-'+long2hex(GUID.D4[0],2)+long2hex(GUID.D4[1],2)+
  1124. '-'+long2hex(GUID.D4[2],2)+long2hex(GUID.D4[3],2)+
  1125. long2hex(GUID.D4[4],2)+long2hex(GUID.D4[5],2)+
  1126. long2hex(GUID.D4[6],2)+long2hex(GUID.D4[7],2)+
  1127. '}';
  1128. end;
  1129. function UpdateAlignmentStr(s:string;var a:talignmentinfo):boolean;
  1130. var
  1131. tok : string;
  1132. vstr : string;
  1133. l : longint;
  1134. code : integer;
  1135. b : talignmentinfo;
  1136. begin
  1137. UpdateAlignmentStr:=true;
  1138. uppervar(s);
  1139. fillchar(b,sizeof(b),0);
  1140. repeat
  1141. tok:=GetToken(s,'=');
  1142. if tok='' then
  1143. break;
  1144. vstr:=GetToken(s,',');
  1145. val(vstr,l,code);
  1146. if tok='PROC' then
  1147. b.procalign:=l
  1148. else if tok='JUMP' then
  1149. b.jumpalign:=l
  1150. else if tok='LOOP' then
  1151. b.loopalign:=l
  1152. else if tok='CONSTMIN' then
  1153. b.constalignmin:=l
  1154. else if tok='CONSTMAX' then
  1155. b.constalignmax:=l
  1156. else if tok='VARMIN' then
  1157. b.varalignmin:=l
  1158. else if tok='VARMAX' then
  1159. b.varalignmax:=l
  1160. else if tok='LOCALMIN' then
  1161. b.localalignmin:=l
  1162. else if tok='LOCALMAX' then
  1163. b.localalignmax:=l
  1164. else if tok='RECORDMIN' then
  1165. b.recordalignmin:=l
  1166. else if tok='RECORDMAX' then
  1167. b.recordalignmax:=l
  1168. else if tok='PARAALIGN' then
  1169. b.paraalign:=l
  1170. else { Error }
  1171. UpdateAlignmentStr:=false;
  1172. until false;
  1173. UpdateAlignment(a,b);
  1174. end;
  1175. {****************************************************************************
  1176. Init
  1177. ****************************************************************************}
  1178. {$ifdef unix}
  1179. {$define need_path_search}
  1180. {$endif unix}
  1181. {$ifdef os2}
  1182. {$define need_path_search}
  1183. {$endif os2}
  1184. procedure get_exepath;
  1185. var
  1186. hs1 : namestr;
  1187. hs2 : extstr;
  1188. begin
  1189. {$ifdef delphi}
  1190. exepath:=dmisc.getenv('PPC_EXEC_PATH');
  1191. {$else delphi}
  1192. exepath:=dos.getenv('PPC_EXEC_PATH');
  1193. {$endif delphi}
  1194. if exepath='' then
  1195. fsplit(FixFileName(system.paramstr(0)),exepath,hs1,hs2);
  1196. {$ifdef need_path_search}
  1197. if exepath='' then
  1198. begin
  1199. if pos(source_info.exeext,hs1) <>
  1200. (length(hs1) - length(source_info.exeext)+1) then
  1201. hs1 := hs1 + source_info.exeext;
  1202. {$ifdef delphi}
  1203. findfile(hs1,dmisc.getenv('PATH'),exepath);
  1204. {$else delphi}
  1205. findfile(hs1,dos.getenv('PATH'),exepath);
  1206. {$endif delphi}
  1207. exepath:=SplitPath(exepath);
  1208. end;
  1209. {$endif need_path_search}
  1210. exepath:=FixPath(exepath,false);
  1211. end;
  1212. procedure DoneGlobals;
  1213. begin
  1214. initdefines.free;
  1215. if assigned(DLLImageBase) then
  1216. StringDispose(DLLImageBase);
  1217. RelocSection:=true;
  1218. RelocSectionSetExplicitly:=false;
  1219. UseDeffileForExport:=true;
  1220. librarysearchpath.Free;
  1221. unitsearchpath.Free;
  1222. objectsearchpath.Free;
  1223. includesearchpath.Free;
  1224. end;
  1225. procedure InitGlobals;
  1226. begin
  1227. get_exepath;
  1228. { reset globals }
  1229. do_build:=false;
  1230. do_release:=false;
  1231. do_make:=true;
  1232. compile_level:=0;
  1233. DLLsource:=false;
  1234. inlining_procedure:=false;
  1235. resolving_forward:=false;
  1236. in_args:=false;
  1237. make_ref:=false;
  1238. { Output }
  1239. OutputFile:='';
  1240. OutputExeDir:='';
  1241. OutputUnitDir:='';
  1242. { Utils directory }
  1243. utilsdirectory:='';
  1244. { Search Paths }
  1245. librarysearchpath:=TSearchPathList.Create;
  1246. unitsearchpath:=TSearchPathList.Create;
  1247. includesearchpath:=TSearchPathList.Create;
  1248. objectsearchpath:=TSearchPathList.Create;
  1249. { Def file }
  1250. usewindowapi:=false;
  1251. description:='Compiled by FPC '+version_string+' - '+target_cpu_string;
  1252. dllversion:='';
  1253. nwscreenname := '';
  1254. nwthreadname := '';
  1255. nwcopyright := '';
  1256. { Init values }
  1257. initmodeswitches:=fpcmodeswitches;
  1258. initlocalswitches:=[cs_check_io,cs_typed_const_writable];
  1259. initmoduleswitches:=[cs_extsyntax,cs_browser];
  1260. initglobalswitches:=[cs_check_unit_name,cs_link_static];
  1261. initoutputformat:=target_asm.id;
  1262. fillchar(initalignment,sizeof(talignmentinfo),0);
  1263. {$ifdef i386}
  1264. initoptprocessor:=Class386;
  1265. initspecificoptprocessor:=Class386;
  1266. initpackenum:=4;
  1267. {$IFDEF testvarsets}
  1268. initsetalloc:=0;
  1269. {$ENDIF}
  1270. initasmmode:=asmmode_i386_att;
  1271. {$else not i386}
  1272. {$ifdef m68k}
  1273. initoptprocessor:=MC68000;
  1274. include(initmoduleswitches,cs_fp_emulation);
  1275. initpackenum:=4;
  1276. {$IFDEF testvarsets}
  1277. initsetalloc:=0;
  1278. {$ENDIF}
  1279. initasmmode:=asmmode_m68k_mot;
  1280. {$endif m68k}
  1281. {$endif i386}
  1282. initinterfacetype:=it_interfacecom;
  1283. initdefproccall:=pocall_none;
  1284. initdefines:=TStringList.Create;
  1285. { memory sizes, will be overriden by parameter or default for target
  1286. in options or init_parser }
  1287. stacksize:=0;
  1288. heapsize:=0;
  1289. maxheapsize:=0;
  1290. { compile state }
  1291. in_args:=false;
  1292. { must_be_valid:=true; obsolete PM }
  1293. not_unit_proc:=true;
  1294. apptype:=app_cui;
  1295. have_local_threadvars := false;
  1296. end;
  1297. {$ifdef EXTDEBUG}
  1298. begin
  1299. {$ifdef FPC}
  1300. EntryMemUsed:=system.HeapSize-MemAvail;
  1301. {$endif FPC}
  1302. {$endif}
  1303. end.
  1304. {
  1305. $Log$
  1306. Revision 1.53 2002-04-02 17:11:28 peter
  1307. * tlocation,treference update
  1308. * LOC_CONSTANT added for better constant handling
  1309. * secondadd splitted in multiple routines
  1310. * location_force_reg added for loading a location to a register
  1311. of a specified size
  1312. * secondassignment parses now first the right and then the left node
  1313. (this is compatible with Kylix). This saves a lot of push/pop especially
  1314. with string operations
  1315. * adapted some routines to use the new cg methods
  1316. Revision 1.52 2002/03/28 16:07:52 armin
  1317. + initialize threadvars defined local in units
  1318. Revision 1.51 2002/01/24 18:25:48 peter
  1319. * implicit result variable generation for assembler routines
  1320. * removed m_tp modeswitch, use m_tp7 or not(m_fpc) instead
  1321. Revision 1.50 2001/12/06 17:57:33 florian
  1322. + parasym to tparaitem added
  1323. Revision 1.49 2001/10/25 21:22:32 peter
  1324. * calling convention rewrite
  1325. Revision 1.48 2001/10/23 21:49:42 peter
  1326. * $calling directive and -Cc commandline patch added
  1327. from Pavel Ozerski
  1328. Revision 1.47 2001/10/21 12:33:05 peter
  1329. * array access for properties added
  1330. Revision 1.46 2001/10/20 20:30:20 peter
  1331. * read only typed const support, switch $J-
  1332. Revision 1.45 2001/10/16 15:10:34 jonas
  1333. * fixed goto/label/try bugs
  1334. Revision 1.44 2001/10/12 16:06:17 peter
  1335. * pathexists fix (merged)
  1336. Revision 1.43 2001/09/18 11:30:47 michael
  1337. * Fixes win32 linking problems with import libraries
  1338. * LINKLIB Libraries are now looked for using C file extensions
  1339. * get_exepath fix
  1340. Revision 1.42 2001/09/17 21:29:11 peter
  1341. * merged netbsd, fpu-overflow from fixes branch
  1342. Revision 1.41 2001/08/19 11:22:22 peter
  1343. * palmos support from v10 merged
  1344. Revision 1.40 2001/08/04 10:23:54 peter
  1345. * updates so it works with the ide
  1346. Revision 1.39 2001/07/01 20:16:15 peter
  1347. * alignmentinfo record added
  1348. * -Oa argument supports more alignment settings that can be specified
  1349. per type: PROC,LOOP,VARMIN,VARMAX,CONSTMIN,CONSTMAX,RECORDMIN
  1350. RECORDMAX,LOCALMIN,LOCALMAX. It is possible to set the mimimum
  1351. required alignment and the maximum usefull alignment. The final
  1352. alignment will be choosen per variable size dependent on these
  1353. settings
  1354. Revision 1.38 2001/06/18 20:36:24 peter
  1355. * -Ur switch (merged)
  1356. * masm fixes (merged)
  1357. * quoted filenames for go32v2 and win32
  1358. Revision 1.37 2001/06/03 21:57:35 peter
  1359. + hint directive parsing support
  1360. Revision 1.36 2001/06/03 20:21:08 peter
  1361. * Kylix fixes, mostly case names of units
  1362. Revision 1.35 2001/05/30 21:35:48 peter
  1363. * netware patches for copyright, screenname, threadname directives
  1364. Revision 1.34 2001/05/12 12:11:31 peter
  1365. * simplify_ppu is now the default, a recompile of the compiler now
  1366. only compiles pp.pas
  1367. Revision 1.33 2001/05/06 14:49:17 peter
  1368. * ppu object to class rewrite
  1369. * move ppu read and write stuff to fppu
  1370. Revision 1.32 2001/04/18 22:01:53 peter
  1371. * registration of targets and assemblers
  1372. Revision 1.31 2001/04/15 09:48:29 peter
  1373. * fixed crash in labelnode
  1374. * easier detection of goto and label in try blocks
  1375. Revision 1.30 2001/04/13 01:22:07 peter
  1376. * symtable change to classes
  1377. * range check generation and errors fixed, make cycle DEBUG=1 works
  1378. * memory leaks fixed
  1379. Revision 1.29 2001/04/04 21:30:42 florian
  1380. * applied several fixes to get the DD8 Delphi Unit compiled
  1381. e.g. "forward"-interfaces are working now
  1382. Revision 1.28 2001/02/20 21:41:16 peter
  1383. * new fixfilename, findfile for unix. Look first for lowercase, then
  1384. NormalCase and last for UPPERCASE names.
  1385. Revision 1.27 2001/02/09 23:05:45 peter
  1386. * default packenum=1 for tp7 mode
  1387. Revision 1.26 2001/02/05 20:47:00 peter
  1388. * support linux unit for ver1_0 compilers
  1389. Revision 1.25 2001/01/21 20:32:45 marco
  1390. * Renamefest. Compiler part. Not that hard.
  1391. Revision 1.24 2001/01/20 18:32:52 hajny
  1392. + APPTYPE support under OS/2, app_fs, GetEnvPChar for OS/2
  1393. Revision 1.23 2001/01/13 00:03:41 peter
  1394. * fixed findexe to also support already extension in name
  1395. Revision 1.22 2000/12/26 15:57:25 peter
  1396. * use system.paramstr()
  1397. Revision 1.21 2000/12/25 00:07:26 peter
  1398. + new tlinkedlist class (merge of old tstringqueue,tcontainer and
  1399. tlinkedlist objects)
  1400. Revision 1.20 2000/11/13 15:26:12 marco
  1401. * Renamefest
  1402. Revision 1.19 2000/11/12 22:20:37 peter
  1403. * create generic toutputsection for binary writers
  1404. Revision 1.18 2000/11/04 14:25:19 florian
  1405. + merged Attila's changes for interfaces, not tested yet
  1406. Revision 1.17 2000/10/31 22:02:46 peter
  1407. * symtable splitted, no real code changes
  1408. Revision 1.16 2000/10/04 14:51:08 pierre
  1409. * IsExe restored
  1410. Revision 1.15 2000/09/27 21:20:56 peter
  1411. * also set initlocalswitches in setcompilemode (merged)
  1412. Revision 1.14 2000/09/26 10:50:41 jonas
  1413. * initmodeswitches is changed is you change the compiler mode from the
  1414. command line (the -S<x> switches didn't work anymore for changing the
  1415. compiler mode) (merged from fixes branch)
  1416. Revision 1.13 2000/09/24 21:33:46 peter
  1417. * message updates merges
  1418. Revision 1.12 2000/09/24 21:19:50 peter
  1419. * delphi compile fixes
  1420. Revision 1.11 2000/09/24 15:12:40 peter
  1421. * fixed typo
  1422. Revision 1.10 2000/09/24 15:06:16 peter
  1423. * use defines.inc
  1424. Revision 1.9 2000/09/24 10:33:07 peter
  1425. * searching of exe in path also for OS/2
  1426. * fixed searching of exe in path.
  1427. Revision 1.8 2000/09/11 17:00:22 florian
  1428. + first implementation of Netware Module support, thanks to
  1429. Armin Diehl ([email protected]) for providing the patches
  1430. Revision 1.7 2000/08/27 16:11:51 peter
  1431. * moved some util functions from globals,cobjects to cutils
  1432. * splitted files into finput,fmodule
  1433. Revision 1.6 2000/08/12 19:14:58 peter
  1434. * ELF writer works now also with -g
  1435. * ELF writer is default again for linux
  1436. Revision 1.5 2000/08/12 15:30:44 peter
  1437. * IDE patch for stream reading (merged)
  1438. Revision 1.4 2000/08/02 19:49:59 peter
  1439. * first things for default parameters
  1440. Revision 1.3 2000/07/13 12:08:25 michael
  1441. + patched to 1.1.0 with former 1.09patch from peter
  1442. Revision 1.2 2000/07/13 11:32:41 michael
  1443. + removed logs
  1444. }