globals.pas 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577
  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 windows}
  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,cfileutl,
  37. cpuinfo,
  38. {$if defined(LLVM) and not defined(GENERIC_CPU)}
  39. llvminfo,
  40. {$endif LLVM and not GENERIC_CPU}
  41. globtype,version,systems;
  42. const
  43. delphimodeswitches =
  44. [m_delphi,m_class,m_objpas,m_result,m_string_pchar,
  45. m_pointer_2_procedure,m_autoderef,m_tp_procvar,m_initfinal,m_default_ansistring,
  46. m_out,m_default_para,m_duplicate_names,m_hintdirective,
  47. m_property,m_default_inline,m_except,m_advanced_records];
  48. delphiunicodemodeswitches = delphimodeswitches + [m_systemcodepage,m_default_unicodestring];
  49. fpcmodeswitches =
  50. [m_fpc,m_string_pchar,m_nested_comment,m_repeat_forward,
  51. m_cvar_support,m_initfinal,m_hintdirective,
  52. m_property,m_default_inline];
  53. objfpcmodeswitches =
  54. [m_objfpc,m_fpc,m_class,m_objpas,m_result,m_string_pchar,m_nested_comment,
  55. m_repeat_forward,m_cvar_support,m_initfinal,m_out,m_default_para,m_hintdirective,
  56. m_property,m_default_inline,m_except];
  57. tpmodeswitches =
  58. [m_tp7,m_tp_procvar,m_duplicate_names];
  59. {$ifdef gpc_mode}
  60. gpcmodeswitches =
  61. [m_gpc,m_tp_procvar];
  62. {$endif}
  63. macmodeswitches =
  64. [m_mac,m_cvar_support,m_mac_procvar,m_nested_procvars,m_non_local_goto,m_isolike_unary_minus,m_default_inline];
  65. isomodeswitches =
  66. [m_iso,m_tp_procvar,m_duplicate_names,m_nested_procvars,m_non_local_goto,m_isolike_unary_minus,m_isolike_io,
  67. m_isolike_program_para,
  68. m_isolike_mod];
  69. extpasmodeswitches =
  70. [m_extpas,m_tp_procvar,m_duplicate_names,m_nested_procvars,m_non_local_goto,m_isolike_unary_minus,m_isolike_io,
  71. m_isolike_program_para,
  72. m_isolike_mod];
  73. { maximum nesting of routines }
  74. maxnesting = 32;
  75. { Filenames and extensions }
  76. sourceext = '.pp';
  77. pasext = '.pas';
  78. pext = '.p';
  79. treelogfilename = 'tree.log';
  80. {$if defined(CPUARM) and defined(FPUFPA)}
  81. MathQNaN : tcompdoublerec = (bytes : (0,0,252,255,0,0,0,0));
  82. MathInf : tcompdoublerec = (bytes : (0,0,240,127,0,0,0,0));
  83. MathNegInf : tcompdoublerec = (bytes : (0,0,240,255,0,0,0,0));
  84. MathPi : tcompdoublerec = (bytes : (251,33,9,64,24,45,68,84));
  85. {$else}
  86. {$ifdef FPC_LITTLE_ENDIAN}
  87. MathQNaN : tcompdoublerec = (bytes : (0,0,0,0,0,0,252,255));
  88. MathInf : tcompdoublerec = (bytes : (0,0,0,0,0,0,240,127));
  89. MathNegInf : tcompdoublerec = (bytes : (0,0,0,0,0,0,240,255));
  90. MathPi : tcompdoublerec = (bytes : (24,45,68,84,251,33,9,64));
  91. MathPiExtended : tcompextendedrec = (bytes : (53,194,104,33,162,218,15,201,0,64));
  92. {$else FPC_LITTLE_ENDIAN}
  93. MathQNaN : tcompdoublerec = (bytes : (255,252,0,0,0,0,0,0));
  94. MathInf : tcompdoublerec = (bytes : (127,240,0,0,0,0,0,0));
  95. MathNegInf : tcompdoublerec = (bytes : (255,240,0,0,0,0,0,0));
  96. MathPi : tcompdoublerec = (bytes : (64,9,33,251,84,68,45,24));
  97. MathPiExtended : tcompextendedrec = (bytes : (64,0,201,15,218,162,33,104,194,53));
  98. {$endif FPC_LITTLE_ENDIAN}
  99. {$endif}
  100. CP_UTF8 = 65001;
  101. CP_UTF16LE = 1200;
  102. CP_UTF16BE = 1201;
  103. CP_NONE = 65535;
  104. { by default no local variable trashing }
  105. localvartrashing: longint = -1;
  106. nroftrashvalues = 4;
  107. trashintvalues: array[0..nroftrashvalues-1] of int64 = ($5555555555555555,$AAAAAAAAAAAAAAAA,$EFEFEFEFEFEFEFEF,0);
  108. type
  109. { this is written to ppus during token recording for generics,
  110. it used to required to be packed,
  111. but this requirement is now obsolete,
  112. as the fields are written one by one. PM 2012-06-13 }
  113. tsettings = record
  114. alignment : talignmentinfo;
  115. globalswitches : tglobalswitches;
  116. targetswitches : ttargetswitches;
  117. moduleswitches : tmoduleswitches;
  118. localswitches : tlocalswitches;
  119. modeswitches : tmodeswitches;
  120. optimizerswitches : toptimizerswitches;
  121. { generate information necessary to perform these wpo's during a subsequent compilation }
  122. genwpoptimizerswitches: twpoptimizerswitches;
  123. { perform these wpo's using information generated during a previous compilation }
  124. dowpoptimizerswitches: twpoptimizerswitches;
  125. debugswitches : tdebugswitches;
  126. { 0: old behaviour for sets <=256 elements
  127. >0: round to this size }
  128. setalloc,
  129. packenum : shortint;
  130. packrecords : shortint;
  131. maxfpuregisters : shortint;
  132. cputype,
  133. optimizecputype,
  134. asmcputype : tcputype;
  135. fputype : tfputype;
  136. asmmode : tasmmode;
  137. interfacetype : tinterfacetypes;
  138. defproccall : tproccalloption;
  139. sourcecodepage : tstringencoding;
  140. minfpconstprec : tfloattype;
  141. disabledircache : boolean;
  142. {$if defined(i8086)}
  143. x86memorymodel : tx86memorymodel;
  144. {$endif defined(i8086)}
  145. {$if defined(ARM)}
  146. instructionset : tinstructionset;
  147. {$endif defined(ARM)}
  148. {$if defined(LLVM) and not defined(GENERIC_CPU)}
  149. llvmversion: tllvmversion;
  150. {$endif defined(LLVM) and not defined(GENERIC_CPU)}
  151. { CPU targets with microcontroller support can add a controller specific unit }
  152. controllertype : tcontrollertype;
  153. { WARNING: this pointer cannot be written as such in record token }
  154. pmessage : pmessagestaterecord;
  155. end;
  156. const
  157. LinkMapWeightDefault = 1000;
  158. type
  159. TLinkRec = record
  160. Key : AnsiString;
  161. Value : AnsiString; // key expands to valuelist "value"
  162. Weight: longint;
  163. end;
  164. TLinkStrMap = class
  165. private
  166. itemcnt : longint;
  167. fmap : Array Of TLinkRec;
  168. function Lookup(key:Ansistring):longint;
  169. function getlinkrec(i:longint):TLinkRec;
  170. public
  171. procedure Add(key:ansistring;value:AnsiString='';weight:longint=LinkMapWeightDefault);
  172. procedure addseries(keys:AnsiString;weight:longint=LinkMapWeightDefault);
  173. function AddDep(keyvalue:String):boolean;
  174. function AddWeight(keyvalue:String):boolean;
  175. procedure SetValue(key:AnsiString;Weight:Integer);
  176. procedure SortonWeight;
  177. function Find(key:AnsiString):AnsiString;
  178. procedure Expand(src:TCmdStrList;dest: TLinkStrMap);
  179. procedure UpdateWeights(Weightmap:TLinkStrMap);
  180. constructor Create;
  181. property count : longint read itemcnt;
  182. property items[I:longint]:TLinkRec read getlinkrec; default;
  183. end;
  184. tpendingstate = record
  185. nextverbositystr : shortstring;
  186. nextlocalswitches : tlocalswitches;
  187. nextverbosityfullswitch: longint;
  188. nextcallingstr : shortstring;
  189. nextmessagerecord : pmessagestaterecord;
  190. nextalignment : talignmentinfo;
  191. alignmentchanged,
  192. verbosityfullswitched,
  193. localswitcheschanged : boolean;
  194. end;
  195. var
  196. { specified inputfile }
  197. inputfilepath : string;
  198. inputfilename : string;
  199. { specified outputfile with -o parameter }
  200. outputfilename : string;
  201. outputprefix : pshortstring;
  202. outputsuffix : pshortstring;
  203. { specified with -FE or -FU }
  204. outputexedir : TPathStr;
  205. outputunitdir : TPathStr;
  206. { specified with -FW and -Fw }
  207. wpofeedbackinput,
  208. wpofeedbackoutput : TPathStr;
  209. { external assembler extra option }
  210. asmextraopt : string;
  211. { things specified with parameters }
  212. paralinkoptions : TCmdStr;
  213. paradynamiclinker : string;
  214. paraprintnodetree : byte;
  215. {$ifdef PREPROCWRITE}
  216. parapreprocess : boolean;
  217. {$endif PREPROCWRITE}
  218. printnodefile : text;
  219. { typical cross compiling params}
  220. { directory where the utils can be found (options -FD) }
  221. utilsdirectory : TPathStr;
  222. { targetname specific prefix used by these utils (options -XP<path>) }
  223. utilsprefix : TCmdStr;
  224. cshared : boolean; { pass --shared to ld to link C libs shared}
  225. Dontlinkstdlibpath: Boolean; { Don't add std paths to linkpath}
  226. rlinkpath : TCmdStr; { rpath-link linkdir override}
  227. sysrootpath : TCmdStr; { target system root to search dyn linker }
  228. { some flags for global compiler switches }
  229. do_build,
  230. do_release,
  231. do_make : boolean;
  232. { Path to ppc }
  233. exepath : TPathStr;
  234. { Path to unicode charmap/collation binaries }
  235. unicodepath : TPathStr;
  236. { path for searching units, different paths can be seperated by ; }
  237. librarysearchpath,
  238. unitsearchpath,
  239. objectsearchpath,
  240. includesearchpath,
  241. frameworksearchpath : TSearchPathList;
  242. packagesearchpath : TSearchPathList;
  243. { contains tpackageentry entries }
  244. packagelist : TFPHashList;
  245. autoloadunits : string;
  246. { linking }
  247. usewindowapi : boolean;
  248. description : string;
  249. SetPEFlagsSetExplicity,
  250. SetPEOptFlagsSetExplicity,
  251. SetPEOSVersionSetExplicitely,
  252. SetPESubSysVersionSetExplicitely,
  253. SetPEUserVersionSetExplicitely,
  254. ImageBaseSetExplicity,
  255. MinStackSizeSetExplicity,
  256. MaxStackSizeSetExplicity,
  257. DescriptionSetExplicity : boolean;
  258. dllversion : string;
  259. dllmajor,
  260. dllminor,
  261. dllrevision : word; { revision only for netware }
  262. { win pe }
  263. peosversionminor,
  264. peosversionmajor,
  265. pesubsysversionminor,
  266. pesubsysversionmajor,
  267. peuserversionminor,
  268. peuserversionmajor : word;
  269. peoptflags,
  270. peflags : longint;
  271. minstacksize,
  272. maxstacksize,
  273. imagebase : puint;
  274. UseDeffileForExports : boolean;
  275. UseDeffileForExportsSetExplicitly : boolean;
  276. GenerateImportSection,
  277. GenerateImportSectionSetExplicitly,
  278. RelocSection : boolean;
  279. MacOSXVersionMin,
  280. iPhoneOSVersionMin: string[15];
  281. RelocSectionSetExplicitly : boolean;
  282. current_tokenpos, { position of the last token }
  283. current_filepos : tfileposinfo; { current position }
  284. nwscreenname : string;
  285. nwthreadname : string;
  286. nwcopyright : string;
  287. codegenerror : boolean; { true if there is an error reported }
  288. exception_raised : boolean; { true if there is an exception reported }
  289. block_type : tblock_type; { type of currently parsed block }
  290. compile_level : word;
  291. exceptblockcounter : integer; { each except block gets a unique number check gotos }
  292. current_exceptblock : integer; { the exceptblock number of the current block (0 if none) }
  293. LinkLibraryAliases : TLinkStrMap;
  294. LinkLibraryOrder : TLinkStrMap;
  295. init_settings,
  296. current_settings : tsettings;
  297. pendingstate : tpendingstate;
  298. { Memory sizes }
  299. heapsize,
  300. maxheapsize,
  301. stacksize : longint;
  302. {$Ifdef EXTDEBUG}
  303. { parameter switches }
  304. debugstop : boolean;
  305. {$EndIf EXTDEBUG}
  306. { Application type (platform specific)
  307. see globtype.pas for description }
  308. apptype : tapptype;
  309. features : tfeatures;
  310. { prefix added to automatically generated setters/getters. If empty,
  311. no getters/setters will be automatically generated except if required
  312. for visibility reasons (but in that case the names will be mangled so
  313. they are unique) }
  314. prop_auto_getter_prefix,
  315. prop_auto_setter_prefix : string;
  316. const
  317. Inside_asm_statement : boolean = false;
  318. global_unit_count : word = 0;
  319. { for error info in pp.pas }
  320. parser_current_file : string = '';
  321. {$if defined(m68k) or defined(arm)}
  322. { PalmOS resources }
  323. palmos_applicationname : string = 'FPC Application';
  324. palmos_applicationid : string[4] = 'FPCA';
  325. {$endif defined(m68k) or defined(arm)}
  326. { default name of the C-style "main" procedure of the library/program }
  327. { (this will be prefixed with the target_info.cprefix) }
  328. defaultmainaliasname = 'main';
  329. mainaliasname : string = defaultmainaliasname;
  330. const
  331. default_settings : TSettings = (
  332. alignment : (
  333. procalign : 0;
  334. loopalign : 0;
  335. jumpalign : 0;
  336. constalignmin : 0;
  337. constalignmax : 0;
  338. varalignmin : 0;
  339. varalignmax : 0;
  340. localalignmin : 0;
  341. localalignmax : 0;
  342. recordalignmin : 0;
  343. recordalignmax : 0;
  344. maxCrecordalign : 0;
  345. );
  346. globalswitches : [cs_check_unit_name,cs_link_static];
  347. targetswitches : [];
  348. moduleswitches : [cs_extsyntax,cs_implicit_exceptions];
  349. localswitches : [cs_check_io,cs_typed_const_writable,cs_pointermath,cs_imported_data{$ifdef i8086},cs_force_far_calls{$endif}];
  350. modeswitches : fpcmodeswitches;
  351. optimizerswitches : [];
  352. genwpoptimizerswitches : [];
  353. dowpoptimizerswitches : [];
  354. debugswitches : [ds_dwarf_sets];
  355. setalloc : 0;
  356. packenum : 4;
  357. {$ifdef i8086}
  358. packrecords : 1;
  359. {$else i8086}
  360. packrecords : 0;
  361. {$endif i8086}
  362. maxfpuregisters : 0;
  363. { Note: GENERIC_CPU is used together with generic subdirectory to
  364. be able to compile some of the units without any real CPU.
  365. This is used to generate a CPU independant PPUDUMP utility. PM }
  366. {$ifdef GENERIC_CPU}
  367. cputype : cpu_none;
  368. optimizecputype : cpu_none;
  369. asmcputype : cpu_none;
  370. fputype : fpu_none;
  371. {$else not GENERIC_CPU}
  372. {$ifdef i386}
  373. cputype : cpu_Pentium;
  374. optimizecputype : cpu_Pentium3;
  375. asmcputype : cpu_none;
  376. fputype : fpu_x87;
  377. {$endif i386}
  378. {$ifdef m68k}
  379. cputype : cpu_MC68020;
  380. optimizecputype : cpu_MC68020;
  381. asmcputype : cpu_none;
  382. fputype : fpu_soft;
  383. {$endif m68k}
  384. {$ifdef powerpc}
  385. cputype : cpu_PPC604;
  386. optimizecputype : cpu_ppc7400;
  387. asmcputype : cpu_none;
  388. fputype : fpu_standard;
  389. {$endif powerpc}
  390. {$ifdef POWERPC64}
  391. cputype : cpu_PPC970;
  392. optimizecputype : cpu_ppc970;
  393. asmcputype : cpu_none;
  394. fputype : fpu_standard;
  395. {$endif POWERPC64}
  396. {$ifdef sparc}
  397. cputype : cpu_SPARC_V9;
  398. optimizecputype : cpu_SPARC_V9;
  399. asmcputype : cpu_none;
  400. fputype : fpu_hard;
  401. {$endif sparc}
  402. {$ifdef sparc64}
  403. cputype : cpu_SPARC_V9;
  404. optimizecputype : cpu_SPARC_V9;
  405. asmcputype : cpu_none;
  406. fputype : fpu_hard;
  407. {$endif sparc64}
  408. {$ifdef arm}
  409. cputype : cpu_armv4;
  410. optimizecputype : cpu_armv4;
  411. asmcputype : cpu_none;
  412. fputype : fpu_fpa;
  413. {$endif arm}
  414. {$ifdef x86_64}
  415. cputype : cpu_athlon64;
  416. optimizecputype : cpu_athlon64;
  417. asmcputype : cpu_none;
  418. fputype : fpu_sse64;
  419. {$endif x86_64}
  420. {$ifdef avr}
  421. cputype : cpuinfo.cpu_avr5;
  422. optimizecputype : cpuinfo.cpu_avr5;
  423. asmcputype : cpu_none;
  424. fputype : fpu_none;
  425. {$endif avr}
  426. {$ifdef mips}
  427. cputype : cpu_mips2;
  428. optimizecputype : cpu_mips2;
  429. asmcputype : cpu_none;
  430. fputype : fpu_mips2;
  431. {$endif mips}
  432. {$ifdef jvm}
  433. cputype : cpu_none;
  434. optimizecputype : cpu_none;
  435. asmcputype : cpu_none;
  436. fputype : fpu_standard;
  437. {$endif jvm}
  438. {$ifdef aarch64}
  439. cputype : cpu_armv8;
  440. optimizecputype : cpu_armv8;
  441. asmcputype : cpu_none;
  442. fputype : fpu_vfp;
  443. {$endif aarch64}
  444. {$ifdef i8086}
  445. cputype : cpu_8086;
  446. optimizecputype : cpu_8086;
  447. { Use cpu_none by default,
  448. because using cpu_8086 by default means
  449. that we reject any instruction above bare 8086 instruction set
  450. for all assembler code PM }
  451. asmcputype : cpu_none;
  452. fputype : fpu_x87;
  453. {$endif i8086}
  454. {$endif not GENERIC_CPU}
  455. asmmode : asmmode_standard;
  456. {$ifndef jvm}
  457. interfacetype : it_interfacecom;
  458. {$else jvm}
  459. interfacetype : it_interfacejava;
  460. {$endif jvm}
  461. defproccall : pocall_default;
  462. sourcecodepage : 28591;
  463. minfpconstprec : s32real;
  464. disabledircache : false;
  465. {$if defined(i8086)}
  466. x86memorymodel : mm_small;
  467. {$endif defined(i8086)}
  468. {$if defined(ARM)}
  469. instructionset : is_arm;
  470. {$endif defined(ARM)}
  471. {$if defined(LLVM) and not defined(GENERIC_CPU)}
  472. llvmversion : llvmver_3_9_0;
  473. {$endif defined(LLVM) and not defined(GENERIC_CPU)}
  474. controllertype : ct_none;
  475. pmessage : nil;
  476. );
  477. var
  478. starttime : real;
  479. function getdatestr:string;
  480. function gettimestr:string;
  481. function filetimestring( t : longint) : string;
  482. function getrealtime : real;
  483. procedure DefaultReplacements(var s:ansistring);
  484. function GetEnvPChar(const envname:ansistring):pchar;
  485. procedure FreeEnvPChar(p:pchar);
  486. function is_number_float(d : double) : boolean;
  487. { discern +0.0 and -0.0 }
  488. function get_real_sign(r: bestreal): longint;
  489. procedure InitGlobals;
  490. procedure DoneGlobals;
  491. procedure register_initdone_proc(init,done:tprocedure);
  492. function string2guid(const s: string; var GUID: TGUID): boolean;
  493. function guid2string(const GUID: TGUID): string;
  494. function SetAktProcCall(const s:string; var a:tproccalloption):boolean;
  495. function Setabitype(const s:string;var a:tabi):boolean;
  496. function Setoptimizecputype(const s:string;var a:tcputype):boolean;
  497. function Setcputype(const s:string;var a:tsettings):boolean;
  498. function SetFpuType(const s:string;var a:tfputype):boolean;
  499. function SetControllerType(const s:string;var a:tcontrollertype):boolean;
  500. function HandleFeature(const s : string) : boolean;
  501. function SetMinFPConstPrec(const s: string; var a: tfloattype) : boolean;
  502. {# Routine to get the required alignment for size of data, which will
  503. be placed in bss segment, according to the current alignment requirements }
  504. function var_align(want_align: longint): shortint;
  505. function var_align_size(siz: longint): shortint;
  506. {# Routine to get the required alignment for size of data, which will
  507. be placed in data/const segment, according to the current alignment requirements }
  508. function const_align(want_align: longint): shortint;
  509. function const_align_size(siz: longint): shortint;
  510. {$ifdef ARM}
  511. function is_double_hilo_swapped: boolean;{$ifdef USEINLINE}inline;{$endif}
  512. {$endif ARM}
  513. function floating_point_range_check_error : boolean;
  514. function use_dotted_functions: boolean;
  515. { hide Sysutils.ExecuteProcess in units using this one after SysUtils}
  516. const
  517. ExecuteProcess = 'Do not use' deprecated 'Use cfileutil.RequotedExecuteProcess instead, ExecuteProcess cannot deal with single quotes as used by Unix command lines';
  518. implementation
  519. {$if defined(macos)}
  520. uses
  521. macutils;
  522. {$elseif defined(mswindows)}
  523. uses
  524. windirs;
  525. {$endif}
  526. {****************************************************************************
  527. TLinkStrMap
  528. ****************************************************************************}
  529. Constructor TLinkStrMap.create;
  530. begin
  531. inherited;
  532. itemcnt:=0;
  533. end;
  534. procedure TLinkStrMap.Add(key:ansistring;value:AnsiString='';weight:longint=LinkMapWeightDefault);
  535. begin
  536. if lookup(key)<>-1 Then
  537. exit;
  538. if itemcnt<=length(fmap) Then
  539. setlength(fmap,itemcnt+10);
  540. fmap[itemcnt].key:=key;
  541. fmap[itemcnt].value:=value;
  542. fmap[itemcnt].weight:=weight;
  543. inc(itemcnt);
  544. end;
  545. function TLinkStrMap.AddDep(keyvalue:String):boolean;
  546. var
  547. i : Longint;
  548. begin
  549. AddDep:=false;
  550. i:=pos('=',keyvalue);
  551. if i=0 then
  552. exit;
  553. Add(Copy(KeyValue,1,i-1),Copy(KeyValue,i+1,length(KeyValue)-i));
  554. AddDep:=True;
  555. end;
  556. function TLinkStrMap.AddWeight(keyvalue:String):boolean;
  557. var
  558. i,j : Longint;
  559. Code : Word;
  560. s : AnsiString;
  561. begin
  562. AddWeight:=false;
  563. i:=pos('=',keyvalue);
  564. if i=0 then
  565. exit;
  566. s:=Copy(KeyValue,i+1,length(KeyValue)-i);
  567. val(s,j,code);
  568. if code=0 Then
  569. begin
  570. Add(Copy(KeyValue,1,i-1),'',j);
  571. AddWeight:=True;
  572. end;
  573. end;
  574. procedure TLinkStrMap.addseries(keys:AnsiString;weight:longint);
  575. var
  576. i,j,k : longint;
  577. begin
  578. k:=length(keys);
  579. i:=1;
  580. while i<=k do
  581. begin
  582. j:=i;
  583. while (i<=k) and (keys[i]<>',') do
  584. inc(i);
  585. add(copy(keys,j,i-j),'',weight);
  586. inc(i);
  587. end;
  588. end;
  589. procedure TLinkStrMap.SetValue(Key:Ansistring;weight:Integer);
  590. var
  591. j : longint;
  592. begin
  593. j:=lookup(key);
  594. if j<>-1 then
  595. fmap[j].weight:=weight;
  596. end;
  597. function TLinkStrMap.find(key:Ansistring):Ansistring;
  598. var
  599. j : longint;
  600. begin
  601. find:='';
  602. j:=lookup(key);
  603. if j<>-1 then
  604. find:=fmap[j].value;
  605. end;
  606. function TLinkStrMap.lookup(key:Ansistring):longint;
  607. var
  608. i : longint;
  609. begin
  610. lookup:=-1;
  611. i:=0;
  612. while (i<itemcnt) and (fmap[i].key<>key) do
  613. inc(i);
  614. if i<>itemcnt then
  615. lookup:=i;
  616. end;
  617. procedure TLinkStrMap.SortOnWeight;
  618. var
  619. i, j : longint;
  620. m : TLinkRec;
  621. begin
  622. if itemcnt <2 then exit;
  623. for i:=0 to itemcnt-1 do
  624. for j:=i+1 to itemcnt-1 do
  625. begin
  626. if fmap[i].weight>fmap[j].weight Then
  627. begin
  628. m:=fmap[i];
  629. fmap[i]:=fmap[j];
  630. fmap[j]:=m;
  631. end;
  632. end;
  633. end;
  634. function TLinkStrMap.getlinkrec(i:longint):TLinkRec;
  635. begin
  636. result:=fmap[i];
  637. end;
  638. procedure TLinkStrMap.Expand(Src:TCmdStrList;Dest:TLinkStrMap);
  639. // expands every thing in Src to Dest for linkorder purposes.
  640. var
  641. r : longint;
  642. LibN : TCmdStr;
  643. begin
  644. while not src.empty do
  645. begin
  646. LibN:=src.getfirst;
  647. r:=lookup (LibN);
  648. if r=-1 then
  649. dest.add(LibN)
  650. else
  651. dest.addseries(fmap[r].value);
  652. end;
  653. end;
  654. procedure TLinkStrMap.UpdateWeights(Weightmap:TLinkStrMap);
  655. var
  656. l,r : longint;
  657. begin
  658. for l := 0 to itemcnt-1 do
  659. begin
  660. r:=weightmap.lookup (fmap[l].key);
  661. if r<>-1 then
  662. fmap[l].weight:=weightmap[r].weight;
  663. end;
  664. end;
  665. {****************************************************************************
  666. Time Handling
  667. ****************************************************************************}
  668. Function L0(l:longint):string;
  669. {
  670. return the string of value l, if l<10 then insert a zero, so
  671. the string is always at least 2 chars '01','02',etc
  672. }
  673. var
  674. s : string;
  675. begin
  676. Str(l,s);
  677. if l<10 then
  678. s:='0'+s;
  679. L0:=s;
  680. end;
  681. function gettimestr:string;
  682. {
  683. get the current time in a string HH:MM:SS
  684. }
  685. var
  686. st: TSystemTime;
  687. begin
  688. GetLocalTime(st);
  689. gettimestr:=L0(st.Hour)+':'+L0(st.Minute)+':'+L0(st.Second);
  690. end;
  691. function getdatestr:string;
  692. {
  693. get the current date in a string YY/MM/DD
  694. }
  695. var
  696. st: TSystemTime;
  697. begin
  698. GetLocalTime(st);
  699. getdatestr:=L0(st.Year)+'/'+L0(st.Month)+'/'+L0(st.Day);
  700. end;
  701. function filetimestring( t : longint) : string;
  702. {
  703. convert dos datetime t to a string YY/MM/DD HH:MM:SS
  704. }
  705. var
  706. DT : TDateTime;
  707. hsec : word;
  708. Year,Month,Day: Word;
  709. hour,min,sec : word;
  710. begin
  711. if t=-1 then
  712. begin
  713. Result := 'Not Found';
  714. exit;
  715. end;
  716. DT := FileDateToDateTime(t);
  717. DecodeTime(DT,hour,min,sec,hsec);
  718. DecodeDate(DT,year,month,day);
  719. Result := L0(Year)+'/'+L0(Month)+'/'+L0(Day)+' '+L0(Hour)+':'+L0(min)+':'+L0(sec);
  720. end;
  721. function getrealtime : real;
  722. var
  723. st:TSystemTime;
  724. begin
  725. GetLocalTime(st);
  726. result:=st.Hour*3600.0+st.Minute*60.0+st.Second+st.MilliSecond/1000.0;
  727. end;
  728. {****************************************************************************
  729. Default Macro Handling
  730. ****************************************************************************}
  731. procedure DefaultReplacements(var s:ansistring);
  732. {$ifdef mswindows}
  733. procedure ReplaceSpecialFolder(const MacroName: string; const ID: integer);
  734. begin
  735. // Only try to receive the special folders (and thus dynamically
  736. // load shfolder.dll) when that's needed.
  737. if pos(MacroName,s)>0 then
  738. Replace(s,MacroName,GetWindowsSpecialDir(ID));
  739. end;
  740. {$endif mswindows}
  741. var
  742. envstr: string;
  743. envvalue: pchar;
  744. i: integer;
  745. begin
  746. { Replace some macros }
  747. Replace(s,'$FPCVERSION',version_string);
  748. Replace(s,'$FPCFULLVERSION',full_version_string);
  749. Replace(s,'$FPCDATE',date_string);
  750. Replace(s,'$FPCCPU',target_cpu_string);
  751. Replace(s,'$FPCOS',target_os_string);
  752. if (tf_use_8_3 in Source_Info.Flags) or
  753. (tf_use_8_3 in Target_Info.Flags) then
  754. Replace(s,'$FPCTARGET',target_os_string)
  755. else
  756. Replace(s,'$FPCTARGET',target_full_string);
  757. Replace(s,'$FPCSUBARCH',lower(cputypestr[init_settings.cputype]));
  758. Replace(s,'$FPCABI',lower(abiinfo[target_info.abi].name));
  759. {$ifdef i8086}
  760. Replace(s,'$FPCMEMORYMODEL',lower(x86memorymodelstr[init_settings.x86memorymodel]));
  761. {$else i8086}
  762. Replace(s,'$FPCMEMORYMODEL','flat');
  763. {$endif i8086}
  764. {$ifdef mswindows}
  765. ReplaceSpecialFolder('$LOCAL_APPDATA',CSIDL_LOCAL_APPDATA);
  766. ReplaceSpecialFolder('$APPDATA',CSIDL_APPDATA);
  767. ReplaceSpecialFolder('$COMMON_APPDATA',CSIDL_COMMON_APPDATA);
  768. ReplaceSpecialFolder('$PERSONAL',CSIDL_PERSONAL);
  769. ReplaceSpecialFolder('$PROGRAM_FILES',CSIDL_PROGRAM_FILES);
  770. ReplaceSpecialFolder('$PROGRAM_FILES_COMMON',CSIDL_PROGRAM_FILES_COMMON);
  771. ReplaceSpecialFolder('$PROFILE',CSIDL_PROFILE);
  772. {$endif mswindows}
  773. { Replace environment variables between dollar signs }
  774. i := pos('$',s);
  775. while i>0 do
  776. begin
  777. envstr:=copy(s,i+1,length(s)-i);
  778. i:=pos('$',envstr);
  779. if i>0 then
  780. begin
  781. envstr := copy(envstr,1,i-1);
  782. envvalue := GetEnvPChar(envstr);
  783. if assigned(envvalue) then
  784. begin
  785. Replace(s,'$'+envstr+'$',envvalue);
  786. // Look if there is another env.var in the string
  787. i:=pos('$',s);
  788. end
  789. else
  790. // if the env.var is not set, do not replace the env.variable
  791. // and stop looking for more env.var within the string
  792. i := 0;
  793. FreeEnvPChar(envvalue);
  794. end;
  795. end;
  796. end;
  797. {****************************************************************************
  798. OS Dependent things
  799. ****************************************************************************}
  800. function GetEnvPChar(const envname:ansistring):pchar;
  801. {$ifdef mswindows}
  802. var
  803. s : string;
  804. i,len : longint;
  805. hp,p,p2 : pchar;
  806. {$endif}
  807. begin
  808. {$ifdef hasunix}
  809. GetEnvPchar:=BaseUnix.fpGetEnv(pansichar(envname));
  810. {$define GETENVOK}
  811. {$endif}
  812. {$ifdef mswindows}
  813. GetEnvPchar:=nil;
  814. p:=GetEnvironmentStringsA;
  815. hp:=p;
  816. while hp^<>#0 do
  817. begin
  818. s:=strpas(hp);
  819. i:=pos('=',s);
  820. len:=strlen(hp);
  821. if upper(copy(s,1,i-1))=upper(envname) then
  822. begin
  823. GetMem(p2,len-length(envname));
  824. Move(hp[i],p2^,len-length(envname));
  825. GetEnvPchar:=p2;
  826. break;
  827. end;
  828. { next string entry}
  829. hp:=hp+len+1;
  830. end;
  831. FreeEnvironmentStrings(p);
  832. {$define GETENVOK}
  833. {$endif}
  834. {$ifdef os2}
  835. GetEnvPChar := Dos.GetEnvPChar (EnvName);
  836. {$define GETENVOK}
  837. {$endif}
  838. {$ifdef GETENVOK}
  839. {$undef GETENVOK}
  840. {$else}
  841. GetEnvPchar:=StrPNew(GetEnvironmentVariable(envname));
  842. if (length(GetEnvPChar)=0) then
  843. begin
  844. FreeEnvPChar(GetEnvPChar);
  845. GetEnvPChar:=nil;
  846. end;
  847. {$endif}
  848. end;
  849. procedure FreeEnvPChar(p:pchar);
  850. begin
  851. {$ifndef hasunix}
  852. {$ifndef os2}
  853. freemem(p);
  854. {$endif}
  855. {$endif}
  856. end;
  857. function is_number_float(d : double) : boolean;
  858. var
  859. bytearray : array[0..7] of byte;
  860. begin
  861. move(d,bytearray,8);
  862. { only 1.1 save, 1.0.x will use always little endian }
  863. {$ifdef FPC_BIG_ENDIAN}
  864. result:=((bytearray[0] and $7f)<>$7f) or ((bytearray[1] and $f0)<>$f0);
  865. {$else FPC_BIG_ENDIAN}
  866. result:=((bytearray[7] and $7f)<>$7f) or ((bytearray[6] and $f0)<>$f0);
  867. {$endif FPC_BIG_ENDIAN}
  868. end;
  869. function get_real_sign(r: bestreal): longint;
  870. var
  871. p: pbyte;
  872. begin
  873. p := pbyte(@r);
  874. {$ifdef CPU_ARM}
  875. inc(p,4);
  876. {$else}
  877. {$ifdef FPC_LITTLE_ENDIAN}
  878. inc(p,sizeof(r)-1);
  879. {$endif}
  880. {$endif}
  881. if (p^ and $80) = 0 then
  882. result := 1
  883. else
  884. result := -1;
  885. end;
  886. function convertdoublerec(d : tcompdoublerec) : tcompdoublerec;{$ifdef USEINLINE}inline;{$endif}
  887. {$ifdef CPUARM}
  888. var
  889. i : longint;
  890. begin
  891. for i:=0 to 3 do
  892. begin
  893. result.bytes[i+4]:=d.bytes[i];
  894. result.bytes[i]:=d.bytes[i+4];
  895. end;
  896. {$else CPUARM}
  897. begin
  898. result:=d;
  899. {$endif CPUARM}
  900. end;
  901. { '('D1:'00000000-'D2:'0000-'D3:'0000-'D4:'0000-000000000000)' }
  902. function string2guid(const s: string; var GUID: TGUID): boolean;
  903. function ishexstr(const hs: string): boolean;
  904. var
  905. i: integer;
  906. begin
  907. ishexstr:=false;
  908. for i:=1 to Length(hs) do begin
  909. if not (hs[i] in ['0'..'9','A'..'F','a'..'f']) then
  910. exit;
  911. end;
  912. ishexstr:=true;
  913. end;
  914. function hexstr2longint(const hexs: string): longint;
  915. var
  916. i: integer;
  917. rl: longint;
  918. begin
  919. rl:=0;
  920. for i:=1 to length(hexs) do begin
  921. rl:=rl shl 4;
  922. case hexs[i] of
  923. '0'..'9' : inc(rl,ord(hexs[i])-ord('0'));
  924. 'A'..'F' : inc(rl,ord(hexs[i])-ord('A')+10);
  925. 'a'..'f' : inc(rl,ord(hexs[i])-ord('a')+10);
  926. end
  927. end;
  928. hexstr2longint:=rl;
  929. end;
  930. var
  931. i: integer;
  932. begin
  933. if (Length(s)=38) and (s[1]='{') and (s[38]='}') and
  934. (s[10]='-') and (s[15]='-') and (s[20]='-') and (s[25]='-') and
  935. ishexstr(copy(s,2,8)) and ishexstr(copy(s,11,4)) and
  936. ishexstr(copy(s,16,4)) and ishexstr(copy(s,21,4)) and
  937. ishexstr(copy(s,26,12)) then begin
  938. GUID.D1:=dword(hexstr2longint(copy(s,2,8)));
  939. { these values are arealdy in the correct range (4 chars = word) }
  940. GUID.D2:=word(hexstr2longint(copy(s,11,4)));
  941. GUID.D3:=word(hexstr2longint(copy(s,16,4)));
  942. for i:=0 to 1 do
  943. GUID.D4[i]:=byte(hexstr2longint(copy(s,21+i*2,2)));
  944. for i:=2 to 7 do
  945. GUID.D4[i]:=byte(hexstr2longint(copy(s,22+i*2,2)));
  946. string2guid:=true;
  947. end
  948. else if (length(s)=0) then
  949. begin
  950. FillChar(GUID,SizeOf(GUID),0);
  951. string2guid:=true;
  952. end
  953. else
  954. string2guid:=false;
  955. end;
  956. function guid2string(const GUID: TGUID): string;
  957. begin
  958. guid2string:=
  959. '{'+hexstr(GUID.D1,8)+
  960. '-'+hexstr(GUID.D2,4)+
  961. '-'+hexstr(GUID.D3,4)+
  962. '-'+hexstr(GUID.D4[0],2)+hexstr(GUID.D4[1],2)+
  963. '-'+hexstr(GUID.D4[2],2)+hexstr(GUID.D4[3],2)+
  964. hexstr(GUID.D4[4],2)+hexstr(GUID.D4[5],2)+
  965. hexstr(GUID.D4[6],2)+hexstr(GUID.D4[7],2)+
  966. '}';
  967. end;
  968. function SetAktProcCall(const s:string; var a:tproccalloption):boolean;
  969. const
  970. DefProcCallName : array[tproccalloption] of string[16] = ('',
  971. 'CDECL',
  972. 'CPPDECL',
  973. 'FAR16',
  974. 'OLDFPCCALL',
  975. '', { internproc }
  976. '', { syscall }
  977. 'PASCAL',
  978. 'REGISTER',
  979. 'SAFECALL',
  980. 'STDCALL',
  981. 'SOFTFLOAT',
  982. 'MWPASCAL',
  983. 'INTERRUPT',
  984. 'HARDFLOAT',
  985. 'SYSV_ABI_DEFAULT',
  986. 'SYSV_ABI_CDECL',
  987. 'MS_ABI_DEFAULT',
  988. 'MS_ABI_CDECL',
  989. 'VECTORCALL'
  990. );
  991. var
  992. t : tproccalloption;
  993. hs : string;
  994. begin
  995. result:=false;
  996. if (s = '') then
  997. exit;
  998. hs:=upper(s);
  999. if (hs = 'DEFAULT') then
  1000. begin
  1001. a := pocall_default;
  1002. result := true;
  1003. exit;
  1004. end;
  1005. for t:=low(tproccalloption) to high(tproccalloption) do
  1006. if DefProcCallName[t]=hs then
  1007. begin
  1008. a:=t;
  1009. result:=true;
  1010. break;
  1011. end;
  1012. end;
  1013. function Setabitype(const s:string;var a:tabi):boolean;
  1014. var
  1015. t : tabi;
  1016. hs : string;
  1017. begin
  1018. result:=false;
  1019. hs:=Upper(s);
  1020. for t:=low(t) to high(t) do
  1021. if abiinfo[t].supported and
  1022. (abiinfo[t].name=hs) then
  1023. begin
  1024. a:=t;
  1025. { abi_old_win32_gnu is a win32 i386 specific "feature" }
  1026. if (t<>abi_old_win32_gnu) or (target_info.system=system_i386_win32) then
  1027. result:=true;
  1028. break;
  1029. end;
  1030. end;
  1031. function Setoptimizecputype(const s:string;var a:tcputype):boolean;
  1032. var
  1033. t : tcputype;
  1034. hs : string;
  1035. begin
  1036. result:=false;
  1037. hs:=Upper(s);
  1038. for t:=low(tcputype) to high(tcputype) do
  1039. if cputypestr[t]=hs then
  1040. begin
  1041. a:=t;
  1042. result:=true;
  1043. break;
  1044. end;
  1045. end;
  1046. function Setcputype(const s:string;var a:tsettings):boolean;
  1047. var
  1048. t : tcputype;
  1049. hs : string;
  1050. begin
  1051. result:=false;
  1052. hs:=Upper(s);
  1053. for t:=low(tcputype) to high(tcputype) do
  1054. if cputypestr[t]=hs then
  1055. begin
  1056. a.cputype:=t;
  1057. result:=true;
  1058. break;
  1059. end;
  1060. {$ifdef arm}
  1061. { set default instruction set for arm }
  1062. if result then
  1063. begin
  1064. if a.cputype in [cpu_armv6m,cpu_armv6t2,cpu_armv7m,cpu_armv7em] then
  1065. a.instructionset:=is_thumb
  1066. else
  1067. a.instructionset:=is_arm;
  1068. end;
  1069. {$endif arm}
  1070. end;
  1071. function SetFpuType(const s:string;var a:tfputype):boolean;
  1072. var
  1073. t : tfputype;
  1074. begin
  1075. result:=false;
  1076. for t:=low(tfputype) to high(tfputype) do
  1077. if fputypestr[t]=s then
  1078. begin
  1079. a:=t;
  1080. result:=true;
  1081. break;
  1082. end;
  1083. end;
  1084. function SetControllerType(const s:string;var a:tcontrollertype):boolean;
  1085. var
  1086. t : tcontrollertype;
  1087. hs : string;
  1088. begin
  1089. { The following check allows to reduce amount of code for platforms }
  1090. { not supporting microcontrollers due to evaluation at compile time. }
  1091. {$PUSH}
  1092. {$WARN 6018 OFF} (* Unreachable code due to compile time evaluation *)
  1093. if ControllerSupport then
  1094. begin
  1095. result:=false;
  1096. hs:=Upper(s);
  1097. for t:=low(tcontrollertype) to high(tcontrollertype) do
  1098. if embedded_controllers[t].controllertypestr=hs then
  1099. begin
  1100. a:=t;
  1101. result:=true;
  1102. break;
  1103. end;
  1104. end
  1105. else
  1106. begin
  1107. a := ct_none;
  1108. Result := true;
  1109. end;
  1110. {$POP}
  1111. end;
  1112. function HandleFeature(const s : string) : boolean;
  1113. var
  1114. i : tfeature;
  1115. begin
  1116. result:=true;
  1117. for i:=low(tfeature) to high(tfeature) do
  1118. if s=featurestr[i] then
  1119. begin
  1120. include(features,i);
  1121. exit;
  1122. end;
  1123. { Also support -Sfnoheap to exclude heap }
  1124. if Copy(S,1,2)='NO' then
  1125. for i:=low(tfeature) to high(tfeature) do
  1126. if s='NO'+featurestr[i] then
  1127. begin
  1128. exclude(features,i);
  1129. exit;
  1130. end;
  1131. result:=false;
  1132. end;
  1133. function SetMinFPConstPrec(const s: string; var a: tfloattype) : boolean;
  1134. var
  1135. value, error: longint;
  1136. begin
  1137. if (upper(s)='DEFAULT') then
  1138. begin
  1139. a:=s32real;
  1140. result:=true;
  1141. exit;
  1142. end;
  1143. result:=false;
  1144. val(s,value,error);
  1145. if (error<>0) then
  1146. exit;
  1147. case value of
  1148. 32: a:=s32real;
  1149. 64: a:=s64real;
  1150. { adding support for 80 bit here is tricky, since we can't really }
  1151. { check whether the target cpu+OS actually supports it }
  1152. else
  1153. exit;
  1154. end;
  1155. result:=true;
  1156. end;
  1157. function var_align(want_align: longint): shortint;
  1158. begin
  1159. var_align := used_align(want_align,current_settings.alignment.varalignmin,current_settings.alignment.varalignmax);
  1160. end;
  1161. function var_align_size(siz: longint): shortint;
  1162. begin
  1163. siz := size_2_align(siz);
  1164. var_align_size := var_align(siz);
  1165. end;
  1166. function const_align(want_align: longint): shortint;
  1167. begin
  1168. const_align := used_align(want_align,current_settings.alignment.constalignmin,current_settings.alignment.constalignmax);
  1169. end;
  1170. function const_align_size(siz: longint): shortint;
  1171. begin
  1172. siz := size_2_align(siz);
  1173. const_align_size := const_align(siz);
  1174. end;
  1175. {$ifdef ARM}
  1176. function is_double_hilo_swapped: boolean;{$ifdef USEINLINE}inline;{$endif}
  1177. begin
  1178. result := (current_settings.fputype in [fpu_fpa,fpu_fpa10,fpu_fpa11]) and
  1179. not(cs_fp_emulation in current_settings.moduleswitches);
  1180. {$ifdef FPC_DOUBLE_HILO_SWAPPED}
  1181. { inverse result if compiler was compiled with swapped hilo already }
  1182. result := not result;
  1183. {$endif FPC_DOUBLE_HILO_SWAPPED}
  1184. end;
  1185. {$endif ARM}
  1186. function floating_point_range_check_error : boolean;
  1187. begin
  1188. result:=cs_ieee_errors in current_settings.localswitches;
  1189. end;
  1190. function use_dotted_functions: boolean;
  1191. begin
  1192. result:=
  1193. (target_info.system in systems_dotted_function_names) and
  1194. (target_info.abi<>abi_powerpc_elfv2);
  1195. end;
  1196. {****************************************************************************
  1197. Init
  1198. ****************************************************************************}
  1199. {$ifdef unix}
  1200. {$define need_path_search}
  1201. {$endif unix}
  1202. {$ifdef os2}
  1203. {$define need_path_search}
  1204. {$endif os2}
  1205. {$ifdef macos}
  1206. {$define need_path_search}
  1207. {$endif macos}
  1208. procedure get_exepath;
  1209. var
  1210. localExepath : TCmdStr;
  1211. exeName:TCmdStr;
  1212. {$ifdef need_path_search}
  1213. hs1 : TPathStr;
  1214. {$endif need_path_search}
  1215. begin
  1216. localexepath:=GetEnvironmentVariable('PPC_EXEC_PATH');
  1217. exeName := '';
  1218. if localexepath='' then
  1219. begin
  1220. exeName := FixFileName(system.paramstr(0));
  1221. localexepath := ExtractFilePath(exeName);
  1222. end;
  1223. {$ifdef need_path_search}
  1224. if localexepath='' then
  1225. begin
  1226. hs1 := ExtractFileName(exeName);
  1227. ChangeFileExt(hs1,source_info.exeext);
  1228. {$ifdef macos}
  1229. FindFile(hs1,GetEnvironmentVariable('Commands'),false,localExepath);
  1230. {$else macos}
  1231. FindFile(hs1,GetEnvironmentVariable('PATH'),false,localExepath);
  1232. {$endif macos}
  1233. localExepath:=ExtractFilePath(localExepath);
  1234. end;
  1235. {$endif need_path_search}
  1236. exepath:=FixPath(localExepath,false);
  1237. end;
  1238. type
  1239. tinitdoneentry=record
  1240. init:tprocedure;
  1241. done:tprocedure;
  1242. end;
  1243. pinitdoneentry=^tinitdoneentry;
  1244. const
  1245. initdoneprocs : TFPList = nil;
  1246. procedure allocinitdoneprocs;
  1247. begin
  1248. { Avoid double initialization }
  1249. if assigned(initdoneprocs) then
  1250. exit;
  1251. initdoneprocs:=tfplist.create;
  1252. end;
  1253. procedure register_initdone_proc(init,done:tprocedure);
  1254. var
  1255. entry : pinitdoneentry;
  1256. begin
  1257. new(entry);
  1258. entry^.init:=init;
  1259. entry^.done:=done;
  1260. { Do not rely on the fact that
  1261. globals unit initialization code
  1262. has already been executed.
  1263. Unit initialization order is too
  1264. uncertian for that. PM }
  1265. if not assigned(initdoneprocs) then
  1266. allocinitdoneprocs;
  1267. initdoneprocs.add(entry);
  1268. end;
  1269. procedure callinitprocs;
  1270. var
  1271. i : longint;
  1272. begin
  1273. if not assigned(initdoneprocs) then
  1274. exit;
  1275. for i:=0 to initdoneprocs.count-1 do
  1276. with pinitdoneentry(initdoneprocs[i])^ do
  1277. if assigned(init) then
  1278. init();
  1279. end;
  1280. procedure calldoneprocs;
  1281. var
  1282. i : longint;
  1283. begin
  1284. if not assigned(initdoneprocs) then
  1285. exit;
  1286. for i:=0 to initdoneprocs.count-1 do
  1287. with pinitdoneentry(initdoneprocs[i])^ do
  1288. if assigned(done) then
  1289. done();
  1290. end;
  1291. procedure freeinitdoneprocs;
  1292. var
  1293. i : longint;
  1294. begin
  1295. if not assigned(initdoneprocs) then
  1296. exit;
  1297. for i:=0 to initdoneprocs.count-1 do
  1298. dispose(pinitdoneentry(initdoneprocs[i]));
  1299. initdoneprocs.free;
  1300. { Reset variable, to be on the safe side }
  1301. initdoneprocs:=nil;
  1302. end;
  1303. procedure DoneGlobals;
  1304. begin
  1305. calldoneprocs;
  1306. librarysearchpath.Free;
  1307. unitsearchpath.Free;
  1308. objectsearchpath.Free;
  1309. includesearchpath.Free;
  1310. frameworksearchpath.Free;
  1311. LinkLibraryAliases.Free;
  1312. LinkLibraryOrder.Free;
  1313. packagesearchpath.Free;
  1314. end;
  1315. procedure InitGlobals;
  1316. begin
  1317. get_exepath;
  1318. { reset globals }
  1319. do_build:=false;
  1320. do_release:=false;
  1321. do_make:=true;
  1322. compile_level:=0;
  1323. codegenerror:=false;
  1324. { Output }
  1325. OutputFileName:='';
  1326. OutputPrefix:=Nil;
  1327. OutputSuffix:=Nil;
  1328. OutputExeDir:='';
  1329. OutputUnitDir:='';
  1330. { Utils directory }
  1331. utilsdirectory:='';
  1332. utilsprefix:='';
  1333. cshared:=false;
  1334. rlinkpath:='';
  1335. sysrootpath:='';
  1336. { Search Paths }
  1337. unicodepath:='';
  1338. librarysearchpath:=TSearchPathList.Create;
  1339. unitsearchpath:=TSearchPathList.Create;
  1340. includesearchpath:=TSearchPathList.Create;
  1341. objectsearchpath:=TSearchPathList.Create;
  1342. frameworksearchpath:=TSearchPathList.Create;
  1343. packagesearchpath:=TSearchPathList.Create;
  1344. { Def file }
  1345. usewindowapi:=false;
  1346. description:='Compiled by FPC '+version_string+' - '+target_cpu_string;
  1347. DescriptionSetExplicity:=false;
  1348. SetPEFlagsSetExplicity:=false;
  1349. SetPEOptFlagsSetExplicity:=false;
  1350. SetPEOSVersionSetExplicitely:=false;
  1351. SetPESubSysVersionSetExplicitely:=false;
  1352. SetPEUserVersionSetExplicitely:=false;
  1353. ImageBaseSetExplicity:=false;
  1354. MinStackSizeSetExplicity:=false;
  1355. MaxStackSizeSetExplicity:=false;
  1356. dllversion:='';
  1357. dllmajor:=1;
  1358. dllminor:=0;
  1359. dllrevision:=0;
  1360. nwscreenname := '';
  1361. nwthreadname := '';
  1362. nwcopyright := '';
  1363. UseDeffileForExports:=false;
  1364. UseDeffileForExportsSetExplicitly:=false;
  1365. GenerateImportSection:=false;
  1366. RelocSection:=false;
  1367. RelocSectionSetExplicitly:=false;
  1368. MacOSXVersionMin:='';
  1369. iPhoneOSVersionMin:='';
  1370. { memory sizes, will be overridden by parameter or default for target
  1371. in options or init_parser }
  1372. stacksize:=0;
  1373. { not initialized yet }
  1374. apptype:=app_cui;
  1375. { Init values }
  1376. init_settings:=default_settings;
  1377. if init_settings.optimizecputype=cpu_none then
  1378. init_settings.optimizecputype:=init_settings.cputype;
  1379. LinkLibraryAliases :=TLinkStrMap.Create;
  1380. LinkLibraryOrder :=TLinkStrMap.Create;
  1381. { enable all features by default }
  1382. features:=[low(Tfeature)..high(Tfeature)];
  1383. callinitprocs;
  1384. end;
  1385. initialization
  1386. allocinitdoneprocs;
  1387. finalization
  1388. freeinitdoneprocs;
  1389. end.