globals.pas 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563
  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,cs_implicit_exceptions];
  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.67 2002-10-16 19:01:43 peter
  1324. + $IMPLICITEXCEPTIONS switch to turn on/off generation of the
  1325. implicit exception frames for procedures with initialized variables
  1326. and for constructors. The default is on for compatibility
  1327. Revision 1.66 2002/09/05 19:28:29 peter
  1328. * removed repetitive pass counting
  1329. * display heapsize also for extdebug
  1330. Revision 1.65 2002/08/19 19:36:42 peter
  1331. * More fixes for cross unit inlining, all tnodes are now implemented
  1332. * Moved pocall_internconst to po_internconst because it is not a
  1333. calling type at all and it conflicted when inlining of these small
  1334. functions was requested
  1335. Revision 1.64 2002/08/12 15:08:39 carl
  1336. + stab register indexes for powerpc (moved from gdb to cpubase)
  1337. + tprocessor enumeration moved to cpuinfo
  1338. + linker in target_info is now a class
  1339. * many many updates for m68k (will soon start to compile)
  1340. - removed some ifdef or correct them for correct cpu
  1341. Revision 1.63 2002/08/10 14:46:29 carl
  1342. + moved target_cpu_string to cpuinfo
  1343. * renamed asmmode enum.
  1344. * assembler reader has now less ifdef's
  1345. * move from nppcmem.pas -> ncgmem.pas vec. node.
  1346. Revision 1.62 2002/07/28 20:45:22 florian
  1347. + added direct assembler reader for PowerPC
  1348. Revision 1.61 2002/07/20 17:12:42 florian
  1349. + source code page support
  1350. Revision 1.60 2002/07/01 18:46:22 peter
  1351. * internal linker
  1352. * reorganized aasm layer
  1353. Revision 1.59 2002/07/01 16:23:52 peter
  1354. * cg64 patch
  1355. * basics for currency
  1356. * asnode updates for class and interface (not finished)
  1357. Revision 1.58 2002/05/18 13:34:08 peter
  1358. * readded missing revisions
  1359. Revision 1.57 2002/05/16 19:46:36 carl
  1360. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  1361. + try to fix temp allocation (still in ifdef)
  1362. + generic constructor calls
  1363. + start of tassembler / tmodulebase class cleanup
  1364. Revision 1.55 2002/04/20 21:32:23 carl
  1365. + generic FPC_CHECKPOINTER
  1366. + first parameter offset in stack now portable
  1367. * rename some constants
  1368. + move some cpu stuff to other units
  1369. - remove unused constents
  1370. * fix stacksize for some targets
  1371. * fix generic size problems which depend now on EXTEND_SIZE constant
  1372. Revision 1.54 2002/04/07 13:24:30 carl
  1373. + moved constant from cpuinfo, these are NOT cpu specific
  1374. constant, but more related to compiler functionality.
  1375. Revision 1.53 2002/04/02 17:11:28 peter
  1376. * tlocation,treference update
  1377. * LOC_CONSTANT added for better constant handling
  1378. * secondadd splitted in multiple routines
  1379. * location_force_reg added for loading a location to a register
  1380. of a specified size
  1381. * secondassignment parses now first the right and then the left node
  1382. (this is compatible with Kylix). This saves a lot of push/pop especially
  1383. with string operations
  1384. * adapted some routines to use the new cg methods
  1385. Revision 1.52 2002/03/28 16:07:52 armin
  1386. + initialize threadvars defined local in units
  1387. Revision 1.51 2002/01/24 18:25:48 peter
  1388. * implicit result variable generation for assembler routines
  1389. * removed m_tp modeswitch, use m_tp7 or not(m_fpc) instead
  1390. }