mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-03 08:30:47 +03:00
Fix error message formatting
This commit is contained in:
parent
06ad20a920
commit
241dc9135f
2 changed files with 28 additions and 58 deletions
|
@ -37,10 +37,9 @@ static bool endsWith(const std::string &str, const std::string &end) {
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
static void CreateDirectoryOnDisk(llvm::StringRef fileName) {
|
static void CreateDirectoryOnDisk(llvm::StringRef fileName) {
|
||||||
llvm::StringRef dir(llvm::sys::path::parent_path(fileName));
|
auto dir = llvm::sys::path::parent_path(fileName);
|
||||||
if (!dir.empty() && !llvm::sys::fs::exists(dir)) {
|
if (!dir.empty() && !llvm::sys::fs::exists(dir)) {
|
||||||
std::error_code ec = llvm::sys::fs::create_directory(dir);
|
if (auto ec = llvm::sys::fs::create_directory(dir)) {
|
||||||
if (ec) {
|
|
||||||
error(Loc(), "failed to create path to file: %s\n%s", dir.data(),
|
error(Loc(), "failed to create path to file: %s\n%s", dir.data(),
|
||||||
ec.message().c_str());
|
ec.message().c_str());
|
||||||
fatal();
|
fatal();
|
||||||
|
|
|
@ -346,27 +346,26 @@ void writeModule(llvm::Module *m, std::string filename) {
|
||||||
global.params.targetTriple.getOS() == llvm::Triple::AIX);
|
global.params.targetTriple.getOS() == llvm::Triple::AIX);
|
||||||
|
|
||||||
// eventually do our own path stuff, dmd's is a bit strange.
|
// eventually do our own path stuff, dmd's is a bit strange.
|
||||||
typedef llvm::SmallString<128> LLPath;
|
using LLPath = llvm::SmallString<128>;
|
||||||
|
|
||||||
|
#if LDC_LLVM_VER >= 306
|
||||||
|
using ErrorInfo = std::error_code;
|
||||||
|
#define ERRORINFO_STRING(errinfo) errinfo.message().c_str()
|
||||||
|
#else
|
||||||
|
using ErrorInfo = std::string;
|
||||||
|
#define ERRORINFO_STRING(errinfo) errinfo.c_str()
|
||||||
|
#endif
|
||||||
|
|
||||||
// write LLVM bitcode
|
// write LLVM bitcode
|
||||||
if (global.params.output_bc) {
|
if (global.params.output_bc) {
|
||||||
LLPath bcpath = LLPath(filename);
|
LLPath bcpath(filename);
|
||||||
llvm::sys::path::replace_extension(bcpath, global.bc_ext);
|
llvm::sys::path::replace_extension(bcpath, global.bc_ext);
|
||||||
Logger::println("Writing LLVM bitcode to: %s\n", bcpath.c_str());
|
Logger::println("Writing LLVM bitcode to: %s\n", bcpath.c_str());
|
||||||
#if LDC_LLVM_VER >= 306
|
ErrorInfo errinfo;
|
||||||
std::error_code errinfo;
|
|
||||||
#else
|
|
||||||
std::string errinfo;
|
|
||||||
#endif
|
|
||||||
llvm::raw_fd_ostream bos(bcpath.c_str(), errinfo, llvm::sys::fs::F_None);
|
llvm::raw_fd_ostream bos(bcpath.c_str(), errinfo, llvm::sys::fs::F_None);
|
||||||
if (bos.has_error()) {
|
if (bos.has_error()) {
|
||||||
error(Loc(), "cannot write LLVM bitcode file '%s': %s", bcpath.c_str(),
|
error(Loc(), "cannot write LLVM bitcode file '%s': %s", bcpath.c_str(),
|
||||||
#if LDC_LLVM_VER >= 306
|
ERRORINFO_STRING(errinfo));
|
||||||
errinfo
|
|
||||||
#else
|
|
||||||
errinfo.c_str()
|
|
||||||
#endif
|
|
||||||
);
|
|
||||||
fatal();
|
fatal();
|
||||||
}
|
}
|
||||||
llvm::WriteBitcodeToFile(m, bos);
|
llvm::WriteBitcodeToFile(m, bos);
|
||||||
|
@ -374,23 +373,14 @@ void writeModule(llvm::Module *m, std::string filename) {
|
||||||
|
|
||||||
// write LLVM IR
|
// write LLVM IR
|
||||||
if (global.params.output_ll) {
|
if (global.params.output_ll) {
|
||||||
LLPath llpath = LLPath(filename);
|
LLPath llpath(filename);
|
||||||
llvm::sys::path::replace_extension(llpath, global.ll_ext);
|
llvm::sys::path::replace_extension(llpath, global.ll_ext);
|
||||||
Logger::println("Writing LLVM asm to: %s\n", llpath.c_str());
|
Logger::println("Writing LLVM asm to: %s\n", llpath.c_str());
|
||||||
#if LDC_LLVM_VER >= 306
|
ErrorInfo errinfo;
|
||||||
std::error_code errinfo;
|
|
||||||
#else
|
|
||||||
std::string errinfo;
|
|
||||||
#endif
|
|
||||||
llvm::raw_fd_ostream aos(llpath.c_str(), errinfo, llvm::sys::fs::F_None);
|
llvm::raw_fd_ostream aos(llpath.c_str(), errinfo, llvm::sys::fs::F_None);
|
||||||
if (aos.has_error()) {
|
if (aos.has_error()) {
|
||||||
error(Loc(), "cannot write LLVM asm file '%s': %s", llpath.c_str(),
|
error(Loc(), "cannot write LLVM asm file '%s': %s", llpath.c_str(),
|
||||||
#if LDC_LLVM_VER >= 306
|
ERRORINFO_STRING(errinfo));
|
||||||
errinfo
|
|
||||||
#else
|
|
||||||
errinfo.c_str()
|
|
||||||
#endif
|
|
||||||
);
|
|
||||||
fatal();
|
fatal();
|
||||||
}
|
}
|
||||||
AssemblyAnnotator annotator;
|
AssemblyAnnotator annotator;
|
||||||
|
@ -399,18 +389,14 @@ void writeModule(llvm::Module *m, std::string filename) {
|
||||||
|
|
||||||
// write native assembly
|
// write native assembly
|
||||||
if (global.params.output_s || assembleExternally) {
|
if (global.params.output_s || assembleExternally) {
|
||||||
LLPath spath = LLPath(filename);
|
LLPath spath(filename);
|
||||||
llvm::sys::path::replace_extension(spath, global.s_ext);
|
llvm::sys::path::replace_extension(spath, global.s_ext);
|
||||||
if (!global.params.output_s) {
|
if (!global.params.output_s) {
|
||||||
llvm::sys::fs::createUniqueFile("ldc-%%%%%%%.s", spath);
|
llvm::sys::fs::createUniqueFile("ldc-%%%%%%%.s", spath);
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger::println("Writing native asm to: %s\n", spath.c_str());
|
Logger::println("Writing native asm to: %s\n", spath.c_str());
|
||||||
#if LDC_LLVM_VER >= 306
|
ErrorInfo errinfo;
|
||||||
std::error_code errinfo;
|
|
||||||
#else
|
|
||||||
std::string errinfo;
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
llvm::raw_fd_ostream out(spath.c_str(), errinfo, llvm::sys::fs::F_None);
|
llvm::raw_fd_ostream out(spath.c_str(), errinfo, llvm::sys::fs::F_None);
|
||||||
#if LDC_LLVM_VER >= 306
|
#if LDC_LLVM_VER >= 306
|
||||||
|
@ -422,20 +408,13 @@ void writeModule(llvm::Module *m, std::string filename) {
|
||||||
codegenModule(*gTargetMachine, *m, out,
|
codegenModule(*gTargetMachine, *m, out,
|
||||||
llvm::TargetMachine::CGFT_AssemblyFile);
|
llvm::TargetMachine::CGFT_AssemblyFile);
|
||||||
} else {
|
} else {
|
||||||
error(Loc(), "cannot write native asm: %s",
|
error(Loc(), "cannot write native asm: %s", ERRORINFO_STRING(errinfo));
|
||||||
#if LDC_LLVM_VER >= 306
|
|
||||||
errinfo
|
|
||||||
#else
|
|
||||||
errinfo.c_str()
|
|
||||||
#endif
|
|
||||||
);
|
|
||||||
fatal();
|
fatal();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (assembleExternally) {
|
if (assembleExternally) {
|
||||||
LLPath objpath(filename);
|
assemble(spath.str(), filename);
|
||||||
assemble(spath.str(), objpath.str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!global.params.output_s) {
|
if (!global.params.output_s) {
|
||||||
|
@ -444,15 +423,11 @@ void writeModule(llvm::Module *m, std::string filename) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (global.params.output_o && !assembleExternally) {
|
if (global.params.output_o && !assembleExternally) {
|
||||||
LLPath objpath = LLPath(filename);
|
Logger::println("Writing object file to: %s\n", filename.c_str());
|
||||||
Logger::println("Writing object file to: %s\n", objpath.c_str());
|
ErrorInfo errinfo;
|
||||||
#if LDC_LLVM_VER >= 306
|
|
||||||
std::error_code errinfo;
|
|
||||||
#else
|
|
||||||
std::string errinfo;
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
llvm::raw_fd_ostream out(objpath.c_str(), errinfo, llvm::sys::fs::F_None);
|
llvm::raw_fd_ostream out(filename.c_str(), errinfo,
|
||||||
|
llvm::sys::fs::F_None);
|
||||||
#if LDC_LLVM_VER >= 306
|
#if LDC_LLVM_VER >= 306
|
||||||
if (!errinfo)
|
if (!errinfo)
|
||||||
#else
|
#else
|
||||||
|
@ -462,15 +437,11 @@ void writeModule(llvm::Module *m, std::string filename) {
|
||||||
codegenModule(*gTargetMachine, *m, out,
|
codegenModule(*gTargetMachine, *m, out,
|
||||||
llvm::TargetMachine::CGFT_ObjectFile);
|
llvm::TargetMachine::CGFT_ObjectFile);
|
||||||
} else {
|
} else {
|
||||||
error(Loc(), "cannot write object file: %s",
|
error(Loc(), "cannot write object file: %s", ERRORINFO_STRING(errinfo));
|
||||||
#if LDC_LLVM_VER >= 306
|
|
||||||
errinfo
|
|
||||||
#else
|
|
||||||
errinfo.c_str()
|
|
||||||
#endif
|
|
||||||
);
|
|
||||||
fatal();
|
fatal();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#undef ERRORINFO_STRING
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue