globals.pas 50 KB

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