globals.pas 50 KB

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