globals.pas 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. This unit implements some support functions and global variables
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit globals;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. {$ifdef win32}
  22. windows,
  23. {$endif}
  24. {$ifdef os2}
  25. dos,
  26. {$endif os2}
  27. {$ifdef hasunix}
  28. Baseunix,unix,
  29. {$endif}
  30. {$IFNDEF USE_FAKE_SYSUTILS}
  31. sysutils,
  32. {$ELSE}
  33. fksysutl,
  34. {$ENDIF}
  35. { comphook pulls in sysutils anyways }
  36. cutils,cclasses,cfileutils,
  37. cpuinfo,
  38. globtype,version,systems;
  39. const
  40. delphimodeswitches : tmodeswitches=
  41. [m_delphi,m_all,m_class,m_objpas,m_result,m_string_pchar,
  42. m_pointer_2_procedure,m_autoderef,m_tp_procvar,m_initfinal,m_default_ansistring,
  43. m_out,m_default_para,m_duplicate_names,m_hintdirective,m_add_pointer,
  44. m_property,m_default_inline,m_except];
  45. fpcmodeswitches : tmodeswitches=
  46. [m_fpc,m_all,m_string_pchar,m_nested_comment,m_repeat_forward,
  47. m_cvar_support,m_initfinal,m_add_pointer,m_hintdirective,
  48. m_property,m_default_inline];
  49. objfpcmodeswitches : tmodeswitches=
  50. [m_objfpc,m_fpc,m_all,m_class,m_objpas,m_result,m_string_pchar,m_nested_comment,
  51. m_repeat_forward,m_cvar_support,m_initfinal,m_add_pointer,m_out,m_default_para,m_hintdirective,
  52. m_property,m_default_inline,m_except];
  53. tpmodeswitches : tmodeswitches=
  54. [m_tp7,m_all,m_tp_procvar,m_duplicate_names];
  55. gpcmodeswitches : tmodeswitches=
  56. [m_gpc,m_all,m_tp_procvar];
  57. macmodeswitches : tmodeswitches=
  58. [m_mac,m_all,m_result,m_cvar_support,m_mac_procvar];
  59. { maximum nesting of routines }
  60. maxnesting = 32;
  61. { Filenames and extensions }
  62. sourceext = '.pp';
  63. pasext = '.pas';
  64. pext = '.p';
  65. treelogfilename = 'tree.log';
  66. {$if defined(CPUARM) and defined(FPUFPA)}
  67. MathQNaN : tdoublerec = (bytes : (0,0,252,255,0,0,0,0));
  68. MathInf : tdoublerec = (bytes : (0,0,240,127,0,0,0,0));
  69. MathNegInf : tdoublerec = (bytes : (0,0,240,255,0,0,0,0));
  70. MathPi : tdoublerec = (bytes : (251,33,9,64,24,45,68,84));
  71. {$else}
  72. {$ifdef FPC_LITTLE_ENDIAN}
  73. MathQNaN : tdoublerec = (bytes : (0,0,0,0,0,0,252,255));
  74. MathInf : tdoublerec = (bytes : (0,0,0,0,0,0,240,127));
  75. MathNegInf : tdoublerec = (bytes : (0,0,0,0,0,0,240,255));
  76. MathPi : tdoublerec = (bytes : (24,45,68,84,251,33,9,64));
  77. MathPiExtended : textendedrec = (bytes : (53,194,104,33,162,218,15,201,0,64));
  78. {$else FPC_LITTLE_ENDIAN}
  79. MathQNaN : tdoublerec = (bytes : (255,252,0,0,0,0,0,0));
  80. MathInf : tdoublerec = (bytes : (127,240,0,0,0,0,0,0));
  81. MathNegInf : tdoublerec = (bytes : (255,240,0,0,0,0,0,0));
  82. MathPi : tdoublerec = (bytes : (64,9,33,251,84,68,45,24));
  83. MathPiExtended : textendedrec = (bytes : (64,0,201,15,218,162,33,104,194,53));
  84. {$endif FPC_LITTLE_ENDIAN}
  85. {$endif}
  86. type
  87. TFPUException = (exInvalidOp, exDenormalized, exZeroDivide,
  88. exOverflow, exUnderflow, exPrecision);
  89. TFPUExceptionMask = set of TFPUException;
  90. pfileposinfo = ^tfileposinfo;
  91. tfileposinfo = record
  92. line : longint;
  93. column : word;
  94. fileindex : word;
  95. moduleindex : word;
  96. end;
  97. tcodepagestring = string[20];
  98. tsettings = record
  99. globalswitches : tglobalswitches;
  100. moduleswitches : tmoduleswitches;
  101. localswitches : tlocalswitches;
  102. modeswitches : tmodeswitches;
  103. optimizerswitches : toptimizerswitches;
  104. { 0: old behaviour for sets <=256 elements
  105. >0: round to this size }
  106. setalloc,
  107. packenum : shortint;
  108. alignment : talignmentinfo;
  109. cputype,
  110. optimizecputype : tcputype;
  111. fputype : tfputype;
  112. asmmode : tasmmode;
  113. interfacetype : tinterfacetypes;
  114. defproccall : tproccalloption;
  115. sourcecodepage : tcodepagestring;
  116. packrecords : shortint;
  117. maxfpuregisters : shortint;
  118. end;
  119. const
  120. LinkMapWeightDefault = 1000;
  121. type
  122. TLinkRec = record
  123. Key : AnsiString;
  124. Value : AnsiString; // key expands to valuelist "value"
  125. Weight: longint;
  126. end;
  127. TLinkStrMap = class
  128. private
  129. itemcnt : longint;
  130. fmap : Array Of TLinkRec;
  131. function Lookup(key:Ansistring):longint;
  132. function getlinkrec(i:longint):TLinkRec;
  133. public
  134. procedure Add(key:ansistring;value:AnsiString='';weight:longint=LinkMapWeightDefault);
  135. procedure addseries(keys:AnsiString;weight:longint=LinkMapWeightDefault);
  136. function AddDep(keyvalue:String):boolean;
  137. function AddWeight(keyvalue:String):boolean;
  138. procedure SetValue(key:AnsiString;Weight:Integer);
  139. procedure SortonWeight;
  140. function Find(key:AnsiString):AnsiString;
  141. procedure Expand(src:TStringList;dest: TLinkStrMap);
  142. procedure UpdateWeights(Weightmap:TLinkStrMap);
  143. constructor Create;
  144. property count : longint read itemcnt;
  145. property items[I:longint]:TLinkRec read getlinkrec; default;
  146. end;
  147. var
  148. { specified inputfile }
  149. inputfilepath : string;
  150. inputfilename : string;
  151. { specified outputfile with -o parameter }
  152. outputfilename : string;
  153. outputprefix : pshortstring;
  154. outputsuffix : pshortstring;
  155. { specified with -FE or -FU }
  156. outputexedir : TPathStr;
  157. outputunitdir : TPathStr;
  158. { things specified with parameters }
  159. paratarget : tsystem;
  160. paratargetdbg : tdbg;
  161. paratargetasm : tasm;
  162. paralinkoptions,
  163. paradynamiclinker : string;
  164. paraprintnodetree : byte;
  165. parapreprocess : boolean;
  166. printnodefile : text;
  167. { typical cross compiling params}
  168. { directory where the utils can be found (options -FD) }
  169. utilsdirectory : TPathStr;
  170. { targetname specific prefix used by these utils (options -XP<path>) }
  171. utilsprefix : TPathStr;
  172. cshared : boolean; { pass --shared to ld to link C libs shared}
  173. Dontlinkstdlibpath: Boolean; { Don't add std paths to linkpath}
  174. rlinkpath : TPathStr; { rpath-link linkdir override}
  175. { some flags for global compiler switches }
  176. do_build,
  177. do_release,
  178. do_make : boolean;
  179. { path for searching units, different paths can be seperated by ; }
  180. exepath : TPathStr; { Path to ppc }
  181. librarysearchpath,
  182. unitsearchpath,
  183. objectsearchpath,
  184. includesearchpath : TSearchPathList;
  185. autoloadunits : string;
  186. { linking }
  187. usewindowapi : boolean;
  188. description : string;
  189. SetPEFlagsSetExplicity,
  190. ImageBaseSetExplicity,
  191. MinStackSizeSetExplicity,
  192. MaxStackSizeSetExplicity,
  193. DescriptionSetExplicity : boolean;
  194. dllversion : string;
  195. dllmajor,
  196. dllminor,
  197. dllrevision : word; { revision only for netware }
  198. { win pe }
  199. peflags : longint;
  200. minstacksize,
  201. maxstacksize,
  202. imagebase : aword;
  203. UseDeffileForExports : boolean;
  204. UseDeffileForExportsSetExplicitly : boolean;
  205. GenerateImportSection,
  206. GenerateImportSectionSetExplicitly,
  207. RelocSection : boolean;
  208. RelocSectionSetExplicitly : boolean;
  209. LinkTypeSetExplicitly : boolean;
  210. current_tokenpos, { position of the last token }
  211. current_filepos : tfileposinfo; { current position }
  212. nwscreenname : string;
  213. nwthreadname : string;
  214. nwcopyright : string;
  215. codegenerror : boolean; { true if there is an error reported }
  216. block_type : tblock_type; { type of currently parsed block }
  217. parsing_para_level : integer; { parameter level, used to convert
  218. proc calls to proc loads in firstcalln }
  219. compile_level : word;
  220. resolving_forward : boolean; { used to add forward reference as second ref }
  221. inlining_procedure : boolean; { are we inlining a procedure }
  222. exceptblockcounter : integer; { each except block gets a unique number check gotos }
  223. aktexceptblock : integer; { the exceptblock number of the current block (0 if none) }
  224. LinkLibraryAliases : TLinkStrMap;
  225. LinkLibraryOrder : TLinkStrMap;
  226. init_settings,
  227. current_settings : tsettings;
  228. nextlocalswitches : tlocalswitches;
  229. localswitcheschanged : boolean;
  230. { Memory sizes }
  231. heapsize,
  232. stacksize,
  233. jmp_buf_size : longint;
  234. {$Ifdef EXTDEBUG}
  235. { parameter switches }
  236. debugstop : boolean;
  237. {$EndIf EXTDEBUG}
  238. { windows / OS/2 application type }
  239. apptype : tapptype;
  240. features : tfeatures;
  241. const
  242. DLLsource : boolean = false;
  243. DLLImageBase : pshortstring = nil;
  244. { used to set all registers used for each global function
  245. this should dramatically decrease the number of
  246. recompilations needed PM }
  247. simplify_ppu : boolean = true;
  248. { should we allow non static members ? }
  249. allow_only_static : boolean = false;
  250. Inside_asm_statement : boolean = false;
  251. global_unit_count : word = 0;
  252. { for error info in pp.pas }
  253. parser_current_file : string = '';
  254. {$if defined(m68k) or defined(arm)}
  255. { PalmOS resources }
  256. palmos_applicationname : string = 'FPC Application';
  257. palmos_applicationid : string[4] = 'FPCA';
  258. {$endif defined(m68k) or defined(arm)}
  259. {$ifdef powerpc}
  260. { default calling convention used on MorphOS }
  261. syscall_convention : string = 'LEGACY';
  262. {$endif powerpc}
  263. { default name of the C-style "main" procedure of the library/program }
  264. { (this will be prefixed with the target_info.cprefix) }
  265. mainaliasname : string = 'main';
  266. { by default no local variable trashing }
  267. localvartrashing: longint = -1;
  268. { actual values are defined in ncgutil.pas }
  269. nroftrashvalues = 4;
  270. function getdatestr:string;
  271. function gettimestr:string;
  272. function filetimestring( t : longint) : string;
  273. procedure DefaultReplacements(var s:string);
  274. function Shell(const command:ansistring): longint;
  275. function GetEnvPChar(const envname:string):pchar;
  276. procedure FreeEnvPChar(p:pchar);
  277. procedure SetFPUExceptionMask(const Mask: TFPUExceptionMask);
  278. function is_number_float(d : double) : boolean;
  279. { discern +0.0 and -0.0 }
  280. function get_real_sign(r: bestreal): longint;
  281. procedure InitGlobals;
  282. procedure DoneGlobals;
  283. function string2guid(const s: string; var GUID: TGUID): boolean;
  284. function guid2string(const GUID: TGUID): string;
  285. function SetAktProcCall(const s:string; var a:tproccalloption):boolean;
  286. function Setcputype(const s:string;var a:tcputype):boolean;
  287. function SetFpuType(const s:string;var a:tfputype):boolean;
  288. function UpdateAlignmentStr(s:string;var a:talignmentinfo):boolean;
  289. function UpdateOptimizerStr(s:string;var a:toptimizerswitches):boolean;
  290. function IncludeFeature(const s : string) : boolean;
  291. {# Routine to get the required alignment for size of data, which will
  292. be placed in bss segment, according to the current alignment requirements }
  293. function var_align(siz: shortint): shortint;
  294. {# Routine to get the required alignment for size of data, which will
  295. be placed in data/const segment, according to the current alignment requirements }
  296. function const_align(siz: shortint): shortint;
  297. implementation
  298. uses
  299. {$ifdef macos}
  300. macutils,
  301. {$endif}
  302. comphook;
  303. {****************************************************************************
  304. TLinkStrMap
  305. ****************************************************************************}
  306. Constructor TLinkStrMap.create;
  307. begin
  308. inherited;
  309. itemcnt:=0;
  310. end;
  311. procedure TLinkStrMap.Add(key:ansistring;value:AnsiString='';weight:longint=LinkMapWeightDefault);
  312. begin
  313. if lookup(key)<>-1 Then
  314. exit;
  315. if itemcnt<=length(fmap) Then
  316. setlength(fmap,itemcnt+10);
  317. fmap[itemcnt].key:=key;
  318. fmap[itemcnt].value:=value;
  319. fmap[itemcnt].weight:=weight;
  320. inc(itemcnt);
  321. end;
  322. function TLinkStrMap.AddDep(keyvalue:String):boolean;
  323. var
  324. i : Longint;
  325. begin
  326. AddDep:=false;
  327. i:=pos('=',keyvalue);
  328. if i=0 then
  329. exit;
  330. Add(Copy(KeyValue,1,i-1),Copy(KeyValue,i+1,length(KeyValue)-i));
  331. AddDep:=True;
  332. end;
  333. function TLinkStrMap.AddWeight(keyvalue:String):boolean;
  334. var
  335. i,j : Longint;
  336. Code : Word;
  337. s : AnsiString;
  338. begin
  339. AddWeight:=false;
  340. i:=pos('=',keyvalue);
  341. if i=0 then
  342. exit;
  343. s:=Copy(KeyValue,i+1,length(KeyValue)-i);
  344. val(s,j,code);
  345. if code=0 Then
  346. begin
  347. Add(Copy(KeyValue,1,i-1),'',j);
  348. AddWeight:=True;
  349. end;
  350. end;
  351. procedure TLinkStrMap.addseries(keys:AnsiString;weight:longint);
  352. var
  353. i,j,k : longint;
  354. begin
  355. k:=length(keys);
  356. i:=1;
  357. while i<=k do
  358. begin
  359. j:=i;
  360. while (i<=k) and (keys[i]<>',') do
  361. inc(i);
  362. add(copy(keys,j,i-j),'',weight);
  363. inc(i);
  364. end;
  365. end;
  366. procedure TLinkStrMap.SetValue(Key:Ansistring;weight:Integer);
  367. var
  368. j : longint;
  369. begin
  370. j:=lookup(key);
  371. if j<>-1 then
  372. fmap[j].weight:=weight;
  373. end;
  374. function TLinkStrMap.find(key:Ansistring):Ansistring;
  375. var
  376. j : longint;
  377. begin
  378. find:='';
  379. j:=lookup(key);
  380. if j<>-1 then
  381. find:=fmap[j].value;
  382. end;
  383. function TLinkStrMap.lookup(key:Ansistring):longint;
  384. var
  385. i : longint;
  386. begin
  387. lookup:=-1;
  388. i:=0;
  389. while (i<itemcnt) and (fmap[i].key<>key) do
  390. inc(i);
  391. if i<>itemcnt then
  392. lookup:=i;
  393. end;
  394. procedure TLinkStrMap.SortOnWeight;
  395. var
  396. i, j : longint;
  397. m : TLinkRec;
  398. begin
  399. if itemcnt <2 then exit;
  400. for i:=0 to itemcnt-1 do
  401. for j:=i+1 to itemcnt-1 do
  402. begin
  403. if fmap[i].weight>fmap[j].weight Then
  404. begin
  405. m:=fmap[i];
  406. fmap[i]:=fmap[j];
  407. fmap[j]:=m;
  408. end;
  409. end;
  410. end;
  411. function TLinkStrMap.getlinkrec(i:longint):TLinkRec;
  412. begin
  413. result:=fmap[i];
  414. end;
  415. procedure TLinkStrMap.Expand(Src:TStringList;Dest:TLinkStrMap);
  416. // expands every thing in Src to Dest for linkorder purposes.
  417. var
  418. l,r : longint;
  419. LibN : String;
  420. begin
  421. while not src.empty do
  422. begin
  423. LibN:=src.getfirst;
  424. r:=lookup (LibN);
  425. if r=-1 then
  426. dest.add(LibN)
  427. else
  428. dest.addseries(fmap[r].value);
  429. end;
  430. end;
  431. procedure TLinkStrMap.UpdateWeights(Weightmap:TLinkStrMap);
  432. var
  433. l,r : longint;
  434. begin
  435. for l := 0 to itemcnt-1 do
  436. begin
  437. r:=weightmap.lookup (fmap[l].key);
  438. if r<>-1 then
  439. fmap[l].weight:=weightmap[r].weight;
  440. end;
  441. end;
  442. {****************************************************************************
  443. Time Handling
  444. ****************************************************************************}
  445. Function L0(l:longint):string;
  446. {
  447. return the string of value l, if l<10 then insert a zero, so
  448. the string is always at least 2 chars '01','02',etc
  449. }
  450. var
  451. s : string;
  452. begin
  453. Str(l,s);
  454. if l<10 then
  455. s:='0'+s;
  456. L0:=s;
  457. end;
  458. function gettimestr:string;
  459. {
  460. get the current time in a string HH:MM:SS
  461. }
  462. var
  463. hour,min,sec,hsec : word;
  464. begin
  465. DecodeTime(Time,hour,min,sec,hsec);
  466. gettimestr:=L0(Hour)+':'+L0(min)+':'+L0(sec);
  467. end;
  468. function getdatestr:string;
  469. {
  470. get the current date in a string YY/MM/DD
  471. }
  472. var
  473. Year,Month,Day: Word;
  474. begin
  475. DecodeDate(Date,year,month,day);
  476. getdatestr:=L0(Year)+'/'+L0(Month)+'/'+L0(Day);
  477. end;
  478. function filetimestring( t : longint) : string;
  479. {
  480. convert dos datetime t to a string YY/MM/DD HH:MM:SS
  481. }
  482. var
  483. DT : TDateTime;
  484. hsec : word;
  485. Year,Month,Day: Word;
  486. hour,min,sec : word;
  487. begin
  488. if t=-1 then
  489. begin
  490. Result := 'Not Found';
  491. exit;
  492. end;
  493. DT := FileDateToDateTime(t);
  494. DecodeTime(DT,hour,min,sec,hsec);
  495. DecodeDate(DT,year,month,day);
  496. Result := L0(Year)+'/'+L0(Month)+'/'+L0(Day)+' '+L0(Hour)+':'+L0(min)+':'+L0(sec);
  497. end;
  498. {****************************************************************************
  499. Default Macro Handling
  500. ****************************************************************************}
  501. procedure DefaultReplacements(var s:string);
  502. begin
  503. { Replace some macros }
  504. Replace(s,'$FPCVERSION',version_string);
  505. Replace(s,'$FPCFULLVERSION',full_version_string);
  506. Replace(s,'$FPCDATE',date_string);
  507. Replace(s,'$FPCCPU',target_cpu_string);
  508. Replace(s,'$FPCOS',target_os_string);
  509. if tf_use_8_3 in Source_Info.Flags then
  510. Replace(s,'$FPCTARGET',target_os_string)
  511. else
  512. Replace(s,'$FPCTARGET',target_full_string);
  513. end;
  514. {****************************************************************************
  515. OS Dependent things
  516. ****************************************************************************}
  517. function GetEnvPChar(const envname:string):pchar;
  518. {$ifdef win32}
  519. var
  520. s : string;
  521. i,len : longint;
  522. hp,p,p2 : pchar;
  523. {$endif}
  524. begin
  525. {$ifdef hasunix}
  526. GetEnvPchar:=BaseUnix.fpGetEnv(envname);
  527. {$define GETENVOK}
  528. {$endif}
  529. {$ifdef win32}
  530. GetEnvPchar:=nil;
  531. p:=GetEnvironmentStrings;
  532. hp:=p;
  533. while hp^<>#0 do
  534. begin
  535. s:=strpas(hp);
  536. i:=pos('=',s);
  537. len:=strlen(hp);
  538. if upper(copy(s,1,i-1))=upper(envname) then
  539. begin
  540. GetMem(p2,len-length(envname));
  541. Move(hp[i],p2^,len-length(envname));
  542. GetEnvPchar:=p2;
  543. break;
  544. end;
  545. { next string entry}
  546. hp:=hp+len+1;
  547. end;
  548. FreeEnvironmentStrings(p);
  549. {$define GETENVOK}
  550. {$endif}
  551. {$ifdef os2}
  552. GetEnvPChar := Dos.GetEnvPChar (EnvName);
  553. {$define GETENVOK}
  554. {$endif}
  555. {$ifdef GETENVOK}
  556. {$undef GETENVOK}
  557. {$else}
  558. GetEnvPchar:=StrPNew(GetEnvironmentVariable(envname));
  559. {$endif}
  560. end;
  561. procedure FreeEnvPChar(p:pchar);
  562. begin
  563. {$ifndef hasunix}
  564. {$ifndef os2}
  565. freemem(p);
  566. {$endif}
  567. {$endif}
  568. end;
  569. {$if defined(MORPHOS) or defined(AMIGA)}
  570. {$define AMIGASHELL}
  571. {$endif}
  572. function Shell(const command:ansistring): longint;
  573. { This is already defined in the linux.ppu for linux, need for the *
  574. expansion under linux }
  575. {$ifdef hasunix}
  576. begin
  577. result := Unix.Shell(command);
  578. end;
  579. {$else hasunix}
  580. {$ifdef amigashell}
  581. begin
  582. result := ExecuteProcess('',command);
  583. end;
  584. {$else amigashell}
  585. var
  586. comspec : string;
  587. begin
  588. comspec:=GetEnvironmentVariable('COMSPEC');
  589. result := ExecuteProcess(comspec,' /C '+command);
  590. end;
  591. {$endif amigashell}
  592. {$endif hasunix}
  593. {$UNDEF AMIGASHELL}
  594. {$ifdef CPUI386}
  595. {$asmmode att}
  596. {$define HASSETFPUEXCEPTIONMASK}
  597. { later, this should be replaced by the math unit }
  598. const
  599. Default8087CW : word = $1332;
  600. procedure Set8087CW(cw:word);assembler;
  601. asm
  602. movw cw,%ax
  603. movw %ax,default8087cw
  604. fnclex
  605. fldcw default8087cw
  606. end;
  607. function Get8087CW:word;assembler;
  608. asm
  609. pushl $0
  610. fnstcw (%esp)
  611. popl %eax
  612. end;
  613. procedure SetFPUExceptionMask(const Mask: TFPUExceptionMask);
  614. var
  615. CtlWord: Word;
  616. begin
  617. CtlWord:=Get8087CW;
  618. Set8087CW( (CtlWord and $FFC0) or Byte(Longint(Mask)) );
  619. end;
  620. {$endif CPUI386}
  621. {$ifdef CPUX86_64}
  622. {$define HASSETFPUEXCEPTIONMASK}
  623. { later, this should be replaced by the math unit }
  624. const
  625. Default8087CW : word = $1332;
  626. procedure Set8087CW(cw:word);assembler;
  627. asm
  628. movw cw,%ax
  629. movw %ax,default8087cw
  630. fnclex
  631. fldcw default8087cw
  632. end;
  633. function Get8087CW:word;assembler;
  634. asm
  635. pushq $0
  636. fnstcw (%rsp)
  637. popq %rax
  638. end;
  639. procedure SetSSECSR(w : dword);
  640. var
  641. _w : dword;
  642. begin
  643. _w:=w;
  644. asm
  645. ldmxcsr _w
  646. end;
  647. end;
  648. function GetSSECSR : dword;
  649. var
  650. _w : dword;
  651. begin
  652. asm
  653. stmxcsr _w
  654. end;
  655. result:=_w;
  656. end;
  657. procedure SetFPUExceptionMask(const Mask: TFPUExceptionMask);
  658. var
  659. CtlWord: Word;
  660. newmask : dword;
  661. const
  662. MM_MaskInvalidOp = %0000000010000000;
  663. MM_MaskDenorm = %0000000100000000;
  664. MM_MaskDivZero = %0000001000000000;
  665. MM_MaskOverflow = %0000010000000000;
  666. MM_MaskUnderflow = %0000100000000000;
  667. MM_MaskPrecision = %0001000000000000;
  668. begin
  669. { classic FPU }
  670. CtlWord:=Get8087CW;
  671. Set8087CW( (CtlWord and $FFC0) or Byte(Longint(Mask)) );
  672. { SSE }
  673. newmask:=GetSSECSR;
  674. { invalid operation }
  675. if (exInvalidOp in mask) then
  676. newmask:=newmask or MM_MaskInvalidOp
  677. else
  678. newmask:=newmask and not(MM_MaskInvalidOp);
  679. { denormals }
  680. if (exDenormalized in mask) then
  681. newmask:=newmask or MM_MaskDenorm
  682. else
  683. newmask:=newmask and not(MM_MaskDenorm);
  684. { zero divide }
  685. if (exZeroDivide in mask) then
  686. newmask:=newmask or MM_MaskDivZero
  687. else
  688. newmask:=newmask and not(MM_MaskDivZero);
  689. { overflow }
  690. if (exOverflow in mask) then
  691. newmask:=newmask or MM_MaskOverflow
  692. else
  693. newmask:=newmask and not(MM_MaskOverflow);
  694. { underflow }
  695. if (exUnderflow in mask) then
  696. newmask:=newmask or MM_MaskUnderflow
  697. else
  698. newmask:=newmask and not(MM_MaskUnderflow);
  699. { Precision (inexact result) }
  700. if (exPrecision in mask) then
  701. newmask:=newmask or MM_MaskPrecision
  702. else
  703. newmask:=newmask and not(MM_MaskPrecision);
  704. SetSSECSR(newmask);
  705. end;
  706. {$endif CPUX86_64}
  707. {$ifdef CPUPOWERPC}
  708. {$define HASSETFPUEXCEPTIONMASK}
  709. procedure SetFPUExceptionMask(const Mask: TFPUExceptionMask);
  710. var
  711. newmask: record
  712. case byte of
  713. 1: (d: double);
  714. 2: (a,b: cardinal);
  715. end;
  716. begin
  717. { load current control register contents }
  718. asm
  719. mffs f0
  720. stfd f0,newmask.d
  721. end;
  722. { invalid operation: bit 24 (big endian, bit 0 = left-most bit) }
  723. if (exInvalidOp in mask) then
  724. newmask.b := newmask.b and not(1 shl (31-24))
  725. else
  726. newmask.b := newmask.b or (1 shl (31-24));
  727. { denormals can not cause exceptions on the PPC }
  728. { zero divide: bit 27 }
  729. if (exZeroDivide in mask) then
  730. newmask.b := newmask.b and not(1 shl (31-27))
  731. else
  732. newmask.b := newmask.b or (1 shl (31-27));
  733. { overflow: bit 25 }
  734. if (exOverflow in mask) then
  735. newmask.b := newmask.b and not(1 shl (31-25))
  736. else
  737. newmask.b := newmask.b or (1 shl (31-25));
  738. { underflow: bit 26 }
  739. if (exUnderflow in mask) then
  740. newmask.b := newmask.b and not(1 shl (31-26))
  741. else
  742. newmask.b := newmask.b or (1 shl (31-26));
  743. { Precision (inexact result): bit 28 }
  744. if (exPrecision in mask) then
  745. newmask.b := newmask.b and not(1 shl (31-28))
  746. else
  747. newmask.b := newmask.b or (1 shl (31-28));
  748. { update control register contents }
  749. asm
  750. lfd f0, newmask.d
  751. mtfsf 255,f0
  752. end;
  753. end;
  754. {$endif CPUPOWERPC}
  755. {$ifdef CPUSPARC}
  756. {$define HASSETFPUEXCEPTIONMASK}
  757. procedure SetFPUExceptionMask(const Mask: TFPUExceptionMask);
  758. var
  759. fsr : cardinal;
  760. begin
  761. { load current control register contents }
  762. asm
  763. st %fsr,fsr
  764. end;
  765. { invalid operation: bit 27 }
  766. if (exInvalidOp in mask) then
  767. fsr:=fsr and not(1 shl 27)
  768. else
  769. fsr:=fsr or (1 shl 27);
  770. { zero divide: bit 24 }
  771. if (exZeroDivide in mask) then
  772. fsr:=fsr and not(1 shl 24)
  773. else
  774. fsr:=fsr or (1 shl 24);
  775. { overflow: bit 26 }
  776. if (exOverflow in mask) then
  777. fsr:=fsr and not(1 shl 26)
  778. else
  779. fsr:=fsr or (1 shl 26);
  780. { underflow: bit 25 }
  781. if (exUnderflow in mask) then
  782. fsr:=fsr and not(1 shl 25)
  783. else
  784. fsr:=fsr or (1 shl 25);
  785. { Precision (inexact result): bit 23 }
  786. if (exPrecision in mask) then
  787. fsr:=fsr and not(1 shl 23)
  788. else
  789. fsr:=fsr or (1 shl 23);
  790. { update control register contents }
  791. asm
  792. ld fsr,%fsr
  793. end;
  794. end;
  795. {$endif CPUSPARC}
  796. {$ifndef HASSETFPUEXCEPTIONMASK}
  797. procedure SetFPUExceptionMask(const Mask: TFPUExceptionMask);
  798. begin
  799. end;
  800. {$endif HASSETFPUEXCEPTIONMASK}
  801. function is_number_float(d : double) : boolean;
  802. var
  803. bytearray : array[0..7] of byte;
  804. begin
  805. move(d,bytearray,8);
  806. { only 1.1 save, 1.0.x will use always little endian }
  807. {$ifdef FPC_BIG_ENDIAN}
  808. result:=((bytearray[0] and $7f)<>$7f) or ((bytearray[1] and $f0)<>$f0);
  809. {$else FPC_BIG_ENDIAN}
  810. result:=((bytearray[7] and $7f)<>$7f) or ((bytearray[6] and $f0)<>$f0);
  811. {$endif FPC_BIG_ENDIAN}
  812. end;
  813. function get_real_sign(r: bestreal): longint;
  814. var
  815. p: pbyte;
  816. begin
  817. p := pbyte(@r);
  818. {$ifdef CPU_ARM}
  819. inc(p,4);
  820. {$else}
  821. {$ifdef FPC_LITTLE_ENDIAN}
  822. inc(p,sizeof(r)-1);
  823. {$endif}
  824. {$endif}
  825. if (p^ and $80) = 0 then
  826. result := 1
  827. else
  828. result := -1;
  829. end;
  830. function convertdoublerec(d : tdoublerec) : tdoublerec;{$ifdef USEINLINE}inline;{$endif}
  831. {$ifdef CPUARM}
  832. var
  833. i : longint;
  834. begin
  835. for i:=0 to 3 do
  836. begin
  837. result.bytes[i+4]:=d.bytes[i];
  838. result.bytes[i]:=d.bytes[i+4];
  839. end;
  840. {$else CPUARM}
  841. begin
  842. result:=d;
  843. {$endif CPUARM}
  844. end;
  845. { '('D1:'00000000-'D2:'0000-'D3:'0000-'D4:'0000-000000000000)' }
  846. function string2guid(const s: string; var GUID: TGUID): boolean;
  847. function ishexstr(const hs: string): boolean;
  848. var
  849. i: integer;
  850. begin
  851. ishexstr:=false;
  852. for i:=1 to Length(hs) do begin
  853. if not (hs[i] in ['0'..'9','A'..'F','a'..'f']) then
  854. exit;
  855. end;
  856. ishexstr:=true;
  857. end;
  858. function hexstr2longint(const hexs: string): longint;
  859. var
  860. i: integer;
  861. rl: longint;
  862. begin
  863. rl:=0;
  864. for i:=1 to length(hexs) do begin
  865. rl:=rl shl 4;
  866. case hexs[i] of
  867. '0'..'9' : inc(rl,ord(hexs[i])-ord('0'));
  868. 'A'..'F' : inc(rl,ord(hexs[i])-ord('A')+10);
  869. 'a'..'f' : inc(rl,ord(hexs[i])-ord('a')+10);
  870. end
  871. end;
  872. hexstr2longint:=rl;
  873. end;
  874. var
  875. i: integer;
  876. begin
  877. if (Length(s)=38) and (s[1]='{') and (s[38]='}') and
  878. (s[10]='-') and (s[15]='-') and (s[20]='-') and (s[25]='-') and
  879. ishexstr(copy(s,2,8)) and ishexstr(copy(s,11,4)) and
  880. ishexstr(copy(s,16,4)) and ishexstr(copy(s,21,4)) and
  881. ishexstr(copy(s,26,12)) then begin
  882. GUID.D1:=dword(hexstr2longint(copy(s,2,8)));
  883. { these values are arealdy in the correct range (4 chars = word) }
  884. GUID.D2:=word(hexstr2longint(copy(s,11,4)));
  885. GUID.D3:=word(hexstr2longint(copy(s,16,4)));
  886. for i:=0 to 1 do
  887. GUID.D4[i]:=byte(hexstr2longint(copy(s,21+i*2,2)));
  888. for i:=2 to 7 do
  889. GUID.D4[i]:=byte(hexstr2longint(copy(s,22+i*2,2)));
  890. string2guid:=true;
  891. end
  892. else
  893. string2guid:=false;
  894. end;
  895. function guid2string(const GUID: TGUID): string;
  896. function long2hex(l, len: longint): string;
  897. const
  898. hextbl: array[0..15] of char = '0123456789ABCDEF';
  899. var
  900. rs: string;
  901. i: integer;
  902. begin
  903. rs[0]:=chr(len);
  904. for i:=len downto 1 do begin
  905. rs[i]:=hextbl[l and $F];
  906. l:=l shr 4;
  907. end;
  908. long2hex:=rs;
  909. end;
  910. begin
  911. guid2string:=
  912. '{'+long2hex(GUID.D1,8)+
  913. '-'+long2hex(GUID.D2,4)+
  914. '-'+long2hex(GUID.D3,4)+
  915. '-'+long2hex(GUID.D4[0],2)+long2hex(GUID.D4[1],2)+
  916. '-'+long2hex(GUID.D4[2],2)+long2hex(GUID.D4[3],2)+
  917. long2hex(GUID.D4[4],2)+long2hex(GUID.D4[5],2)+
  918. long2hex(GUID.D4[6],2)+long2hex(GUID.D4[7],2)+
  919. '}';
  920. end;
  921. function SetAktProcCall(const s:string; var a:tproccalloption):boolean;
  922. const
  923. DefProcCallName : array[tproccalloption] of string[12] = ('',
  924. 'CDECL',
  925. 'CPPDECL',
  926. 'FAR16',
  927. 'OLDFPCCALL',
  928. '', { internproc }
  929. '', { syscall }
  930. 'PASCAL',
  931. 'REGISTER',
  932. 'SAFECALL',
  933. 'STDCALL',
  934. 'SOFTFLOAT',
  935. 'MWPASCAL'
  936. );
  937. var
  938. t : tproccalloption;
  939. hs : string;
  940. begin
  941. result:=false;
  942. if (s = '') then
  943. exit;
  944. hs:=upper(s);
  945. if (hs = 'DEFAULT') then
  946. begin
  947. a := pocall_default;
  948. result := true;
  949. exit;
  950. end;
  951. for t:=low(tproccalloption) to high(tproccalloption) do
  952. if DefProcCallName[t]=hs then
  953. begin
  954. a:=t;
  955. result:=true;
  956. break;
  957. end;
  958. end;
  959. function Setcputype(const s:string;var a:tcputype):boolean;
  960. var
  961. t : tcputype;
  962. hs : string;
  963. begin
  964. result:=false;
  965. hs:=Upper(s);
  966. for t:=low(tcputype) to high(tcputype) do
  967. if cputypestr[t]=hs then
  968. begin
  969. a:=t;
  970. result:=true;
  971. break;
  972. end;
  973. end;
  974. function SetFpuType(const s:string;var a:tfputype):boolean;
  975. var
  976. t : tfputype;
  977. begin
  978. result:=false;
  979. for t:=low(tfputype) to high(tfputype) do
  980. if fputypestr[t]=s then
  981. begin
  982. a:=t;
  983. result:=true;
  984. break;
  985. end;
  986. end;
  987. function UpdateAlignmentStr(s:string;var a:talignmentinfo):boolean;
  988. var
  989. tok : string;
  990. vstr : string;
  991. l : longint;
  992. code : integer;
  993. b : talignmentinfo;
  994. begin
  995. UpdateAlignmentStr:=true;
  996. uppervar(s);
  997. fillchar(b,sizeof(b),0);
  998. repeat
  999. tok:=GetToken(s,'=');
  1000. if tok='' then
  1001. break;
  1002. vstr:=GetToken(s,',');
  1003. val(vstr,l,code);
  1004. if tok='PROC' then
  1005. b.procalign:=l
  1006. else if tok='JUMP' then
  1007. b.jumpalign:=l
  1008. else if tok='LOOP' then
  1009. b.loopalign:=l
  1010. else if tok='CONSTMIN' then
  1011. b.constalignmin:=l
  1012. else if tok='CONSTMAX' then
  1013. b.constalignmax:=l
  1014. else if tok='VARMIN' then
  1015. b.varalignmin:=l
  1016. else if tok='VARMAX' then
  1017. b.varalignmax:=l
  1018. else if tok='LOCALMIN' then
  1019. b.localalignmin:=l
  1020. else if tok='LOCALMAX' then
  1021. b.localalignmax:=l
  1022. else if tok='RECORDMIN' then
  1023. b.recordalignmin:=l
  1024. else if tok='RECORDMAX' then
  1025. b.recordalignmax:=l
  1026. else { Error }
  1027. UpdateAlignmentStr:=false;
  1028. until false;
  1029. UpdateAlignment(a,b);
  1030. end;
  1031. function UpdateOptimizerStr(s:string;var a:toptimizerswitches):boolean;
  1032. var
  1033. tok : string;
  1034. doset,
  1035. found : boolean;
  1036. opt : toptimizerswitch;
  1037. begin
  1038. result:=true;
  1039. uppervar(s);
  1040. repeat
  1041. tok:=GetToken(s,',');
  1042. if tok='' then
  1043. break;
  1044. if Copy(tok,1,2)='NO' then
  1045. begin
  1046. delete(tok,1,2);
  1047. doset:=false;
  1048. end
  1049. else
  1050. doset:=true;
  1051. found:=false;
  1052. for opt:=low(toptimizerswitch) to high(toptimizerswitch) do
  1053. begin
  1054. if OptimizerSwitchStr[opt]=tok then
  1055. begin
  1056. found:=true;
  1057. break;
  1058. end;
  1059. end;
  1060. if found then
  1061. begin
  1062. if doset then
  1063. include(a,opt)
  1064. else
  1065. exclude(a,opt);
  1066. end
  1067. else
  1068. result:=false;
  1069. until false;
  1070. end;
  1071. function IncludeFeature(const s : string) : boolean;
  1072. var
  1073. i : tfeature;
  1074. begin
  1075. result:=true;
  1076. for i:=low(tfeature) to high(tfeature) do
  1077. if s=featurestr[i] then
  1078. begin
  1079. include(features,i);
  1080. exit;
  1081. end;
  1082. result:=false;
  1083. end;
  1084. function var_align(siz: shortint): shortint;
  1085. begin
  1086. siz := size_2_align(siz);
  1087. var_align := used_align(siz,current_settings.alignment.varalignmin,current_settings.alignment.varalignmax);
  1088. end;
  1089. function const_align(siz: shortint): shortint;
  1090. begin
  1091. siz := size_2_align(siz);
  1092. const_align := used_align(siz,current_settings.alignment.constalignmin,current_settings.alignment.constalignmax);
  1093. end;
  1094. {****************************************************************************
  1095. Init
  1096. ****************************************************************************}
  1097. {$ifdef unix}
  1098. {$define need_path_search}
  1099. {$endif unix}
  1100. {$ifdef os2}
  1101. {$define need_path_search}
  1102. {$endif os2}
  1103. {$ifdef macos}
  1104. {$define need_path_search}
  1105. {$endif macos}
  1106. procedure get_exepath;
  1107. var
  1108. exeName:String;
  1109. {$ifdef need_path_search}
  1110. hs1 : TPathStr;
  1111. p : pchar;
  1112. {$endif need_path_search}
  1113. begin
  1114. exepath:=GetEnvironmentVariable('PPC_EXEC_PATH');
  1115. if exepath='' then
  1116. begin
  1117. exeName := FixFileName(system.paramstr(0));
  1118. exepath := ExtractFilePath(exeName);
  1119. end;
  1120. {$ifdef need_path_search}
  1121. if exepath='' then
  1122. begin
  1123. hs1 := ExtractFileName(exeName);
  1124. ChangeFileExt(hs1,source_info.exeext);
  1125. {$ifdef macos}
  1126. p:=GetEnvPchar('Commands');
  1127. {$else macos}
  1128. p:=GetEnvPchar('PATH');
  1129. {$endif macos}
  1130. FindFilePChar(hs1,p,false,exepath);
  1131. FreeEnvPChar(p);
  1132. exepath:=ExtractFilePath(exepath);
  1133. end;
  1134. {$endif need_path_search}
  1135. exepath:=FixPath(exepath,false);
  1136. end;
  1137. procedure DoneGlobals;
  1138. begin
  1139. if assigned(DLLImageBase) then
  1140. StringDispose(DLLImageBase);
  1141. librarysearchpath.Free;
  1142. unitsearchpath.Free;
  1143. objectsearchpath.Free;
  1144. includesearchpath.Free;
  1145. LinkLibraryAliases.Free;
  1146. LinkLibraryOrder.Free;
  1147. end;
  1148. procedure InitGlobals;
  1149. var
  1150. i : tfeature;
  1151. begin
  1152. get_exepath;
  1153. { reset globals }
  1154. do_build:=false;
  1155. do_release:=false;
  1156. do_make:=true;
  1157. compile_level:=0;
  1158. DLLsource:=false;
  1159. inlining_procedure:=false;
  1160. resolving_forward:=false;
  1161. LinkTypeSetExplicitly:=false;
  1162. paratarget:=system_none;
  1163. paratargetasm:=as_none;
  1164. paratargetdbg:=dbg_none;
  1165. { Output }
  1166. OutputFileName:='';
  1167. OutputPrefix:=Nil;
  1168. OutputSuffix:=Nil;
  1169. OutputExeDir:='';
  1170. OutputUnitDir:='';
  1171. { Utils directory }
  1172. utilsdirectory:='';
  1173. utilsprefix:='';
  1174. cshared:=false;
  1175. rlinkpath:='';
  1176. { Search Paths }
  1177. librarysearchpath:=TSearchPathList.Create;
  1178. unitsearchpath:=TSearchPathList.Create;
  1179. includesearchpath:=TSearchPathList.Create;
  1180. objectsearchpath:=TSearchPathList.Create;
  1181. { Def file }
  1182. usewindowapi:=false;
  1183. description:='Compiled by FPC '+version_string+' - '+target_cpu_string;
  1184. DescriptionSetExplicity:=false;
  1185. SetPEFlagsSetExplicity:=false;
  1186. ImageBaseSetExplicity:=false;
  1187. MinStackSizeSetExplicity:=false;
  1188. MaxStackSizeSetExplicity:=false;
  1189. dllversion:='';
  1190. dllmajor:=1;
  1191. dllminor:=0;
  1192. dllrevision:=0;
  1193. nwscreenname := '';
  1194. nwthreadname := '';
  1195. nwcopyright := '';
  1196. UseDeffileForExports:=false;
  1197. UseDeffileForExportsSetExplicitly:=false;
  1198. GenerateImportSection:=false;
  1199. RelocSection:=false;
  1200. RelocSectionSetExplicitly:=false;
  1201. LinkTypeSetExplicitly:=false;
  1202. { memory sizes, will be overriden by parameter or default for target
  1203. in options or init_parser }
  1204. stacksize:=0;
  1205. { not initialized yet }
  1206. jmp_buf_size:=-1;
  1207. apptype:=app_cui;
  1208. { Init values }
  1209. init_settings.modeswitches:=fpcmodeswitches;
  1210. init_settings.localswitches:=[cs_check_io,cs_typed_const_writable];
  1211. init_settings.moduleswitches:=[cs_extsyntax,cs_implicit_exceptions];
  1212. init_settings.globalswitches:=[cs_check_unit_name,cs_link_static];
  1213. init_settings.optimizerswitches:=[];
  1214. init_settings.sourcecodepage:='8859-1';
  1215. init_settings.packenum:=4;
  1216. init_settings.setalloc:=0;
  1217. fillchar(init_settings.alignment,sizeof(talignmentinfo),0);
  1218. { might be overridden later }
  1219. init_settings.asmmode:=asmmode_standard;
  1220. init_settings.cputype:=cpu_none;
  1221. init_settings.optimizecputype:=cpu_none;
  1222. init_settings.fputype:=fpu_none;
  1223. init_settings.interfacetype:=it_interfacecom;
  1224. init_settings.defproccall:=pocall_default;
  1225. { Target specific defaults, these can override previous default options }
  1226. {$ifdef i386}
  1227. init_settings.cputype:=cpu_Pentium;
  1228. init_settings.optimizecputype:=cpu_Pentium3;
  1229. init_settings.fputype:=fpu_x87;
  1230. {$endif i386}
  1231. {$ifdef m68k}
  1232. init_settings.cputype:=cpu_MC68020;
  1233. init_settings.fputype:=fpu_soft;
  1234. {$endif m68k}
  1235. {$ifdef powerpc}
  1236. init_settings.cputype:=cpu_PPC604;
  1237. init_settings.fputype:=fpu_standard;
  1238. {$endif powerpc}
  1239. {$ifdef POWERPC64}
  1240. init_settings.cputype:=cpu_PPC970;
  1241. init_settings.fputype:=fpu_standard;
  1242. {$endif POWERPC64}
  1243. {$ifdef sparc}
  1244. init_settings.cputype:=cpu_SPARC_V8;
  1245. init_settings.fputype:=fpu_hard;
  1246. {$endif sparc}
  1247. {$ifdef arm}
  1248. init_settings.cputype:=cpu_armv3;
  1249. init_settings.fputype:=fpu_fpa;
  1250. {$endif arm}
  1251. {$ifdef x86_64}
  1252. init_settings.cputype:=cpu_athlon64;
  1253. init_settings.fputype:=fpu_sse64;
  1254. {$endif x86_64}
  1255. if init_settings.optimizecputype=cpu_none then
  1256. init_settings.optimizecputype:=init_settings.cputype;
  1257. LinkLibraryAliases :=TLinkStrMap.Create;
  1258. LinkLibraryOrder :=TLinkStrMap.Create;
  1259. { enable all features by default }
  1260. for i:=low(tfeature) to high(tfeature) do
  1261. include(features,i);
  1262. end;
  1263. end.