globals.pas 50 KB

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