globals.pas 43 KB

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