globals.pas 46 KB

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