-
Notifications
You must be signed in to change notification settings - Fork 4
/
Program.cs
1681 lines (1653 loc) · 80.7 KB
/
Program.cs
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
using System.Collections.ObjectModel;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Xml.Linq;
namespace DSPtoVCXPROJ;
// The purpose of this program is to convert the .DSP project files used in Visual Studio 6.0 (and maybe also 5.0?) into .VCXPROJ project
// files for use in modern version of Visual Studio. This MIGHT work for .DSP project files from other versions of Visual Studio, but 6.0
// is primarily what was tested. (Testing is hard because finding .DSP project files in the wild these days is hard.)
// This will only support VS 2015 and later, because at the time of (re-)doing this, those are the only ones with readily available docs.
// Knowing which VS 6.0 options were and weren't available was only possible from installing VS 6.0 inside of a VM.
// The BSC32 sections are ignored, as modern versions of Visual Studio do not use it anymore.
// While it is possible it might not be correct, MTL sections are also ignored, if only because modern Visual Studio doesn't have a good
// way to handle the MIDL arguments.
// NOTE: Some parts of this could be made a little more efficient when .NET 8 comes out, as it offers an extension for ReadOnlySpan<T> to
// split by a delimiter, so using string.Split can be avoided to avoid the extra allocations.
static class Program
{
/// <summary>
/// The XML namespace for the entirety of the MSBuild XML files.
/// </summary>
internal static readonly XNamespace NS = XNamespace.Get("http://schemas.microsoft.com/developer/msbuild/2003");
/// <summary>
/// The project's configuration type, set when # TARGTYPE is encountered.
/// </summary>
internal static string ConfigurationType = null!;
/// <summary>
/// The groups that are created by modern versions of Visual Studio for a new project, which differ from how Visual Studio 6.0 did them.
/// </summary>
static readonly Dictionary<string, (string Extensions, Guid GUID)> ExistingGroups = new()
{
["Source Files"] = (
"cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx",
new("{4FC737F1-C7A5-4376-A066-2A32D752A2FF}")
),
["Header Files"] = (
"h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd",
new("{93995380-89BD-4b04-88EB-625FBE52EBFB}")
),
["Resource Files"] = (
"rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms",
new("{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}")
)
};
/// <summary>
/// A collection of <see cref="ProjectConfiguration" /> elements, using <see cref="KeyedCollection{TKey, TItem}" /> to allow them to
/// be accessed by key while still being stored like a list.
/// </summary>
internal class ProjectConfigurations : KeyedCollection<string, ProjectConfiguration>
{
protected override string GetKeyForItem(ProjectConfiguration item) => $"{item.Platform} {item.Configuration}";
}
/// <summary>
/// Throws an <see cref="ArgumentException" /> with the given data for an invalid value.
/// </summary>
/// <param name="name">The name (either an option name or a program name) that had the invalid value.</param>
/// <param name="label">The label of what was invalid (usually something like "argument" or "flag").</param>
/// <param name="value">The value that was invalid.</param>
/// <param name="lineNumber">The line number where the invalid value was found.</param>
/// <param name="valueName">The optional name of the value to append after <paramref name="name" />.</param>
/// <returns>
/// This method does not actually return, but the return value is needed to prevent the compiler from thinking that there might be code
/// after this call, despite the <see cref="DoesNotReturnAttribute" />.
/// </returns>
[DoesNotReturn]
static Exception ThrowInvalid(string name, string label, ReadOnlySpan<char> value, int lineNumber, string? valueName = null) =>
throw new ArgumentException($"Invalid {name}{(valueName is null ? "" : $" {valueName}")} {label} [{value}] - Line {lineNumber}");
/// <summary>
/// Throws an <see cref="ArgumentException" /> with the given data for an invalid value.
/// </summary>
/// <typeparam name="T">The type is only needed to allow this to be called in places that expect a return value.</typeparam>
/// <param name="name">The name (either an option name or a program name) that had the invalid value.</param>
/// <param name="label">The label of what was invalid (usually something like "argument" or "flag").</param>
/// <param name="value">The value that was invalid.</param>
/// <param name="lineNumber">The line number where the invalid value was found.</param>
/// <param name="valueName">The optional name of the value to append after <paramref name="name" />.</param>
/// <returns>
/// This method does not actually return, but the return value is needed to prevent the compiler from thinking that there might be code
/// after this call, despite the <see cref="DoesNotReturnAttribute" />.
/// </returns>
[DoesNotReturn]
static T ThrowInvalid<T>(string name, string label, ReadOnlySpan<char> value, int lineNumber, string? valueName = null) =>
throw new ArgumentException($"Invalid {name}{(valueName is null ? "" : $" {valueName}")} {label} [{value}] - Line {lineNumber}");
/// <summary>
/// Throws an <see cref="ArgumentException" /> with the given data for an invalid argument.
/// </summary>
/// <param name="name">The name (either an option name or a program name) that had the invalid argument.</param>
/// <param name="argument">The argument that was invalid.</param>
/// <param name="lineNumber">The line number where the invalid argument was found.</param>
/// <returns>
/// This method does not actually return, but the return value is needed to prevent the compiler from thinking that there might be code
/// after this call, despite the <see cref="DoesNotReturnAttribute" />.
/// </returns>
[DoesNotReturn]
static Exception ThrowInvalidArgument(string name, ReadOnlySpan<char> argument, int lineNumber) =>
Program.ThrowInvalid(name, "argument", argument, lineNumber);
/// <summary>
/// Throws an <see cref="ArgumentException" /> with the given data for an invalid argument.
/// </summary>
/// <typeparam name="T">The type is only needed to allow this to be called in places that expect a return value.</typeparam>
/// <param name="name">The name (either an option name or a program name) that had the invalid argument.</param>
/// <param name="argument">The argument that was invalid.</param>
/// <param name="lineNumber">The line number where the invalid argument was found.</param>
/// <returns>
/// This method does not actually return, but the return value is needed to prevent the compiler from thinking that there might be code
/// after this call, despite the <see cref="DoesNotReturnAttribute" />.
/// </returns>
[DoesNotReturn]
static T ThrowInvalidArgument<T>(string name, ReadOnlySpan<char> argument, int lineNumber) =>
Program.ThrowInvalid<T>(name, "argument", argument, lineNumber);
/// <summary>
/// Throws an <see cref="ArgumentException" /> with the given data for an invalid flag.
/// </summary>
/// <param name="name">The name (either an option name or a program name) that had the invalid flag.</param>
/// <param name="flag">The flag that was invalid.</param>
/// <param name="lineNumber">The line number where the invalid flag was found.</param>
/// <param name="flagName">The optional name of the flag to append after <paramref name="name" />.</param>
/// <returns>
/// This method does not actually return, but the return value is needed to prevent the compiler from thinking that there might be code
/// after this call, despite the <see cref="DoesNotReturnAttribute" />.
/// </returns>
[DoesNotReturn]
static Exception ThrowInvalidFlag(string name, ReadOnlySpan<char> flag, int lineNumber, string? flagName = null) =>
Program.ThrowInvalid(name, "flag", flag, lineNumber, flagName);
/// <summary>
/// Throws an <see cref="ArgumentException" /> with the given data for an invalid flag.
/// </summary>
/// <typeparam name="T">The type is only needed to allow this to be called in places that expect a return value.</typeparam>
/// <param name="name">The name (either an option name or a program name) that had the invalid flag.</param>
/// <param name="flag">The flag that was invalid.</param>
/// <param name="lineNumber">The line number where the invalid flag was found.</param>
/// <param name="flagName">The optional name of the flag to append after <paramref name="name" />.</param>
/// <returns>
/// This method does not actually return, but the return value is needed to prevent the compiler from thinking that there might be code
/// after this call, despite the <see cref="DoesNotReturnAttribute" />.
/// </returns>
[DoesNotReturn]
static T ThrowInvalidFlag<T>(string name, ReadOnlySpan<char> flag, int lineNumber, string? flagName = null) =>
Program.ThrowInvalid<T>(name, "flag", flag, lineNumber, flagName);
/// <summary>
/// Gathers up files of the given type only and adds them to an ItemGroup in both the main project file and the filters file.
/// </summary>
/// <typeparam name="T">The specific type that needs to be added to the files.</typeparam>
/// <param name="vcxprojRootXML">The XML containing the main project file.</param>
/// <param name="filtersRootXML">The XML containing the filters file.</param>
/// <param name="files">The files to be filtered and added.</param>
static void GetFiles<T>(XElement vcxprojRootXML, XElement filtersRootXML, List<SourceFile> files) where T : None
{
// Create the ItemGroup blocks for both files.
var filtersItemGroup = Program.CreateItemGroupBlock(null);
var vcxprojItemGroup = Program.CreateItemGroupBlock(null);
// I can't do "f.Debug is T" because when T is None, it'll catch everything, and I don't want that.
foreach (var file in files.Where(static f => f.Configurations.Values.First().GetType() == typeof(T)))
{
var values = file.Configurations.Values;
var firstValue = values.First();
// Create the filter block first, if there is a filter, and add it to the filters file.
if (firstValue.Filter is not null)
filtersItemGroup.Add(firstValue.GetBlock());
// Remove all the filters so we can get the blocks for the project file.
foreach (var config in values)
config.Filter = null;
// Create the project block from the first configuration, then add the extra elements from all the other configurations.
var vcxprojItemGroupBlock = firstValue.GetBlock();
foreach (var config in values.Skip(1))
foreach (var elem in config.GetBlock().Elements())
{
elem.Remove();
vcxprojItemGroupBlock.Add(elem);
}
// Add the project block to the project file.
vcxprojItemGroup.Add(vcxprojItemGroupBlock);
}
// Only add the ItemGroup blocks if they had elements.
if (filtersItemGroup.HasElements)
filtersRootXML.Add(filtersItemGroup);
if (vcxprojItemGroup.HasElements)
vcxprojRootXML.Add(vcxprojItemGroup);
}
/// <summary>
/// Creates an ItemGroup block, with optional label.
/// </summary>
/// <param name="Label">The optional value for the Label attribute.</param>
/// <param name="elements">The child elements to add to the block.</param>
/// <returns>The ItemGroup <see cref="XElement" /> block.</returns>
static XElement CreateItemGroupBlock(string? Label, params object[] elements)
{
var block = Program.CreateElement("ItemGroup", elements);
block.AddAttributeIfNotBlank(Label);
return block;
}
/// <summary>
/// Creates a PropertyGroup block, with optional condition and label.
/// </summary>
/// <param name="Condition">The optional value for the Condtional attribute.</param>
/// <param name="Label">The optional value for the Label attribute.</param>
/// <param name="elements">The child elements to add to the block.</param>
/// <returns>The PropertyGroup <see cref="XElement" /> block.</returns>
internal static XElement CreatePropertyGroupBlock(string? Condition, string? Label, params object[] elements)
{
var block = Program.CreateElement("PropertyGroup", elements);
block.AddAttributeIfNotBlank(Condition);
block.AddAttributeIfNotBlank(Label);
return block;
}
/// <summary>
/// Creates an Import block for a given project, with optional conditional and label.
/// </summary>
/// <param name="Project">The value for the Project attribute.</param>
/// <param name="Condition">The optional value for the Conditional attribute.</param>
/// <param name="Label">The optional value for the Label attribute.</param>
/// <returns>The Import <see cref="XElement" /> block.</returns>
static XElement CreateImportBlock(string Project, string? Condition, string? Label)
{
var block = Program.CreateElement("Import");
block.AddAttributeIfNotBlank(Project);
block.AddAttributeIfNotBlank(Condition);
block.AddAttributeIfNotBlank(Label);
return block;
}
/// <summary>
/// Creates an ImportGroup block, with condition and label.
/// </summary>
/// <param name="Condition">The value for the Condition attribute.</param>
/// <param name="Label">The value for the Label attribute.</param>
/// <param name="elements">The child elements to add to the block.</param>
/// <returns>The ImportGroup <see cref="XElement" /> block.</returns>
static XElement CreateImportGroupBlock(string Condition, string Label, params object[] elements)
{
var block = Program.CreateElement("ImportGroup", elements);
block.AddAttributeIfNotBlank(Condition);
block.AddAttributeIfNotBlank(Label);
return block;
}
/// <summary>
/// Creates a generic <see cref="XElement" /> block with the MSBuild namespace attached to it.
/// </summary>
/// <param name="name">The name of the element.</param>
/// <param name="elements">The child elements to add to the block.</param>
/// <returns>The generic <see cref="XElement" /> block.</returns>
internal static XElement CreateElement(string name, params object[] elements) => new(Program.NS + name, elements);
static string rootNamespace = null!;
static readonly ProjectConfigurations projectConfigurations = new();
static ProjectConfiguration? currentConfig = null;
static readonly List<Filter> filters = new();
static Filter? currentFilter = null;
static readonly MultipleClCompile multipleClCompile = new();
static readonly MultipleResourceCompile multipleResourceCompile = new();
static readonly List<SourceFile> files = new();
static SourceFile? currentFile = null;
/// <summary>
/// Process a line containing a property.
/// </summary>
/// <param name="line">The contents of the line.</param>
/// <param name="lineNumber">The line number of the line.</param>
static void ProcessProps(string line, int lineNumber)
{
string[] props = line.Split(' ', StringSplitOptions.RemoveEmptyEntries);
switch (props[2])
{
case "Use_MFC":
switch (int.Parse(props[3], CultureInfo.InvariantCulture))
{
case 0:
break; // Ignored because this is the default
case 1 or 5:
Program.currentConfig!.Properties.UseOfMfc = "Static";
break;
case 2 or 6:
Program.currentConfig!.Properties.UseOfMfc = "Dynamic";
break;
default:
throw Program.ThrowInvalidArgument("Use_MFC", props[3], lineNumber);
}
break;
case "Use_Debug_Libraries":
switch (int.Parse(props[3], CultureInfo.InvariantCulture))
{
case 0:
break; // Ignored because this is the default
case 1:
Program.currentConfig!.Properties.UseDebugLibraries = true;
break;
default:
throw Program.ThrowInvalidArgument("Use_Debug_Libraries", props[3], lineNumber);
}
break;
case "Output_Dir":
Program.currentConfig!.Properties.OutDir = props[3].Trim('"');
break;
case "Intermediate_Dir":
Program.currentConfig!.Properties.IntDir = props[3].Trim('"');
break;
case "Default_Filter":
if (Program.currentFilter is not null)
{
string filter = props[3].Trim('"');
if (!string.IsNullOrWhiteSpace(filter))
Program.currentFilter.Extensions = filter;
}
break;
case "Exclude_From_Build":
Program.multipleClCompile.ExcludedFromBuild = int.Parse(props[3], CultureInfo.InvariantCulture) switch
{
0 => false,
1 => true,
_ => Program.ThrowInvalidArgument<bool>("Exclude_From_Build", props[3], lineNumber)
};
break;
}
}
/// <summary>
/// Process a line for the compiler.
/// </summary>
/// <param name="line">The contents of the line.</param>
/// <param name="lineNumber">The line number of the line.</param>
static void ProcessCPP(string line, int lineNumber)
{
bool hadNoLogo = false;
string[] cppFlags = line[(line.Contains("BASE") ? 15 : 10)..].Split(' ', StringSplitOptions.RemoveEmptyEntries);
int numCppFlags = cppFlags.Length;
for (int i = 0; i < numCppFlags; ++i)
{
var cppFlag = cppFlags[i].AsSpan();
if (cppFlag[0] is '/' or '-')
{
cppFlag = cppFlag[1..];
switch (cppFlag)
{
case "C":
Program.multipleClCompile.PreprocessKeepComments = true;
break;
case var _ when cppFlag.StartsWith("D", StringComparison.InvariantCulture):
{
// Allowed to have a space between the flag and the argument
var define = (cppFlag.Length > 1 ? cppFlag[1..] : cppFlags[++i]).Trim('"');
switch (define)
{
case "_MBCS":
Program.currentConfig!.Properties.CharacterSet = "MultiByte";
break;
case "_UNICODE":
Program.currentConfig!.Properties.CharacterSet = "Unicode";
break;
default:
Program.multipleClCompile.PreprocessorDefinitionsAdd($"{define}");
if (define is "_AFXEXT")
Program.multipleClCompile.PreprocessorDefinitionsAdd("_WINDLL");
break;
}
break;
}
case { Length: > 2 } when cppFlag.StartsWith("EH", StringComparison.InvariantCulture):
{
var ehFlag = cppFlag[2..];
// Ignoring if /EHsc was being set, as this is the default
if (ehFlag is not "sc")
Program.multipleClCompile.ExceptionHandling = ehFlag switch
{
"a" => "Async",
"s" => "SyncCThrow",
_ => Program.ThrowInvalidFlag<string>("cl.exe", ehFlag, lineNumber, "/EH")
};
break;
}
case "EP":
Program.multipleClCompile.PreprocessSuppressLineNumbers = true;
break;
case var _ when cppFlag.StartsWith("F", StringComparison.InvariantCulture):
{
var fFlag = cppFlag.Length > 1 ? cppFlag[1..] : new();
switch (fFlag)
{
case "A":
Program.multipleClCompile.AssemblerOutput = "AssemblyCode";
break;
case "Ac":
Program.multipleClCompile.AssemblerOutput = "AssemblyAndMachineCode";
break;
case "Acs":
Program.multipleClCompile.AssemblerOutput = "All";
break;
case "As":
Program.multipleClCompile.AssemblerOutput = "AssemblyAndSourceCode";
break;
case var _ when fFlag.StartsWith("a", StringComparison.InvariantCulture):
{
// Unsure if this will ever have a space after it or not
var location = (fFlag.Length > 1 ? fFlag[1..] : cppFlags[++i]).Trim('"');
// Ignoring if location was $(IntDir), as this is the default
if (location is not "$(IntDir)")
Program.multipleClCompile.AssemblerListingLocation = $"{location}";
break;
}
case { Length: > 1 } when fFlag.StartsWith("d", StringComparison.InvariantCulture):
{
// Not allowed to have a space between the flag and the argument
var filename = fFlag[1..].Trim('"');
// Ignoring if filename was $(IntDir)vc$(PlatformToolsetVersion).pdb, as this is the default
if (filename is not "$(IntDir)vc$(PlatformToolsetVersion).pdb")
Program.multipleClCompile.ProgramDataBaseFileName = $"{filename}";
break;
}
case var _ when fFlag.StartsWith("I", StringComparison.InvariantCulture):
// Allowed to have a space between the flag and the argument
Program.multipleClCompile.
ForcedIncludeFilesAdd($"{(fFlag.Length > 1 ? fFlag[2..] : cppFlags[++i]).Trim('"')}");
break;
case { Length: > 1 } when fFlag.StartsWith("o", StringComparison.InvariantCulture):
{
// Not allowed to have a space between the flag and the argument
var filename = fFlag[1..].Trim('"');
// Ignoring if filename was $(IntDir), as this is the default
if (filename is not "$(IntDir)")
Program.multipleClCompile.ObjectFileName = $"{filename}";
break;
}
case { Length: > 1 } when fFlag.StartsWith("p", StringComparison.InvariantCulture):
{
// Not allowed to have a space between the flag and the argument
var filename = fFlag[1..].Trim('"');
// Ignoring if filename was $(IntDir)$(TargetName).pch, as this is the default
if (filename is not "$(IntDir)$(TargetName).pch")
Program.multipleClCompile.PrecompiledHeaderOutputFile = $"{filename}";
break;
}
case var _ when fFlag.StartsWith("R", StringComparison.InvariantCulture):
case var _ when fFlag.StartsWith("r", StringComparison.InvariantCulture):
// 'r' is deprecated but does nearly the same thing as 'R'
Program.multipleClCompile.BrowseInformation = true;
// Not allowed to have a space between the flag and the argument
if (fFlag.Length > 1)
{
var filename = fFlag[1..].Trim('"');
// Ignoring if filename was $(IntDir), as this is the default
if (filename is not "$(IntDir)")
Program.multipleClCompile.BrowseInformationFile = $"{filename}";
}
break;
case { Length: > 1 } when fFlag.StartsWith("e", StringComparison.InvariantCulture):
case { Length: > 1 } when fFlag.StartsWith("m", StringComparison.InvariantCulture):
case { Length: 0 }: // Handles /F <num>
case { Length: > 0 } when int.TryParse(fFlag.Trim('"'), out _): // Handles /F<num>
// For /F, allowed to have a space between the flag and the argument (but we 'trim' that space away)
if (cppFlag.Length == 0)
Program.multipleClCompile.AdditionalOptionsAdd($"/F{cppFlags[++i].Trim('"')}");
else
Program.multipleClCompile.AdditionalOptionsAdd($"{cppFlag}");
break;
case "D":
break; // Ignored because it no longer exists in VS 2015 and later
default:
throw Program.ThrowInvalidFlag("cl.exe", fFlag, lineNumber, "/F");
}
break;
}
case { Length: > 1 } when cppFlag.StartsWith("G", StringComparison.InvariantCulture):
switch (cppFlag[1..])
{
case "d":
break; // Ignored as it is the default
case "F" or "f":
// Technically "f" no longer exists in VS 2015 and later, but probably good to handle here it too...
Program.multipleClCompile.StringPooling = true;
break;
case "R":
Program.multipleClCompile.RuntimeTypeInfo = true;
break;
case "R-":
Program.multipleClCompile.RuntimeTypeInfo = false;
break;
case "r":
Program.multipleClCompile.CallingConvention = "FastCall";
break;
case "T":
Program.multipleClCompile.EnableFiberSafeOptimizations = true;
break;
case "X-":
Program.multipleClCompile.ExceptionHandling = "false";
break;
case "y":
Program.multipleClCompile.FunctionLevelLinking = true;
break;
case "Z": // Equivalent of /RTCs
Program.multipleClCompile.BasicRuntimeChecks = "StackFrameRuntimeCheck";
break;
case "z":
Program.multipleClCompile.CallingConvention = "StdCall";
break;
case "A" or "h":
case { Length: > 2 } when cppFlag[1] == 's' && int.TryParse(cppFlag[2..], out _):
// Not allowed to have a space between the flag and the argument for /Gs
Program.multipleClCompile.AdditionalOptionsAdd($"{cppFlag}");
break;
case "X":
break; // Ignored because this would be the same as setting /EHsc and this is the default
case "e" or "m" or "m-":
break; // Ignored because they are deprecated
case "3" or "4" or "5" or "6" or "B" or "D" or "i" or "i-":
break; // Ignored because they no longer exist in VS 2015 and later
default:
throw Program.ThrowInvalidFlag("cl.exe", cppFlag[1..], lineNumber, "/G");
}
break;
case var _ when cppFlag.StartsWith("I", StringComparison.InvariantCulture):
// Allowed to have a space between the flag and the argument
Program.multipleClCompile.
AdditionalIncludeDirectoriesAdd($"{(cppFlag.Length > 1 ? cppFlag[1..] : cppFlags[++i]).Trim('"')}");
break;
case { Length: > 1 } when cppFlag.StartsWith("M", StringComparison.InvariantCulture):
switch (cppFlag[1..])
{
case "D":
// Ignoring if UseDebugLibraries is set to false (or not set at all), as this is the default
if (Program.currentConfig!.Properties.UseDebugLibraries == true)
Program.multipleClCompile.RuntimeLibrary = "MultiThreadedDLL";
break;
case "Dd":
// Ignoring if UseDebugLibraries is set to true, as this is the default
if (Program.currentConfig!.Properties.UseDebugLibraries != true)
Program.multipleClCompile.RuntimeLibrary = "MultiThreadedDebugDLL";
break;
case "T":
Program.multipleClCompile.RuntimeLibrary = "MultiThreaded";
break;
case "Td":
Program.multipleClCompile.RuntimeLibrary = "MultiThreadedDebug";
break;
case "L" or "Ld":
break; // Ignored because they no longer exist in VS 2015 and later
default:
throw Program.ThrowInvalidFlag("cl.exe", cppFlag[1..], lineNumber, "/M");
}
break;
case "nologo":
hadNoLogo = true;
break;
case { Length: > 1 } when cppFlag.StartsWith("O", StringComparison.InvariantCulture):
switch (cppFlag[1..])
{
case "1":
Program.multipleClCompile.Optimization = "MinSpace";
break;
case "2":
// Ignoring if UseDebugLibraries is set to false (or not set at all), as this is the default
if (Program.currentConfig!.Properties.UseDebugLibraries == true)
Program.multipleClCompile.Optimization = "MaxSpeed";
break;
case "b0":
Program.multipleClCompile.InlineFunctionExpansion = "Disabled";
break;
case "b1":
Program.multipleClCompile.InlineFunctionExpansion = "OnlyExplicitInline";
break;
case "b2":
Program.multipleClCompile.InlineFunctionExpansion = "AnySuitable";
break;
case "d":
// Ignoring if UseDebugLibraries is set to true, as this is the default
if (Program.currentConfig!.Properties.UseDebugLibraries != true)
Program.multipleClCompile.Optimization = "Disabled";
break;
case "i":
Program.multipleClCompile.IntrinsicFunctions = true;
break;
case "s":
Program.multipleClCompile.FavorSizeOrSpeed = "Size";
break;
case "t":
Program.multipleClCompile.FavorSizeOrSpeed = "Speed";
break;
case "x":
Program.multipleClCompile.Optimization = "Full";
break;
case "y":
Program.multipleClCompile.OmitFramePointers = true;
break;
case "y-":
// Ignoring if Platform is Win32, as this is the default
if (Program.currentConfig!.Platform != "Win32")
Program.multipleClCompile.OmitFramePointers = false;
break;
case "g":
break; // Ignored because it is deprecated
case "a" or "p" or "p-" or "w":
break; // Ignored because they no longer exist in VS 2015 and later
default:
throw Program.ThrowInvalidFlag("cl.exe", cppFlag[1..], lineNumber, "/O");
}
break;
case "P":
Program.multipleClCompile.PreprocessToFile = true;
break;
case { Length: 2 } when cppFlag.StartsWith("T", StringComparison.InvariantCulture):
Program.multipleClCompile.CompileAs = cppFlag[1] switch
{
'C' => "CompileAsC",
'P' => "CompileAsCpp",
// NOTE: Not handling c or p here, if they exist, it is probably an error,
// compiling a file as C or C++ is set individually on the file in the IDE
_ => Program.ThrowInvalidFlag<string>("cl.exe", cppFlag[1..], lineNumber, "/T")
};
break;
case var _ when cppFlag.StartsWith("U", StringComparison.InvariantCulture):
// Allowed to have a space between the flag and the argument
Program.multipleClCompile.
UndefinePreprocessorDefinitionsAdd($"{(cppFlag.Length > 1 ? cppFlag[1..] : cppFlags[++i]).Trim('"')}");
break;
case "u":
Program.multipleClCompile.UndefineAllPreprocessorDefinitions = true;
break;
case var _ when cppFlag.StartsWith("W", StringComparison.InvariantCulture):
{
// Allowed to have a space between the flag and the argument
var level = cppFlag.Length > 1 ? cppFlag[1..] : cppFlags[++i];
if (level.Length == 1 && char.IsNumber(level[0]))
{
// Ignoring /W1, as this is the default
if (level[0] != '1')
Program.multipleClCompile.WarningLevel = level[0] == '0' ? "TurnOffAllWarnings" : $"Level{level}";
}
else
Program.multipleClCompile.TreatWarningAsError = (level.Length == 1 && level[0] == 'X') ||
Program.ThrowInvalidFlag<bool>("cl.exe", level, lineNumber, "/W");
break;
}
case "w":
// Special case, it is the same as /W0
Program.multipleClCompile.WarningLevel = "TurnOffAllWarnings";
break;
case "X":
Program.multipleClCompile.IgnoreStandardIncludePath = true;
break;
case { Length: > 1 } when cppFlag.StartsWith("Y", StringComparison.InvariantCulture):
switch (cppFlag[1])
{
case 'c':
Program.multipleClCompile.PrecompiledHeader = "Create";
break;
case 'u':
Program.multipleClCompile.PrecompiledHeader = "Use";
break;
case 'd':
break; // Ignored because it is deprecated
case 'X':
break; // Ignored because it no longer exists in VS 2015 and later
default:
throw Program.ThrowInvalidFlag("cl.exe", cppFlag[2..], lineNumber, "/Y");
}
// Unsure if this will ever have a space after it or not (not handling that case because of it)
if (cppFlag.Length > 2)
{
var filename = cppFlag[2..].Trim('"');
// Ignoring if the filename was stdafx.h, as this is the default
if (filename is not "stdafx.h")
Program.multipleClCompile.PrecompiledHeaderFile = $"{filename}";
}
break;
case { Length: > 1 } when cppFlag.StartsWith("Z", StringComparison.InvariantCulture):
switch (cppFlag[1])
{
case '7':
Program.multipleClCompile.DebugInformationFormat = "OldStyle";
break;
case 'a':
Program.multipleClCompile.DisableLanguageExtensions = true;
break;
case 'I':
// Ignoring if UseDebugLibraries is true, as this is the default
if (Program.currentConfig!.Properties.UseDebugLibraries != true)
Program.multipleClCompile.DebugInformationFormat = "EditAndContinue";
break;
case 'i':
// Ignoring if UseDebugLibraries is false (or not set at all), as this is the default
if (Program.currentConfig!.Properties.UseDebugLibraries == true)
Program.multipleClCompile.DebugInformationFormat = "ProgramDatabase";
break;
case 'l':
Program.multipleClCompile.OmitDefaultLibName = true;
break;
case 'p':
switch (cppFlag)
{
case { Length: 2 }:
break; // Ignored because it is the default
case { Length: > 2 } when int.TryParse(cppFlag[2..], out int bytes) && bytes is 1 or 2 or 4 or 8 or 16:
Program.multipleClCompile.StructMemberAlignment = $"{bytes}byte{(bytes == 1 ? "" : "s")}";
break;
default:
throw Program.ThrowInvalidFlag("cl.exe", cppFlag[2..], lineNumber, "/Zp");
}
break;
case 'm' when cppFlag.Length > 2 && int.TryParse(cppFlag[2..], out _):
case 's': // This probably won't ever be set in the IDE
// Unsure if /Zm will ever have a space after it or not (not handling that case because of it)
Program.multipleClCompile.AdditionalOptionsAdd($"{cppFlag}");
break;
case 'e':
break; // Ignored because it is deprecated
case 'd' or 'g' or 'n':
break; // Ignored because they no longer exist in VS 2015 and later
default:
throw Program.ThrowInvalidFlag("cl.exe", cppFlag[1..], lineNumber, "/Z");
}
break;
case "E" or "J" or "LD" or "LDd" or "link" or "vd0" or "vd1" or "vmb" or "vmg" or "vmm" or "vms" or "vmv":
Program.multipleClCompile.AdditionalOptionsAdd($"{cppFlag}");
if (cppFlag is "link")
Program.multipleClCompile.AdditionalOptionsAdd(cppFlags[++i]);
break;
case "c":
break; // Ignoring as there is really no reason this would ever be in an IDE project file
case var _ when cppFlag.StartsWith("H", StringComparison.InvariantCulture):
case var _ when cppFlag.StartsWith("V", StringComparison.InvariantCulture):
// Ignoring because they are deprecated
if (cppFlag is "H" or "V")
++i; // Skips the next flag, as it is the argument for /H or /V
break;
case "noBool" or "QI0f" or "QI0f-" or "QIfdiv" or "QIfdiv-" or "Qlf":
break; // Ignoring because they no longer exist in VS 2015 and later
default:
throw Program.ThrowInvalidFlag("cl.exe", cppFlag, lineNumber);
}
}
else
throw Program.ThrowInvalidArgument("cl.exe", cppFlag, lineNumber);
}
// This is being done like this because SuppressStartupBanner defaults to true
if (Program.currentFile is null && !hadNoLogo)
Program.multipleClCompile.SuppressStartupBanner = false;
}
/// <summary>
/// Process a line for the linker.
/// </summary>
/// <param name="line">The contents of the line.</param>
/// <param name="lineNumber">The line number of the line.</param>
static void ProcessLink(string line, int lineNumber)
{
bool hadNoLogo = false;
foreach (string flag in line[(line.Contains("BASE") ? 18 : 13)..].Split(' ', StringSplitOptions.RemoveEmptyEntries))
if (!string.IsNullOrEmpty(flag))
{
var linkFlag = flag.AsSpan();
if (linkFlag[0] is '/' or '-')
{
linkFlag = linkFlag[1..];
switch (linkFlag)
{
case { Length: > 6 } when linkFlag.StartsWith("align:", StringComparison.InvariantCultureIgnoreCase):
Program.currentConfig!.Properties.Link.SectionAlignment = $"{linkFlag[6..].Trim('"')}";
break;
case { Length: > 5 } when linkFlag.StartsWith("base:", StringComparison.InvariantCultureIgnoreCase):
Program.currentConfig!.Properties.Link.BaseAddress = $"{linkFlag[5..].Trim('"')}";
break;
case var _ when linkFlag.Equals("debug", StringComparison.InvariantCultureIgnoreCase):
Program.currentConfig!.Properties.Link.GenerateDebugInformation = true;
break;
case { Length: > 4 } when linkFlag.StartsWith("def:", StringComparison.InvariantCultureIgnoreCase):
Program.currentConfig!.Properties.Link.ModuleDefinitionFile = $"{linkFlag[4..].Trim('"')}";
break;
case { Length: > 6 } when linkFlag.StartsWith("delay:", StringComparison.InvariantCultureIgnoreCase):
{
var delayFlag = linkFlag[6..];
switch (delayFlag)
{
case var _ when delayFlag.Equals("nobind", StringComparison.InvariantCultureIgnoreCase):
Program.currentConfig!.Properties.Link.SupportNobindOfDelayLoadedDLL = true;
break;
case var _ when delayFlag.Equals("unload", StringComparison.InvariantCultureIgnoreCase):
Program.currentConfig!.Properties.Link.SupportUnloadOfDelayLoadedDLL = true;
break;
default:
throw Program.ThrowInvalidFlag("link.exe", delayFlag, lineNumber, "/delay:");
}
break;
}
case { Length: > 10 } when linkFlag.StartsWith("delayload:", StringComparison.InvariantCultureIgnoreCase):
_ = Program.currentConfig!.Properties.Link.DelayLoadDLLs.Add($"{linkFlag[10..].Trim('"')}");
break;
case var _ when linkFlag.StartsWith("driver", StringComparison.InvariantCultureIgnoreCase):
{
var driverFlag = linkFlag.Length > 6 ? linkFlag[6..] : new();
Program.currentConfig!.Properties.Link.Driver = driverFlag switch
{
{ Length: 0 } => "Driver",
var _ when driverFlag.Equals(":uponly", StringComparison.InvariantCultureIgnoreCase) => "UpOnly",
var _ when driverFlag.Equals(":wdm", StringComparison.InvariantCultureIgnoreCase) => "WDM",
_ => Program.ThrowInvalidFlag<string>("link.exe", driverFlag, lineNumber, "/driver")
};
break;
}
case { Length: > 6 } when linkFlag.StartsWith("entry:", StringComparison.InvariantCultureIgnoreCase):
Program.currentConfig!.Properties.Link.EntryPointSymbol = $"{linkFlag[6..].Trim('"')}";
break;
case var _ when linkFlag.StartsWith("fixed", StringComparison.InvariantCultureIgnoreCase):
{
var fixedFlag = linkFlag.Length > 5 ? linkFlag[5..] : new();
Program.currentConfig!.Properties.Link.FixedBaseAddress = fixedFlag switch
{
{ Length: 0 } => true,
var _ when fixedFlag.Equals(":no", StringComparison.InvariantCultureIgnoreCase) => false,
_ => Program.ThrowInvalidFlag<bool>("link.exe", fixedFlag, lineNumber, "/fixed")
};
break;
}
case var _ when linkFlag.StartsWith("force", StringComparison.InvariantCultureIgnoreCase):
{
var forceFlag = linkFlag.Length > 5 ? linkFlag[5..] : new();
Program.currentConfig!.Properties.Link.ForceFileOutput = forceFlag switch
{
{ Length: 0 } => "Enabled",
var _ when forceFlag.Equals(":multiple", StringComparison.InvariantCultureIgnoreCase) =>
"MultiplyDefinedSymbolOnly",
var _ when forceFlag.Equals(":unresolved", StringComparison.InvariantCultureIgnoreCase) =>
"UndefinedSymbolOnly",
_ => Program.ThrowInvalidFlag<string>("link.exe", forceFlag, lineNumber, "/force")
};
break;
}
case { Length: > 5 } when linkFlag.StartsWith("heap:", StringComparison.InvariantCultureIgnoreCase):
{
// Maybe TODO: Check if the arguments are integers or not
var heapFlag = linkFlag[5..];
int comma = heapFlag.IndexOf(',');
Program.currentConfig!.Properties.Link.HeapReserveSize =
$"{(comma == -1 ? heapFlag : heapFlag[..comma]).Trim('"')}";
if (comma != -1)
Program.currentConfig!.Properties.Link.HeapCommitSize = $"{heapFlag[(comma + 1)..].Trim('"')}";
break;
}
case { Length: > 7 } when linkFlag.StartsWith("implib:", StringComparison.InvariantCultureIgnoreCase):
{
var library = linkFlag[7..].Trim('"');
// Ignoring if the library was $(OutDir)$(TargetName).lib, as this is the default
if (library is not "$(OutDir)$(TargetName).lib")
Program.currentConfig!.Properties.Link.ImportLibrary = $"{library}";
break;
}
case { Length: > 8 } when linkFlag.StartsWith("include:", StringComparison.InvariantCultureIgnoreCase):
_ = Program.currentConfig!.Properties.Link.ForceSymbolReferences.Add($"{linkFlag[8..].Trim('"')}");
break;
case { Length: > 12 } when linkFlag.StartsWith("incremental:", StringComparison.InvariantCultureIgnoreCase):
{
var incrementalFlag = linkFlag[12..];
switch (incrementalFlag)
{
case var _ when incrementalFlag.Equals("yes", StringComparison.InvariantCultureIgnoreCase):
// Ignoring if UseDebugLibraries is set to true, as this is the default
if (Program.currentConfig!.Properties.UseDebugLibraries != true)
Program.currentConfig!.Properties.Link.LinkIncremental = true;
break;
case var _ when incrementalFlag.Equals("no", StringComparison.InvariantCultureIgnoreCase):
Program.currentConfig!.Properties.Link.LinkIncremental = false;
break;
default:
throw Program.ThrowInvalidFlag("link.exe", incrementalFlag, lineNumber, "/incremental:");
}
break;
}
case var _ when linkFlag.Equals("largeaddressaware", StringComparison.InvariantCultureIgnoreCase):
{
var laaFlag = linkFlag.Length > 17 ? linkFlag[17..] : new();
Program.currentConfig!.Properties.Link.LargeAddressAware = laaFlag switch
{
{ Length: 0 } => true,
var _ when laaFlag.Equals(":no", StringComparison.InvariantCultureIgnoreCase) => false,
_ => Program.ThrowInvalidFlag<bool>("link.exe", laaFlag, lineNumber, "/largeaddressaware")
};
break;
}
case { Length: > 8 } when linkFlag.StartsWith("libpath:", StringComparison.InvariantCultureIgnoreCase):
_ = Program.currentConfig!.Properties.Link.AdditionalLibraryDirectories.Add($"{linkFlag[8..].Trim('"')}");
break;
case { Length: > 8 } when linkFlag.StartsWith("machine:", StringComparison.InvariantCultureIgnoreCase):
{
var machineFlag = linkFlag[8..];
switch (machineFlag)
{
case var _ when machineFlag.Equals("arm", StringComparison.InvariantCultureIgnoreCase):
Program.currentConfig!.Properties.Link.TargetMachine = "MachineARM";
break;
case var _ when machineFlag.Equals("ix86", StringComparison.InvariantCultureIgnoreCase):
case var _ when machineFlag.Equals("i386", StringComparison.InvariantCultureIgnoreCase):
case var _ when machineFlag.Equals("x86", StringComparison.InvariantCultureIgnoreCase):
// This might be wrong to use for ix86
// i386 is here even though it isn't in the docs because the VS 6.0 IDE seems to set that
// x86 is here because I've encountered an edited (probably) project containing it
// Igorning if Platform is Win32, as this is the default
if (Program.currentConfig!.Platform != "Win32")
Program.currentConfig!.Properties.Link.TargetMachine = "MachineX86";
break;
case var _ when machineFlag.Equals("mips", StringComparison.InvariantCultureIgnoreCase):
Program.currentConfig!.Properties.Link.TargetMachine = "MachineMIPS";
break;
case var _ when machineFlag.Equals("mips16", StringComparison.InvariantCultureIgnoreCase):
Program.currentConfig!.Properties.Link.TargetMachine = "MachineMIPS16";
break;
case var _ when machineFlag.Equals("sh4", StringComparison.InvariantCultureIgnoreCase):
Program.currentConfig!.Properties.Link.TargetMachine = "MachineSH4";
break;
case var _ when machineFlag.Equals("alpha", StringComparison.InvariantCultureIgnoreCase):
case var _ when machineFlag.Equals("mipsr41xx", StringComparison.InvariantCultureIgnoreCase):
case var _ when machineFlag.Equals("ppc", StringComparison.InvariantCultureIgnoreCase):
case var _ when machineFlag.Equals("sh3", StringComparison.InvariantCultureIgnoreCase):
break; // Ignoring these flags as they no longer exists in VS 2015 and later
default:
throw Program.ThrowInvalidFlag("link.exe", machineFlag, lineNumber, "/machine:");
}
break;
}
case var _ when linkFlag.StartsWith("map", StringComparison.InvariantCultureIgnoreCase):
if (linkFlag.Length > 8 && linkFlag.StartsWith("mapinfo:", StringComparison.InvariantCultureIgnoreCase))
{
var mapinfoFlag = linkFlag[8..];
switch (mapinfoFlag)
{
case var _ when mapinfoFlag.Equals("exports", StringComparison.InvariantCultureIgnoreCase):
Program.currentConfig!.Properties.Link.MapExports = true;
break;
case var _ when mapinfoFlag.Equals("fixups", StringComparison.InvariantCultureIgnoreCase):
case var _ when mapinfoFlag.Equals("lines", StringComparison.InvariantCultureIgnoreCase):
break; // Ignoring these flags as they no longer exists in VS 2015 and later
default:
throw Program.ThrowInvalidFlag("link.exe", mapinfoFlag, lineNumber, "/mapinfo:");
}
}
else
{
Program.currentConfig!.Properties.Link.GenerateMapFile = true;
if (linkFlag.Length > 3)
Program.currentConfig!.Properties.Link.MapFileName = linkFlag[3] == ':' ? $"{linkFlag[4..].Trim('"')}" :
Program.ThrowInvalidFlag<string>("link.exe", linkFlag[3..], lineNumber, "/map");
}
break;
case { Length: > 6 } when linkFlag.StartsWith("merge:", StringComparison.InvariantCultureIgnoreCase):
Program.currentConfig!.Properties.Link.MergeSections = $"{linkFlag[6..].Trim('"')}";
break;
case var _ when linkFlag.StartsWith("nodefaultlib", StringComparison.InvariantCultureIgnoreCase):
switch (linkFlag)
{
case { Length: 12 }:
Program.currentConfig!.Properties.Link.IgnoreAllDefaultLibraries = true;
break;
case { Length: > 13 } when linkFlag[12] == ':':
_ = Program.currentConfig!.Properties.Link.IgnoreSpecificDefaultLibraries.
Add($"{linkFlag[13..].Trim('"')}");
break;
default:
throw Program.ThrowInvalidFlag("link.exe", linkFlag[12..], lineNumber, "/nodefaultlib");
}
break;
case var _ when linkFlag.Equals("noentry", StringComparison.InvariantCultureIgnoreCase):
Program.currentConfig!.Properties.Link.NoEntryPoint = true;
break;
case var _ when linkFlag.Equals("nologo", StringComparison.InvariantCultureIgnoreCase):
hadNoLogo = true;
break;
case { Length: > 4 } when linkFlag.StartsWith("opt:", StringComparison.InvariantCultureIgnoreCase):
{
var optFlag = linkFlag[4..];
switch (optFlag)
{
case var _ when optFlag.StartsWith("icf", StringComparison.InvariantCultureIgnoreCase):
switch (optFlag)
{
case { Length: 3 }:
Program.currentConfig!.Properties.Link.EnableCOMDATFolding = true;
break;
case { Length: > 3 } when optFlag[3] == ',':
_ = Program.currentConfig!.Properties.Link.AdditionalOptions.Add(flag.Replace(',', '='));
break;
default:
throw Program.ThrowInvalidFlag("link.exe", optFlag, lineNumber, "/opt:");
}
break;
case var _ when optFlag.Equals("noicf", StringComparison.InvariantCultureIgnoreCase):
Program.currentConfig!.Properties.Link.EnableCOMDATFolding = false;
break;
case var _ when optFlag.Equals("noref", StringComparison.InvariantCultureIgnoreCase):
Program.currentConfig!.Properties.Link.OptimizeReferences = false;