globals.pas 50 KB

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