globals.pas 50 KB

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