fpswitch.pas 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599
  1. {
  2. This file is part of the Free Pascal Integrated Development Environment
  3. Copyright (c) 1998-2000 by Berczi Gabor
  4. Compiler switches routines for the IDE
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. unit FPSwitch;
  12. interface
  13. uses
  14. Objects,
  15. Systems,
  16. WUtils,
  17. FPConst;
  18. const
  19. MinMemSize = 1024; { min. local heap and stack size }
  20. MaxMemSize = 67107840; { max. local heap and stack size }
  21. type
  22. TParamID =
  23. (idNone,idAlign,idRangeChecks,idStackChecks,idIOChecks,
  24. idOverflowChecks,idObjMethCallChecks,
  25. idAsmDirect,idAsmATT,idAsmIntel,idAsmMot,idAsmStandard,
  26. idSymInfNone,idSymInfGlobalOnly,idSymInfGlobalLocal,
  27. idStackSize,idHeapSize,idStrictVarStrings,idExtendedSyntax,
  28. idMMXOps,idTypedAddress,idPackRecords,idPackEnum,idStackFrames,
  29. idReferenceInfo,idDebugInfo,idBoolEval,
  30. idAnsiString,idTypeInfo);
  31. TSwitchMode = (om_Normal,om_Debug,om_Release);
  32. TSwitchItemTyp = (ot_Select,ot_Boolean,ot_String,ot_MultiString,ot_Longint);
  33. PSwitchItem = ^TSwitchItem;
  34. TSwitchItem = object(TObject)
  35. Typ : TSwitchItemTyp;
  36. Name : string[50];
  37. Param : string[10];
  38. ParamID : TParamID;
  39. constructor Init(const n,p:string; AID: TParamID);
  40. function NeedParam:boolean;virtual;
  41. function ParamValue(nr:sw_integer):string;virtual;
  42. function ParamValueBool(SM: TSwitchMode):boolean;virtual;
  43. function ParamCount:sw_integer;virtual;
  44. function GetSwitchStr(SM: TSwitchMode): string; virtual;
  45. function GetNumberStr(SM: TSwitchMode): string; virtual;
  46. function GetOptionStr(SM: TSwitchMode): string; virtual;
  47. procedure Reset;virtual;
  48. end;
  49. PSelectItem = ^TSelectItem;
  50. TSelectItem = object(TSwitchItem)
  51. IsDefault : boolean;
  52. constructor Init(const n,p:string; AID: TParamID);
  53. { Select to avoid anything in config file }
  54. constructor InitDefault(const n:string);
  55. end;
  56. PBooleanItem = ^TBooleanItem;
  57. TBooleanItem = object(TSwitchItem)
  58. IsSet : array[TSwitchMode] of boolean;
  59. constructor Init(const n,p:string; AID: TParamID);
  60. function NeedParam:boolean;virtual;
  61. procedure Reset;virtual;
  62. function GetSwitchStr(SM: TSwitchMode): string; virtual;
  63. function ParamValueBool(SM: TSwitchMode):boolean;virtual;
  64. end;
  65. PStringItem = ^TStringItem;
  66. TStringItem = object(TSwitchItem)
  67. Str : array[TSwitchMode] of string;
  68. multiple : boolean;
  69. SeparateSpaces : boolean;
  70. constructor Init(const n,p:string;AID: TParamID; mult,allowspaces:boolean);
  71. function NeedParam:boolean;virtual;
  72. function ParamValue(nr:sw_integer):string;virtual;
  73. procedure Reset;virtual;
  74. end;
  75. PMultiStringItem = ^TMultiStringItem;
  76. TMultiStringItem = object(TSwitchItem)
  77. MultiStr : array[TSwitchMode] of PunsortedStringCollection;
  78. constructor Init(const n,p:string;AID: TParamID);
  79. function NeedParam:boolean;virtual;
  80. function ParamValue(nr:sw_integer):string;virtual;
  81. function ParamCount:sw_integer;virtual;
  82. procedure Reset;virtual;
  83. destructor done;virtual;
  84. end;
  85. PLongintItem = ^TLongintItem;
  86. TLongintItem = object(TSwitchItem)
  87. Val : array[TSwitchMode] of longint;
  88. constructor Init(const n,p:string; AID: TParamID);
  89. function NeedParam:boolean;virtual;
  90. function ParamValue(nr:sw_integer):string;virtual;
  91. function GetNumberStr(SM: TSwitchMode): string; virtual;
  92. procedure Reset;virtual;
  93. end;
  94. PSwitches = ^TSwitches;
  95. TSwitches = object
  96. constructor Init(ch:char);
  97. constructor InitSelect(ch:char);
  98. destructor Done;
  99. { general items }
  100. function ItemCount:integer;
  101. function ItemName(index:integer):string;
  102. function ItemParam(index:integer):string;
  103. { type specific }
  104. procedure AddSelectItem(const name,param:string; AID: TParamID);
  105. procedure AddDefaultSelect(const name:string);
  106. procedure AddBooleanItem(const name,param:string; AID: TParamID);
  107. procedure AddLongintItem(const name,param:string; AID: TParamID);
  108. procedure AddStringItem(const name,param:string;AID: TParamID;mult,allowspaces:boolean);
  109. procedure AddMultiStringItem(const name,param:string;AID: TParamID);
  110. function GetCurrSel:integer;
  111. function GetCurrSelParam : String;
  112. function GetBooleanItem(index:integer):boolean;
  113. function GetLongintItem(index:integer):longint;
  114. function GetStringItem(index:integer):string;
  115. function GetMultiStringItem(index:integer):PunsortedStringCollection;
  116. function GetItemTyp(index:integer):TSwitchItemTyp;
  117. procedure SetCurrSel(index:integer);
  118. function SetCurrSelParam(const s:string) : boolean;
  119. procedure SetBooleanItem(index:integer;b:boolean);
  120. procedure SetLongintItem(index:integer;l:longint);
  121. procedure SetStringItem(index:integer;const s:string);
  122. { read / write to cfgfile which must be open }
  123. procedure WriteItemsCfg;
  124. function ReadItemsCfg(const s:string):boolean;
  125. private
  126. IsSel : boolean;
  127. Prefix : char;
  128. SelNr : array[TSwitchMode] of integer;
  129. Items : PCollection;
  130. end;
  131. const
  132. SwitchesMode : TSwitchMode = om_Normal;
  133. SwitchesModeName : array[TSwitchMode] of string[10]=
  134. ('~N~ormal','~D~ebug','~R~elease');
  135. SwitchesModeStr : array[TSwitchMode] of string[8]=
  136. ('NORMAL','DEBUG','RELEASE');
  137. CustomArg : array[TSwitchMode] of string{$ifndef FPC}[128]{$endif}=
  138. ('','','');
  139. var
  140. LibLinkerSwitches,
  141. OtherLinkerSwitches,
  142. DebugInfoSwitches,
  143. LinkAfterSwitches,
  144. ProfileInfoSwitches,
  145. {MemorySizeSwitches, doubled !! }
  146. SyntaxSwitches,
  147. CompilerModeSwitches,
  148. VerboseSwitches,
  149. CodegenSwitches,
  150. OptimizationSwitches,
  151. ProcessorCodeGenerationSwitches,
  152. ProcessorOptimizationSwitches,
  153. AsmReaderSwitches,
  154. AsmInfoSwitches,
  155. AsmOutputSwitches,
  156. TargetSwitches,
  157. ConditionalSwitches,
  158. MemorySwitches,
  159. BrowserSwitches,
  160. DirectorySwitches : PSwitches;
  161. { write/read the Switches to fpc.cfg file }
  162. procedure WriteSwitches(const fn:string);
  163. procedure ReadSwitches(const fn:string);
  164. procedure UpdateAsmOutputSwitches;
  165. { initialize }
  166. procedure InitSwitches;
  167. procedure SetDefaultSwitches;
  168. procedure DoneSwitches;
  169. function GetSourceDirectories : string;
  170. procedure GetCompilerOptionLines(C: PUnsortedStringCollection);
  171. implementation
  172. uses
  173. Dos,
  174. GlobType,
  175. CpuInfo,
  176. FPVars,FPUtils;
  177. var
  178. CfgFile : text;
  179. {$ifdef useresstrings}
  180. resourcestring
  181. {$else}
  182. const
  183. {$endif}
  184. msg_automaticallycreateddontedit = 'Automaticly created file, don''t edit.';
  185. { Compiler options }
  186. opt_objectpascal = 'Object pascal support';
  187. opt_clikeoperators = 'C-like operators';
  188. opt_stopafterfirsterror = 'Stop after first error';
  189. opt_allowlabelandgoto = 'Allow LABEL and GOTO';
  190. opt_cplusplusstyledinline = 'Allow inline';
  191. opt_globalcmacros = 'Enable macros';
  192. opt_allowstaticinobjects = 'Allow STATIC in objects';
  193. opt_assertions = 'Include assertion code';
  194. opt_kylix = 'Load Kylix compat. unit';
  195. opt_ansistring = 'Use Ansi Strings';
  196. opt_strictvarstrings = 'Strict var-strings';
  197. opt_extendedsyntax = 'Extended syntax';
  198. opt_allowmmxoperations = 'Allow MMX operations';
  199. opt_mode_freepascal = 'Free Pascal dialect';
  200. opt_mode_objectpascal = 'Object Pascal extension on';
  201. opt_mode_turbopascal = 'Turbo Pascal compatible';
  202. opt_mode_delphi = 'Delphi compatible';
  203. opt_mode_macpascal = 'Macintosh Pascal dialect';
  204. opt_mode_gnupascal = 'GNU Pascal';
  205. { Verbose options }
  206. opt_warnings = '~W~arnings';
  207. opt_notes = 'N~o~tes';
  208. opt_hints = '~H~ints';
  209. opt_generalinfo = 'General ~I~nfo';
  210. opt_usedtriedinfo = '~U~sed,tried info';
  211. opt_all = '~A~ll';
  212. opt_showallprocsonerror = 'Show all ~P~rocedures if error';
  213. { Checking options }
  214. opt_rangechecking = '~R~ange checking';
  215. opt_stackchecking = '~S~tack checking';
  216. opt_iochecking = '~I~/O checking';
  217. opt_overflowchecking = 'Integer ~o~verflow checking';
  218. opt_objmethcallvalid = 'Object ~m~ethod call checking';
  219. { Code generation }
  220. opt_pic = '~P~osition independent code';
  221. opt_smart = 'Create smart~l~inkable units';
  222. { Code options }
  223. //opt_generatefastercode = 'Generate ~f~aster code';
  224. opt_generatesmallercode = 'G~e~nerate smaller code';
  225. opt_useregistervariables = 'Use regis~t~er-variables';
  226. opt_uncertainoptimizations = '~U~ncertain optimizations';
  227. opt_level1optimizations = 'Level ~1~ optimizations';
  228. opt_level2optimizations = 'Level ~2~ optimizations';
  229. opt_level3optimizations = 'Level ~3~ optimizations';
  230. { optimization processor target }
  231. opt_i386486 = 'i~3~86/i486';
  232. opt_pentium = 'P~e~ntium (tm)';
  233. opt_pentiummmx = 'PentiumMM~X~ (tm)';
  234. opt_pentiumpro = '~P~entium2/PentiumM/AMD';
  235. opt_pentiumiv = 'Pentium~4~';
  236. opt_pentiumm = 'Pentium~M~';
  237. opt_m68000 = 'm~6~8000';
  238. opt_m68020 = 'm680~2~0';
  239. { Assembler options }
  240. opt_directassembler = '~D~irect assembler';
  241. opt_defaultassembler = '~D~efault style assembler';
  242. opt_attassembler = '~A~T&T style assembler';
  243. opt_intelassembler = '~I~ntel style assembler';
  244. opt_motassembler = '~M~otorola style assembler';
  245. opt_standardassembler = '~S~tandard style assembler';
  246. opt_listsource = '~L~ist source';
  247. opt_listregisterallocation = 'list ~r~egister allocation';
  248. opt_listtempallocation = 'list ~t~emp allocation';
  249. opt_listnodeallocation = 'list ~n~ode allocation';
  250. opt_useasmpipe = 'use ~p~ipe with assembler';
  251. { Assembler output selection }
  252. opt_usedefaultas = 'Use ~d~efault output';
  253. opt_usegnuas = 'Use ~G~NU as';
  254. { I386 assembler output selection }
  255. opt_usenasmcoff = 'Use ~N~ASM coff';
  256. opt_usenasmwin32 = 'Use NASM ~w~in32';
  257. opt_usenasmwdosx= 'Use ~N~ASM w~d~osx';
  258. opt_usenasmelf = 'Use NASM el~f~';
  259. opt_usenasmbeos = 'Use NASM ~b~eos';
  260. opt_usenasmobj = 'Use NASM ~o~bj';
  261. opt_usemasm = 'Use ~M~ASM';
  262. opt_usetasm = 'Use ~T~ASM';
  263. opt_usewasm = 'Use ~W~ASM';
  264. opt_usecoff = 'Use internal ~c~off';
  265. opt_usepecoff = 'Use internal ~p~ecoff';
  266. opt_usepecoffwdosx = 'Use internal pewdos~x~';
  267. opt_useelf= 'Use internal ~e~lf';
  268. { Browser options }
  269. opt_nobrowser = 'N~o~ browser';
  270. opt_globalonlybrowser = 'Only Glob~a~l browser';
  271. opt_localglobalbrowser = '~L~ocal and global browser';
  272. { Conditional defines }
  273. opt_conditionaldefines = 'Conditio~n~al defines';
  274. { Memory sizes }
  275. opt_stacksize = '~S~tack size';
  276. opt_heapsize = '~H~eap size';
  277. { Directory options }
  278. opt_unitdirectories = '~U~nit directories';
  279. opt_includedirectories = '~I~nclude directories';
  280. opt_librarydirectories = '~L~ibrary directories';
  281. opt_objectdirectories = '~O~bject directories';
  282. opt_exeppudirectories = '~E~XE output directory';
  283. opt_ppuoutputdirectory = '~P~PU output directory';
  284. opt_cross_tools_directory = '~C~ross tools directory';
  285. opt_dynamic_linker = '~D~ynamic linker path';
  286. { Library options }
  287. opt_librariesdefault = '~T~arget default';
  288. opt_dynamiclibraries = 'Link to ~D~ynamic libraries';
  289. opt_staticlibraries = 'Link to ~S~tatic libraries';
  290. opt_smartlibraries = 'Link to S~m~art libraries';
  291. opt_forcestaticlibs = 'Only link to st~a~tic libraries';
  292. { Symbol info options }
  293. opt_stripalldebugsymbols = '~S~trip all debug symbols from executable';
  294. opt_nogendebugsymbolinfo = 'Skip ~d~ebug information generation';
  295. opt_gendebugsymbolinfo = 'Generate ~d~ebug symbol information';
  296. opt_gensymbolandbacktraceinfo = 'Generate also backtrace ~l~ine information';
  297. opt_valgrindinfo = 'Generate ~v~algrind compatible debug info';
  298. { Link after options }
  299. opt_linkafter = 'Call ~l~inker after';
  300. { Profiling options }
  301. opt_noprofileinfo = '~N~o profile information';
  302. opt_gprofinfo = 'Generate profile code for g~p~rof';
  303. {*****************************************************************************
  304. TSwitchItem
  305. *****************************************************************************}
  306. constructor TSwitchItem.Init(const n,p:string; AID: TParamID);
  307. begin
  308. Inherited Init;
  309. Name:=n;
  310. Param:=p;
  311. ParamID:=AID;
  312. end;
  313. function TSwitchItem.NeedParam:boolean;
  314. begin
  315. NeedParam:=false;
  316. end;
  317. function TSwitchItem.ParamValue(nr:sw_integer):string;
  318. begin
  319. ParamValue:='';
  320. end;
  321. function TSwitchItem.ParamValueBool(SM: TSwitchMode):boolean;
  322. begin
  323. Abstract;
  324. ParamValueBool:=false;
  325. end;
  326. function TSwitchItem.ParamCount:sw_integer;
  327. begin
  328. ParamCount:=1;
  329. end;
  330. function TSwitchItem.GetSwitchStr(SM: TSwitchMode): string;
  331. begin
  332. Abstract;
  333. GetSwitchStr:='';
  334. end;
  335. function TSwitchItem.GetNumberStr(SM: TSwitchMode): string;
  336. begin
  337. Abstract;
  338. GetNumberStr:='';
  339. end;
  340. function TSwitchItem.GetOptionStr(SM: TSwitchMode): string;
  341. begin
  342. Abstract;
  343. GetOptionStr:='';
  344. end;
  345. procedure TSwitchItem.Reset;
  346. begin
  347. end;
  348. {*****************************************************************************
  349. TSelectItem
  350. *****************************************************************************}
  351. constructor TSelectItem.Init(const n,p:string; AID: TParamID);
  352. begin
  353. Inherited Init(n,p,AID);
  354. Typ:=ot_Select;
  355. IsDefault:=false;
  356. end;
  357. constructor TSelectItem.InitDefault(const n:string);
  358. begin
  359. Inherited Init(n,'',idNone);
  360. Typ:=ot_Select;
  361. IsDefault:=true;
  362. end;
  363. {*****************************************************************************
  364. TBooleanItem
  365. *****************************************************************************}
  366. constructor TBooleanItem.Init(const n,p:string; AID: TParamID);
  367. begin
  368. Inherited Init(n,p,AID);
  369. Typ:=ot_Boolean;
  370. Reset;
  371. end;
  372. function TBooleanItem.NeedParam:boolean;
  373. begin
  374. NeedParam:=IsSet[SwitchesMode];
  375. end;
  376. procedure TBooleanItem.Reset;
  377. begin
  378. FillChar(IsSet,sizeof(IsSet),0);
  379. end;
  380. function TBooleanItem.ParamValueBool(SM: TSwitchMode):boolean;
  381. begin
  382. ParamValueBool:=IsSet[SM];
  383. end;
  384. function TBooleanItem.GetSwitchStr(SM: TSwitchMode): string;
  385. begin
  386. GetSwitchStr:=BoolToStr(IsSet[SM],'+','-');
  387. end;
  388. {*****************************************************************************
  389. TStringItem
  390. *****************************************************************************}
  391. constructor TStringItem.Init(const n,p:string; AID: TParamID; mult,allowspaces:boolean);
  392. begin
  393. Inherited Init(n,p,AID);
  394. Typ:=ot_String;
  395. Multiple:=mult;
  396. SeparateSpaces:=not allowspaces;
  397. Reset;
  398. end;
  399. function TStringItem.NeedParam:boolean;
  400. begin
  401. NeedParam:=(Str[SwitchesMode]<>'');
  402. end;
  403. function TStringItem.ParamValue(nr:sw_integer):string;
  404. begin
  405. ParamValue:=Str[SwitchesMode];
  406. end;
  407. procedure TStringItem.Reset;
  408. begin
  409. FillChar(Str,sizeof(Str),0);
  410. end;
  411. {*****************************************************************************
  412. TMultiStringItem
  413. *****************************************************************************}
  414. constructor TMultiStringItem.Init(const n,p:string;AID:TParamID);
  415. var i:TSwitchMode;
  416. begin
  417. inherited Init(n,p,AID);
  418. typ:=ot_MultiString;
  419. for i:=low(MultiStr) to high(MultiStr) do
  420. new(MultiStr[i],init(5,5));
  421. { Reset;}
  422. end;
  423. function TMultiStringItem.NeedParam:boolean;
  424. begin
  425. NeedParam:=(multistr[SwitchesMode]^.count<>0);
  426. end;
  427. function TMultiStringItem.ParamValue(nr:sw_integer):string;
  428. begin
  429. ParamValue:=MultiStr[SwitchesMode]^.at(nr)^;
  430. end;
  431. function TMultiStringItem.ParamCount:sw_integer;
  432. begin
  433. ParamCount:=Multistr[SwitchesMode]^.count;
  434. end;
  435. procedure TMultiStringItem.Reset;
  436. var i:TSwitchMode;
  437. begin
  438. for i:=low(multiStr) to high(multiStr) do
  439. MultiStr[i]^.freeall;
  440. end;
  441. destructor TmultiStringItem.done;
  442. var i:TSwitchMode;
  443. begin
  444. for i:=low(MultiStr) to high(MultiStr) do
  445. dispose(MultiStr[i],done);
  446. inherited done;
  447. end;
  448. {*****************************************************************************
  449. TLongintItem
  450. *****************************************************************************}
  451. constructor TLongintItem.Init(const n,p:string; AID: TParamID);
  452. begin
  453. Inherited Init(n,p,AID);
  454. Typ:=ot_Longint;
  455. Reset;
  456. end;
  457. function TLongintItem.NeedParam:boolean;
  458. begin
  459. NeedParam:=(Val[SwitchesMode]<>0);
  460. end;
  461. function TLongintItem.ParamValue(nr:sw_integer):string;
  462. var
  463. s : string;
  464. begin
  465. Str(Val[SwitchesMode],s);
  466. ParamValue:=s;
  467. end;
  468. procedure TLongintItem.Reset;
  469. begin
  470. FillChar(Val,sizeof(Val),0);
  471. end;
  472. function TLongintItem.GetNumberStr(SM: TSwitchMode): string;
  473. begin
  474. GetNumberStr:=IntToStr(Val[SM]);
  475. end;
  476. {*****************************************************************************
  477. TSwitch
  478. *****************************************************************************}
  479. constructor TSwitches.Init(ch:char);
  480. begin
  481. new(Items,Init(10,5));
  482. Prefix:=ch;
  483. FillChar(SelNr,SizeOf(SelNr),#0);
  484. IsSel:=false;
  485. end;
  486. constructor TSwitches.InitSelect(ch:char);
  487. begin
  488. new(Items,Init(10,5));
  489. Prefix:=ch;
  490. FillChar(SelNr,SizeOf(SelNr),#0);
  491. IsSel:=true;
  492. end;
  493. destructor TSwitches.Done;
  494. begin
  495. dispose(Items,Done);
  496. end;
  497. procedure TSwitches.AddSelectItem(const name,param:string; AID: TParamID);
  498. begin
  499. Items^.Insert(New(PSelectItem,Init(name,Param,AID)));
  500. end;
  501. procedure TSwitches.AddDefaultSelect(const name:string);
  502. begin
  503. Items^.Insert(New(PSelectItem,InitDefault(name)));
  504. end;
  505. procedure TSwitches.AddBooleanItem(const name,param:string; AID: TParamID);
  506. begin
  507. Items^.Insert(New(PBooleanItem,Init(name,Param,AID)));
  508. end;
  509. procedure TSwitches.AddLongintItem(const name,param:string; AID: TParamID);
  510. begin
  511. Items^.Insert(New(PLongintItem,Init(name,Param,AID)));
  512. end;
  513. procedure TSwitches.AddStringItem(const name,param:string;AID:TParamID;mult,allowspaces:boolean);
  514. begin
  515. Items^.Insert(New(PStringItem,Init(name,Param,AID,mult,allowspaces)));
  516. end;
  517. procedure TSwitches.AddMultiStringItem(const name,param:string;AID:TParamID);
  518. begin
  519. Items^.Insert(New(PMultiStringItem,Init(name,Param,AID)));
  520. end;
  521. function TSwitches.ItemCount:integer;
  522. begin
  523. ItemCount:=Items^.Count;
  524. end;
  525. function TSwitches.ItemName(index:integer):string;
  526. var
  527. P : PSwitchItem;
  528. begin
  529. if index<ItemCount then
  530. P:=Items^.At(Index)
  531. else
  532. P:=nil;
  533. if assigned(P) then
  534. ItemName:=P^.Name
  535. else
  536. ItemName:='';
  537. end;
  538. function TSwitches.ItemParam(index:integer):string;
  539. var
  540. P : PSwitchItem;
  541. begin
  542. if index<ItemCount then
  543. P:=Items^.At(Index)
  544. else
  545. P:=nil;
  546. if assigned(P) then
  547. ItemParam:='-'+Prefix+P^.Param
  548. else
  549. ItemParam:='';
  550. end;
  551. function TSwitches.GetBooleanItem(index:integer):boolean;
  552. var
  553. P : PBooleanItem;
  554. begin
  555. if index<ItemCount then
  556. P:=Items^.At(Index)
  557. else
  558. P:=nil;
  559. if assigned(P) and (P^.Typ=ot_boolean) then
  560. GetBooleanItem:=P^.IsSet[SwitchesMode]
  561. else
  562. GetBooleanItem:=false;
  563. end;
  564. function TSwitches.GetLongintItem(index:integer):longint;
  565. var
  566. P : PLongintItem;
  567. begin
  568. if index<ItemCount then
  569. P:=Items^.At(Index)
  570. else
  571. P:=nil;
  572. if assigned(P) and (P^.Typ=ot_longint) then
  573. GetLongintItem:=P^.Val[SwitchesMode]
  574. else
  575. GetLongintItem:=0;
  576. end;
  577. function TSwitches.GetStringItem(index:integer):string;
  578. var
  579. P : PStringItem;
  580. begin
  581. if index<ItemCount then
  582. P:=Items^.At(Index)
  583. else
  584. P:=nil;
  585. if assigned(P) and (P^.Typ=ot_string) then
  586. GetStringItem:=P^.Str[SwitchesMode]
  587. else
  588. GetStringItem:='';
  589. end;
  590. function TSwitches.GetMultiStringItem(index:integer):PUnsortedStringCollection;
  591. var p:PMultiStringItem;
  592. begin
  593. if index<ItemCount then
  594. p:=Items^.at(Index)
  595. else
  596. p:=nil;
  597. if (p<>nil) and (p^.typ=ot_multistring) then
  598. GetMultiStringItem:=p^.MultiStr[SwitchesMode]
  599. else
  600. GetMultiStringItem:=nil;
  601. end;
  602. function TSwitches.GetItemTyp(index:integer):TSwitchItemTyp;
  603. var p:PSwitchItem;
  604. begin
  605. assert(index<itemcount);
  606. GetItemTyp:=PSwitchItem(items^.at(index))^.typ;
  607. end;
  608. procedure TSwitches.SetBooleanItem(index:integer;b:boolean);
  609. var
  610. P : PBooleanItem;
  611. begin
  612. if index<ItemCount then
  613. P:=Items^.At(Index)
  614. else
  615. P:=nil;
  616. if assigned(P) and (P^.Typ=ot_boolean) then
  617. P^.IsSet[SwitchesMode]:=b;
  618. end;
  619. procedure TSwitches.SetLongintItem(index:integer;l:longint);
  620. var
  621. P : PLongintItem;
  622. begin
  623. if index<ItemCount then
  624. P:=Items^.At(Index)
  625. else
  626. P:=nil;
  627. if assigned(P) and (P^.Typ=ot_longint) then
  628. P^.Val[SwitchesMode]:=l;
  629. end;
  630. procedure TSwitches.SetStringItem(index:integer;const s:string);
  631. var
  632. P : PStringItem;
  633. begin
  634. if index<ItemCount then
  635. P:=Items^.At(Index)
  636. else
  637. P:=nil;
  638. if assigned(P) and (P^.Typ=ot_string) then
  639. P^.Str[SwitchesMode]:=s;
  640. end;
  641. function TSwitches.GetCurrSel:integer;
  642. begin
  643. if IsSel then
  644. GetCurrSel:=SelNr[SwitchesMode]
  645. else
  646. GetCurrSel:=-1;
  647. end;
  648. function TSwitches.GetCurrSelParam : String;
  649. begin
  650. if IsSel then
  651. GetCurrSelParam:=PSwitchItem(Items^.At(SelNr[SwitchesMode]))^.Param
  652. else
  653. GetCurrSelParam:='';
  654. end;
  655. procedure TSwitches.SetCurrSel(index:integer);
  656. begin
  657. if index<ItemCount then
  658. SelNr[SwitchesMode]:=index;
  659. end;
  660. function TSwitches.SetCurrSelParam(const s : String) : boolean;
  661. function checkitem(P:PSwitchItem):boolean;
  662. begin
  663. { empty items are not equivalent to others !! }
  664. CheckItem:=((S='') and (P^.Param='')) or
  665. ((Length(S)>0) and (P^.Param=s));
  666. end;
  667. var
  668. FoundP : PSwitchItem;
  669. begin
  670. FoundP:=Items^.FirstThat(@CheckItem);
  671. if Assigned(FoundP) then
  672. begin
  673. SetCurrSelParam:=true;
  674. SelNr[SwitchesMode]:=Items^.IndexOf(FoundP);
  675. end
  676. else
  677. SetCurrSelParam:=false;
  678. end;
  679. procedure TSwitches.WriteItemsCfg;
  680. var
  681. Pref : char;
  682. procedure writeitem(P:PSwitchItem);
  683. var
  684. s,s1 : string;
  685. i,j : integer;
  686. begin
  687. if P^.NeedParam then
  688. begin
  689. if (P^.Typ=ot_string) and (PStringItem(P)^.Multiple) then
  690. begin
  691. s:=PStringItem(P)^.Str[SwitchesMode];
  692. repeat
  693. i:=pos(';',s);
  694. if PStringItem(P)^.SeparateSpaces then
  695. j:=pos(' ',s)
  696. else
  697. j:=0;
  698. if i=0 then
  699. i:=256;
  700. if (j>0) and (j<i) then
  701. i:=j;
  702. s1:=Copy(s,1,i-1);
  703. if s1<>'' then
  704. writeln(CfgFile,' -'+Pref+P^.Param+s1);
  705. Delete(s,1,i);
  706. until s='';
  707. end
  708. else
  709. if P^.Param<>'/' then
  710. for i:=0 to p^.ParamCount-1 do
  711. Writeln(CfgFile,' -'+Pref+P^.Param+P^.ParamValue(i));
  712. end;
  713. end;
  714. var
  715. P : PSelectItem;
  716. begin
  717. Pref:=Prefix;
  718. if IsSel then
  719. begin
  720. { can be empty for some targets }
  721. If Items^.count>0 then
  722. begin
  723. P:=Items^.At(SelNr[SwitchesMode]);
  724. if not P^.IsDefault then
  725. writeln(CfgFile,' '+ItemParam(SelNr[SwitchesMode]));
  726. end;
  727. end
  728. else
  729. Items^.ForEach(@writeitem);
  730. end;
  731. procedure WriteCustom;
  732. var
  733. s : string;
  734. i : longint;
  735. begin
  736. s:=CustomArg[SwitchesMode];
  737. While s<>'' do
  738. begin
  739. i:=pos(' ',s);
  740. if i=0 then i:=256;
  741. writeln(CfgFile,' '+Copy(s,1,i-1));
  742. if i=256 then
  743. s:=''
  744. else
  745. s:=copy(s,i+1,255);
  746. end;
  747. end;
  748. function TSwitches.ReadItemsCfg(const s:string):boolean;
  749. function checkitem(P:PSwitchItem):boolean;
  750. begin
  751. { empty items are not equivalent to others !! }
  752. { but -dGDB didn't work because of this PM }
  753. CheckItem:=((P^.Param='') and ((S='') or (P^.typ in [ot_Boolean,ot_String]))) or
  754. ((Length(P^.Param)>0) and (upcase(P^.Param)=upcase(S)) and
  755. not (P^.typ in [ot_Boolean,ot_String])) or
  756. ((Length(P^.Param)>0) and (P^.typ<>ot_Select) and
  757. (P^.Param=Copy(s,1,length(P^.Param))));
  758. end;
  759. var
  760. FoundP : PSwitchItem;
  761. code : integer;
  762. begin
  763. FoundP:=Items^.FirstThat(@checkitem);
  764. if assigned(FoundP) then
  765. begin
  766. case FoundP^.Typ of
  767. ot_Select : SelNr[SwitchesMode]:=Items^.IndexOf(FoundP);
  768. ot_Boolean : PBooleanItem(FoundP)^.IsSet[SwitchesMode]:=true;
  769. ot_String : begin
  770. if (PStringItem(FoundP)^.Multiple) and (PStringItem(FoundP)^.Str[SwitchesMode]<>'') then
  771. PStringItem(FoundP)^.Str[SwitchesMode]:=PStringItem(FoundP)^.Str[SwitchesMode]+';'+
  772. Copy(s,length(FoundP^.Param)+1,255)
  773. else
  774. PStringItem(FoundP)^.Str[SwitchesMode]:=Copy(s,length(FoundP^.Param)+1,255);
  775. end;
  776. ot_MultiString :
  777. PMultiStringItem(foundP)^.MultiStr[SwitchesMode]^.insert(newstr(copy(s,length(foundP^.param)+1,255)));
  778. ot_Longint : Val(Copy(s,length(FoundP^.Param)+1,255),PLongintItem(FoundP)^.Val[SwitchesMode],code);
  779. end;
  780. ReadItemsCfg:=true;
  781. end
  782. else
  783. ReadItemsCfg:=false;
  784. end;
  785. {*****************************************************************************
  786. Read / Write
  787. *****************************************************************************}
  788. procedure WriteSwitches(const fn:string);
  789. var
  790. OldSwitchesMode, SWM: TSwitchMode;
  791. begin
  792. { create the switches }
  793. assign(CfgFile,fn);
  794. {$I-}
  795. rewrite(CfgFile);
  796. {$I+}
  797. if ioresult<>0 then
  798. exit;
  799. writeln(CfgFile,'# '+msg_automaticallycreateddontedit);
  800. OldSwitchesMode:=SwitchesMode;
  801. for SWM:=low(TSwitchMode) to high(TSwitchMode) do
  802. begin
  803. SwitchesMode := SWM;
  804. Writeln(CfgFile,'#IFDEF '+SwitchesModeStr[SwitchesMode]);
  805. TargetSwitches^.WriteItemsCfg;
  806. CompilerModeSwitches^.WriteItemsCfg;
  807. VerboseSwitches^.WriteItemsCfg;
  808. SyntaxSwitches^.WriteItemsCfg;
  809. CodegenSwitches^.WriteItemsCfg;
  810. OptimizationSwitches^.WriteItemsCfg;
  811. ProcessorCodeGenerationSwitches^.WriteItemsCfg;
  812. ProcessorOptimizationSwitches^.WriteItemsCfg;
  813. AsmReaderSwitches^.WriteItemsCfg;
  814. AsmInfoSwitches^.WriteItemsCfg;
  815. AsmOutputSwitches^.WriteItemsCfg;
  816. DirectorySwitches^.WriteItemsCfg;
  817. MemorySwitches^.WriteItemsCfg;
  818. ConditionalSwitches^.WriteItemsCfg;
  819. LibLinkerSwitches^.WriteItemsCfg;
  820. OtherLinkerSwitches^.WriteItemsCfg;
  821. DebugInfoSwitches^.WriteItemsCfg;
  822. ProfileInfoSwitches^.WriteItemsCfg;
  823. LinkAfterSwitches^.WriteItemsCfg;
  824. BrowserSwitches^.WriteItemsCfg;
  825. {MemorySizeSwitches^.WriteItemsCfg;}
  826. WriteCustom;
  827. Writeln(CfgFile,'#ENDIF');
  828. Writeln(CfgFile,'');
  829. end;
  830. close(CfgFile);
  831. SwitchesMode:=OldSwitchesMode;
  832. end;
  833. procedure ReadSwitches(const fn:string);
  834. var
  835. c : char;
  836. s : string;
  837. res : boolean;
  838. OldSwitchesMode,i : TSwitchMode;
  839. begin
  840. assign(CfgFile,fn);
  841. {$I-}
  842. reset(CfgFile);
  843. {$I+}
  844. if ioresult<>0 then
  845. begin
  846. SetDefaultSwitches;
  847. exit;
  848. end;
  849. OldSwitchesMode:=SwitchesMode;
  850. SwitchesMode:=om_Normal;
  851. while not eof(CfgFile) do
  852. begin
  853. readln(CfgFile,s);
  854. s:=LTrim(s);
  855. if (length(s)>=2) and (s[1]='-') then
  856. begin
  857. c:=s[2];
  858. res:=false;
  859. Delete(s,1,2);
  860. case c of
  861. 'a' : res:=AsmInfoSwitches^.ReadItemsCfg(s);
  862. 'A' : res:=AsmOutputSwitches^.ReadItemsCfg(s);
  863. 'b' : res:=BrowserSwitches^.ReadItemsCfg(s);
  864. 'C' : begin
  865. res:=CodegenSwitches^.ReadItemsCfg(s);
  866. if not res then
  867. res:=MemorySwitches^.ReadItemsCfg(s);
  868. if not res then
  869. res:=ProcessorCodeGenerationSwitches^.ReadItemsCfg(s);
  870. end;
  871. 'd' : res:=ConditionalSwitches^.ReadItemsCfg(s);
  872. 'F' : res:=DirectorySwitches^.ReadItemsCfg(s);
  873. 'g' : res:=DebugInfoSwitches^.ReadItemsCfg(s);
  874. 'O' : begin
  875. res:=OptimizationSwitches^.ReadItemsCfg(s);
  876. if not res then
  877. res:=ProcessorOptimizationSwitches^.ReadItemsCfg(s);
  878. end;
  879. 'M' : res:=CompilerModeSwitches^.ReadItemsCfg(s);
  880. 'p' : res:=ProfileInfoSwitches^.ReadItemsCfg(s);
  881. 's' : res:=LinkAfterSwitches^.ReadItemsCfg(s);
  882. 'R' : res:=AsmReaderSwitches^.ReadItemsCfg(s);
  883. 'S' : res:=SyntaxSwitches^.ReadItemsCfg(s);
  884. 'T' : res:=TargetSwitches^.ReadItemsCfg(s);
  885. 'v' : res:=VerboseSwitches^.ReadItemsCfg(s);
  886. 'X' : begin
  887. res:=LibLinkerSwitches^.ReadItemsCfg(s);
  888. if not res then
  889. res:=OtherLinkerSwitches^.ReadItemsCfg(s);
  890. end;
  891. end;
  892. { keep all others as a string }
  893. if not res then
  894. CustomArg[SwitchesMode]:=CustomArg[SwitchesMode]+' -'+c+s;
  895. end
  896. else
  897. if (Copy(s,1,7)='#IFDEF ') then
  898. begin
  899. Delete(s,1,7);
  900. for i:=low(TSwitchMode) to high(TSwitchMode) do
  901. if s=SwitchesModeStr[i] then
  902. begin
  903. SwitchesMode:=i;
  904. break;
  905. end;
  906. end
  907. else;
  908. end;
  909. close(CfgFile);
  910. SwitchesMode:=OldSwitchesMode;
  911. end;
  912. function GetSourceDirectories : string;
  913. var
  914. P : PStringItem;
  915. S : String;
  916. c : char;
  917. function checkitem(P:PSwitchItem):boolean;
  918. begin
  919. CheckItem:=(P^.Typ=ot_string) and (P^.Param=c);
  920. end;
  921. begin
  922. GetSourceDirectories:='';
  923. c:='u';
  924. P:=DirectorySwitches^.Items^.FirstThat(@CheckItem);
  925. S:='';
  926. if assigned(P) then
  927. S:=P^.Str[SwitchesMode];
  928. c:='i';
  929. P:=DirectorySwitches^.Items^.FirstThat(@CheckItem);
  930. if assigned(P) then
  931. S:=P^.Str[SwitchesMode]+';'+S;
  932. if S='' then
  933. GetSourceDirectories:=SourceDirs+';'
  934. else
  935. GetSourceDirectories:=SourceDirs+';'+S+';';
  936. end;
  937. {*****************************************************************************
  938. AsmOutputInitialize
  939. *****************************************************************************}
  940. procedure UpdateAsmOutputSwitches;
  941. var
  942. ta : tasm;
  943. st : string;
  944. begin
  945. if assigned(AsmOutputSwitches) then
  946. dispose(AsmOutputSwitches,Done);
  947. New(AsmOutputSwitches,InitSelect('A'));
  948. with AsmOutputSwitches^ do
  949. begin
  950. AddDefaultSelect(opt_usedefaultas);
  951. for ta:=low(tasm) to high(tasm) do
  952. if assigned(asminfos[ta]) and
  953. ((target_info.system in asminfos[ta]^.supported_targets) or
  954. (system_any in asminfos[ta]^.supported_targets)) then
  955. begin
  956. st:='Asm '+asminfos[ta]^.idtxt;
  957. if asminfos[ta]^.idtxt='AS' then
  958. st:=opt_usegnuas;
  959. {$ifdef I386}
  960. if asminfos[ta]^.idtxt='NASMCOFF' then
  961. st:=opt_usenasmcoff;
  962. if asminfos[ta]^.idtxt='NASMOBJ' then
  963. st:=opt_usenasmobj;
  964. if asminfos[ta]^.idtxt='NASMWIN32' then
  965. st:=opt_usenasmwin32;
  966. if asminfos[ta]^.idtxt='NASMWDOSX' then
  967. st:=opt_usenasmwdosx;
  968. if asminfos[ta]^.idtxt='NASMELF' then
  969. st:=opt_usenasmelf;
  970. if asminfos[ta]^.idtxt='NASMBEOS' then
  971. st:=opt_usenasmbeos;
  972. if asminfos[ta]^.idtxt='MASM' then
  973. st:=opt_usemasm;
  974. if asminfos[ta]^.idtxt='TASM' then
  975. st:=opt_usetasm;
  976. if asminfos[ta]^.idtxt='WASM' then
  977. st:=opt_usewasm;
  978. if asminfos[ta]^.idtxt='COFF' then
  979. st:=opt_usecoff;
  980. if asminfos[ta]^.idtxt='PECOFF' then
  981. st:=opt_usepecoff;
  982. if asminfos[ta]^.idtxt='PEWDOSX' then
  983. st:=opt_usepecoffwdosx;
  984. if asminfos[ta]^.idtxt='ELF' then
  985. st:=opt_useelf;
  986. {$endif I386}
  987. AddSelectItem(st,asminfos[ta]^.idtxt,idNone);
  988. end;
  989. end;
  990. end;
  991. {*****************************************************************************
  992. Initialize
  993. *****************************************************************************}
  994. procedure InitSwitches;
  995. var
  996. t : tsystem;
  997. cpu : tcputype;
  998. st : string;
  999. begin
  1000. New(SyntaxSwitches,Init('S'));
  1001. with SyntaxSwitches^ do
  1002. begin
  1003. // AddBooleanItem(opt_objectpascal,'2',idNone);
  1004. AddBooleanItem(opt_stopafterfirsterror,'e',idNone);
  1005. AddBooleanItem(opt_allowlabelandgoto,'g',idNone);
  1006. AddBooleanItem(opt_globalcmacros,'m',idNone);
  1007. AddBooleanItem(opt_cplusplusstyledinline,'i',idNone);
  1008. // AddBooleanItem(opt_tp7compatibility,'o',idNone);
  1009. // AddBooleanItem(opt_delphicompatibility,'d',idNone);
  1010. AddBooleanItem(opt_assertions,'a',idNone);
  1011. AddBooleanItem(opt_ansistring,'h',idAnsiString);
  1012. AddBooleanItem(opt_kylix,'k',idNone);
  1013. AddBooleanItem(opt_allowstaticinobjects,'s',idNone);
  1014. AddBooleanItem(opt_clikeoperators,'c',idNone);
  1015. { Useless as they are not passed to the compiler PM
  1016. AddBooleanItem(opt_strictvarstrings,'/',idStrictVarStrings);
  1017. AddBooleanItem(opt_extendedsyntax,'/',idExtendedSyntax);
  1018. AddBooleanItem(opt_allowmmxoperations,'/',idMMXOps); }
  1019. end;
  1020. New(CompilerModeSwitches,InitSelect('M'));
  1021. with CompilerModeSwitches^ do
  1022. begin
  1023. AddSelectItem(opt_mode_freepascal,'fpc',idNone);
  1024. AddSelectItem(opt_mode_objectpascal,'objfpc',idNone);
  1025. AddSelectItem(opt_mode_turbopascal,'tp',idNone);
  1026. AddSelectItem(opt_mode_delphi,'delphi',idNone);
  1027. AddSelectItem(opt_mode_macpascal,'macpascal',idNone);
  1028. { GNU Pascal mode doesn't do much, better disable it
  1029. AddSelectItem(opt_mode_gnupascal,'gpc',idNone);}
  1030. end;
  1031. New(VerboseSwitches,Init('v'));
  1032. with VerboseSwitches^ do
  1033. begin
  1034. AddBooleanItem(opt_warnings,'w',idNone);
  1035. AddBooleanItem(opt_notes,'n',idNone);
  1036. AddBooleanItem(opt_hints,'h',idNone);
  1037. AddBooleanItem(opt_generalinfo,'i',idNone);
  1038. AddBooleanItem(opt_usedtriedinfo,'ut',idNone);
  1039. AddBooleanItem(opt_all,'a',idNone);
  1040. AddBooleanItem(opt_showallprocsonerror,'b',idNone);
  1041. end;
  1042. New(CodegenSwitches,Init('C'));
  1043. with CodegenSwitches^ do
  1044. begin
  1045. AddBooleanItem(opt_rangechecking,'r',idRangeChecks);
  1046. AddBooleanItem(opt_stackchecking,'t',idStackChecks);
  1047. AddBooleanItem(opt_iochecking,'i',idIOChecks);
  1048. AddBooleanItem(opt_overflowchecking,'o',idOverflowChecks);
  1049. AddBooleanItem(opt_objmethcallvalid,'R',idObjMethCallChecks);
  1050. AddBooleanItem(opt_pic,'g',idNone);
  1051. AddBooleanItem(opt_smart,'X',idNone);
  1052. end;
  1053. New(OptimizationSwitches,Init('O'));
  1054. with OptimizationSwitches^ do
  1055. begin
  1056. AddBooleanItem(opt_generatesmallercode,'s',idNone);
  1057. {$ifdef I386}
  1058. AddBooleanItem(opt_useregistervariables,'oregvar',idNone);
  1059. AddBooleanItem(opt_uncertainoptimizations,'ouncertain',idNone);
  1060. AddBooleanItem(opt_level1optimizations,'1',idNone);
  1061. AddBooleanItem(opt_level2optimizations,'2',idNone);
  1062. AddBooleanItem(opt_level3optimizations,'3',idNone);
  1063. {$else not I386}
  1064. {$ifdef m68k}
  1065. AddBooleanItem(opt_level1optimizations,'a',idNone);
  1066. AddBooleanItem(opt_useregistervariables,'x',idNone);
  1067. {$endif m68k}
  1068. {$endif I386}
  1069. end;
  1070. New(ProcessorOptimizationSwitches,InitSelect('O'));
  1071. with ProcessorOptimizationSwitches^ do
  1072. begin
  1073. for cpu:=low(tcputype) to high(tcputype) do
  1074. begin
  1075. st:=cputypestr[cpu];
  1076. {$ifdef I386}
  1077. if st='386' then
  1078. st:=opt_i386486;
  1079. if st='PENTIUM' then
  1080. st:=opt_pentium;
  1081. if st='PENTIUM2' then
  1082. st:=opt_pentiummmx;
  1083. if st='PENTIUM3' then
  1084. st:=opt_pentiumpro;
  1085. if st='PENTIUM4' then
  1086. st:=opt_pentiumiv;
  1087. if st='PENTIUMM' then
  1088. st:=opt_pentiumM;
  1089. {$endif not I386}
  1090. {$ifdef m68k}
  1091. if st='68000' then
  1092. st:=opt_m68000;
  1093. if st='68020' then
  1094. st:=opt_m68020;
  1095. {$endif m68k}
  1096. if st<>'' then
  1097. AddSelectItem(st,'p'+cputypestr[cpu],idNone);
  1098. end;
  1099. end;
  1100. New(ProcessorCodeGenerationSwitches,InitSelect('C'));
  1101. with ProcessorCodeGenerationSwitches^ do
  1102. begin
  1103. for cpu:=low(tcputype) to high(tcputype) do
  1104. begin
  1105. st:=cputypestr[cpu];
  1106. {$ifdef I386}
  1107. if st='386' then
  1108. st:=opt_i386486;
  1109. if st='PENTIUM' then
  1110. st:=opt_pentium;
  1111. if st='PENTIUM2' then
  1112. st:=opt_pentiummmx;
  1113. if st='PENTIUM3' then
  1114. st:=opt_pentiumpro;
  1115. if st='PENTIUM4' then
  1116. st:=opt_pentiumiv;
  1117. if st='PENTIUMM' then
  1118. st:=opt_pentiumM;
  1119. {$endif not I386}
  1120. {$ifdef m68k}
  1121. if st='68000' then
  1122. st:=opt_m68000;
  1123. if st='68020' then
  1124. st:=opt_m68020;
  1125. {$endif m68k}
  1126. { we use the string twice so kill duplicate highlights }
  1127. while pos('~',st)<>0 do
  1128. delete(st,pos('~',st),1);
  1129. if st<>'' then
  1130. AddSelectItem(st,'p'+cputypestr[cpu],idNone);
  1131. end;
  1132. end;
  1133. New(TargetSwitches,InitSelect('T'));
  1134. with TargetSwitches^ do
  1135. begin
  1136. { better, we've a correct target list without "tilded" names instead a wrong one }
  1137. for t:=low(tsystem) to high(tsystem) do
  1138. if assigned(targetinfos[t]) then
  1139. AddSelectItem(targetinfos[t]^.name,targetinfos[t]^.shortname,idNone);
  1140. end;
  1141. New(AsmReaderSwitches,InitSelect('R'));
  1142. with AsmReaderSwitches^ do
  1143. begin
  1144. {$ifdef I386}
  1145. AddSelectItem(opt_defaultassembler,'default',idNone);
  1146. { AddSelectItem(opt_directassembler,'direct',idAsmDirect);}
  1147. AddSelectItem(opt_attassembler,'att',idAsmATT);
  1148. AddSelectItem(opt_intelassembler,'intel',idAsmIntel);
  1149. {$endif I386}
  1150. {$ifdef M68K}
  1151. AddSelectItem(opt_defaultassembler,'default',idNone);
  1152. //AddSelectItem(opt_standardassembler,'standard',idAsmStandard);
  1153. AddSelectItem(opt_motassembler,'motorola',idAsmMot);
  1154. {$endif M68K}
  1155. end;
  1156. New(AsmInfoSwitches,Init('a'));
  1157. with AsmInfoSwitches^ do
  1158. begin
  1159. AddBooleanItem(opt_listsource,'l',idNone);
  1160. AddBooleanItem(opt_listregisterallocation,'r',idNone);
  1161. AddBooleanItem(opt_listtempallocation,'t',idNone);
  1162. AddBooleanItem(opt_listnodeallocation,'n',idNone);
  1163. AddBooleanItem(opt_useasmpipe,'p',idNone);
  1164. end;
  1165. UpdateAsmOutputSwitches;
  1166. New(BrowserSwitches,InitSelect('b'));
  1167. with BrowserSwitches^ do
  1168. begin
  1169. AddSelectItem(opt_nobrowser,'-',idSymInfNone);
  1170. AddSelectItem(opt_globalonlybrowser,'+',idSymInfGlobalOnly);
  1171. AddSelectItem(opt_localglobalbrowser,'l',idSymInfGlobalLocal);
  1172. end;
  1173. New(ConditionalSwitches,Init('d'));
  1174. with ConditionalSwitches^ do
  1175. begin
  1176. AddStringItem(opt_conditionaldefines,'',idNone,true,false);
  1177. end;
  1178. New(MemorySwitches,Init('C'));
  1179. with MemorySwitches^ do
  1180. begin
  1181. AddLongintItem(opt_stacksize,'s',idStackSize);
  1182. AddLongintItem(opt_heapsize,'h',idHeapSize);
  1183. end;
  1184. New(DirectorySwitches,Init('F'));
  1185. with DirectorySwitches^ do
  1186. begin
  1187. AddMultiStringItem(opt_unitdirectories,'u',idNone);
  1188. AddMultiStringItem(opt_includedirectories,'i',idNone);
  1189. AddMultiStringItem(opt_librarydirectories,'l',idNone);
  1190. AddMultiStringItem(opt_objectdirectories,'o',idNone);
  1191. AddStringItem(opt_exeppudirectories,'E',idNone,true,true);
  1192. AddStringItem(opt_ppuoutputdirectory,'U',idNone,true,true);
  1193. AddStringItem(opt_cross_tools_directory,'D',idNone,true,true);
  1194. AddStringItem(opt_dynamic_linker,'L',idNone,false,false);
  1195. end;
  1196. New(LibLinkerSwitches,InitSelect('X'));
  1197. with LibLinkerSwitches^ do
  1198. begin
  1199. AddDefaultSelect(opt_librariesdefault);
  1200. AddSelectItem(opt_dynamiclibraries,'D',idNone);
  1201. AddSelectItem(opt_staticlibraries,'S',idNone);
  1202. AddSelectItem(opt_smartlibraries,'X',idNone);
  1203. end;
  1204. New(OtherLinkerSwitches,Init('X'));
  1205. with OtherLinkerSwitches^ do
  1206. begin
  1207. AddBooleanItem(opt_stripalldebugsymbols,'s',idNone);
  1208. AddBooleanItem(opt_forcestaticlibs,'t',idNone);
  1209. end;
  1210. New(DebugInfoSwitches,InitSelect('g'));
  1211. with DebugInfoSwitches^ do
  1212. begin
  1213. AddSelectItem(opt_nogendebugsymbolinfo,'-',idNone);
  1214. AddSelectItem(opt_gendebugsymbolinfo,'',idNone);
  1215. AddSelectItem(opt_gensymbolandbacktraceinfo,'l',idNone);
  1216. AddSelectItem(opt_valgrindinfo,'v',idNone);
  1217. { AddSelectItem('Generate ~d~bx symbol information','d');
  1218. does not work anyhow (PM) }
  1219. end;
  1220. New(LinkAfterSwitches,Init('s'));
  1221. LinkAfterSwitches^.AddBooleanItem(opt_linkafter,'',idNone);
  1222. New(ProfileInfoSwitches,InitSelect('p'));
  1223. with ProfileInfoSwitches^ do
  1224. begin
  1225. AddSelectItem(opt_noprofileinfo,'-',idNone);
  1226. AddSelectItem(opt_gprofinfo,'g',idNone);
  1227. end;
  1228. {New(MemorySizeSwitches,Init('C'));
  1229. with MemorySizeSwitches^ do
  1230. begin
  1231. AddLongIntItem('~S~tack size','s');
  1232. AddLongIntItem('Local ~h~eap size','h');
  1233. end;}
  1234. SwitchesPath:=LocateFile(SwitchesName);
  1235. if SwitchesPath='' then
  1236. SwitchesPath:=SwitchesName;
  1237. SwitchesPath:=FExpand(SwitchesPath);
  1238. end;
  1239. procedure SetDefaultSwitches;
  1240. var
  1241. i,OldSwitchesMode : TSwitchMode;
  1242. begin
  1243. { setup some useful defaults }
  1244. OldSwitchesMode:=SwitchesMode;
  1245. for i:=low(TSwitchMode) to high(TSwitchMode) do
  1246. begin
  1247. SwitchesMode:=i;
  1248. { default is Pentium }
  1249. ProcessorOptimizationSwitches^.SetCurrSel(1);
  1250. { AT&T reader }
  1251. AsmReaderSwitches^.SetCurrSel(1);
  1252. { FPC mode}
  1253. CompilerModeSwitches^.SetCurrSel(0);
  1254. (* Use platform defaults for memory switches. *)
  1255. { 128k stack }
  1256. { MemorySwitches^.SetLongintItem(0,65536*2);}
  1257. MemorySwitches^.SetLongintItem(0,0);
  1258. { 2 MB heap }
  1259. { MemorySwitches^.SetLongintItem(1,1024*1024*2);}
  1260. MemorySwitches^.SetLongintItem(1,0);
  1261. { goto/lable allowed }
  1262. SyntaxSwitches^.SetBooleanItem(1,true);
  1263. { inline allowed }
  1264. SyntaxSwitches^.SetBooleanItem(3,true);
  1265. { Exe size complaints are louder than speed complaints: Optimize for size by default. }
  1266. OptimizationSwitches^.SetBooleanItem(0,true);
  1267. case i of
  1268. om_debug:
  1269. begin
  1270. { debugging info on }
  1271. DebugInfoSwitches^.SetCurrSel(1);
  1272. { range checking }
  1273. CodegenSwitches^.SetBooleanItem(0,true);
  1274. { io checking }
  1275. CodegenSwitches^.SetBooleanItem(2,true);
  1276. { overflow checking }
  1277. CodegenSwitches^.SetBooleanItem(3,true);
  1278. { method call checking }
  1279. CodegenSwitches^.SetBooleanItem(4,true);
  1280. { assertions on }
  1281. SyntaxSwitches^.SetBooleanItem(4,true);
  1282. end;
  1283. om_normal:
  1284. begin
  1285. {Register variables.}
  1286. OptimizationSwitches^.SetBooleanItem(1,true);
  1287. {Level 1 optimizations.}
  1288. OptimizationSwitches^.SetBooleanItem(3,true);
  1289. end;
  1290. om_release:
  1291. begin
  1292. {Register variables.}
  1293. OptimizationSwitches^.SetBooleanItem(1,true);
  1294. {Level 2 optimizations.}
  1295. OptimizationSwitches^.SetBooleanItem(4,true);
  1296. {Smart linking.}
  1297. LibLinkerSwitches^.SetCurrSel(3);
  1298. CodegenSwitches^.SetBooleanItem(6,true);
  1299. {Strip debug info}
  1300. OtherLinkerSwitches^.SetBooleanItem(0,true);
  1301. end;
  1302. end;
  1303. { set appriopriate default target }
  1304. TargetSwitches^.SetCurrSelParam(target_info.shortname);
  1305. end;
  1306. SwitchesMode:=OldSwitchesMode;
  1307. end;
  1308. procedure DoneSwitches;
  1309. begin
  1310. dispose(SyntaxSwitches,Done);
  1311. dispose(CompilerModeSwitches,Done);
  1312. dispose(VerboseSwitches,Done);
  1313. dispose(CodegenSwitches,Done);
  1314. dispose(OptimizationSwitches,Done);
  1315. dispose(ProcessorOptimizationSwitches,Done);
  1316. dispose(ProcessorCodeGenerationSwitches,Done);
  1317. dispose(BrowserSwitches,Done);
  1318. dispose(TargetSwitches,Done);
  1319. dispose(AsmReaderSwitches,Done);
  1320. dispose(AsmOutputSwitches,Done);
  1321. dispose(AsmInfoSwitches,Done);
  1322. dispose(ConditionalSwitches,Done);
  1323. dispose(MemorySwitches,Done);
  1324. {dispose(MemorySizeSwitches,Done);}
  1325. dispose(DirectorySwitches,Done);
  1326. dispose(DebugInfoSwitches,Done);
  1327. dispose(LibLinkerSwitches,Done);
  1328. dispose(LinkAfterSwitches,Done);
  1329. dispose(OtherLinkerSwitches,Done);
  1330. dispose(ProfileInfoSwitches,Done);
  1331. end;
  1332. procedure GetCompilerOptionLines(C: PUnsortedStringCollection);
  1333. procedure AddLine(const S: string);
  1334. begin
  1335. C^.Insert(NewStr(S));
  1336. end;
  1337. procedure ConstructSwitchModeDirectives(SM: TSwitchMode; const IfDefSym: string);
  1338. var SwitchParams: PStringCollection;
  1339. MiscParams : PStringCollection;
  1340. procedure AddSwitch(const S: string);
  1341. begin
  1342. SwitchParams^.Insert(NewStr(S));
  1343. end;
  1344. procedure AddParam(const S: string);
  1345. begin
  1346. MiscParams^.Insert(NewStr(S));
  1347. end;
  1348. procedure EnumSwitches(P: PSwitches);
  1349. procedure HandleSwitch(P: PSwitchItem);
  1350. begin
  1351. case P^.ParamID of
  1352. { idAlign :}
  1353. idRangeChecks : AddSwitch('R'+P^.GetSwitchStr(SM));
  1354. idStackChecks : AddSwitch('S'+P^.GetSwitchStr(SM));
  1355. idIOChecks : AddSwitch('I'+P^.GetSwitchStr(SM));
  1356. idOverflowChecks : AddSwitch('Q'+P^.GetSwitchStr(SM));
  1357. idObjMethCallChecks: AddSwitch('OBJECTCHECKS'+P^.GetSwitchStr(SM));
  1358. { idAsmDirect : if P^.GetParamValueBool[SM] then AddParam('ASMMODE DIRECT');
  1359. idAsmATT : if P^.GetParamValueBool[SM] then AddParam('ASMMODE ATT');
  1360. idAsmIntel : if P^.GetParamValueBool[SM] then AddParam('ASMMODE INTEL');
  1361. idAsmMot : if P^.GetParamValueBool[SM] then AddParam('ASMMODE MOTOROLA');
  1362. idAsmStandard : if P^.GetParamValueBool[SM] then AddParam('ASMMODE STANDARD');}
  1363. { idSymInfNone : ;
  1364. idSymInfGlobalOnly:;
  1365. idSymInfGlobalLocal:if P^.ParamValueBool(SM) then AddSwitch('L+');}
  1366. { idStackSize
  1367. idHeapSize}
  1368. idStrictVarStrings: AddSwitch('V'+P^.GetSwitchStr(SM));
  1369. idExtendedSyntax : AddSwitch('X'+P^.GetSwitchStr(SM));
  1370. idMMXOps : if P^.ParamValueBool(SM) then AddParam('MMX');
  1371. idTypedAddress : AddSwitch('T'+P^.GetSwitchStr(SM));
  1372. { idPackRecords
  1373. idPackEnum}
  1374. idStackFrames : AddSwitch('W'+P^.GetSwitchStr(SM));
  1375. idReferenceInfo : AddSwitch('Y'+P^.GetSwitchStr(SM));
  1376. idDebugInfo : AddSwitch('D'+P^.GetSwitchStr(SM));
  1377. idBoolEval : AddSwitch('B'+P^.GetSwitchStr(SM));
  1378. idAnsiString : AddSwitch('H'+P^.GetSwitchStr(SM));
  1379. idTypeInfo : AddSwitch('M'+P^.GetSwitchStr(SM));
  1380. end;
  1381. end;
  1382. begin
  1383. P^.Items^.ForEach(@HandleSwitch);
  1384. end;
  1385. var I: integer;
  1386. S: string;
  1387. begin
  1388. AddLine('{$IFDEF '+IfDefSym+'}');
  1389. New(SwitchParams, Init(10,10));
  1390. New(MiscParams, Init(10,10));
  1391. EnumSwitches(LibLinkerSwitches);
  1392. EnumSwitches(OtherLinkerSwitches);
  1393. EnumSwitches(DebugInfoSwitches);
  1394. EnumSwitches(ProfileInfoSwitches);
  1395. EnumSwitches(SyntaxSwitches);
  1396. EnumSwitches(CompilerModeSwitches);
  1397. EnumSwitches(VerboseSwitches);
  1398. EnumSwitches(CodegenSwitches);
  1399. EnumSwitches(OptimizationSwitches);
  1400. EnumSwitches(ProcessorOptimizationSwitches);
  1401. EnumSwitches(ProcessorCodeGenerationSwitches);
  1402. EnumSwitches(AsmReaderSwitches);
  1403. EnumSwitches(AsmInfoSwitches);
  1404. EnumSwitches(AsmOutputSwitches);
  1405. EnumSwitches(TargetSwitches);
  1406. EnumSwitches(ConditionalSwitches);
  1407. EnumSwitches(MemorySwitches);
  1408. EnumSwitches(BrowserSwitches);
  1409. EnumSwitches(DirectorySwitches);
  1410. S:='';
  1411. for I:=0 to SwitchParams^.Count-1 do
  1412. begin
  1413. if I=0 then S:='{$' else S:=S+',';
  1414. S:=S+PString(SwitchParams^.At(I))^;
  1415. end;
  1416. if S<>'' then S:=S+'}';
  1417. if S<>'' then AddLine(' '+S);
  1418. for I:=0 to MiscParams^.Count-1 do
  1419. AddLine(' {$'+PString(MiscParams^.At(I))^+'}');
  1420. Dispose(SwitchParams, Done); Dispose(MiscParams, Done);
  1421. AddLine('{$ENDIF '+IfDefSym+'}');
  1422. end;
  1423. var SM: TSwitchMode;
  1424. begin
  1425. for SM:=Low(TSwitchMode) to High(TSwitchMode) do
  1426. ConstructSwitchModeDirectives(SM,SwitchesModeStr[SM]);
  1427. end;
  1428. end.