Skip to content

Commit

Permalink
Rename M_E_ to M_E. Start refactoring stuff in efxc2Cmds to reduce so…
Browse files Browse the repository at this point in the history
…me code-duplication.
  • Loading branch information
JPeterMugaas committed Jul 1, 2024
1 parent da0a9df commit a3841b6
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 59 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

cmake_minimum_required (VERSION 3.21)

set(EFXC2_VERSION 0.0.13.268)
set(EFXC2_VERSION 0.0.13.269)
project (efxc2 VERSION ${EFXC2_VERSION}
DESCRIPTION "Enhanced fxc2"
HOMEPAGE_URL "https://github.com/JPeterMugaas/efxc2"
Expand Down
2 changes: 1 addition & 1 deletion efxc2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ int main(int argc, char* argv[]) {
efxc2Cmds::cmd_D(params, temp);
continue;
}
else if (efxc2Utils::parseOpt(efxc2Cmds::M_E_, args, &index, &temp)) {
else if (efxc2Utils::parseOpt(efxc2Cmds::M_E, args, &index, &temp)) {
efxc2Cmds::cmd_E(params, temp);
continue;
}
Expand Down
77 changes: 22 additions & 55 deletions efxc2Cmds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,19 @@ void efxc2Cmds::FindDebug(const efxc2Utils::M_CMD_PARAMS& args, efxc2CompilerPar
return;
}

void efxc2Cmds::print_string_parameter(efxc2CompilerParams::CompilerParams& ComParams,
const efxc2Utils::M_STRING_VIEW cmdParam,
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::option_ignored(_In_ const efxc2Utils::M_STRING_VIEW Opt, _In_ const efxc2CompilerParams::CompilerParams& params) {
if (params.get_verbose() && params.get_debug()) {
#ifdef _WIN32
Expand Down Expand Up @@ -134,9 +147,7 @@ void efxc2Cmds::cmd_E(efxc2CompilerParams::CompilerParams& params, _In_ const ef
std::string entryPoint = { _entryPoint.data(), _entryPoint.size() };
#endif
params.set_entryPoint(entryPoint);
if (params.get_verbose() && params.get_debug()) {
std::cout << M_FORMAT("option -E (Entry Point) with arg {}'\n", entryPoint);
}
print_string_parameter(params, M_E, M_E_DESCR, _entryPoint);
return;
}

Expand All @@ -155,13 +166,7 @@ void efxc2Cmds::cmd_Fc(efxc2CompilerParams::CompilerParams& params, efxc2Files::
UINT cmd = params.get_commands();
cmd = cmd | efxc2Utils::CMD_WRITE_ASSEMBLY_CODE;
params.set_commands(cmd);
if (params.get_verbose() && params.get_debug()) {
#ifdef _WIN32
std::wcout << M_FORMAT(L"option -Fc (assembly code) with arg {}\n", assemblyCodeFile);
#else
std::cout << M_FORMAT("option -Fc (assembly code) with arg {}\n", assemblyCodeFile);
#endif
}
print_string_parameter(params, M_FC, M_FC_DESCR, assemblyCodeFile);
return;
}

Expand All @@ -172,13 +177,7 @@ void efxc2Cmds::cmd_Fd(efxc2CompilerParams::CompilerParams& params, efxc2Files::
cmd = cmd | efxc2Utils::CMD_WRITE_PDB_FILE;
params.set_commands(cmd);

if (params.get_verbose() && params.get_debug()) {
#ifdef _WIN32
std::wcout << M_FORMAT(L"option -Fd (.PDB) with arg {}\n", pdbFile);
#else
std::cout << M_FORMAT("option -Fd (.PDB) with arg {}\n", pdbFile);
#endif
}
print_string_parameter(params, M_FD, M_FD_DESCR, pdbFile);
return;
}

Expand All @@ -187,13 +186,7 @@ void efxc2Cmds::cmd_Fh(efxc2CompilerParams::CompilerParams& params, efxc2Files::
UINT cmd = params.get_commands();
cmd = cmd | efxc2Utils::CMD_WRITE_HEADER;
params.set_commands(cmd);
if (params.get_verbose() && params.get_debug()) {
#ifdef _WIN32
std::wcout << M_FORMAT(L"option -Fh (Output File) with arg {}\n", outputFile);
#else
std::cout << M_FORMAT("option -Fh (Output File) with arg {}\n", outputFile);
#endif
}
print_string_parameter(params, M_FH, M_FH_DESCR, outputFile);
return;
}

Expand All @@ -202,13 +195,7 @@ void efxc2Cmds::cmd_Fo(efxc2CompilerParams::CompilerParams& params, efxc2Files::
UINT cmd = params.get_commands();
cmd = cmd | efxc2Utils::CMD_WRITE_OBJECT;
params.set_commands(cmd);
if (params.get_verbose() && params.get_debug()) {
#ifdef _WIN32
std::wcout << M_FORMAT(L"option -FO (Output File) with arg {}\n", outputFile);
#else
std::cout << M_FORMAT("option -FO (Output File) with arg {}\n", outputFile);
#endif
}
print_string_parameter(params, M_FO, M_FO_DESCR, outputFile);
return;
}

Expand Down Expand Up @@ -283,14 +270,8 @@ void efxc2Cmds::cmd_Gpp(efxc2CompilerParams::CompilerParams& params) {
}

void efxc2Cmds::cmd_I(efxc2CompilerParams::CompilerParams& params, _In_ const efxc2Utils::M_STRING_VIEW _includeDir) {
if (params.get_verbose() && params.get_debug()) {
#ifdef _WIN32
std::wcout << M_FORMAT(L"option -I (Shader Include Dir) with arg {}\n", _includeDir);
#else
std::cout << M_FORMAT("option -I (Shader Include Dir) with arg {}\n", _includeDir);
#endif
}
params.get_includeDirs()->AddIncludeDir(_includeDir);
print_string_parameter(params, M_I, M_FH_DESCR, _includeDir);
return;
}

Expand Down Expand Up @@ -387,13 +368,7 @@ void efxc2Cmds::cmd_P(efxc2CompilerParams::CompilerParams& params, efxc2Files::F
UINT cmd = params.get_commands();
cmd = cmd | efxc2Utils::CMD_PREPROCESS_FILE;
params.set_commands(cmd);
if (params.get_verbose() && params.get_debug()) {
#ifdef _WIN32
std::wcout << M_FORMAT(L"option -P (Output File) with arg {}\n", outputFile);
#else
std::cout << M_FORMAT("option -P (Output File) with arg {}\n", outputFile);
#endif
}
print_string_parameter(params, M_P, M_P_DESCR, outputFile);
return;
}

Expand Down Expand Up @@ -449,14 +424,8 @@ void efxc2Cmds::cmd_res_may_alias(efxc2CompilerParams::CompilerParams& params) {

void efxc2Cmds::cmd_setprivate(efxc2CompilerParams::CompilerParams& params, efxc2Files::Files& files, _In_ const efxc2Utils::M_STRING_VIEW inputfile) {
files.set_privateDataFile(inputfile);
if (params.get_verbose() && params.get_debug()) {
#ifdef _WIN32
std::wcout << M_FORMAT(L"option -setprivate (Input File) with arg {}\n", inputfile);
#else
std::cout << M_FORMAT("option -setprivate (Input File) with arg {}\n", inputfile);
#endif
}
files.LoadPrivateDataFile(params);
print_string_parameter(params, M_SETPRIVATE, M_SETPRIVATE_DESCR, inputfile);
return;
}

Expand All @@ -466,10 +435,8 @@ void efxc2Cmds::cmd_T(efxc2CompilerParams::CompilerParams& params, _In_ const ef
#else
std::string model = { _model.data(), _model.size() };
#endif
if (params.get_verbose() && params.get_debug()) {
std::cout << M_FORMAT("option -T (Shader Model/Profile) with arg {}\n", model);
}
params.set_model(model);
print_string_parameter(params, M_T, M_T_DESCR, _model);
return;
}

Expand Down
32 changes: 30 additions & 2 deletions efxc2Cmds.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ namespace efxc2Cmds {
constexpr const wchar_t* M_DEBUG = L"debug";
constexpr const wchar_t* M_DECOMPRESS = L"decompress";
constexpr const wchar_t* M_DUMPBIN = L"dumpbin";
constexpr const wchar_t* M_E_ = L"E";
constexpr const wchar_t* M_E = L"E";
constexpr const wchar_t* M_ENABLE_UNBOUNDED_DESCRIPTOR_TABLES = L"enable_unbounded_descriptor_tables";
constexpr const wchar_t* M_FC = L"Fc";
constexpr const wchar_t* M_FD = L"Fd";
Expand Down Expand Up @@ -138,7 +138,7 @@ namespace efxc2Cmds {
constexpr const char* M_DEBUG = "debug";
constexpr const char* M_DECOMPRESS = "decompress";
constexpr const char* M_DUMPBIN = "dumpbin";
constexpr const char* M_E_ = "E";
constexpr const char* M_E = "E";
constexpr const char* M_ENABLE_UNBOUNDED_DESCRIPTOR_TABLES = "enable_unbounded_descriptor_tables";
constexpr const char* M_FC = "Fc";
constexpr const char* M_FD = "Fd";
Expand Down Expand Up @@ -191,6 +191,29 @@ namespace efxc2Cmds {
constexpr const char* M_ZSS = "Zss";
#endif /* _WIN32 */

/*Parameter Descriptions*/
#ifdef _WIN32
#define M_E_DESCR L"Entry Point"
#define M_FC_DESCR L"Assembly Code"
#define M_FD_DESCR L".PDB"
#define M_FH_DESCR L"Header File"
#define M_FO_DESCR L"Object File"
#define M_I_DESCR L"Include Dir"
#define M_P_DESCR L"Preprocesed Output"
#define M_SETPRIVATE_DESCR L"Private Data"
#define M_T_DESCR L"Shader Model/Profile"
#else
#define M_E_DESCR "Entry Point"
#define M_FC_DESCR "Assembly Code"
#define M_FD_DESCR ".PDB"
#define M_FH_DESCR "Header File"
#define M_FO_DESCR "Object File"
#define M_I_DESCR "Include Dir"
#define M_P_DESCR "Preprocessor Output"
#define M_SETPRIVATE_DESCR "Private Data"
#define M_T_DESCR "Shader Model/Profile"
#endif

using gCompilerFilep = void(efxc2CompilerParams::CompilerParams&, efxc2Files::Files&, const efxc2Utils::M_STRING_VIEW);
struct CompileFileEntry {
const efxc2Utils::M_STRING Param;
Expand All @@ -214,6 +237,11 @@ namespace efxc2Cmds {
efxc2CompilerParams::CompilerParams& params,
efxc2Files::Files& files);

void print_string_parameter(efxc2CompilerParams::CompilerParams& ComParams,
const efxc2Utils::M_STRING_VIEW cmdParam,
const efxc2Utils::M_STRING_VIEW ADesc,
_In_ const efxc2Utils::M_STRING_VIEW fileName);

using gCompilerp = void(efxc2CompilerParams::CompilerParams&);
struct CompilerOnlyEntry {
const efxc2Utils::M_STRING Param;
Expand Down

0 comments on commit a3841b6

Please sign in to comment.