Catch exceptions and write out their message

This commit is contained in:
Magnus Norddahl 2016-11-29 13:53:02 +01:00
parent f4d5fb4c25
commit 046f5f2b2e

View file

@ -633,78 +633,86 @@ void AddSourceFileTimestamp(const char *timestamp)
int main(int argc, char **argv)
{
if (argc != 2)
try
{
std::cerr << "Usage: " << argv[0] << "<output filename>" << std::endl;
return 1;
}
std::string timestamp_filename = argv[1] + std::string(".timestamp");
FILE *file = fopen(timestamp_filename.c_str(), "rb");
if (file != nullptr)
{
char buffer[4096];
int bytes_read = fread(buffer, 1, 4096, file);
fclose(file);
std::string last_timestamp;
if (bytes_read > 0)
last_timestamp = std::string(buffer, bytes_read);
if (AllTimestamps() == last_timestamp)
if (argc != 2)
{
std::cout << "Not recompiling drawers because the object file is already up to date." << std::endl;
exit(0);
std::cerr << "Usage: " << argv[0] << "<output filename>" << std::endl;
return 1;
}
std::string timestamp_filename = argv[1] + std::string(".timestamp");
FILE *file = fopen(timestamp_filename.c_str(), "rb");
if (file != nullptr)
{
char buffer[4096];
int bytes_read = fread(buffer, 1, 4096, file);
fclose(file);
std::string last_timestamp;
if (bytes_read > 0)
last_timestamp = std::string(buffer, bytes_read);
if (AllTimestamps() == last_timestamp)
{
std::cout << "Not recompiling drawers because the object file is already up to date." << std::endl;
exit(0);
}
}
llvm::install_fatal_error_handler([](void *user_data, const std::string& reason, bool gen_crash_diag)
{
std::cerr << "LLVM fatal error: " << reason;
exit(1);
});
llvm::InitializeNativeTarget();
llvm::InitializeNativeTargetAsmPrinter();
std::string cpuName = "pentium4";
std::cout << "Compiling drawer code for " << cpuName << ".." << std::endl;
LLVMDrawers drawersSSE2(cpuName, "_SSE2");
file = fopen(argv[1], "wb");
if (file == nullptr)
{
std::cerr << "Unable to open " << argv[1] << " for writing." << std::endl;
return 1;
}
int result = fwrite(drawersSSE2.ObjectFile.data(), drawersSSE2.ObjectFile.size(), 1, file);
fclose(file);
if (result != 1)
{
std::cerr << "Could not write data to " << argv[1] << std::endl;
return 1;
}
file = fopen(timestamp_filename.c_str(), "wb");
if (file == nullptr)
{
std::cerr << "Could not create timestamp file" << std::endl;
return 1;
}
result = fwrite(AllTimestamps().data(), AllTimestamps().length(), 1, file);
fclose(file);
if (result != 1)
{
std::cerr << "Could not write timestamp file" << std::endl;
return 1;
}
//LLVMDrawers drawersSSE4("core2");
//LLVMDrawers drawersAVX("sandybridge");
//LLVMDrawers drawersAVX2("haswell");
return 0;
}
llvm::install_fatal_error_handler([](void *user_data, const std::string& reason, bool gen_crash_diag)
catch (const std::exception &e)
{
std::cerr << "LLVM fatal error: " << reason;
exit(1);
});
llvm::InitializeNativeTarget();
llvm::InitializeNativeTargetAsmPrinter();
std::string cpuName = "pentium4";
std::cout << "Compiling drawer code for " << cpuName << ".." << std::endl;
LLVMDrawers drawersSSE2(cpuName, "_SSE2");
file = fopen(argv[1], "wb");
if (file == nullptr)
{
std::cerr << "Unable to open " << argv[1] << " for writing." << std::endl;
std::cerr << e.what() << std::endl;
return 1;
}
int result = fwrite(drawersSSE2.ObjectFile.data(), drawersSSE2.ObjectFile.size(), 1, file);
fclose(file);
if (result != 1)
{
std::cerr << "Could not write data to " << argv[1] << std::endl;
return 1;
}
file = fopen(timestamp_filename.c_str(), "wb");
if (file == nullptr)
{
std::cerr << "Could not create timestamp file" << std::endl;
return 1;
}
result = fwrite(AllTimestamps().data(), AllTimestamps().length(), 1, file);
fclose(file);
if (result != 1)
{
std::cerr << "Could not write timestamp file" << std::endl;
return 1;
}
//LLVMDrawers drawersSSE4("core2");
//LLVMDrawers drawersAVX("sandybridge");
//LLVMDrawers drawersAVX2("haswell");
return 0;
}