-
Notifications
You must be signed in to change notification settings - Fork 0
/
efxc2Cmds.cpp
635 lines (580 loc) · 23.2 KB
/
efxc2Cmds.cpp
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
//--------------------------------------------------------------------------------------
// File: efxc2Cmds.cpp
//
// Copyright (c) J. Peter Mugaas
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
//--------------------------------------------------------------------------------------
#include "efxc2Cmds.h"
#include "efxc2Utils.h"
#include "efxc2Files.h"
#include "efxc2Exception.h"
void efxc2Cmds::FindNOLOGO(const efxc2Utils::M_CMD_PARAMS& args, efxc2CompilerParams::CompilerParams& params) {
/*first scan specifically for the nologo argument so no output
is given regardless of parameter order*/
size_t index = 0;
while (index < args.size()) {
/* Detect the end of the options. */
if (efxc2Utils::parseOpt(efxc2Cmds::M_NOLOGO, args, &index, nullptr)) {
params.set_verbose(false);
break;
}
else {
index++;
}
}
return;
}
void efxc2Cmds::FindDebug(const efxc2Utils::M_CMD_PARAMS& args, efxc2CompilerParams::CompilerParams& params) {
/* scan for debug parameter*/
size_t index = 0;
while (index < args.size()) {
/* Detect the end of the options. */
if (efxc2Utils::parseOpt(efxc2Cmds::M_DEBUG, args, &index, nullptr)) {
params.set_debug(true);
break;
}
else {
index++;
}
}
return;
}
void efxc2Cmds::print_string_parameter(_In_ const efxc2CompilerParams::CompilerParams& ComParams,
_In_ const efxc2Utils::M_STRING_VIEW cmdParam,
_In_ const efxc2Utils::M_STRING_VIEW ADesc,
_In_ const efxc2Utils::M_STRING_VIEW fileName) {
if (ComParams.get_verbose() && ComParams.get_debug()) {
#ifdef _WIN32
std::wcout << M_FORMAT(L"option -{} ({}) with arg {}\n", cmdParam, ADesc, fileName);
#else
std::cout << M_FORMAT("option -{} ({}) with arg {}\n", cmdParam, ADesc, fileName);
#endif
}
}
void efxc2Cmds::print_flag_parameter(_In_ const efxc2CompilerParams::CompilerParams& ComParams,
_In_ const std::string_view cmdParam,
_In_ const std::string_view AFlagsVar,
_In_ const std::string_view AflagName) {
if (ComParams.get_verbose() && ComParams.get_debug()) {
std::cout << M_FORMAT("option -{} {} | {}\n", cmdParam, AFlagsVar, AflagName);
}
}
void efxc2Cmds::option_ignored(_In_ const efxc2Utils::M_STRING_VIEW Opt, _In_ const efxc2CompilerParams::CompilerParams& params) {
if (params.get_verbose() && params.get_debug()) {
#ifdef _WIN32
std::wcout << M_FORMAT(L"Option {} ignored", Opt);
#else
std::cout << M_FORMAT("Option {} ignored", Opt);
#endif
}
return;
}
void efxc2Cmds::parseInputFile(_In_ const efxc2Utils::M_STRING_VIEW parameter, efxc2CompilerParams::CompilerParams& params, efxc2Files::Files& files) {
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable: 6001)
#pragma warning(disable: 6011)
#endif
if (files.get_inputFile().empty()) {
#ifdef _MSC_VER
#pragma warning(pop)
#endif
if (params.get_verbose() && params.get_debug()) {
std::cout << "Parse input file name\n";
}
efxc2Utils::M_STRING inputFile = parameter.data();
#ifdef _WIN32
std::string c_inputFile = "";
#endif
#ifdef _WIN32
efxc2Utils::FixupFileName(inputFile);
c_inputFile = efxc2Utils::wstring_to_utf8(inputFile);
params.set_inputFile(c_inputFile);
#endif /* _WIN32 */
files.set_inputFile(inputFile);
if (params.get_verbose() && params.get_debug()) {
#ifdef _WIN32
std::wcout << M_FORMAT(L"input file: {}\n", inputFile);
#else
std::cout << M_FORMAT("input file: {}\n", inputFile);
#endif
}
files.LoadInputFile(params);
}
else {
efxc2Utils::print_usage_toomany();
throw efxc2Exception::TooManyParameters();
}
}
void efxc2Cmds::cmd_all_resources_bound(efxc2CompilerParams::CompilerParams& params) {
UINT sflags = params.get_sflags();
sflags = sflags | D3DCOMPILE_ALL_RESOURCES_BOUND;
params.set_sflags(sflags);
print_flag_parameter(params, "all_resources_bound", M_SFLAGS_VAR, "D3DCOMPILE_ALL_RESOURCES_BOUND");
return;
}
void efxc2Cmds::cmd_Cc(efxc2CompilerParams::CompilerParams& params) {
UINT disassembly_flags = params.get_disassembly_flags();
disassembly_flags = disassembly_flags | D3D_DISASM_ENABLE_COLOR_CODE;
params.set_disassembly_flags(disassembly_flags);
print_flag_parameter(params, "Cc", M_DISASM_FLAGS_VAR, "D3D_DISASM_ENABLE_COLOR_CODE");
return;
}
void efxc2Cmds::cmd_D(efxc2CompilerParams::CompilerParams& params, _In_ const efxc2Utils::M_STRING_VIEW _defineOption) {
#ifdef _WIN32
std::string defineOption = efxc2Utils::wstring_to_utf8({ _defineOption.data(), _defineOption.size() });
#else
std::string defineOption = { _defineOption.data(), _defineOption.size() };
#endif
params.add_define(defineOption);
print_string_parameter(params, M_D, M_FH_DESCR, _defineOption);
}
void efxc2Cmds::cmd_E(efxc2CompilerParams::CompilerParams& params, _In_ const efxc2Utils::M_STRING_VIEW _entryPoint) {
#ifdef _WIN32
std::string entryPoint = efxc2Utils::wstring_to_utf8({ _entryPoint.data(), _entryPoint.size() });
#else
std::string entryPoint = { _entryPoint.data(), _entryPoint.size() };
#endif
params.set_entryPoint(entryPoint);
print_string_parameter(params, M_E_, M_E_DESCR, _entryPoint);
return;
}
void efxc2Cmds::cmd_enable_unbounded_descriptor_tables(efxc2CompilerParams::CompilerParams& params) {
UINT sflags = params.get_sflags();
sflags = sflags | D3DCOMPILE_ENABLE_UNBOUNDED_DESCRIPTOR_TABLES;
params.set_sflags(sflags);
print_flag_parameter(params, "enable_unbounded_descriptor_tables", M_SFLAGS_VAR, "D3DCOMPILE_ENABLE_UNBOUNDED_DESCRIPTOR_TABLE");
return;
}
void efxc2Cmds::cmd_Fc(efxc2CompilerParams::CompilerParams& params, efxc2Files::Files& files, _In_ const efxc2Utils::M_STRING_VIEW assemblyCodeFile) {
files.set_DisassemblyFile(assemblyCodeFile);
UINT cmd = params.get_commands();
cmd = cmd | efxc2Utils::CMD_WRITE_ASSEMBLY_CODE;
params.set_commands(cmd);
print_string_parameter(params, M_FC, M_FC_DESCR, assemblyCodeFile);
return;
}
void efxc2Cmds::cmd_Fd(efxc2CompilerParams::CompilerParams& params, efxc2Files::Files& files, _In_ const efxc2Utils::M_STRING_VIEW pdbFile) {
files.set_pdbFile(pdbFile);
UINT cmd = params.get_commands();
cmd = cmd | efxc2Utils::CMD_WRITE_PDB_FILE;
params.set_commands(cmd);
print_string_parameter(params, M_FD, M_FD_DESCR, pdbFile);
return;
}
void efxc2Cmds::cmd_Fh(efxc2CompilerParams::CompilerParams& params, efxc2Files::Files& files, _In_ const efxc2Utils::M_STRING_VIEW outputFile) {
files.set_IncludeFile(outputFile);
UINT cmd = params.get_commands();
cmd = cmd | efxc2Utils::CMD_WRITE_HEADER;
params.set_commands(cmd);
print_string_parameter(params, M_FH, M_FH_DESCR, outputFile);
return;
}
void efxc2Cmds::cmd_Fo(efxc2CompilerParams::CompilerParams& params, efxc2Files::Files& files, _In_ const efxc2Utils::M_STRING_VIEW outputFile) {
files.set_ObjectFile(outputFile);
UINT cmd = params.get_commands();
cmd = cmd | efxc2Utils::CMD_WRITE_OBJECT;
params.set_commands(cmd);
print_string_parameter(params, M_FO, M_FO_DESCR, outputFile);
return;
}
void efxc2Cmds::cmd_Gch(efxc2CompilerParams::CompilerParams& params) {
UINT eflags = params.get_eflags();
eflags = eflags | D3DCOMPILE_EFFECT_CHILD_EFFECT;
params.set_eflags(eflags);
print_flag_parameter(params, "Gch", M_EFLAGS_VAR, "D3DCOMPILE_EFFECT_CHILD_EFFECT");
return;
}
void efxc2Cmds::cmd_Gdp(efxc2CompilerParams::CompilerParams& params) {
UINT eflags = params.get_eflags();
eflags = eflags | D3DCOMPILE_EFFECT_ALLOW_SLOW_OPS;
params.set_eflags(eflags);
print_flag_parameter(params, "Gdp", M_EFLAGS_VAR, "D3DCOMPILE_EFFECT_ALLOW_SLOW_OPS");
return;
}
void efxc2Cmds::cmd_Gec(efxc2CompilerParams::CompilerParams& params) {
UINT sflags = params.get_sflags();
sflags = sflags | D3DCOMPILE_ENABLE_BACKWARDS_COMPATIBILITY;
params.set_sflags(sflags);
print_flag_parameter(params, "Gec", M_SFLAGS_VAR, "D3DCOMPILE_ENABLE_BACKWARDS_COMPATIBILITY");
return;
}
void efxc2Cmds::cmd_Ges(efxc2CompilerParams::CompilerParams& params) {
UINT sflags = params.get_sflags();
sflags = sflags | D3DCOMPILE_ENABLE_STRICTNESS;
params.set_sflags(sflags);
print_flag_parameter(params, "Ges", M_SFLAGS_VAR, "D3DCOMPILE_ENABLE_STRICTNESS");
return;
}
void efxc2Cmds::cmd_Gfa(efxc2CompilerParams::CompilerParams& params) {
UINT sflags = params.get_sflags();
sflags = sflags | D3DCOMPILE_AVOID_FLOW_CONTROL;
params.set_sflags(sflags);
print_flag_parameter(params, "Gfa", M_SFLAGS_VAR, "D3DCOMPILE_AVOID_FLOW_CONTROL");
return;
}
void efxc2Cmds::cmd_Gis(efxc2CompilerParams::CompilerParams& params) {
UINT sflags = params.get_sflags();
sflags = sflags | D3DCOMPILE_IEEE_STRICTNESS;
params.set_sflags(sflags);
print_flag_parameter(params, "Gis", M_SFLAGS_VAR, "D3DCOMPILE_IEEE_STRICTNESS");
return;
}
void efxc2Cmds::cmd_Gpp(efxc2CompilerParams::CompilerParams& params) {
UINT sflags = params.get_sflags();
sflags = sflags | D3DCOMPILE_PARTIAL_PRECISION;
params.set_sflags(sflags);
print_flag_parameter(params, "Gpp", M_SFLAGS_VAR, "D3DCOMPILE_PARTIAL_PRECISION");
return;
}
void efxc2Cmds::cmd_I(efxc2CompilerParams::CompilerParams& params, _In_ const efxc2Utils::M_STRING_VIEW _includeDir) {
params.get_includeDirs()->AddIncludeDir(_includeDir);
print_string_parameter(params, M_I, M_FH_DESCR, _includeDir);
return;
}
void efxc2Cmds::cmd_Lx(efxc2CompilerParams::CompilerParams& params) {
if (params.get_verbose() && params.get_debug()) {
std::cout << "option -Lx - output hexadecimal literals\n";
}
params.set_outputHex(TRUE);
return;
}
void efxc2Cmds::cmd_Ni(efxc2CompilerParams::CompilerParams& params) {
UINT disassembly_flags = params.get_disassembly_flags();
disassembly_flags = disassembly_flags | D3D_DISASM_ENABLE_INSTRUCTION_NUMBERING;
params.set_disassembly_flags(disassembly_flags);
print_flag_parameter(params, "Ni", M_DISASM_FLAGS_VAR, "D3D_DISASM_ENABLE_INSTRUCTION_NUMBERING");
return;
}
void efxc2Cmds::cmd_No(efxc2CompilerParams::CompilerParams& params) {
UINT disassembly_flags = params.get_disassembly_flags();
disassembly_flags = disassembly_flags | D3D_DISASM_ENABLE_INSTRUCTION_OFFSET;
params.set_disassembly_flags(disassembly_flags);
print_flag_parameter(params, "No", M_DISASM_FLAGS_VAR, "D3D_DISASM_ENABLE_INSTRUCTION_OFFSET");
return;
}
void efxc2Cmds::cmd_O0(efxc2CompilerParams::CompilerParams& params) {
UINT sflags = params.get_sflags();
sflags = sflags | D3DCOMPILE_OPTIMIZATION_LEVEL0;
params.set_sflags(sflags);
print_flag_parameter(params, "O0", M_SFLAGS_VAR, "D3DCOMPILE_OPTIMIZATION_LEVEL0");
return;
}
void efxc2Cmds::cmd_O1(efxc2CompilerParams::CompilerParams& params) {
UINT sflags = params.get_sflags();
sflags = sflags | D3DCOMPILE_OPTIMIZATION_LEVEL1;
params.set_sflags(sflags);
print_flag_parameter(params, "O1", M_SFLAGS_VAR, "D3DCOMPILE_OPTIMIZATION_LEVEL1");
return;
}
void efxc2Cmds::cmd_O2(efxc2CompilerParams::CompilerParams& params) {
UINT sflags = params.get_sflags();
sflags = sflags | D3DCOMPILE_OPTIMIZATION_LEVEL2;
params.set_sflags(sflags);
print_flag_parameter(params, "O2", M_SFLAGS_VAR, "D3DCOMPILE_OPTIMIZATION_LEVEL2");
return;
}
void efxc2Cmds::cmd_O3(efxc2CompilerParams::CompilerParams& params) {
UINT sflags = params.get_sflags();
sflags = sflags | D3DCOMPILE_OPTIMIZATION_LEVEL3;
params.set_sflags(sflags);
print_flag_parameter(params, "O3", M_SFLAGS_VAR, "D3DCOMPILE_OPTIMIZATION_LEVEL3");
return;
}
void efxc2Cmds::cmd_Od(efxc2CompilerParams::CompilerParams& params) {
UINT sflags = params.get_sflags();
sflags = sflags | D3DCOMPILE_SKIP_OPTIMIZATION;
params.set_sflags(sflags);
print_flag_parameter(params, "Od", M_SFLAGS_VAR, "D3DCOMPILE_SKIP_OPTIMIZATION");
return;
}
void efxc2Cmds::cmd_Op(efxc2CompilerParams::CompilerParams& params) {
UINT sflags = params.get_sflags();
sflags = sflags | D3DCOMPILE_NO_PRESHADER;
params.set_sflags(sflags);
print_flag_parameter(params, "Op", M_SFLAGS_VAR, "D3DCOMPILE_NO_PRESHADER");
return;
}
void efxc2Cmds::cmd_P(efxc2CompilerParams::CompilerParams& params, efxc2Files::Files& files, _In_ const efxc2Utils::M_STRING_VIEW outputFile) {
files.set_preprocessFile(outputFile);
UINT cmd = params.get_commands();
cmd = cmd | efxc2Utils::CMD_PREPROCESS_FILE;
params.set_commands(cmd);
print_string_parameter(params, M_P, M_P_DESCR, outputFile);
return;
}
void efxc2Cmds::cmd_Qstrip_debug(efxc2CompilerParams::CompilerParams& params) {
UINT strip_flags = params.get_strip_flags();
strip_flags = strip_flags | D3DCOMPILER_STRIP_DEBUG_INFO;
params.set_strip_flags(strip_flags);
print_flag_parameter(params, "Qstrip_debug", M_STRIP_FLAGS_VAR, "D3DCOMPILER_STRIP_DEBUG_INFO");
return;
}
void efxc2Cmds::cmd_Qstrip_priv(efxc2CompilerParams::CompilerParams& params) {
UINT strip_flags = params.get_strip_flags();
strip_flags = strip_flags | D3DCOMPILER_STRIP_PRIVATE_DATA;
params.set_strip_flags(strip_flags);
print_flag_parameter(params, "Qstrip_priv", M_STRIP_FLAGS_VAR, "D3DCOMPILER_STRIP_PRIVATE_DATA");
return;
}
void efxc2Cmds::cmd_Qstrip_reflect(efxc2CompilerParams::CompilerParams& params) {
UINT strip_flags = params.get_strip_flags();
strip_flags = strip_flags | D3DCOMPILER_STRIP_REFLECTION_DATA;
params.set_strip_flags(strip_flags);
print_flag_parameter(params, "Qstrip_reflect", M_STRIP_FLAGS_VAR, "D3DCOMPILER_STRIP_REFLECTION_DATA");
return;
}
void efxc2Cmds::cmd_Qstrip_rootsignature(efxc2CompilerParams::CompilerParams& params) {
UINT strip_flags = params.get_strip_flags();
strip_flags = strip_flags | D3DCOMPILER_STRIP_ROOT_SIGNATURE;
params.set_strip_flags(strip_flags);
print_flag_parameter(params, "Qstrip_rootsignature", M_STRIP_FLAGS_VAR, "D3DCOMPILER_STRIP_ROOT_SIGNATURE");
return;
}
void efxc2Cmds::cmd_res_may_alias(efxc2CompilerParams::CompilerParams& params) {
UINT sflags = params.get_sflags();
sflags = sflags | D3DCOMPILE_RESOURCES_MAY_ALIAS;
params.set_sflags(sflags);
print_flag_parameter(params, "res_may_alias", M_SFLAGS_VAR, "D3DCOMPILE_RESOURCES_MAY_ALIAS");
return;
}
void efxc2Cmds::cmd_setprivate(efxc2CompilerParams::CompilerParams& params, efxc2Files::Files& files, _In_ const efxc2Utils::M_STRING_VIEW inputfile) {
files.set_privateDataFile(inputfile);
files.LoadPrivateDataFile(params);
print_string_parameter(params, M_SETPRIVATE, M_SETPRIVATE_DESCR, inputfile);
return;
}
void efxc2Cmds::cmd_T(efxc2CompilerParams::CompilerParams& params, _In_ const efxc2Utils::M_STRING_VIEW _model) {
#ifdef _WIN32
std::string model = efxc2Utils::wstring_to_utf8({ _model.data(), _model.size() });
#else
std::string model = { _model.data(), _model.size() };
#endif
params.set_model(model);
print_string_parameter(params, M_T, M_T_DESCR, _model);
return;
}
void efxc2Cmds::cmd_Vd(efxc2CompilerParams::CompilerParams& params) {
UINT sflags = params.get_sflags();
sflags = sflags | D3DCOMPILE_SKIP_VALIDATION;
params.set_sflags(sflags);
print_flag_parameter(params, "Vd", M_SFLAGS_VAR, "D3DCOMPILE_SKIP_VALIDATION");
return;
}
void efxc2Cmds::cmd_Vn(efxc2CompilerParams::CompilerParams& params, _In_ const efxc2Utils::M_STRING_VIEW _variableName) {
#ifdef _WIN32
std::string variableName = efxc2Utils::wstring_to_utf8({ _variableName.data(), _variableName.size() });
#else
std::string variableName = { _variableName.data(), _variableName.size() };
#endif
params.set_variableName(variableName);
print_string_parameter(params, M_VN, M_P_DESCR, _variableName);
return;
}
void efxc2Cmds::cmd_WX(efxc2CompilerParams::CompilerParams& params) {
UINT sflags = params.get_sflags();
sflags = sflags | D3DCOMPILE_WARNINGS_ARE_ERRORS;
params.set_sflags(sflags);
print_flag_parameter(params, "WX", M_SFLAGS_VAR, "D3DCOMPILE_WARNINGS_ARE_ERRORS");
return;
}
void efxc2Cmds::cmd_Zi(efxc2CompilerParams::CompilerParams& params) {
UINT sflags = params.get_sflags();
sflags = sflags | D3DCOMPILE_DEBUG;
params.set_sflags(sflags);
print_flag_parameter(params, "Zi", M_SFLAGS_VAR, "D3DCOMPILE_DEBUG");
return;
}
void efxc2Cmds::cmd_Zpc(efxc2CompilerParams::CompilerParams& params) {
UINT sflags = params.get_sflags();
sflags = sflags | D3DCOMPILE_PACK_MATRIX_COLUMN_MAJOR;
params.set_sflags(sflags);
print_flag_parameter(params, "Zpc", M_SFLAGS_VAR, "D3DCOMPILE_PACK_MATRIX_COLUMN_MAJOR");
return;
}
void efxc2Cmds::cmd_Zpr(efxc2CompilerParams::CompilerParams& params) {
UINT sflags = params.get_sflags();
sflags = sflags | D3DCOMPILE_PACK_MATRIX_ROW_MAJOR;
params.set_sflags(sflags);
print_flag_parameter(params, "Zpr", M_SFLAGS_VAR, "D3DCOMPILE_PACK_MATRIX_ROW_MAJOR");
return;
}
void efxc2Cmds::cmd_Zsb(efxc2CompilerParams::CompilerParams& params) {
UINT sflags = params.get_sflags();
sflags = sflags | D3DCOMPILE_DEBUG_NAME_FOR_BINARY;
params.set_sflags(sflags);
print_flag_parameter(params, "Zsb", M_SFLAGS_VAR, "D3DCOMPILE_DEBUG_NAME_FOR_BINARY");
return;
}
void efxc2Cmds::cmd_Zss(efxc2CompilerParams::CompilerParams& params) {
UINT sflags = params.get_sflags();
sflags = sflags | D3DCOMPILE_DEBUG_NAME_FOR_SOURCE;
params.set_sflags(sflags);
print_flag_parameter(params, "Zss", M_SFLAGS_VAR, "D3DCOMPILE_DEBUG_NAME_FOR_SOURCE");
return;
}
bool efxc2Cmds::parseCompilerOnlyCall(
_In_ const efxc2Utils::M_CMD_PARAMS& args,
_Inout_ size_t* index,
efxc2CompilerParams::CompilerParams& params) {
bool terminate_routine = false;
bool result = false;
if (index == nullptr || *index >= args.size()) {
terminate_routine = true;
}
efxc2Utils::M_STRING argument;
size_t arg_idx = 0;
if (terminate_routine == false) {
/* Disable warning V1004 because we checked the pointer for nullptr.*/
argument = args[*index]; //-V1004
if (argument[0] == '-' || argument[0] == '/') {
arg_idx++;
if (argument[arg_idx] == '-') {
arg_idx++;
}
}
else {
terminate_routine = true;
}
}
if (terminate_routine == false) {
for (CompilerOnlyEntry currentEntry : g_CompilerOnlyCall) {
if (argument.compare(arg_idx, currentEntry.Param.size(), currentEntry.Param) == 0) {
currentEntry.method(params);
*index += 1;
result = true;
break;
}
}
}
return result;
}
bool efxc2Cmds::parseCompilerFileCall(
_In_ const efxc2Utils::M_CMD_PARAMS& args,
_Inout_ size_t* index,
efxc2CompilerParams::CompilerParams& params,
efxc2Files::Files& files) {
bool terminate_routine = false;
bool result = false;
efxc2Utils::M_STRING argumentOption = efxc2Utils::M_STRING_INIT;
efxc2Utils::M_STRING_VIEW argument;
size_t arg_idx = 0;
if (index == nullptr || *index >= args.size()) {
terminate_routine = true;
}
/* Disable warning V1004 because we checked the pointer for nullptr.*/
if (terminate_routine == false) {
argument = args[*index]; //-V1004
if (argument[0] == '-' || argument[0] == '/') {
arg_idx++;
if (argument[arg_idx] == '-') {
arg_idx++;
}
}
else {
terminate_routine = true;
}
}
if (terminate_routine == false) {
for (CompileFileEntry currentEntry : g_CompilerFileCall) {
if (argument.compare(arg_idx, currentEntry.Param.size(), currentEntry.Param) != 0) {
continue;
}
arg_idx += currentEntry.Param.size();
if (arg_idx >= argument.size()) {
*index += 1;
efxc2Utils::checkForMissingArg(currentEntry.Param, *index, args);
argumentOption = args[*index];
}
else {
argumentOption = argument.substr(arg_idx, argument.size());
}
currentEntry.method(params, files, argumentOption);
*index += 1;
result = true;
}
}
return result;
}
bool efxc2Cmds::parseIgnoredOptions(
_In_ const efxc2Utils::M_CMD_PARAMS& args,
_Inout_ const size_t* index,
const efxc2CompilerParams::CompilerParams& params) {
/*supress warning /V1004 because we check the pointer for nullptr before using *index.*/
bool terminate_routine = false;
bool result = false;
if ((index == nullptr) || (*index >= args.size())) {
terminate_routine = true;
}
if (terminate_routine == false) {
const efxc2Utils::M_STRING_VIEW argument = args[*index]; //-V1004
size_t arg_idx = 0;
if (argument[0] == '-' || argument[0] == '/') {
arg_idx++;
if (argument[arg_idx] == '-') {
arg_idx++;
}
}
else {
terminate_routine = true;
}
if (terminate_routine == false) {
if (efxc2Utils::M_STRING_VIEW toFind = argument.substr(arg_idx, std::string::npos);
#ifdef RANGES_SUPPORTED
std::ranges::find(g_IgnoredOptions, toFind) != g_IgnoredOptions.end()) {
#else
std::find(g_IgnoredOptions.begin(), g_IgnoredOptions.end(), toFind) != g_IgnoredOptions.end()) {
#endif
option_ignored(argument, params);
result = true;
}
}
}
return result;
}
bool efxc2Cmds::parseNotSupportedOptions(
_In_ const efxc2Utils::M_CMD_PARAMS& args,
_In_ const size_t* index) {
/*supress warning /V1004 because we check the pointer for nullptr before using *index.*/
bool terminate_routine = false;
bool result = false;
if (!index || *index >= args.size()) {
terminate_routine = true;
}
if (terminate_routine == false) {
const efxc2Utils::M_STRING_VIEW argument = args[*index]; //-V1004
size_t arg_idx = 0;
if (argument[0] == '-' || argument[0] == '/') {
arg_idx++;
if (argument[arg_idx] == '-') {
arg_idx++;
}
}
else {
terminate_routine = true;
}
if (terminate_routine == false) {
if (efxc2Utils::M_STRING_VIEW toFind = argument.substr(arg_idx, std::string::npos);
#ifdef RANGES_SUPPORTED
std::ranges::find(g_NotSupportedArgs, toFind) != g_NotSupportedArgs.end()) {
#else
std::find(g_NotSupportedArgs.begin(), g_NotSupportedArgs.end(), toFind) != g_NotSupportedArgs.end()) {
#endif
efxc2Console::Console console = efxc2Console::console;
console.std_err_pink();
#ifdef _WIN32
std::wcerr << M_FORMAT(L"option -{} not supported", argument);
#else
std::cerr << M_FORMAT("option -{} not supported", argument);
#endif
std::cout << efxc2Utils::print_unsupported_arg_help();
console.std_err_reset();
result = true;
}
}
}
return result;
}