globals.pas 42 KB

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