globals.pas 50 KB

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