2
0

globals.pas 45 KB

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