globals.pas 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551
  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. 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. {$endif 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_standard;
  1294. {$endif m68k}
  1295. {$ifdef powerpc}
  1296. initoptprocessor:=PPC604;
  1297. initpackenum:=4;
  1298. {$IFDEF testvarsets}
  1299. initsetalloc:=0;
  1300. {$ENDIF}
  1301. initasmmode:=asmmode_direct;
  1302. {$endif powerpc}
  1303. initinterfacetype:=it_interfacecom;
  1304. initdefproccall:=pocall_none;
  1305. initdefines:=TStringList.Create;
  1306. { memory sizes, will be overriden by parameter or default for target
  1307. in options or init_parser }
  1308. stacksize:=0;
  1309. heapsize:=0;
  1310. { compile state }
  1311. in_args:=false;
  1312. { must_be_valid:=true; obsolete PM }
  1313. not_unit_proc:=true;
  1314. apptype:=app_cui;
  1315. have_local_threadvars := false;
  1316. end;
  1317. {$ifdef EXTDEBUG}
  1318. begin
  1319. {$ifdef FPC}
  1320. EntryMemUsed:=system.HeapSize-MemAvail;
  1321. {$endif FPC}
  1322. {$endif}
  1323. end.
  1324. {
  1325. $Log$
  1326. Revision 1.64 2002-08-12 15:08:39 carl
  1327. + stab register indexes for powerpc (moved from gdb to cpubase)
  1328. + tprocessor enumeration moved to cpuinfo
  1329. + linker in target_info is now a class
  1330. * many many updates for m68k (will soon start to compile)
  1331. - removed some ifdef or correct them for correct cpu
  1332. Revision 1.63 2002/08/10 14:46:29 carl
  1333. + moved target_cpu_string to cpuinfo
  1334. * renamed asmmode enum.
  1335. * assembler reader has now less ifdef's
  1336. * move from nppcmem.pas -> ncgmem.pas vec. node.
  1337. Revision 1.62 2002/07/28 20:45:22 florian
  1338. + added direct assembler reader for PowerPC
  1339. Revision 1.61 2002/07/20 17:12:42 florian
  1340. + source code page support
  1341. Revision 1.60 2002/07/01 18:46:22 peter
  1342. * internal linker
  1343. * reorganized aasm layer
  1344. Revision 1.59 2002/07/01 16:23:52 peter
  1345. * cg64 patch
  1346. * basics for currency
  1347. * asnode updates for class and interface (not finished)
  1348. Revision 1.58 2002/05/18 13:34:08 peter
  1349. * readded missing revisions
  1350. Revision 1.57 2002/05/16 19:46:36 carl
  1351. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  1352. + try to fix temp allocation (still in ifdef)
  1353. + generic constructor calls
  1354. + start of tassembler / tmodulebase class cleanup
  1355. Revision 1.55 2002/04/20 21:32:23 carl
  1356. + generic FPC_CHECKPOINTER
  1357. + first parameter offset in stack now portable
  1358. * rename some constants
  1359. + move some cpu stuff to other units
  1360. - remove unused constents
  1361. * fix stacksize for some targets
  1362. * fix generic size problems which depend now on EXTEND_SIZE constant
  1363. Revision 1.54 2002/04/07 13:24:30 carl
  1364. + moved constant from cpuinfo, these are NOT cpu specific
  1365. constant, but more related to compiler functionality.
  1366. Revision 1.53 2002/04/02 17:11:28 peter
  1367. * tlocation,treference update
  1368. * LOC_CONSTANT added for better constant handling
  1369. * secondadd splitted in multiple routines
  1370. * location_force_reg added for loading a location to a register
  1371. of a specified size
  1372. * secondassignment parses now first the right and then the left node
  1373. (this is compatible with Kylix). This saves a lot of push/pop especially
  1374. with string operations
  1375. * adapted some routines to use the new cg methods
  1376. Revision 1.52 2002/03/28 16:07:52 armin
  1377. + initialize threadvars defined local in units
  1378. Revision 1.51 2002/01/24 18:25:48 peter
  1379. * implicit result variable generation for assembler routines
  1380. * removed m_tp modeswitch, use m_tp7 or not(m_fpc) instead
  1381. }