Add -Xcpp CLI option for C preprocessor flags (-P with ldmd2)

This commit is contained in:
Martin Kinkelin 2023-06-05 17:25:43 +02:00
parent 5b137768a0
commit 1bf7e28c59
5 changed files with 23 additions and 13 deletions

View file

@ -400,13 +400,15 @@ cl::list<std::string>
cl::value_desc("linkerflag"), cl::cat(linkingCategory), cl::value_desc("linkerflag"), cl::cat(linkingCategory),
cl::Prefix); cl::Prefix);
cl::list<std::string> cl::list<std::string> ccSwitches(
ccSwitches("Xcc", cl::desc("Pass <ccflag> to GCC/Clang for linking"), "Xcc", cl::value_desc("ccflag"), cl::cat(linkingCategory),
cl::value_desc("ccflag"), cl::cat(linkingCategory)); cl::desc("Pass <ccflag> to GCC/Clang for linking/preprocessing"));
cl::opt<std::string> cl::list<std::string> cppSwitches("Xcpp", cl::value_desc("cppflag"),
moduleDeps("deps", cl::ValueOptional, cl::ZeroOrMore, cl::desc("Pass <cppflag> to C preprocessor"));
cl::value_desc("filename"),
cl::opt<std::string> moduleDeps(
"deps", cl::ValueOptional, cl::ZeroOrMore, cl::value_desc("filename"),
cl::desc("Write module dependencies to <filename> (only imports). " cl::desc("Write module dependencies to <filename> (only imports). "
"'-deps' alone prints module dependencies " "'-deps' alone prints module dependencies "
"(imports/file/version/debug/lib)")); "(imports/file/version/debug/lib)"));

View file

@ -75,6 +75,7 @@ extern cl::opt<std::string> makeDeps;
extern cl::opt<std::string> cacheDir; extern cl::opt<std::string> cacheDir;
extern cl::list<std::string> linkerSwitches; extern cl::list<std::string> linkerSwitches;
extern cl::list<std::string> ccSwitches; extern cl::list<std::string> ccSwitches;
extern cl::list<std::string> cppSwitches;
extern cl::list<std::string> includeModulePatterns; extern cl::list<std::string> includeModulePatterns;
extern cl::opt<bool> m32bits; extern cl::opt<bool> m32bits;

View file

@ -46,7 +46,9 @@ FileName runCPreprocessor(FileName csrcfile, const Loc &loc, bool &ifile,
for (const auto &ccSwitch : opts::ccSwitches) { for (const auto &ccSwitch : opts::ccSwitches) {
args.push_back(ccSwitch); args.push_back(ccSwitch);
} }
// TODO: -Xcpp switches? for (const auto &cppSwitch : opts::cppSwitches) {
args.push_back(cppSwitch);
}
if (isMSVC) { if (isMSVC) {
args.push_back("/P"); // run preprocessor args.push_back("/P"); // run preprocessor

View file

@ -234,7 +234,9 @@ Where:\n\
#if 0 #if 0
" -os=<os> sets target operating system to <os>\n" " -os=<os> sets target operating system to <os>\n"
#endif #endif
" -preview=<name> enable an upcoming language change identified by 'name'\n\ " -P=<preprocessorflag>\n\
pass preprocessorflag to C preprocessor\n\
-preview=<name> enable an upcoming language change identified by 'name'\n\
-preview=[h|help|?]\n\ -preview=[h|help|?]\n\
list all upcoming language changes\n\ list all upcoming language changes\n\
-profile profile runtime performance of generated code\n" -profile profile runtime performance of generated code\n"
@ -707,7 +709,11 @@ void translateArgs(const llvm::SmallVectorImpl<const char *> &ldmdArgs,
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }
/* -L /* -L
* -defaultlib */
else if (p[1] == 'P') {
ldcArgs.push_back(concat("-Xcpp=", p + 2 + (p[2] == '=' ? 1 : 0)));
}
/* -defaultlib
* -debuglib * -debuglib
* -deps * -deps
* -main * -main

View file

@ -1,5 +1,4 @@
/* REQUIRED_ARGS: -P=-DABC=3 /* REQUIRED_ARGS: -P=-DABC=3
*/ */
// DISABLED: LDC // FIXME
_Static_assert(ABC == 3, "1"); _Static_assert(ABC == 3, "1");