Adapt to changed C preprocessor hook

This commit is contained in:
Martin Kinkelin 2024-03-03 20:04:41 +01:00
parent 3f1c8a77a2
commit 113443db42
5 changed files with 26 additions and 3 deletions

View file

@ -746,7 +746,19 @@ version (IN_LLVM)
/* Apply C preprocessor to the .c file, returning the contents /* Apply C preprocessor to the .c file, returning the contents
* after preprocessing * after preprocessing
*/ */
version (IN_LLVM)
{
const ipath = global.preprocess(srcfile, loc, defines);
srctext = global.fileManager.getFileContents(ipath);
// remove temp file and parent directory
File.remove(ipath.toChars());
File.removeDirectory(FileName.path(ipath.toChars()));
}
else
{
srctext = global.preprocess(srcfile, loc, defines).data; srctext = global.preprocess(srcfile, loc, defines).data;
}
} }
else else
srctext = global.fileManager.getFileContents(filename); srctext = global.fileManager.getFileContents(filename);

View file

@ -412,7 +412,14 @@ else
ErrorSink errorSink; /// where the error messages go ErrorSink errorSink; /// where the error messages go
ErrorSink errorSinkNull; /// where the error messages are ignored ErrorSink errorSinkNull; /// where the error messages are ignored
version (IN_LLVM)
{
extern (C++) FileName function(FileName, ref const Loc, ref OutBuffer) preprocess;
}
else
{
extern (C++) DArray!ubyte function(FileName, ref const Loc, ref OutBuffer) preprocess; extern (C++) DArray!ubyte function(FileName, ref const Loc, ref OutBuffer) preprocess;
}
nothrow: nothrow:

View file

@ -400,7 +400,12 @@ struct Global
ErrorSink* errorSink; // where the error messages go ErrorSink* errorSink; // where the error messages go
ErrorSink* errorSinkNull; // where the error messages disappear ErrorSink* errorSinkNull; // where the error messages disappear
#if IN_LLVM
FileName (*preprocess)(FileName, const Loc&, OutBuffer&);
#else
DArray<unsigned char> (*preprocess)(FileName, const Loc&, OutBuffer&); DArray<unsigned char> (*preprocess)(FileName, const Loc&, OutBuffer&);
#endif
/* Start gagging. Return the current number of gagged errors /* Start gagging. Return the current number of gagged errors
*/ */

View file

@ -71,7 +71,7 @@ FileName getOutputPath(const Loc &loc, const char *csrcfile) {
} }
} // anonymous namespace } // anonymous namespace
FileName runCPreprocessor(FileName csrcfile, const Loc &loc, bool &ifile, FileName runCPreprocessor(FileName csrcfile, const Loc &loc,
OutBuffer &defines) { OutBuffer &defines) {
TimeTraceScope timeScope("Preprocess C file", csrcfile.toChars()); TimeTraceScope timeScope("Preprocess C file", csrcfile.toChars());
@ -154,6 +154,5 @@ FileName runCPreprocessor(FileName csrcfile, const Loc &loc, bool &ifile,
fatal(); fatal();
} }
ifile = true;
return ipath; return ipath;
} }

View file

@ -4,5 +4,5 @@
#include "dmd/globals.h" #include "dmd/globals.h"
#include "dmd/root/filename.h" #include "dmd/root/filename.h"
FileName runCPreprocessor(FileName csrcfile, const Loc &loc, bool &ifile, FileName runCPreprocessor(FileName csrcfile, const Loc &loc,
OutBuffer &defines); OutBuffer &defines);