mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-06 02:45:25 +03:00
Revise recent adaptations to frontend refactorings
This commit is contained in:
parent
a3efe6d89c
commit
1f5c442519
10 changed files with 76 additions and 93 deletions
|
@ -433,30 +433,29 @@ public:
|
|||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static std::string getPragmaStringArg(PragmaDeclaration *decl) {
|
||||
static llvm::StringRef getPragmaStringArg(PragmaDeclaration *decl) {
|
||||
assert(decl->args && decl->args->length == 1);
|
||||
Expression *e = static_cast<Expression *>((*decl->args)[0]);
|
||||
Expression *e = (*decl->args)[0];
|
||||
assert(e->op == TOKstring);
|
||||
StringExp *se = static_cast<StringExp *>(e);
|
||||
DString str = se->toUTF8String();
|
||||
DString str = se->peekString();
|
||||
return {str.ptr, str.length};
|
||||
}
|
||||
|
||||
void visit(PragmaDeclaration *decl) override {
|
||||
if (decl->ident == Id::lib) {
|
||||
assert(!irs->dcomputetarget);
|
||||
const std::string name = getPragmaStringArg(decl);
|
||||
auto nameLen = name.size();
|
||||
llvm::StringRef name = getPragmaStringArg(decl);
|
||||
|
||||
if (global.params.targetTriple->isWindowsGNUEnvironment()) {
|
||||
if (nameLen > 4 && !memcmp(&name[nameLen - 4], ".lib", 4)) {
|
||||
// On MinGW, strip the .lib suffix, if any, to improve
|
||||
// compatibility with code written for DMD (we pass the name to GCC
|
||||
// via -l, just as on Posix).
|
||||
nameLen -= 4;
|
||||
if (name.endswith(".lib")) {
|
||||
// On MinGW, strip the .lib suffix, if any, to improve compatibility
|
||||
// with code written for DMD (we pass the name to GCC via -l, just as
|
||||
// on Posix).
|
||||
name = name.drop_back(4);
|
||||
}
|
||||
|
||||
if (nameLen >= 7 && !memcmp(name.data(), "shell32", 7)) {
|
||||
if (name.startswith("shell32")) {
|
||||
// Another DMD compatibility kludge: Ignore
|
||||
// pragma(lib, "shell32.lib"), it is implicitly provided by
|
||||
// MinGW.
|
||||
|
@ -467,37 +466,33 @@ public:
|
|||
// With LLVM 3.3 or later we can place the library name in the object
|
||||
// file. This seems to be supported only on Windows.
|
||||
if (global.params.targetTriple->isWindowsMSVCEnvironment()) {
|
||||
llvm::SmallString<24> LibName(name);
|
||||
|
||||
// Win32: /DEFAULTLIB:"curl"
|
||||
if (LibName.endswith(".a")) {
|
||||
LibName = LibName.substr(0, LibName.size() - 2);
|
||||
if (name.endswith(".a")) {
|
||||
name = name.drop_back(2);
|
||||
}
|
||||
if (LibName.endswith(".lib")) {
|
||||
LibName = LibName.substr(0, LibName.size() - 4);
|
||||
if (name.endswith(".lib")) {
|
||||
name = name.drop_back(4);
|
||||
}
|
||||
llvm::SmallString<24> tmp("/DEFAULTLIB:\"");
|
||||
tmp.append(LibName);
|
||||
tmp.append("\"");
|
||||
LibName = tmp;
|
||||
|
||||
std::string arg = ("/DEFAULTLIB:\"" + name + "\"").str();
|
||||
|
||||
// Embed library name as linker option in object file
|
||||
auto Value = llvm::MDString::get(gIR->context(), LibName);
|
||||
auto Value = llvm::MDString::get(gIR->context(), arg);
|
||||
gIR->LinkerMetadataArgs.push_back(
|
||||
llvm::MDNode::get(gIR->context(), Value));
|
||||
} else {
|
||||
size_t const n = nameLen + 3;
|
||||
size_t const n = name.size() + 3;
|
||||
char *arg = static_cast<char *>(mem.xmalloc(n));
|
||||
arg[0] = '-';
|
||||
arg[1] = 'l';
|
||||
memcpy(arg + 2, name.data(), nameLen);
|
||||
memcpy(arg + 2, name.data(), name.size());
|
||||
arg[n - 1] = 0;
|
||||
global.params.linkswitches.push(arg);
|
||||
}
|
||||
} else if (decl->ident == Id::linkerDirective) {
|
||||
if (global.params.targetTriple->isWindowsMSVCEnvironment()) {
|
||||
// Embed directly as linker option in object file
|
||||
const std::string directive = getPragmaStringArg(decl);
|
||||
llvm::StringRef directive = getPragmaStringArg(decl);
|
||||
auto Value = llvm::MDString::get(gIR->context(), directive);
|
||||
gIR->LinkerMetadataArgs.push_back(
|
||||
llvm::MDNode::get(gIR->context(), Value));
|
||||
|
@ -523,9 +518,7 @@ public:
|
|||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Declaration_codegen(Dsymbol *decl) {
|
||||
Declaration_codegen(decl, gIR);
|
||||
}
|
||||
void Declaration_codegen(Dsymbol *decl) { Declaration_codegen(decl, gIR); }
|
||||
|
||||
void Declaration_codegen(Dsymbol *decl, IRState *irs) {
|
||||
CodegenVisitor v(irs);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue