forked from ldc-developers/ldc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
112 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#include "driver/cpreprocessor.h" | ||
|
||
#include "dmd/errors.h" | ||
#include "driver/cl_options.h" | ||
#include "driver/tool.h" | ||
|
||
namespace { | ||
const char *getPathToImportc_h(const Loc &loc) { | ||
// importc.h should be next to object.d | ||
static const char *cached = nullptr; | ||
if (!cached) { | ||
cached = FileName::searchPath(global.path, "importc.h", false); | ||
if (!cached) { | ||
error(loc, "cannot find \"importc.h\" along import path"); | ||
fatal(); | ||
} | ||
} | ||
return cached; | ||
} | ||
} // anonymous namespace | ||
|
||
FileName runCPreprocessor(FileName csrcfile, const Loc &loc, bool &ifile, | ||
OutBuffer &defines) { | ||
const char *importc_h = getPathToImportc_h(loc); | ||
const char *ifilename = FileName::forceExt(csrcfile.toChars(), i_ext.ptr); | ||
|
||
const auto &triple = *global.params.targetTriple; | ||
const bool isMSVC = triple.isWindowsMSVCEnvironment(); | ||
|
||
#if 0 //ifdef _WIN32 | ||
// TODO: INCLUDE env var etc.? | ||
windows::MsvcEnvironmentScope msvcEnv; | ||
if (isMSVC) | ||
msvcEnv.setup(); | ||
#endif | ||
|
||
const std::string cc = getGcc(isMSVC ? "cl.exe" : "cc"); | ||
std::vector<std::string> args; | ||
|
||
if (!isMSVC) | ||
appendTargetArgsForGcc(args); | ||
|
||
if (triple.isOSDarwin()) | ||
args.push_back("-fno-blocks"); // disable blocks extension | ||
|
||
for (const auto &ccSwitch : opts::ccSwitches) { | ||
args.push_back(ccSwitch); | ||
} | ||
// TODO: -Xcpp switches? | ||
|
||
if (isMSVC) { | ||
args.push_back("/P"); // run preprocessor | ||
args.push_back("/Zc:preprocessor"); // use the new conforming preprocessor | ||
args.push_back("/PD"); // undocumented: print all macro definitions | ||
args.push_back("/nologo"); | ||
args.push_back(csrcfile.toChars()); | ||
args.push_back((llvm::Twine("/FI") + importc_h).str()); | ||
// preprocessed output file | ||
args.push_back((llvm::Twine("/Fi") + ifilename).str()); | ||
} else { // Posix | ||
// merge #define's with output: | ||
// https://gcc.gnu.org/onlinedocs/cpp/Invocation.html#index-dD | ||
args.push_back("-dD"); | ||
|
||
// need to redefine some macros in importc.h | ||
args.push_back("-Wno-builtin-macro-redefined"); | ||
|
||
args.push_back("-E"); // run preprocessor only | ||
args.push_back("-include"); | ||
args.push_back(importc_h); | ||
args.push_back(csrcfile.toChars()); | ||
args.push_back("-o"); | ||
args.push_back(ifilename); | ||
} | ||
|
||
const int status = executeToolAndWait(loc, cc, args, global.params.verbose); | ||
if (status) { | ||
errorSupplemental(loc, "C preprocessor failed for file '%s'", csrcfile.toChars()); | ||
fatal(); | ||
} | ||
|
||
ifile = true; | ||
return FileName::create(ifilename); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#pragma once | ||
|
||
#include "dmd/common/outbuffer.h" | ||
#include "dmd/globals.h" | ||
#include "dmd/root/filename.h" | ||
|
||
FileName runCPreprocessor(FileName csrcfile, const Loc &loc, bool &ifile, | ||
OutBuffer &defines); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
// https://issues.dlang.org/show_bug.cgi?id=23214 | ||
// DISABLED: LDC // FIXME - need to invoke C pre-processor | ||
|
||
typedef unsigned __int64 uintptr_t; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters