Add new cmdline option -mixin=<filename>

This commit is contained in:
Martin Kinkelin 2018-12-21 19:14:01 +01:00
parent 26c27c664d
commit 389977d084
5 changed files with 22 additions and 1 deletions

View file

@ -1541,6 +1541,8 @@ private void setTargetCPU(ref Param params)
params.cpu = CPU.x87; // cannot support other instruction sets
}
} // !IN_LLVM
/**************************************
* we want to write the mixin expansion file also on error, but there
* are too many ways to terminate dmd (e.g. fatal() which calls exit(EXIT_FAILURE)),
@ -1559,6 +1561,9 @@ extern(C) void flushMixins()
f.write();
}
version (IN_LLVM) {} else
{
/****************************************************
* Parse command line arguments.
*

View file

@ -220,6 +220,10 @@ cl::opt<bool>
hdrKeepAllBodies("Hkeep-all-bodies", cl::ZeroOrMore,
cl::desc("Keep all function bodies in .di files"));
cl::opt<std::string> mixinFile("mixin", cl::ZeroOrMore,
cl::desc("Expand and save mixins to <filename>"),
cl::value_desc("filename"));
static cl::opt<bool, true> unittest("unittest", cl::ZeroOrMore,
cl::desc("Compile in unit tests"),
cl::location(global.params.useUnitTests));

View file

@ -62,6 +62,7 @@ extern cl::list<std::string> jsonFields;
extern cl::opt<std::string> hdrDir;
extern cl::opt<std::string> hdrFile;
extern cl::opt<bool> hdrKeepAllBodies;
extern cl::opt<std::string> mixinFile;
extern cl::list<std::string> versions;
extern cl::list<std::string> transitions;
extern cl::opt<std::string> moduleDeps;

View file

@ -208,6 +208,7 @@ Where:\n\
#endif
" -mcpu=<id> generate instructions for architecture identified by 'id'\n\
-mcpu=? list all architecture options\n\
-mixin=<filename> expand and save mixins to file specified by <filename>\n\
-mscrtlib=<name> MS C runtime library to reference from main/WinMain/DllMain\n\
-mv=<package.module>=<filespec> use <filespec> as source file for <package.module>\n\
-noboundscheck no array bounds checking (deprecated, use -boundscheck=off)\n\
@ -423,7 +424,8 @@ void translateArgs(size_t originalArgc, char **originalArgv,
else if (strcmp(p + 1, "m32mscoff") == 0) {
ldcArgs.push_back("-m32");
}
/* -mscrtlib
/* -mixin
* -mscrtlib
*/
else if (strncmp(p + 1, "profile", 7) == 0) {
if (p[8] == 0) {

View file

@ -85,6 +85,7 @@ void gendocfile(Module *m);
// In dmd/mars.d
void generateJson(Modules *modules);
extern "C" void flushMixins();
using namespace opts;
@ -386,6 +387,14 @@ void parseCommandLine(int argc, char **argv, Strings &sourceFiles,
global.params.doHdrGeneration |=
global.params.hdrdir || global.params.hdrname;
opts::initFromPathString(global.params.mixinFile, mixinFile);
if (global.params.mixinFile) {
global.params.mixinOut = new OutBuffer;
// DMD uses atexit() too, so that the file is written when exiting via
// fatal() etc. too.
atexit(&flushMixins);
}
if (moduleDeps.getNumOccurrences() != 0) {
global.params.moduleDeps = new OutBuffer;
if (!moduleDeps.empty())