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